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

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

[nongnu] elpa/evil-numbers 38e17cb47f 026/145: Allow region processing.


From: ELPA Syncer
Subject: [nongnu] elpa/evil-numbers 38e17cb47f 026/145: Allow region processing.
Date: Thu, 6 Jan 2022 03:00:16 -0500 (EST)

branch: elpa/evil-numbers
commit 38e17cb47f00bd282e75ce10e2ab1eed24dae63a
Author: Matthew L. Fidler <matthew.fidler@gmail.com>
Commit: Matthew L. Fidler <matthew.fidler@gmail.com>

    Allow region processing.
---
 evil-numbers.el | 70 ++++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 42 insertions(+), 28 deletions(-)

diff --git a/evil-numbers.el b/evil-numbers.el
index d92843c288..d10660b9de 100644
--- a/evil-numbers.el
+++ b/evil-numbers.el
@@ -53,36 +53,50 @@
 ;;; Code:
 
 ;;;###autoload
-(defun evil-numbers/inc-at-pt (amount)
+(defun evil-numbers/inc-at-pt (amount &optional no-region)
   "Increment the number at point or after point before end-of-line by `amount'"
   (interactive "p*")
-  (save-match-data
-    (if (not (evil-numbers/search-number))
-        (error "No number at point or until end of line")
-      (or
-       ;; find binary literals
-       (evil-numbers/search-and-replace "0[bB][01]*" "01" "\\([01]+\\)" amount 
2)
-
-       ;; find octal literals
-       (evil-numbers/search-and-replace "0[oO][0-7]*" "01234567" 
"\\([0-7]+\\)" amount 8)
-
-       ;; find hex literals
-       (evil-numbers/search-and-replace "0[xX][0-9a-fA-F]*"
-                                        "0123456789abcdefABCDEF"
-                                        "\\([0-9a-fA-F]+\\)" amount 16)
-
-       ;; find decimal literals
-       (progn
-         (skip-chars-backward "0123456789")
-         (skip-chars-backward "-")
-         (when (looking-at "-?\\([0-9]+\\)")
-           (replace-match
-            (format (format "%%0%dd" (- (match-end 1) (match-beginning 1)))
-                    (+ amount (string-to-number (match-string 0) 10))))
-                  ;; Moves point one position back to conform with Vim
-                  (forward-char -1)
-           t))
-       (error "No number at point or until end of line")))))
+  (cond
+   ((and (not no-region) (region-active-p))
+    (let (deactivate-mark
+          (rb (region-beginning))
+          (re (region-end)))
+      (save-excursion
+        (save-match-data
+          (goto-char rb)
+          (while (re-search-forward 
"\\(?:0\\(?:[Bb][01]+\\|[Oo][0-7]+\\|[Xx][0-9A-Fa-f]+\\)\\|-?[0-9]+\\)" re t)
+            (evil-numbers/inc-at-pt amount 'no-region)
+            ;; Undo vim compatability.
+            (forward-char 1)
+            )))))
+   (t
+    (save-match-data
+      (if (not (evil-numbers/search-number))
+          (error "No number at point or until end of line")
+        (or
+         ;; find binary literals
+         (evil-numbers/search-and-replace "0[bB][01]+" "01" "\\([01]+\\)" 
amount 2)
+
+         ;; find octal literals
+         (evil-numbers/search-and-replace "0[oO][0-7]+" "01234567" 
"\\([0-7]+\\)" amount 8)
+
+         ;; find hex literals
+         (evil-numbers/search-and-replace "0[xX][0-9a-fA-F]*"
+                                          "0123456789abcdefABCDEF"
+                                          "\\([0-9a-fA-F]+\\)" amount 16)
+
+         ;; find decimal literals
+         (progn
+           (skip-chars-backward "0123456789")
+           (skip-chars-backward "-")
+           (when (looking-at "-?\\([0-9]+\\)")
+             (replace-match
+              (format (format "%%0%dd" (- (match-end 1) (match-beginning 1)))
+                      (+ amount (string-to-number (match-string 0) 10))))
+             ;; Moves point one position back to conform with Vim
+             (forward-char -1)
+             t))
+         (error "No number at point or until end of line")))))))
 
 ;;;###autoload
 (defun evil-numbers/dec-at-pt (amount)



reply via email to

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