Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions aidermacs.el
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ nil / 'code – start in code mode (no --chat-mode arg)
'architect – start in architect mode (--chat-mode architect + model flags)
'help – start in help mode (--chat-mode help)."
:type '(choice (const :tag "Code (default)" nil)
(const :tag "Code" code)
(const :tag "Ask" ask)
(const :tag "Architect" architect)
(const :tag "Help" help)))
(const :tag "Code" code)
(const :tag "Ask" ask)
(const :tag "Architect" architect)
(const :tag "Help" help)))

;; DEPRECATED – will disappear in a future release
(defcustom aidermacs-use-architect-mode nil
Expand Down Expand Up @@ -455,8 +455,8 @@ This is useful for working in monorepos where you want to limit aider's scope."
This is useful for working in complex monorepos with nested subprojects."
(interactive
(list (read-file-name "Choose a directory: " nil nil t nil 'file-directory-p)))
(let ((aidermacs-subtree-only t)
(default-directory directory))
(let ((aidermacs-subtree-only t)
(default-directory directory))
(aidermacs-run)))

(defun aidermacs--command-may-edit-files (command)
Expand Down Expand Up @@ -730,9 +730,30 @@ Use highlighted region as context unless IGNORE-CONTEXT is set to non-nil."
(unless (string-empty-p user-command)
(concat ": " user-command)))))

(defun aidermacs--detect-code-change-region ()
"Select the underlying region based on paragraph boundaries.
Returns a cons cell (START . END) of the detected region, or nil if no region found."
(save-excursion
(let ((start (point))
(end (point)))
(backward-paragraph)
(setq start (point))
(forward-paragraph)
(setq end (point))
(cons start end))))

(defun aidermacs--set-code-change-region ()
"Set the region based on detected code change boundaries if no region is active."
(unless (use-region-p)
(when-let ((region (aidermacs--detect-code-change-region)))
(goto-char (car region))
(set-mark (cdr region)))))

(defun aidermacs-direct-change ()
"Prompt the user for an input and send it to aidermacs prefixed with \"/code \"."
"Prompt the user for an input and send it to aidermacs prefixed with \"/code \".
If no region is active, automatically detect and select a relevant region."
(interactive)
(aidermacs--set-code-change-region)
(when-let* ((command (aidermacs--form-prompt "/code" "Make this change" "will edit file")))
(aidermacs--ensure-current-file-tracked)
(aidermacs--send-command command)))
Expand All @@ -743,6 +764,7 @@ If a region is active, include the region text in the question.
If cursor is inside a function, include the function name as context.
If called from the aidermacs buffer, use general question instead."
(interactive)
(aidermacs--set-code-change-region)
(when-let* ((command (aidermacs--form-prompt "/ask" "Propose a solution" "won't edit file")))
(aidermacs--ensure-current-file-tracked)
(aidermacs--send-command command)))
Expand All @@ -752,6 +774,7 @@ If called from the aidermacs buffer, use general question instead."
If region is active, inspect that region.
If point is in a function, inspect that function."
(interactive)
(aidermacs--set-code-change-region)
(when-let* ((command (aidermacs--form-prompt "/architect" "Design a solution" "confirm before edit")))
(aidermacs--ensure-current-file-tracked)
(aidermacs--send-command command)))
Expand Down