branch: elpa/aidermacs
commit 263f7627bf3bb2a9dbedd656d678a40f50d34cad
Author: Mingde (Matthew) Zeng <matthew...@posteo.net>
Commit: Mingde (Matthew) Zeng <matthew...@posteo.net>

    Refactor aidermacs-send-region-by-line
    
    Signed-off-by: Mingde (Matthew) Zeng <matthew...@posteo.net>
---
 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
+[![LICENSE](https://img.shields.io/github/license/MatthewZMD/aidermacs?logo=apache&.svg)](https://github.com/MatthewZMD/aidermacs/blob/master/LICENSE)
 
[![MELPA](https://melpa.org/packages/aidermacs-badge.svg)](https://melpa.org/#/aidermacs)
+[![EMACS](https://img.shields.io/badge/Emacs-29.1-922793?logo=gnu-emacs&logoColor=b39ddb&.svg)](https://www.gnu.org/savannah-checkouts/gnu/emacs/emacs.html)
+[![CONTRIBUTORS](https://img.shields.io/github/contributors/MatthewZMD/aidermacs.svg)](https://github.com/MatthewZMD/aidermacs/graphs/contributors)
+[![ISSUES](https://img.shields.io/github/issues/MatthewZMD/aidermacs.svg)](https://github.com/MatthewZMD/aidermacs/issues)
+[![PR](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](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.

Reply via email to