branch: elpa/aidermacs
commit 2a29cffb7658eeb307c730bb2ac3e631c1448c5e
Author: Mingde (Matthew) Zeng (aider) <[email protected]>
Commit: Mingde (Matthew) Zeng <[email protected]>
feat: Add aidermacs-auto-commits and M-x aidermacs-run-in-current-dir=
Closes #9
Signed-off-by: Mingde (Matthew) Zeng <[email protected]>
---
README.org | 27 +++++++++++++++++++++------
aidermacs.el | 50 ++++++++++++++++++++++++++++++++++++++++++++------
2 files changed, 65 insertions(+), 12 deletions(-)
diff --git a/README.org b/README.org
index 6fa5ddfd1f..c2980e4c33 100644
--- a/README.org
+++ b/README.org
@@ -83,6 +83,7 @@ With =aidermacs=, you get:
* Configuration
** Terminal Backend Selection
+
Choose your preferred terminal backend by setting =aidermacs-backend=:
=vterm= provides better terminal compatibility and bracketed paste support,
while =comint= is a simpler, built-in option.
@@ -96,7 +97,19 @@ Available backends:
- =comint= (default): Uses Emacs' built-in terminal emulation
- =vterm=: Leverages vterm for better terminal compatibility
+** Disabling Auto-Commits
+
+By default, Aidermacs automatically commits changes made by the AI. Some users
may find this behavior disruptive. You can disable auto-commits by setting
=aidermacs-auto-commits= to =nil=:
+
+#+BEGIN_SRC emacs-lisp
+;; Disable auto-commits
+(setq aidermacs-auto-commits nil)
+#+END_SRC
+
+With auto-commits disabled, you'll need to manually commit changes using your
preferred Git workflow.
+
** Multiline Input Configuration
+
When using the comint backend, you can customize the key binding for multiline
input:
#+BEGIN_SRC emacs-lisp
@@ -140,6 +153,7 @@ After adding files to the session, switch to the
=*aidermacs*= buffer to interac
*** Session Control
- Run aidermacs: =M-x aidermacs-run-aidermacs= (=a= in transient menu)
+- Run in current directory: =M-x aidermacs-run-in-current-dir= (=.= in
transient menu)
- Switch to Buffer: =M-x aidermacs-switch-to-buffer= (=z= in transient menu)
- Select Model: =M-x aidermacs-change-model= (=o= in transient menu)
- Clear Session: =M-x aidermacs-clear= (=l= in transient menu)
@@ -215,11 +229,12 @@ Session management commands:
- Access all commands through the transient menu: =M-x
aidermacs-transient-menu=
- The transient menu is a popup menu that provides a convenient way to access
all aidermacs commands.
- The menu groups commands into categories:
- - "aidermacs Process": Basic session management (=a=, =z=, =o=, =l=, =s=,
=x=)
- - "Add File to aidermacs": File management (=f=, =R=, =w=, =d=, =b=)
- - "Code Change": Code modifications (=t=, =c=, =r=, =i=, =U=, =T=, =m=, =u=)
- - "Discussion": Questions and explanations (=q=, =y=, =e=, =p=, =D=)
- - "Other": Additional commands (=g=, =Q=, =p=, =h=)
-- Toggle options are available at the top of some sections
+ - "Session Control": Basic session management (=a=, .=, =z=, =o=, =l=, =s=,
=x=)
+ - "File Management": File management (=f=, =R=, =w=, =d=, =b=, =L=, =D=)
+ - "Code Actions": Code modifications (=c=, =r=, =i=, =t=, =u=)
+ - "Testing": Unit tests and debugging (=U=, =T=, =X=)
+ - "Help & Documentation": Questions and explanations (=q=, =e=, =p=, =h=,
=Q=)
+ - "History & Output": History and output management (=H=, =C=, =m=, =y=,
=g=, =P=)
+- Toggle options are available at the top of relevant sections
Note: The default keybindings in the minor mode map (=C-c C-n=, =C-<return>=,
=C-c C-c=, and =C-c C-z=) are always available when the minor mode is active.
All other commands can be accessed either through =M-x= or through the
transient menu after invoking =M-x aidermacs-transient-menu=.
diff --git a/aidermacs.el b/aidermacs.el
index 68bc2fdcde..e9b6d6f0a7 100644
--- a/aidermacs.el
+++ b/aidermacs.el
@@ -40,6 +40,27 @@
:type '(repeat string)
:group 'aidermacs)
+(defcustom aidermacs-subtree-only nil
+ "When non-nil, run aider with --subtree-only flag to only consider files in
current directory.
+This is useful for working in monorepos where you want to limit aider's scope."
+ :type 'boolean
+ :group 'aidermacs)
+
+(defcustom aidermacs-auto-commits t
+ "When non-nil, enable auto-commits of LLM changes.
+When nil, disable auto-commits requiring manual git commits."
+ :type 'boolean
+ :group 'aidermacs)
+
+(defun aidermacs-project-root ()
+ "Get the project root using project.el, VC, or fallback to file directory."
+ (or (when (fboundp 'project-current)
+ (project-root (project-current)))
+ (vc-git-root default-directory)
+ (when buffer-file-name
+ (file-name-directory buffer-file-name))
+ default-directory))
+
(defcustom aidermacs--switch-to-buffer-other-frame nil
"When non-nil, open aidermacs buffer in a new frame using
`switch-to-buffer-other-frame'.
When nil, use standard `display-buffer' behavior."
@@ -131,7 +152,8 @@ Affects the system message too.")
["aidermacs: AI Pair Programming"
["Session Control"
(aidermacs--infix-switch-to-buffer-other-frame)
- ("a" "Run aidermacs" aidermacs-run-aidermacs)
+ ("a" "Start/Open Aidermacs" aidermacs-run-aidermacs)
+ ("." "Run in Current Dir" aidermacs-run-in-current-dir)
("z" "Switch to Buffer" aidermacs-switch-to-buffer)
("o" "Select Model" aidermacs-change-model)
("l" "Clear Session" aidermacs-clear)
@@ -193,18 +215,34 @@ If not in a git repository and no buffer file exists, an
error is raised."
(error "Not in a git repository and current buffer is not associated
with a file. Please open a file or start aidermacs from within a git
repository.")))))
;;;###autoload
-(defun aidermacs-run-aidermacs (&optional edit-args)
+(defun aidermacs-run-aidermacs (&optional edit-args directory)
"Run aidermacs process using the selected backend.
-With the universal argument, prompt to edit aidermacs-args before running."
+With the universal argument EDIT-ARGS, prompt to edit aidermacs-args before
running.
+Optional DIRECTORY parameter sets working directory, defaults to project root."
(interactive "P")
- (let* ((buffer-name (aidermacs-buffer-name))
+ (let* ((default-directory (or directory (aidermacs-project-root)))
+ (buffer-name (aidermacs-buffer-name))
(current-args (if edit-args
(split-string (read-string "Edit aidermacs
arguments: "
(mapconcat 'identity
aidermacs-args " ")))
- aidermacs-args)))
+ aidermacs-args))
+ (final-args (append current-args
+ (when (not aidermacs-auto-commits)
+ '("--no-auto-commits"))
+ (when aidermacs-subtree-only
+ '("--subtree-only")))))
(if (get-buffer buffer-name)
(aidermacs-switch-to-buffer)
- (aidermacs-run-aidermacs-backend aidermacs-program current-args
buffer-name))))
+ (aidermacs-run-aidermacs-backend aidermacs-program final-args
buffer-name)
+ (aidermacs-switch-to-buffer))))
+
+;;;###autoload
+(defun aidermacs-run-in-current-dir ()
+ "Run aidermacs in the current directory with --subtree-only flag.
+This is useful for working in monorepos where you want to limit aider's scope."
+ (interactive)
+ (let ((aidermacs-subtree-only t))
+ (aidermacs-run-aidermacs nil default-directory)))
(defun aidermacs--send-command (command &optional switch-to-buffer callback)
"Send COMMAND to the corresponding aidermacs process.