[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-numbers 8da2221b7b 047/145: Make padding optional and
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-numbers 8da2221b7b 047/145: Make padding optional and off by default (can be configured) |
Date: |
Thu, 6 Jan 2022 03:00:17 -0500 (EST) |
branch: elpa/evil-numbers
commit 8da2221b7b779ace035eb678c4702d1c319c33c6
Author: Jan Path <jan@jpath.de>
Commit: Jan Path <jan@jpath.de>
Make padding optional and off by default (can be configured)
---
evil-numbers.el | 218 +++++++++++++++++++++++++++++++-------------------------
1 file changed, 120 insertions(+), 98 deletions(-)
diff --git a/evil-numbers.el b/evil-numbers.el
index 0ce0db7578..b91922e3af 100644
--- a/evil-numbers.el
+++ b/evil-numbers.el
@@ -63,7 +63,7 @@
(cons ?- ?⁻)
(cons
(cons ?+ ?⁺)
- (mapcar (lambda (i) (cons
+ (mapcar (lambda (i) (cons
(string-to-char (number-to-string i))
(aref "⁰¹²³⁴⁵⁶⁷⁸⁹" i)))
(number-sequence 0 9)))))
@@ -73,11 +73,16 @@
(cons ?- ?₋)
(cons
(cons ?+ ?₊)
- (mapcar (lambda (i) (cons
+ (mapcar (lambda (i) (cons
(string-to-char (number-to-string i))
(aref "₀₁₂₃₄₅₆₇₈₉" i)))
(number-sequence 0 9)))))
+(defcustom evil-numbers/padDefault nil
+ "Whether numbers are padded by default"
+ :type 'boolean
+ :options '(nil t))
+
(defun evil-numbers/swap-alist (alist)
"Swap association list"
(mapcar (lambda (x) (cons (cdr x) (car x))) alist))
@@ -89,7 +94,7 @@
(mapcar (lambda (c) (cdr (assoc c alist))) string)))
;;;###autoload
-(evil-define-operator evil-numbers/inc-at-pt (amount beg end type &optional
incremental)
+(evil-define-operator evil-numbers/inc-at-pt (amount beg end type &optional
incremental padded)
"Increment the number at point or after point before end-of-line by `amount'.
When region is selected, increment all numbers in the region by `amount'
@@ -100,101 +105,118 @@ applying the regional features of
`evil-numbers/inc-at-point'.
INCREMENTAL causes the first number to be increased by 1*amount, the second by
2*amount and so on.
+PADDED is whether numbers should be padded (e.g. 10 -> 09). nil is default
+behaviour set by `evil-numbers/pad-default', t is the opposite of
+`evil-numbers/pad-default','(t) enables padding and '(nil) disables padding.
+
"
:motion nil
(interactive "*<c><R>")
- (setq amount (or amount 1))
- (cond
- ((and beg end type)
- (let ((count 1))
- (save-excursion
- (save-match-data
- (funcall
- (if (eq type 'block)
- (lambda (f) (evil-apply-on-block f beg end nil))
- (lambda (f) (funcall f beg end)))
- (lambda (beg end)
- (evil-with-restriction beg end
- (while (re-search-forward
"\\(?:0\\(?:[Bb][01]+\\|[Oo][0-7]+\\|[Xx][0-9A-Fa-f]+\\)\\|[+-]?[0-9]+\\|[⁻⁺]?[⁰¹²³⁴⁵⁶⁷⁸⁹]\\|[₋₊]?[₀₁₂₃₄₅₆₇₈₉]\\)"
nil t)
- ;; Backward char, to cancel out the forward-char below. We
need
- ;; this, as re-search-forwards puts us behind the match.
- (backward-char)
- (evil-numbers/inc-at-pt (* amount count) nil nil nil)
- (if incremental (setq count (+ count 1)))
- ;; Undo vim compatability.
- (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 ((pad
- (lambda (len sign arg)
- (format
- (format "%%%s0%dd" (if sign "+" "") len)
- arg)))
- (replace-with
- (lambda (from to)
- (skip-chars-backward
- (funcall from "+-0123456789"))
- (when (looking-at
- (format
- "[%s]?[%s]+"
- (funcall from "-+")
- (funcall from "0123456789")))
- (replace-match
- (funcall
- from
- (funcall
- pad
- (- (match-end 0) (match-beginning 0))
- (memq (string-to-char (match-string 0))
- (funcall from '(?+ ?-)))
- (+ amount (string-to-number
- (funcall to (match-string 0)))))))
- ;; Moves point one position back to conform with Vim
- (forward-char -1)
- t))))
- (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 superscript literals
- (funcall
- replace-with
- (lambda (x)
- (evil-numbers/translate-with-alist
- evil-numbers/superscript-alist x))
- (lambda (x)
- (evil-numbers/translate-with-alist
- (evil-numbers/swap-alist evil-numbers/superscript-alist)
- x)))
-
- ;; find subscript literals
- (funcall
- replace-with
- (lambda (x)
- (evil-numbers/translate-with-alist
- evil-numbers/subscript-alist x))
- (lambda (x)
- (evil-numbers/translate-with-alist
- (evil-numbers/swap-alist evil-numbers/subscript-alist)
- x)))
-
- ;; find normal decimal literals
- (funcall replace-with (lambda (x) x) (lambda (x) x))
- (error "No number at point or until end of line"))))))))
+ (let ((amount (or amount 1))
+ (padded (if (consp padded) (car padded)
+ (funcall
+ (if padded #'not (lambda (x) x))
+ evil-numbers/padDefault))))
+ (cond
+ ((and beg end type)
+ (let ((count 1))
+ (save-excursion
+ (save-match-data
+ (funcall
+ (if (eq type 'block)
+ (lambda (f) (evil-apply-on-block f beg end nil))
+ (lambda (f) (funcall f beg end)))
+ (lambda (beg end)
+ (evil-with-restriction beg end
+ (while (re-search-forward
"\\(?:0\\(?:[Bb][01]+\\|[Oo][0-7]+\\|[Xx][0-9A-Fa-f]+\\)\\|[+-]?[0-9]+\\|[⁻⁺]?[⁰¹²³⁴⁵⁶⁷⁸⁹]\\|[₋₊]?[₀₁₂₃₄₅₆₇₈₉]\\)"
nil t)
+ ;; Backward char, to cancel out the forward-char below. We
need
+ ;; this, as re-search-forwards puts us behind the match.
+ (backward-char)
+ (evil-numbers/inc-at-pt (* amount count) nil nil nil)
+ (if incremental (setq count (+ count 1)))
+ ;; Undo vim compatability.
+ (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 ((pad
+ (lambda (len sign arg)
+ (format
+ (format "%%%s0%dd" (if sign "+" "") len)
+ arg)))
+ (replace-with
+ (lambda (from to)
+ (skip-chars-backward
+ (funcall from "+-0123456789"))
+ (when (looking-at
+ (format
+ "[%s]?\\([%s]+\\)"
+ (funcall from "-+")
+ (funcall from "0123456789")))
+ (replace-match
+ (funcall
+ from
+ (let* ((padded
+ (or padded
+ (eq ?0 (string-to-char (match-string
1)))))
+ (input (string-to-number
+ (funcall to (match-string 0))))
+ (output (+ amount input))
+ (len (- (match-end 0) (match-beginning 0)))
+ (signed (and
+ (memq (string-to-char (match-string
0))
+ (funcall from '(?+ ?-)))
+ (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))))
+ (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 superscript literals
+ (funcall
+ replace-with
+ (lambda (x)
+ (evil-numbers/translate-with-alist
+ evil-numbers/superscript-alist x))
+ (lambda (x)
+ (evil-numbers/translate-with-alist
+ (evil-numbers/swap-alist evil-numbers/superscript-alist)
+ x)))
+
+ ;; find subscript literals
+ (funcall
+ replace-with
+ (lambda (x)
+ (evil-numbers/translate-with-alist
+ evil-numbers/subscript-alist x))
+ (lambda (x)
+ (evil-numbers/translate-with-alist
+ (evil-numbers/swap-alist evil-numbers/subscript-alist)
+ x)))
+
+ ;; find normal decimal literals
+ (funcall replace-with (lambda (x) x) (lambda (x) x))
+ (error "No number at point or until end of line")))))))))
;;;###autoload
-(evil-define-operator evil-numbers/dec-at-pt (amount beg end type &optional
incremental)
+(evil-define-operator evil-numbers/dec-at-pt (amount beg end type &optional
incremental padded)
"Decrement the number at point or after point before end-of-line by `amount'.
If a region is active, decrement all the numbers at a point by `amount'.
@@ -202,10 +224,10 @@ If a region is active, decrement all the numbers at a
point by `amount'.
This function uses `evil-numbers/inc-at-pt'"
:motion nil
(interactive "*<c><R>")
- (evil-numbers/inc-at-pt (- (or amount 1)) beg end type))
+ (evil-numbers/inc-at-pt (- (or amount 1)) beg end type incremental padded))
;;;###autoload
-(evil-define-operator evil-numbers/inc-at-pt-incremental (amount beg end type)
+(evil-define-operator evil-numbers/inc-at-pt-incremental (amount beg end type
padded)
"Increment the number at point or after point before end-of-line by `amount'.
If a region is active, increment all the numbers at a point by `amount'*n,
where
@@ -214,14 +236,14 @@ That is increment the first number by `amount', the
second by 2*`amount', and so
on."
:motion nil
(interactive "*<c><R>")
- (evil-numbers/inc-at-pt amount beg end type 'incremental))
+ (evil-numbers/inc-at-pt amount beg end type 'incremental padded))
;;;###autoload
-(evil-define-operator evil-numbers/dec-at-pt-incremental (amount beg end type)
+(evil-define-operator evil-numbers/dec-at-pt-incremental (amount beg end type
padded)
"Like `evil-numbers/inc-at-pt-incremental' but with negated argument
`amount'"
:motion nil
(interactive "*<c><R>")
- (evil-numbers/inc-at-pt (- (or amount 1)) beg end type 'incemental))
+ (evil-numbers/inc-at-pt (- (or amount 1)) beg end type 'incemental padded))
;;; utils
- [nongnu] elpa/evil-numbers 83b2ad44ff 010/145: Use lowercase and uppercase example., (continued)
- [nongnu] elpa/evil-numbers 83b2ad44ff 010/145: Use lowercase and uppercase example., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers bd2359c96f 003/145: Fix provide., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 2301d66203 009/145: Fix docstrings of inc and dec., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 88de7e9622 007/145: Extract number search., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers b3e906f734 022/145: Fix last glitches., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 6e13c0450a 030/145: Update documentation., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 0a376ace35 021/145: Add autoload comments., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 30b13905a7 013/145: Move search and replace out of increment., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 9e2d6f721f 045/145: Support negative superscripts and fix padding of negative numbers, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 7ff262f36b 042/145: Support block selections, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 8da2221b7b 047/145: Make padding optional and off by default (can be configured),
ELPA Syncer <=
- [nongnu] elpa/evil-numbers cfa8650393 040/145: Remove extra &optional, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers f033965377 046/145: Support subscript numbers, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 154703dca7 048/145: Make binary, octal and hexadecimal numbers honour padDefault, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers b711ef787e 035/145: Document keypad binding variants., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers cbbfd83c79 044/145: Merge https://github.com/unhammer/evil-numbers, ELPA Syncer, 2022/01/06
- [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