branch: elpa/aidermacs commit 9a564f76156595fc0051316fd4af679516f11057 Author: Kang Tu <tni...@gmail.com> Commit: GitHub <nore...@github.com>
Feat: Add aider-send-region function (#44) * refactor: Rename `aider-send-paragraph` to `aider-send-paragraph-by-line` * feat: Add `aider-send-block` function and keybinding for sending paragraphs * docs: Update README description of aider-minor-mode paragraph sending behavior * docs: Update README with aider-minor-mode key bindings documentation * refactor: Update aider-send-paragraph keybinding description * feat: Add `aider-send-block` to Doom menu under Send prefix * refactor: reorder functions for better code organization * feat: Add aider-send-region function with C-c C-r keybinding * refactor: Remove aider-send-block function and related references * refactor: move aider-send-region function definition before keymap --- README.org | 5 ++++- aider-doom.el | 3 ++- aider.el | 17 ++++++++++++++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/README.org b/README.org index 856073242c..089dd21df8 100644 --- a/README.org +++ b/README.org @@ -111,7 +111,10 @@ You can enable Helm-based completion with the following code: *** Aider script interactive mode: aider-minor-mode -- If you prefer writing Aider commands in a separate file and sending them to an Aider session (similar to working with Python or R scripts and sending code blocks to a REPL), you might want to try aider-minor-mode. It by default bind C-c C-n to send current line to aider session, and C-c C-c to send current region to aider session. +- If you prefer writing Aider commands in a separate file and sending them to an Aider session (similar to working with Python or R scripts and sending code blocks to a REPL), you might want to try aider-minor-mode. It provides the following key bindings: + - C-c C-n: Send current line to aider session + - C-c C-c: Send current paragraph line by line to aider session + - C-c C-r: Send current region as a single block to aider session - Enable aider-minor-mode for your editing buffer - To automatically enable aider-minor-mode for any file with "aider" in its filename: diff --git a/aider-doom.el b/aider-doom.el index 769c165275..8f68a6796b 100644 --- a/aider-doom.el +++ b/aider-doom.el @@ -29,7 +29,8 @@ (:prefix ("s" . "Send") :desc "Line at cursor" "l" #'aider-send-line-under-cursor - :desc "Paragraph at cursor" "p" #'aider-send-paragraph + :desc "Paragraph at cursor, line by line" "p" #'aider-send-paragraph-by-line + :desc "Region as block" "r" #'aider-send-region ) (:prefix ("c" . "Code") diff --git a/aider.el b/aider.el index fc9c9ad35d..378e7081df 100644 --- a/aider.el +++ b/aider.el @@ -561,7 +561,7 @@ This function assumes the cursor is on or inside a test function." (aider--send-command command t)) (message "No test function found at cursor position."))) -;;; functions for .aider file related +;;; functions for sending text blocks ;; New function to send "<line under cursor>" to the Aider buffer ;;;###autoload @@ -573,7 +573,7 @@ This function assumes the cursor is on or inside a test function." ;;; New function to send the current paragraph to the Aider buffer ;;;###autoload -(defun aider-send-paragraph () +(defun aider-send-paragraph-by-line () "Get the whole text of the current paragraph, split them into lines, strip the newline character from each line, for each non-empty line, send it to aider session" @@ -588,11 +588,22 @@ This function assumes the cursor is on or inside a test function." (aider--send-command line t))) (split-string paragraph "\n" t)))) +;;;###autoload +(defun aider-send-region () + "Send the current active region text as a whole block to aider session." + (interactive) + (if (region-active-p) + (let ((region-text (buffer-substring-no-properties (region-beginning) (region-end)))) + (unless (string-empty-p region-text) + (aider--send-command region-text t))) + (message "No region selected."))) + ;; Define the keymap for Aider Minor Mode (defvar aider-minor-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "C-c C-n") 'aider-send-line-under-cursor) - (define-key map (kbd "C-c C-c") 'aider-send-paragraph) + (define-key map (kbd "C-c C-c") 'aider-send-paragraph-by-line) + (define-key map (kbd "C-c C-r") 'aider-send-region) map) "Keymap for Aider Minor Mode.")