branch: elpa/aidermacs
commit 9fc3b047754a4ef3fe1d5c664f84170a86a09a4b
Author: Kang Tu <[email protected]>
Commit: GitHub <[email protected]>
Feat: Git repo find / mark / add files, and buffer send command for .aider
file (#7)
* add aider-send-line-under-cursor
* feat: add Aider mode with key binding for .aider files
* add scratch.aider, for batch / reproducible of aider command
* make switch buffer shortcut for aider-mode
* feat: add aider-send-paragraph function and key binding in aider-mode
* reorder function, change short-cut to fit ess key binding
* feat: add function to batch add Dired marked files to Aider buffer
* feat: add interactive function to run find-name-dired from Git repository
root
* update menu
* update README
* remove unused function shortcut
---------
Co-authored-by: Kang Tu <[email protected]>
---
README.org | 6 ++++-
aider.el | 74 +++++++++++++++++++++++++++++++++++++++++++++--------
scratch.aider | 24 +++++++++++++++++
transient_menu.png | Bin 88948 -> 121113 bytes
4 files changed, 92 insertions(+), 12 deletions(-)
diff --git a/README.org b/README.org
index 8ba07305c6..5382646e3a 100644
--- a/README.org
+++ b/README.org
@@ -17,7 +17,7 @@
- Git Repository-Specific aider Sessions in Emacs: Automatically identify the
Git repository of the current file and create a new aider session for it.
Multiple aider sessions can exist for different Git repositories.
-- Batch add files from dired buffer (aider-batch-add-dired-marked-files): Add
multiple Dired marked files to the Aider buffer
+- Batch add files from dired buffer (aider-batch-add-dired-marked-files): Add
multiple Dired marked files to the Aider buffer. These files can be searched
from repo with aider-repo-find-name-dired command
- Region-Based Refactor Support (aider-region-refactor): You can select a
region (e.g., a code block) in a file and ask aider to refactor it.
@@ -39,6 +39,10 @@
(global-set-key (kbd "C-c a") 'aider-transient-menu))
#+END_SRC
+** Optional
+
+- If you use helm, maybe you can load the helm-aider.el manually. That file
added support of command history and completion from helm.
+
* Screenshot
[[file:./screenshot.png]]
diff --git a/aider.el b/aider.el
index a2bed3a8a1..eae1110589 100644
--- a/aider.el
+++ b/aider.el
@@ -49,11 +49,15 @@ This function can be customized or redefined by the user."
["Aider: AI pair programming"
["Aider process"
("a" "Run Aider" aider-run-aider)
- ("f" "Add Current File" aider-add-current-file)
("z" "Switch to Aider Buffer" aider-switch-to-buffer)
("l" "Clear Aider" aider-clear) ;; Menu item for clear command
("s" "Reset Aider" aider-reset) ;; Menu item for reset command
]
+ ["Add file to aider"
+ ("f" "Add Current File" aider-add-current-file)
+ ("F" "Find Files in the Git Repo" aider-repo-find-name-dired)
+ ("b" "Batch Add Dired Marked Files" aider-batch-add-dired-marked-files)
+ ]
["Code change"
("c" "Code Change" aider-code-change)
("r" "Region Code Refactor" aider-region-refactor)
@@ -161,16 +165,6 @@ COMMAND should be a string representing the command to
send."
;; Use the shared helper function to send the command
(aider--send-command command t))))
-;; New function to add multiple Dired marked files to Aider buffer
-(defun aider-batch-add-dired-marked-files ()
- "Add multiple Dired marked files to the Aider buffer with the \"/add\"
command."
- (interactive)
- (let ((files (dired-get-marked-files)))
- (if files
- (let ((command (concat "/add " (mapconcat 'expand-file-name files "
"))))
- (aider--send-command command))
- (message "No files marked in Dired."))))
-
;; Function to send a custom command to corresponding aider buffer
(defun aider-general-command ()
"Prompt the user to input COMMAND and send it to the corresponding aider
comint buffer."
@@ -256,6 +250,64 @@ The command will be formatted as \"/architect \" followed
by the user command an
(let ((line (thing-at-point 'line t)))
(aider--send-command (concat "/ask " (string-trim line)))))
+;;; functions for dired related
+
+;; New function to add multiple Dired marked files to Aider buffer
+(defun aider-batch-add-dired-marked-files ()
+ "Add multiple Dired marked files to the Aider buffer with the \"/add\"
command."
+ (interactive)
+ (let ((files (dired-get-marked-files)))
+ (if files
+ (let ((command (concat "/add " (mapconcat 'expand-file-name files "
"))))
+ (aider--send-command command))
+ (message "No files marked in Dired."))))
+
+;; New function to run `find-name-dired` from the Git repository root directory
+(defun aider-repo-find-name-dired (pattern)
+ "Run `find-name-dired` from the Git repository root directory with the given
PATTERN."
+ (interactive "sFind name (pattern): ")
+ (let* ((git-repo-path (shell-command-to-string "git rev-parse
--show-toplevel"))
+ (repo-path (string-trim git-repo-path)))
+ (if (string-match-p "fatal" repo-path)
+ (message "Not in a git repository")
+ (find-name-dired repo-path pattern))))
+
+;;; functions for .aider file
+
+;; New function to send "<line under cursor>" to the Aider buffer
+(defun aider-send-line-under-cursor ()
+ "Send the command \"ask <line under cursor>\" to the Aider buffer."
+ (interactive)
+ (let ((line (thing-at-point 'line t)))
+ (aider--send-command (string-trim line))))
+
+;;; New function to send the current paragraph to the Aider buffer
+(defun aider-send-paragraph ()
+ "Send the current paragraph to the Aider buffer."
+ (interactive)
+ (let ((paragraph (buffer-substring-no-properties
+ (save-excursion
+ (backward-paragraph)
+ (point))
+ (save-excursion
+ (forward-paragraph)
+ (point)))))
+ (aider--send-command (string-trim paragraph))))
+
+(defun aider-mode-setup ()
+ "Setup key bindings for Aider mode."
+ (local-set-key (kbd "C-c C-n") 'aider-send-line-under-cursor)
+ (local-set-key (kbd "C-c C-c") 'aider-send-paragraph))
+
+(add-hook 'aider-mode-hook 'aider-mode-setup)
+
+(define-derived-mode aider-mode fundamental-mode "Aider"
+ "Major mode for editing Aider files."
+ ;; Add any additional setup for aider-mode here
+)
+
+(add-to-list 'auto-mode-alist '("\\.aider\\'" . aider-mode))
+
(provide 'aider)
;;; aider.el ends here
diff --git a/scratch.aider b/scratch.aider
new file mode 100644
index 0000000000..0750a347e8
--- /dev/null
+++ b/scratch.aider
@@ -0,0 +1,24 @@
+
+/ask what this repo is about?
+
+# This repository appears to be focused on an Emacs package called "Aider,"
which
+# provides an interactive interface for communicating with an AI tool (likely
+# related to programming assistance). The package allows users to send
commands
+# and queries to the Aider program, which seems to facilitate AI pair
programming
+# or code assistance.
+
+# Key features of the repository include:
+
+# • Interactive Commands: Users can run commands like adding files, asking
+# questions, and performing code changes through a transient menu.
+# • Integration with Git: The package can generate buffer names based on the
+# current Git repository, indicating that it is designed to work within a
+# version-controlled environment.
+# • Custom Commands: Users can send custom commands to the Aider buffer,
allowing
+# for flexible interaction with the AI.
+# • File Type Association: The package defines a major mode (aider-mode) for
+# files with the .aider extension, which includes specific key bindings and
+# functionalities tailored for those files.
+
+# Overall, the repository is aimed at enhancing the coding experience by
+# leveraging AI assistance within the Emacs text editor.
diff --git a/transient_menu.png b/transient_menu.png
index 4bd0a6dae8..22610cf5d0 100644
Binary files a/transient_menu.png and b/transient_menu.png differ