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

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

[nongnu] elpa/evil-numbers cbbfd83c79 044/145: Merge https://github.com/


From: ELPA Syncer
Subject: [nongnu] elpa/evil-numbers cbbfd83c79 044/145: Merge https://github.com/unhammer/evil-numbers
Date: Thu, 6 Jan 2022 03:00:17 -0500 (EST)

branch: elpa/evil-numbers
commit cbbfd83c79ecbd598ba7be68dbcff98889a2d23a
Merge: e5dd1e2e31 b754f53c82
Author: Jan Path <jan@jpath.de>
Commit: Jan Path <jan@jpath.de>

    Merge https://github.com/unhammer/evil-numbers
---
 evil-numbers.el | 39 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)

diff --git a/evil-numbers.el b/evil-numbers.el
index 4b676eb5df..a4610ec8d9 100644
--- a/evil-numbers.el
+++ b/evil-numbers.el
@@ -58,6 +58,29 @@
 
 ;;; Code:
 
+(defun evil-number-to-superscript (number)
+  "Turn NUMBER like 29 into superscript like ²⁹.
+If argument is a string, uses `number-to-string' on it."
+  (let ((number (if (numberp number)
+                    number
+                  (number-to-string number))))
+    (concat
+     (mapcar (lambda (digit)
+               (aref "⁰¹²³⁴⁵⁶⁷⁸⁹" (- digit 48)))
+             (number-to-string number)))))
+
+(defun evil-superscript-to-number (string)
+  "Turn a superscript-number STRING like ²⁹ into a regular number like 29."
+  (let ((map                            ; (⁰ . ?0)
+         (mapcar (lambda (i) (cons (aref "⁰¹²³⁴⁵⁶⁷⁸⁹" i)
+                              (aref (number-to-string i) 0)))
+                 (number-sequence 0 9))))
+    (string-to-number
+     (concat
+      (mapcar (lambda (c)
+                (cdr (assoc c map)))
+              string)))))
+
 ;;;###autoload
 (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'.
@@ -85,7 +108,7 @@ INCREMENTAL causes the first number to be increased by 
1*amount, the second by
              (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)
+               (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)
@@ -110,6 +133,17 @@ INCREMENTAL causes the first number to be increased by 
1*amount, the second by
                                             "0123456789abcdefABCDEF"
                                             "\\([0-9a-fA-F]+\\)" amount 16)
 
+           ;; find superscript literals
+           (progn
+             (skip-chars-backward "⁰¹²³⁴⁵⁶⁷⁸⁹")
+             (when (looking-at "⁻?\\([⁰¹²³⁴⁵⁶⁷⁸⁹]+\\)")
+               (replace-match
+                (format (format "%%0%ds" (- (match-end 1) (match-beginning 1)))
+                        (evil-number-to-superscript
+                         (+ amount (evil-superscript-to-number (match-string 
0))))))
+               ;; Moves point one position back to conform with Vim
+               (forward-char -1)
+               t))
            ;; find decimal literals
            (progn
              (skip-chars-backward "0123456789")
@@ -167,6 +201,7 @@ decimal: [0-9]+, e.g. 42 or 23"
   (or
    ;; numbers or format specifier in front
    (looking-back (rx (or (+? digit)
+                         (in "⁰¹²³⁴⁵⁶⁷⁸⁹")
                          (and "0" (or (and (in "bB") (*? (in "01")))
                                       (and (in "oO") (*? (in "0-7")))
                                       (and (in "xX") (*? (in digit 
"A-Fa-f"))))))))
@@ -174,7 +209,7 @@ decimal: [0-9]+, e.g. 42 or 23"
    ;; 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)
+         (re-search-forward "[[:digit:]⁰¹²³⁴⁵⁶⁷⁸⁹]" (point-at-eol) t)
          (or
           (not (memq (char-after) '(?b ?B ?o ?O ?x ?X)))
           (/= (char-before) ?0)



reply via email to

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