From d9130bf6759deec80193fe4d353b24f2aec945b9 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Tue, 26 Nov 2013 01:54:22 +0100 Subject: Add commands to work with numbers --- .emacs.d/init.org | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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 -- cgit v1.2.3-54-g00ecf