[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-numbers 7ff262f36b 042/145: Support block selections
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-numbers 7ff262f36b 042/145: Support block selections |
Date: |
Thu, 6 Jan 2022 03:00:17 -0500 (EST) |
branch: elpa/evil-numbers
commit 7ff262f36bf6f3532a95b3056a8edfc5bcd6a77b
Author: Jan Path <jan@jpath.de>
Commit: Jan Path <jan@jpath.de>
Support block selections
---
evil-numbers.el | 131 +++++++++++++++++++++++++++++---------------------------
1 file changed, 69 insertions(+), 62 deletions(-)
diff --git a/evil-numbers.el b/evil-numbers.el
index 6d622f2c58..4564c72e78 100644
--- a/evil-numbers.el
+++ b/evil-numbers.el
@@ -59,7 +59,7 @@
;;; Code:
;;;###autoload
-(defun evil-numbers/inc-at-pt (amount &optional no-region incremental)
+(evil-define-operator evil-numbers/inc-at-pt (amount beg end type &optional
incremental)
"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'
@@ -71,75 +71,82 @@ INCREMENTAL causes the first number to be increased by
1*amount, the second by
2*amount and so on.
"
- (interactive "p*")
+ :motion nil
+ (interactive "*<c><R>")
+ (setq amount (or amount 1))
(cond
- ((and (not no-region) (region-active-p))
- (let (deactivate-mark
- (count 1))
+ ((and beg end type)
+ (let ((count 1))
(save-excursion
(save-match-data
- (if (< (mark) (point)) (exchange-point-and-mark))
- (while (re-search-forward
"\\(?:0\\(?:[Bb][01]+\\|[Oo][0-7]+\\|[Xx][0-9A-Fa-f]+\\)\\|-?[0-9]+\\)"
(region-end) t)
- (evil-numbers/inc-at-pt (* amount count) 'no-region)
- (if incremental (setq count (+ count 1)))
- ;; Undo vim compatability.
- (forward-char 1)))))
- (setq deactivate-mark t))
- (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")))))))
+ (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)
+ (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
+ (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)
+(evil-define-operator evil-numbers/dec-at-pt (amount beg end type &optional
incremental)
"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'.
This function uses `evil-numbers/inc-at-pt'"
- (interactive "p*")
- (evil-numbers/inc-at-pt (- amount)))
+ :motion nil
+ (interactive "*<c><R>")
+ (evil-numbers/inc-at-pt (- (or amount 1)) beg end type))
;;;###autoload
-(defun evil-numbers/inc-at-pt-incremental (amount)
+(evil-define-operator evil-numbers/inc-at-pt-incremental (amount beg end type)
"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
`n' is the index of the number among the numbers in the region, starting at 1.
That is increment the first number by `amount', the second by 2*`amount', and
so
on."
- (interactive "p*")
- (evil-numbers/inc-at-pt amount nil 'incremental))
+ :motion nil
+ (interactive "*<c><R>")
+ (evil-numbers/inc-at-pt amount beg end type 'incremental))
;;;###autoload
-(defun evil-numbers/dec-at-pt-incremental (amount)
+(evil-define-operator evil-numbers/dec-at-pt-incremental (amount beg end type)
"Like `evil-numbers/inc-at-pt-incremental' but with negated argument
`amount'"
- (interactive "p*")
- (evil-numbers/inc-at-pt-incremental (- amount)))
+ :motion nil
+ (interactive "*<c><R>")
+ (evil-numbers/inc-at-pt (- (or amount 1)) beg end type 'incemental))
;;; utils
@@ -155,21 +162,21 @@ decimal: [0-9]+, e.g. 42 or 23"
(or
;; numbers or format specifier in front
(looking-back (rx (or (+? digit)
- (and "0" (or (and (in "bB") (*? (in "01")))
- (and (in "oO") (*? (in "0-7")))
- (and (in "xX") (*? (in digit "A-Fa-f"))))))))
+ (and "0" (or (and (in "bB") (*? (in "01")))
+ (and (in "oO") (*? (in "0-7")))
+ (and (in "xX") (*? (in digit
"A-Fa-f"))))))))
;; search for number in rest of line
;; match 0 of specifier or digit, being in a literal and after specifier is
;; handled above
(and
- (re-search-forward "[[:digit:]]" (point-at-eol) t)
- (or
- (not (memq (char-after) '(?b ?B ?o ?O ?x ?X)))
- (/= (char-before) ?0)
- (and (> (point) 2) ; Should also take bofp
into consideration
- (not (looking-back "\\W0" 2)))
- ;; skip format specifiers and interpret as bool
- (<= 0 (skip-chars-forward "bBoOxX"))))))
+ (re-search-forward "[[:digit:]]" (point-at-eol) t)
+ (or
+ (not (memq (char-after) '(?b ?B ?o ?O ?x ?X)))
+ (/= (char-before) ?0)
+ (and (> (point) 2) ; Should also take bofp
into consideration
+ (not (looking-back "\\W0" 2)))
+ ;; skip format specifiers and interpret as bool
+ (<= 0 (skip-chars-forward "bBoOxX"))))))
(defun evil-numbers/search-and-replace (look-back skip-back search-forward inc
base)
"When looking back at `LOOK-BACK' skip chars `SKIP-BACK'backwards and
replace number incremented by `INC' in `BASE' and return non-nil."
@@ -179,8 +186,8 @@ decimal: [0-9]+, e.g. 42 or 23"
(replace-match (evil-numbers/format (+ inc (string-to-number (match-string
1) base))
(length (match-string 1))
base))
- ;; Moves point one position back to conform with Vim
- (forward-char -1)
+ ;; Moves point one position back to conform with Vim
+ (forward-char -1)
t))
(defun evil-numbers/format (num width base)
- [nongnu] elpa/evil-numbers b84ee09de1 012/145: Fix license., (continued)
- [nongnu] elpa/evil-numbers b84ee09de1 012/145: Fix license., ELPA Syncer, 2022/01/06
- [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 <=
- [nongnu] elpa/evil-numbers 8da2221b7b 047/145: Make padding optional and off by default (can be configured), ELPA Syncer, 2022/01/06
- [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