branch: elpa/aidermacs
commit 864a99a630c0e80692e70d8570dbd6255c0d19b1
Author: Kang Tu <[email protected]>
Commit: GitHub <[email protected]>
Feat: Add switch for file adding, to toggle between /add and /read-only
command (#35)
* 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
* refactor: Combine region and function explain commands into one
* feat: Add function to refactor region or function based on selection
* feat: Add function to refactor function or region based on selection
* refactor(ui): simplify code change menu options
* refactor(doom): update menu itemsc
* feat: append region text to question in `aider-ask-question`
* fix: Escape newlines in region text for `aider-ask-question`
* refactor: Extract string escaping logic into dedicated function
This commit refactors the string escaping logic in `aider.el` into a
dedicated function, `aider--escape-string-for-aider`. This improves code
readability, maintainability, and reusability by centralizing the escaping
logic in one place. The function replaces newline characters with escaped
newlines, and is now used in `aider-ask-question`, `aider-debug-exception`,
`aider-region-refactor-generate-command`, and `aider-region-explain`. The
`aider-plain-read-string` function no longer per [...]
* refactor: Centralize newline escaping in `aider--send-command`
* fix: Remove extra parenthesis in message call in aider--send-command
* bug fix
* refactor: Remove unnecessary parentheses in `aider-send-command`
* refactor: Refactor aider-send-paragraph to send lines individually
* refactor: Use dash library for list manipulation
* bug fix
* fix: improve `aider-send-paragraph` to handle newlines correctly
* fix: Send whole buffer content when no files are added to chat
* ```
refactor: Only send non-empty lines in `aider-send-paragraph`
```
* refactor: Send non-empty lines to aider in `aider-send-current-test`
* refactor: Improve `aider-send-paragraph` to send whole paragraph to aider
* refactor: remove dash.el dependency
* feat(menu): add toggle for file read-only status in transient menu
refactor: Rename gptel-menu to aider-menu in comments and docstrings
refactor: Simplify aider--add-file-type and read-only infix definition
refactor: Update transient menu key from `:shortarg` to `:key`
refactor: Update aider file type class and read-only infix to use
transient-lisp-variable
fix: Update transient format specifier from %s to %v in aider--add-file-type
style(ui): improve readability of file mode toggle in transient menu
* refactor: Simplify add file transient menu and remove redundant option
* refactor: Modify file-adding functions to respect read-only flag
* docs: update docstring for aider-current-file-read-only function
* docs: update transient menu screenshot
---------
Co-authored-by: Kang Tu <[email protected]>
---
aider.el | 34 ++++++++++++++++++++++++++++------
transient_menu.png | Bin 61567 -> 74864 bytes
2 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/aider.el b/aider.el
index bbb086b29b..e6b38ea158 100644
--- a/aider.el
+++ b/aider.el
@@ -55,6 +55,28 @@ This function can be customized or redefined by the user."
(defalias 'aider-read-string 'aider-plain-read-string)
+(defvar aider--add-file-read-only nil
+ "Set model parameters from `aider-menu' buffer-locally.
+Affects the system message too.")
+
+(defun aider--get-add-command-prefix ()
+ "Return the appropriate command prefix based on aider--add-file-read-only."
+ (if aider--add-file-read-only "/read-only" "/add"))
+
+(defclass aider--add-file-type (transient-lisp-variable)
+ ((variable :initform 'aider--add-file-read-only)
+ (format :initform "%k %d %v")
+ (reader :initform #'transient-lisp-variable--read-value))
+ "Class for toggling aider--add-file-read-only.")
+
+(transient-define-infix aider--infix-add-file-read-only ()
+ "Toggle aider--add-file-read-only between nil and t."
+ :class 'aider--add-file-type
+ :key "="
+ :description "Read-only mode"
+ :reader (lambda (_prompt _initial-input _history)
+ (not aider--add-file-read-only)))
+
;; Transient menu for Aider commands
;; The instruction in the autoload comment is needed, see
;; https://github.com/magit/transient/issues/280.
@@ -70,8 +92,8 @@ This function can be customized or redefined by the user."
("x" "Exit Aider" aider-exit)
]
["Add File to Aider"
+ (aider--infix-add-file-read-only)
("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)
@@ -227,7 +249,7 @@ COMMAND should be a string representing the command to
send."
;; 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 "%s %s" command-prefix (expand-file-name
buffer-file-name))))
+ (let ((command (format "%s %s" (aider--get-add-command-prefix)
(expand-file-name buffer-file-name))))
;; Use the shared helper function to send the command
(aider--send-command command))))
@@ -241,7 +263,7 @@ COMMAND should be a string representing the command to
send."
;; 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."
+ "Send the command \"/read-only <current buffer file full path>\" to the
corresponding aider comint buffer. This is only useful for doom menu now"
(interactive)
(aider-add-or-read-current-file "/read-only"))
@@ -257,7 +279,7 @@ COMMAND should be a string representing the command to
send."
(mapcar 'window-buffer (window-list)))))
(setq files (delq nil files))
(if files
- (let ((command (concat "/add " (mapconcat 'identity files " "))))
+ (let ((command (concat (aider--get-add-command-prefix) " " (mapconcat
'identity files " "))))
(aider--send-command command nil))
(message "No files found in the current window."))))
@@ -447,7 +469,7 @@ The command will be formatted as \"/ask \" followed by the
text from the selecte
(interactive)
(let ((files (dired-get-marked-files)))
(if files
- (let ((command (concat "/add " (mapconcat 'expand-file-name files "
"))))
+ (let ((command (concat (aider--get-add-command-prefix) " " (mapconcat
'expand-file-name files " "))))
(aider--send-command command t))
(message "No files marked in Dired."))))
@@ -468,7 +490,7 @@ If there are more than 40 files, refuse to add and show
warning message."
(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 " "))))
+ (let ((command (concat (aider--get-add-command-prefix) " " (mapconcat
'identity files " "))))
(aider--send-command command t))
(message "Added %d files with suffix .%s"
(length files) current-suffix)))))
diff --git a/transient_menu.png b/transient_menu.png
index 8ec41bad43..d66455a38c 100644
Binary files a/transient_menu.png and b/transient_menu.png differ