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

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

[nongnu] elpa/anzu cf07d6a0ec 125/288: Implement specified lines replace


From: ELPA Syncer
Subject: [nongnu] elpa/anzu cf07d6a0ec 125/288: Implement specified lines replacement
Date: Thu, 6 Jan 2022 03:58:46 -0500 (EST)

branch: elpa/anzu
commit cf07d6a0ec9df9a43612464631d9da64d464b0ec
Author: Syohei YOSHIDA <syohex@gmail.com>
Commit: Syohei YOSHIDA <syohex@gmail.com>

    Implement specified lines replacement
    
    If user specifies numeric prefix for replacement command,
    such as  anzu-query-replace, then anzu.el replaces only
    specified lines.
    
    For example, C-u 3 M-x anzu-query-replace replaces only 3 lines.
---
 anzu.el | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/anzu.el b/anzu.el
index 953a12712d..f6c7977748 100644
--- a/anzu.el
+++ b/anzu.el
@@ -478,20 +478,23 @@
     (and bound (cdr bound))))
 
 (defun anzu--region-begin (use-region thing backward)
-  (if thing
-      (or (anzu--thing-begin thing) (point))
-    (if use-region
-        (region-beginning)
-      (if backward
-          (point-min)
-        (point)))))
+  (cond (current-prefix-arg (line-beginning-position))
+        (thing (or (anzu--thing-begin thing) (point)))
+        (use-region (region-beginning))
+        (backward (point-min))
+        (t (point))))
+
+(defsubst anzu--line-end-position (num)
+  (save-excursion
+    (forward-line (1- num))
+    (line-end-position)))
 
 (defun anzu--region-end (use-region thing)
-  (if thing
-      (or (anzu--thing-end thing) (point-max))
-    (if use-region
-        (region-end)
-      (point-max))))
+  (cond (current-prefix-arg
+         (anzu--line-end-position (prefix-numeric-value current-prefix-arg)))
+        (thing (or (anzu--thing-end thing) (point-max)))
+        (use-region (region-end))
+        (t (point-max))))
 
 (defun anzu--begin-thing (at-cursor thing)
   (cond ((and at-cursor thing) thing)



reply via email to

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