emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/evil-surround 641498131a 059/175: Refactor evil-surround-b


From: ELPA Syncer
Subject: [nongnu] elpa/evil-surround 641498131a 059/175: Refactor evil-surround-block
Date: Mon, 9 Oct 2023 13:01:03 -0400 (EDT)

branch: elpa/evil-surround
commit 641498131afea83dc612b73569ba61055a648ec8
Author: Henrik Lissner <henrik@lissner.net>
Commit: Henrik Lissner <henrik@lissner.net>

    Refactor evil-surround-block
---
 evil-surround.el | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/evil-surround.el b/evil-surround.el
index 4a8aaf5aa5..63df8f6c18 100755
--- a/evil-surround.el
+++ b/evil-surround.el
@@ -217,21 +217,19 @@ overlays OUTER and INNER, which are passed to 
`evil-surround-delete'."
   (define-key evil-operator-shortcut-map "s" 'evil-surround-line)
   (define-key evil-operator-shortcut-map "S" 'evil-surround-line))
 
+(defun evil-surround-column-at (pos)
+  (save-excursion (goto-char pos) (current-column)))
+
 (defun evil-surround-block (beg end char)
-  "Split a block into regions per line and surround each of them individually."
-  (save-excursion
-    (goto-char beg)
-    (let ((lines (- (1+ (line-number-at-pos end)) (line-number-at-pos beg)))
-          (start-col (current-column))
-          (end-col (save-excursion (goto-char end) (current-column))))
-      (while (> lines 0)
-        (move-to-column start-col)
-        ;; skip lines that are empty at this column
-        (unless (/= start-col (current-column))
-          (evil-surround-region (point) (save-excursion (move-to-column 
end-col) (point))
-                                'inclusive char))
-        (setq lines (1- lines))
-        (next-line)))))
+  "Split a block into regions per line and surround them individually. Skips
+lines where the columns don't line up."
+  (let* ((beg-col (evil-surround-column-at beg))
+         (end-col (evil-surround-column-at end)))
+    (evil-apply-on-block
+     (lambda (ibeg iend)
+       (unless (< (evil-surround-column-at ibeg) (min beg-col end-col))
+         (evil-surround-region ibeg iend t char)))
+     beg end nil)))
 
 ;; Dispatcher function in Operator-Pending state.
 ;; "cs" calls `evil-surround-change', "ds" calls `evil-surround-delete',



reply via email to

[Prev in Thread] Current Thread [Next in Thread]