summaryrefslogtreecommitdiffstats
path: root/.emacs.d/init.org
diff options
context:
space:
mode:
Diffstat (limited to '.emacs.d/init.org')
-rw-r--r--.emacs.d/init.org28
1 files changed, 28 insertions, 0 deletions
diff --git a/.emacs.d/init.org b/.emacs.d/init.org
index 36e9983..28b8cf9 100644
--- a/.emacs.d/init.org
+++ b/.emacs.d/init.org
@@ -467,3 +467,31 @@
(autoload 'moz-minor-mode "moz" nil t)
(add-hook 'javascript-mode-hook 'moz-minor-mode)
#+END_SRC
+
+* Change numbers at point
+
+ Sometimes you just want to increase or decrease the number under the
+ cursor, no fuss.
+
+ #+BEGIN_SRC emacs-lisp
+ (defun change-number-at-point (change-func)
+ "Use CHANGE-FUNC to change the number at `point'."
+ (let ((num (number-to-string (funcall change-func (number-at-point))))
+ (bounds (bounds-of-thing-at-point 'word)))
+ (save-excursion
+ (delete-region (car bounds) (cdr bounds))
+ (insert num))))
+
+ (defun decrease-number-at-point ()
+ "Take the number at `point' and replace it with it decreased by 1."
+ (interactive)
+ (change-number-at-point #'1-))
+
+ (defun increase-number-at-point ()
+ "Take the number at `point' and replace it with it increased by 1."
+ (interactive)
+ (change-number-at-point #'1+))
+
+ (global-set-key (kbd "C-c -") #'decrease-number-at-point)
+ (global-set-key (kbd "C-c +") #'increase-number-at-point)
+ #+END_SRC