[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-numbers 15dcea1be0 087/145: Fix #20 The cursor moves
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-numbers 15dcea1be0 087/145: Fix #20 The cursor moves when increment/decrement fails |
Date: |
Thu, 6 Jan 2022 03:00:21 -0500 (EST) |
branch: elpa/evil-numbers
commit 15dcea1be055b8b6eea77801932b03686c42f481
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>
Fix #20 The cursor moves when increment/decrement fails
Only apply the cursor motion on success.
---
evil-numbers.el | 111 ++++++++++++++++++++++++++++++++------------------------
1 file changed, 64 insertions(+), 47 deletions(-)
diff --git a/evil-numbers.el b/evil-numbers.el
index a593763127..3eeb76005f 100644
--- a/evil-numbers.el
+++ b/evil-numbers.el
@@ -183,44 +183,15 @@ number with a + sign."
;; Undo VIM compatibility.
(forward-char 1)))))))))
(t
- (save-match-data
- ;; forward-char, so that we do not match the number directly behind us.
- (forward-char)
- (if (not (evil-numbers--search-number))
- (error "No number at point or until end of line")
- (let ((replace-with
- (lambda (decode-fn encode-fn)
- (skip-chars-backward
- (funcall encode-fn "0123456789"))
- (skip-chars-backward
- (funcall encode-fn "+-") (- (point) 1))
- (when (looking-at
- (format
- "[%s]?\\([%s]+\\)"
- (funcall encode-fn "-+")
- (funcall encode-fn "0123456789")))
- (replace-match
- (funcall
- encode-fn
- (let* ((padded
- (or padded
- (eq ?0 (string-to-char (match-string 1)))))
- (input (string-to-number
- (funcall decode-fn (match-string 0))))
- (output (+ amount input))
- (len (- (match-end 0) (match-beginning 0)))
- (signed (and
- (memq (string-to-char (match-string 0))
- (funcall encode-fn '(?+ ?-)))
- (or padded (>= input 0)))))
- (format
- (format "%%%s0%dd"
- (if signed "+" "")
- (if padded len 0))
- output))))
- ;; Moves point one position back to conform with VIM
- (forward-char -1)
- t))))
+ (let ((point-next nil))
+ (save-excursion
+ (save-match-data
+
+ ;; `forward-char' so that we do not match the number directly behind
us.
+ (forward-char)
+ (unless (evil-numbers--search-number)
+ (error "No number at point or until end of line"))
+
(or
;; Find binary literals.
(evil-numbers--search-and-replace
@@ -253,20 +224,31 @@ number with a + sign."
amount 16)
;; Find superscript literals.
- (funcall
- replace-with
+ (evil-numbers--search-and-replace-decimal
+ amount padded
#'evil-numbers--decode-super
#'evil-numbers--encode-super)
;; Find subscript literals.
- (funcall
- replace-with
+ (evil-numbers--search-and-replace-decimal
+ amount padded
#'evil-numbers--decode-sub
#'evil-numbers--encode-sub)
;; Find normal decimal literals.
- (funcall replace-with #'identity #'identity)
- (error "No number at point or until end of line"))))))))
+ (evil-numbers--search-and-replace-decimal
+ amount padded
+ #'identity #'identity)
+
+ (error "No number at point or until end of line"))
+
+ (setq point-next (point))))
+
+ ;; Moves point one position back to conform with VIM.
+ (goto-char (1- point-next))
+
+ ;; If there was no error, we had success.
+ t))))
;;;###autoload (autoload 'evil-numbers/dec-at-pt "evil-numbers" nil t)
(evil-define-operator evil-numbers/dec-at-pt (amount beg end type &optional
incremental padded)
@@ -408,6 +390,44 @@ Each item in SKIP-CHARS is a cons pair.
(set-match-data match-list)))
t))
+(defun evil-numbers--search-and-replace-decimal (amount padded decode-fn
encode-fn)
+ "Perform the increment/decrement on the current line.
+
+See `evil-numbers/inc-at-pt' for docs on AMOUNT & PADDED.
+
+DECODE-FN and ENCODE-FN optionally decode/encode the string
+into ASCII text (use for subscript & superscript)."
+ (skip-chars-backward
+ (funcall encode-fn "0123456789"))
+ (skip-chars-backward
+ (funcall encode-fn "+-") (- (point) 1))
+ (when (looking-at
+ (format
+ "[%s]?\\([%s]+\\)"
+ (funcall encode-fn "-+")
+ (funcall encode-fn "0123456789")))
+ (replace-match
+ (funcall
+ encode-fn
+ (let* ((padded
+ (or padded
+ (eq ?0 (string-to-char (match-string 1)))))
+ (input (string-to-number
+ (funcall decode-fn (match-string 0))))
+ (output (+ amount input))
+ (len (- (match-end 0) (match-beginning 0)))
+ (signed (and
+ (memq (string-to-char (match-string 0))
+ (funcall encode-fn '(?+ ?-)))
+ (or padded (>= input 0)))))
+ (format
+ (format "%%%s0%dd"
+ (if signed "+" "")
+ (if padded len 0))
+ output))))
+
+ t))
+
(defun evil-numbers--search-and-replace (skip-chars sign-group num-group inc
base)
"Perform the increment/decrement on the current line.
@@ -453,9 +473,6 @@ replace number incremented by INC in BASE and return
non-nil."
;; Replace the number.
(replace-match str-next t t nil num-group))
- ;; Moves point one position back to conform with VIM.
- (forward-char -1)
-
t)))
(defun evil-numbers--format (num width base)
- [nongnu] elpa/evil-numbers ebfb368851 055/145: Create evil-numbers customisation group, (continued)
- [nongnu] elpa/evil-numbers ebfb368851 055/145: Create evil-numbers customisation group, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers d1b1f503a5 057/145: Autoload operators as interactive commands, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers d988041c1f 056/145: List myself as maintainer, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers c2cfdd1eb1 058/145: Merge pull request #6 from hlissner/patch-1, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 02de70f481 062/145: Quiet checkdoc warnings, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 6fa8e02e3b 073/145: Cleanup: avoid right shift, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 963e78cb44 069/145: Change repo URLs in Readme too, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 26ec2d4a52 066/145: Use lexical binding, remove unused function 'pad', ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers a75c4b0a24 071/145: Cleanup: replace tabs with spaces, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 626ea72a21 084/145: Cleanup: add missing argument to doc-string, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 15dcea1be0 087/145: Fix #20 The cursor moves when increment/decrement fails,
ELPA Syncer <=
- [nongnu] elpa/evil-numbers 5622da311d 070/145: Cleanup: spelling, use full sentences, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers ab6d436454 074/145: Cleanup: use '--' separator for private functions, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers ff3bcf4efd 068/145: Change repo URLs, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 6483ab668b 103/145: Cleanup: use '?' instead of '*' for matching sign, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 43036127c1 105/145: Cleanup: line length < 80, spelling, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 0bbf3a8161 109/145: Cleanup: store unicode subscript/superscript in constants, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers d09a0e676a 125/145: Fix #25 increment steps to the next line, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 08f0c1ee93 145/145: Cleanup: warnings for tests, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers e1b60f3b75 133/145: Fix #27 Number directly before the cursor manipulated in some cases, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 3bd94723f8 134/145: Cleanup: indentation, ELPA Syncer, 2022/01/06