[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-numbers 48b528baec 131/145: Refactor: instead of pass
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-numbers 48b528baec 131/145: Refactor: instead of passing an amount, pass in a function |
Date: |
Thu, 6 Jan 2022 03:00:25 -0500 (EST) |
branch: elpa/evil-numbers
commit 48b528baec243d0dc860cdd5d20d0bdb83ffb456
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>
Refactor: instead of passing an amount, pass in a function
This opens up possibilities for changing the number in other ways
besides addition.
---
evil-numbers.el | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/evil-numbers.el b/evil-numbers.el
index 91d050eea6..94ac8225dd 100644
--- a/evil-numbers.el
+++ b/evil-numbers.el
@@ -372,10 +372,11 @@ Each item in MATCH-CHARS is a cons pair.
(defun evil-numbers--inc-at-pt-impl-with-match-chars
(match-chars
sign-group num-group
- amount base
+ base
beg end
padded
do-case
+ number-xform-fn
decode-fn encode-fn)
"Perform the increment/decrement on the current line.
@@ -386,8 +387,8 @@ SIGN-GROUP is the match group used for the sign ('-' or
'+').
When PADDED is non-nil,
the number keeps it's current width (with leading zeroes).
-When all characters are found in sequence,
-replace number incremented by AMOUNT in BASE and return non-nil."
+When all characters are found in sequence, evaluate the number in BASE,
+replacing it by the result of NUMBER-XFORM-FN and return non-nil."
(save-match-data
(when (save-excursion
;; Skip backwards (as needed), there may be no
@@ -410,7 +411,7 @@ replace number incremented by AMOUNT in BASE and return
non-nil."
str-prev))
(num-prev (string-to-number str-prev-strip base))
- (num-next (+ amount num-prev))
+ (num-next (funcall number-xform-fn num-prev))
(str-next
(evil-numbers--format
(abs num-next)
@@ -451,7 +452,7 @@ replace number incremented by AMOUNT in BASE and return
non-nil."
t)))
-(defun evil-numbers--inc-at-pt-impl (amount beg end padded)
+(defun evil-numbers--inc-at-pt-impl (beg end padded number-xform-fn)
"Increment the number at the current POINT by AMOUNT limited by BEG and END.
Keep padding when PADDED is non-nil.
@@ -463,15 +464,16 @@ Return non-nil on success, leaving the point at the end
of the number."
(evil-numbers--inc-at-pt-impl-with-match-chars
`(("+-" \?) ("0" 1) ("bB" 1) ("01" + ,evil-numbers-separator-chars))
1 4 ;; Sign & number groups.
- amount 2 beg end padded nil
+ 2 beg end padded nil number-xform-fn
#'identity #'identity)
;; Find octal literals:
;; 0[oO][0-7]+, e.g. 0o42 or 0O5
(evil-numbers--inc-at-pt-impl-with-match-chars
+
`(("+-" \?) ("0" 1) ("oO" 1) ("0-7" + ,evil-numbers-separator-chars))
1 4 ;; Sign & number groups.
- amount 8 beg end padded nil
+ 8 beg end padded nil number-xform-fn
#'identity #'identity)
;; Find hex literals:
@@ -479,7 +481,7 @@ Return non-nil on success, leaving the point at the end of
the number."
(evil-numbers--inc-at-pt-impl-with-match-chars
`(("+-" \?) ("0" 1) ("xX" 1) ("[:xdigit:]" +
,evil-numbers-separator-chars))
1 4 ;; Sign & number groups.
- amount 16 beg end padded t
+ 16 beg end padded t number-xform-fn
#'identity #'identity)
;; Find decimal literals:
@@ -487,21 +489,21 @@ Return non-nil on success, leaving the point at the end
of the number."
(evil-numbers--inc-at-pt-impl-with-match-chars
`(("+-" \?) ("0123456789" + ,evil-numbers-separator-chars))
1 2 ;; Sign & number groups.
- amount 10 beg end padded nil
+ 10 beg end padded nil number-xform-fn
#'identity #'identity)
;; Find decimal literals (super-script).
(evil-numbers--inc-at-pt-impl-with-match-chars
`(("⁺⁻" \?) (,evil-numbers--chars-superscript + nil))
1 2 ;; Sign & number groups.
- amount 10 beg end padded nil
+ 10 beg end padded nil number-xform-fn
#'evil-numbers--decode-super #'evil-numbers--encode-super)
;; Find decimal literals (sub-script).
(evil-numbers--inc-at-pt-impl-with-match-chars
`(("₊₋" \?) (,evil-numbers--chars-subscript + nil))
1 2 ;; Sign & number groups.
- amount 10 beg end padded nil
+ 10 beg end padded nil number-xform-fn
#'evil-numbers--decode-sub #'evil-numbers--encode-sub)))
(defun evil-numbers--inc-at-pt-impl-with-search (amount beg end padded)
@@ -522,14 +524,14 @@ Return non-nil on success, leaving the point at the end
of the number."
;; Found item, exit the loop.
(null
(when (evil-numbers--inc-at-pt-impl
- amount
;; Clamp limits to line bounds.
;; The caller may use a range that spans lines to
;; allow searching and finding items across
;; multiple lines (currently used for selection).
(max beg (point-at-bol))
(min end (point-at-eol))
- padded)
+ padded
+ #'(lambda (n) (+ n amount)))
(setq found t)))
;; Search failed, exit the loop.
- [nongnu] elpa/evil-numbers ef72a4fea1 135/145: Cleanup: correct doc-strings, (continued)
- [nongnu] elpa/evil-numbers ef72a4fea1 135/145: Cleanup: correct doc-strings, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 70b986276a 117/145: Cleanup: declare nums as `(list)` for readability, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 623bcbd04f 130/145: README: add "similar packages" section, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 1bf577af5c 132/145: Fix #26: Optionally match characters directly before the cursor, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 43ae06047c 115/145: README.org: keypad can be used for other platforms too, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 83e98f9fe2 096/145: Correct invalid limit argument to `looking-back', ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers a6cf01fd90 090/145: Fix #21 increment w/ selection ignores items before the cursor, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 11fc45c760 086/145: Cleanup: move subscript encode/decode into utility functions, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers bea0c102af 088/145: Cleanup: use term amount for both decimal/(hex/bin/octal) functions, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers f33d0137ac 072/145: Cleanup: quiet package-lint warnings, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 48b528baec 131/145: Refactor: instead of passing an amount, pass in a function,
ELPA Syncer <=
- [nongnu] elpa/evil-numbers fd742943fd 127/145: README.org use definition lists for options, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers cd23a7b458 136/145: README.org: update poor wording, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 9841266544 113/145: Cleanup: replace catch/throw with a 'found' variable, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 9cf802c29d 119/145: Fix #24 hexadecimal values case when incrementing/decrementing, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 6ea1c8c3a9 036/145: Use list for contributers., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers a2ce896e05 049/145: Update documentation, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers ac4101f0e4 052/145: Explicitly require evil., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 4fd2d402fe 050/145: Add CHANGELOG, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 8b59acf267 059/145: fix: handle hyphen-separated numbers correctly, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers e0f4ba3d13 004/145: Fix number search., ELPA Syncer, 2022/01/06