summaryrefslogtreecommitdiffstats
path: root/.emacs.d
diff options
context:
space:
mode:
authorGravatar Tom Willemse2013-11-26 01:54:22 +0100
committerGravatar Tom Willemse2013-11-26 01:54:22 +0100
commitd9130bf6759deec80193fe4d353b24f2aec945b9 (patch)
tree2e2836df1d27a014eb731d5f889c3a78292d262d /.emacs.d
parentdf4d655be52d87b97d8df62b889b7c64f65ded41 (diff)
downloademacs-d9130bf6759deec80193fe4d353b24f2aec945b9.tar.gz
emacs-d9130bf6759deec80193fe4d353b24f2aec945b9.zip
Add commands to work with numbers
Diffstat (limited to '.emacs.d')
-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