branch: elpa/aidermacs
commit b636c89b78db509f43626f3d53178592569229fe
Author: Kang Tu <[email protected]>
Commit: GitHub <[email protected]>
Refactor: Merge some dup code, move less used functions to aider-etc.el.
Update the menu. (#33)
* feat(aider): add explain-symbol-under-point command
* feat: add function to explain function under cursor
* feat(aider): add support for Gemini model and function explanation command
* docs(readme): reorganize and expand code explanation features
* refactor: remove unused syntax table code in buffer setup
* feat: add function to add files with same suffix under current dir
* feat: Add function to add same-type files under a directory to Aider
* feat: Add command to add files of same type under current directory
* refactor: Use helper function for adding/reading current file in aider.el
* refactor: Comment out unused functions in aider-main-menu-map
* refactor: move git repository functions to separate file
---------
Co-authored-by: Kang Tu <[email protected]>
---
aider-etc.el | 21 +++++++++++++++++++
aider.el | 68 ++++++++++++++++++++++++++++++------------------------------
2 files changed, 55 insertions(+), 34 deletions(-)
diff --git a/aider-etc.el b/aider-etc.el
new file mode 100644
index 0000000000..00c6d8de77
--- /dev/null
+++ b/aider-etc.el
@@ -0,0 +1,21 @@
+
+;; New function to run `find-name-dired` from the Git repository root directory
+;;;###autoload
+(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))))
+
+;;;###autoload
+(defun aider-git-repo-root-dired ()
+ "Open a Dired buffer at the root of the current Git repository."
+ (interactive)
+ (let ((git-repo-path (shell-command-to-string "git rev-parse
--show-toplevel")))
+ (if (string-match-p "fatal" git-repo-path)
+ (message "The current buffer is not in a Git repository.")
+ (let ((repo-path (string-trim git-repo-path)))
+ (dired-other-window repo-path)))))
diff --git a/aider.el b/aider.el
index e102472626..a0f9560ed2 100644
--- a/aider.el
+++ b/aider.el
@@ -70,9 +70,8 @@ This function can be customized or redefined by the user."
("f" "Add Current File" aider-add-current-file)
("o" "Add Current File Read-Only" aider-current-file-read-only)
("w" "Add All Files in Current Window" aider-add-files-in-current-window)
+ ("d" "Add Same Type Files under dir" aider-add-same-type-files-under-dir)
("b" "Batch Add Dired Marked Files" aider-batch-add-dired-marked-files)
- ("F" "Find Files in Git Repo" aider-repo-find-name-dired)
- ("R" "Open Git Repo Root Dired" aider-git-repo-root-dired)
]
["Code Change"
("c" "Code Change" aider-code-change)
@@ -88,7 +87,7 @@ This function can be customized or redefined by the user."
("e" "Explain Code in Selected Region" aider-region-explain)
("E" "Explain Function Under Cursor" aider-function-explain)
("p" "Explain Symbol Under Cursor" aider-explain-symbol-under-point)
- ("d" "Debug Exception" aider-debug-exception)
+ ("D" "Debug Exception" aider-debug-exception)
]
["Other"
("g" "General Command" aider-general-command)
@@ -120,10 +119,10 @@ If not in a git repository, an error is raised."
(let ((source-keywords font-lock-keywords)
(source-keywords-only font-lock-keywords-only)
(source-keywords-case-fold-search
font-lock-keywords-case-fold-search)
- (source-syntax-table (syntax-table))
+ ;; (source-syntax-table (syntax-table))
(source-defaults font-lock-defaults))
(with-current-buffer (aider-buffer-name)
- (set-syntax-table source-syntax-table)
+ ;; (set-syntax-table source-syntax-table)
(setq font-lock-defaults
(if source-defaults
source-defaults
@@ -222,29 +221,29 @@ COMMAND should be a string representing the command to
send."
(message "No active process found in buffer %s."
(aider-buffer-name))))
(message "Buffer %s does not exist. Please start 'aider' first."
(aider-buffer-name))))
-;; Function to send "/add <current buffer file full path>" to corresponding
aider buffer
;;;###autoload
-(defun aider-add-current-file ()
- "Send the command \"/add <current buffer file full path>\" to the
corresponding aider comint buffer."
- (interactive)
+(defun aider-add-or-read-current-file (command-prefix)
+ "Send the command \"COMMAND-PREFIX <current buffer file full path>\" to the
corresponding aider comint buffer."
;; Ensure the current buffer is associated with a file
(if (not buffer-file-name)
(message "Current buffer is not associated with a file.")
- (let ((command (format "/add %s" (expand-file-name buffer-file-name))))
+ (let ((command (format "%s %s" command-prefix (expand-file-name
buffer-file-name))))
;; Use the shared helper function to send the command
(aider--send-command command))))
+;; Function to send "/add <current buffer file full path>" to corresponding
aider buffer
+;;;###autoload
+(defun aider-add-current-file ()
+ "Send the command \"/add <current buffer file full path>\" to the
corresponding aider comint buffer."
+ (interactive)
+ (aider-add-or-read-current-file "/add"))
+
;; Function to send "/read <current buffer file full path>" to corresponding
aider buffer
;;;###autoload
(defun aider-current-file-read-only ()
"Send the command \"/read-only <current buffer file full path>\" to the
corresponding aider comint buffer."
(interactive)
- ;; Ensure the current buffer is associated with a file
- (if (not buffer-file-name)
- (message "Current buffer is not associated with a file.")
- (let ((command (format "/read-only %s" (expand-file-name
buffer-file-name))))
- ;; Use the shared helper function to send the command
- (aider--send-command command))))
+ (aider-add-or-read-current-file "/read-only"))
;; New function to add files in all buffers in current emacs window
;;;###autoload
@@ -430,26 +429,27 @@ The command will be formatted as \"/ask \" followed by
the text from the selecte
(aider--send-command command t))
(message "No files marked in Dired."))))
-;; New function to run `find-name-dired` from the Git repository root directory
+;; New function to add all files with same suffix as current file under
current directory
;;;###autoload
-(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))))
-
-;;;###autoload
-(defun aider-git-repo-root-dired ()
- "Open a Dired buffer at the root of the current Git repository."
+(defun aider-add-same-type-files-under-dir ()
+ "Add all files with same suffix as current file under current directory to
Aider.
+If there are more than 40 files, refuse to add and show warning message."
(interactive)
- (let ((git-repo-path (shell-command-to-string "git rev-parse
--show-toplevel")))
- (if (string-match-p "fatal" git-repo-path)
- (message "The current buffer is not in a Git repository.")
- (let ((repo-path (string-trim git-repo-path)))
- (dired-other-window repo-path)))))
+ (if (not buffer-file-name)
+ (message "Current buffer is not visiting a file")
+ (let* ((current-suffix (file-name-extension buffer-file-name))
+ (dir (file-name-directory buffer-file-name))
+ (max-files 40)
+ (files (directory-files dir t
+ (concat "\\." current-suffix "$")
+ t))) ; t means don't include . and ..
+ (if (> (length files) max-files)
+ (message "Too many files (%d, > %d) found with suffix .%s. Aborting."
+ (length files) max-files current-suffix)
+ (let ((command (concat "/add " (mapconcat 'identity files " "))))
+ (aider--send-command command t))
+ (message "Added %d files with suffix .%s"
+ (length files) current-suffix)))))
;;; functions for test fixing