summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRavi R Kiran <aine.marina@gmail.com>2020-02-10 12:51:22 (GMT)
committerRavi R Kiran <aine.marina@gmail.com>2020-02-10 12:51:22 (GMT)
commitf096576c0aed58c8312cc10a1c9cce617e71075b (patch)
tree85993728fdd042c5092a115be6d4c04744793df6
parent80d240f0036b0ed4a041f9c65bbe1e23cf344c11 (diff)
downloaddotemacs-f096576c0aed58c8312cc10a1c9cce617e71075b.zip
dotemacs-f096576c0aed58c8312cc10a1c9cce617e71075b.tar.gz
dotemacs-f096576c0aed58c8312cc10a1c9cce617e71075b.tar.bz2
Fix operate-on-numberHEADmaster
Should make a better fix as time allows.
-rw-r--r--lisp/ravi-init-maps.el27
1 files changed, 27 insertions, 0 deletions
diff --git a/lisp/ravi-init-maps.el b/lisp/ravi-init-maps.el
index fa563cd..a8de0a1 100644
--- a/lisp/ravi-init-maps.el
+++ b/lisp/ravi-init-maps.el
@@ -38,6 +38,33 @@
:bind (("M-g M-d" . hydra-operate-on-number/body))
:config
(progn
+ ;; Monkey-patch to fix:
+ ;; https://github.com/knu/operate-on-number.el/issues/5
+ ;; https://github.com/knu/operate-on-number.el/issues/4
+ (defun oon--replace-number (parsed number)
+ "Replace a number specified by PARSED with NUMBER."
+ (let* ((base (elt parsed 0))
+ (beg (elt parsed 1))
+ (spos (elt parsed 2))
+ (nbeg (elt parsed 3))
+ (nend (elt parsed 4))
+ (str (buffer-substring-no-properties nbeg nend))
+ (abs (if (numberp number) (abs number) number))
+ (sign (if (or (not (numberp number)) (< 0 number)) ?+ ?-)))
+ (if (and (null spos)
+ (= sign ?-))
+ (error "cannot replace with a negative number!"))
+ (goto-char nbeg)
+ (delete-region nbeg nend)
+ (insert (oon--format-number abs base str))
+ (if spos
+ (save-excursion
+ (goto-char spos)
+ (if (or (when (looking-at "[+-]")
+ (delete-char 1) t)
+ (= sign ?-))
+ (insert-char sign))))))
+
(defhydra hydra-operate-on-number ()
"
Arithmetic operations: + - * /