branch: elpa/aidermacs
commit 263f7627bf3bb2a9dbedd656d678a40f50d34cad
Author: Mingde (Matthew) Zeng <[email protected]>
Commit: Mingde (Matthew) Zeng <[email protected]>
Refactor aidermacs-send-region-by-line
Signed-off-by: Mingde (Matthew) Zeng <[email protected]>
---
README.md | 5 +++++
aidermacs.el | 25 ++++++++++++-------------
2 files changed, 17 insertions(+), 13 deletions(-)
diff --git a/README.md b/README.md
index a6f117fdf1..02842ef64f 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,12 @@
</p>
# Aidermacs: AI Pair Programming in Emacs
+[](https://github.com/MatthewZMD/aidermacs/blob/master/LICENSE)
[](https://melpa.org/#/aidermacs)
+[](https://www.gnu.org/savannah-checkouts/gnu/emacs/emacs.html)
+[](https://github.com/MatthewZMD/aidermacs/graphs/contributors)
+[](https://github.com/MatthewZMD/aidermacs/issues)
+[](https://github.com/MatthewZMD/aidermacs/pull/new)
Missing [Cursor](https://cursor.sh) but prefer living in Emacs? Aidermacs
brings Cursor-like AI-powered development to your Emacs workflow by integrating
[Aider](https://github.com/paul-gauthier/aider), one of the most powerful
open-source AI pair programming tools. As a community-driven project, Aidermacs
prioritizes Emacs users' needs and preferences while providing the same
powerful features found in Cursor!
diff --git a/aidermacs.el b/aidermacs.el
index 1c6defae52..9f5b5c6c7c 100644
--- a/aidermacs.el
+++ b/aidermacs.el
@@ -1094,19 +1094,18 @@ Otherwise, send the line under cursor."
(when text
(aidermacs--send-command text))))
-(defun aidermacs-send-region-by-line ()
- "Send the text of the current selected region, split into lines."
- (interactive)
- (if (use-region-p)
- (let* ((text (buffer-substring-no-properties
- (region-beginning) (region-end)))
- (lines (split-string text "\n" t)))
- (mapc (lambda (line)
- (let ((trimmed (string-trim line)))
- (when (not (string-empty-p trimmed))
- (aidermacs--send-command trimmed))))
- lines))
- (message "No region selected.")))
+(defun aidermacs-send-region-by-line (start end)
+ "Send the text between START and END, line by line.
+Only sends non-empty lines after trimming whitespace."
+ (interactive "r")
+ (with-restriction start end
+ (save-excursion
+ (goto-char (point-min))
+ (while (not (eobp))
+ (let ((line (string-trim (thing-at-point 'line t))))
+ (when (not (string-empty-p line))
+ (aidermacs--send-command line)))
+ (forward-line 1)))))
(defun aidermacs-send-block-or-region ()
"Send the current active region text or current paragraph content.