Created
June 22, 2013 07:13
-
-
Save d11wtq/5836174 to your computer and use it in GitHub Desktop.
Vim-style increment/decrement numbers under the cursor, for Emacs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; vim-style increment/decrement numbers | |
(defun inc-number-at-point (n) | |
"Increment the number under the point, if present. | |
Called with a prefix argument, changes the number by N." | |
(interactive "p") | |
(let ((amt (or n 1)) | |
(word (thing-at-point 'word)) | |
(bounds (bounds-of-thing-at-point 'word))) | |
(when (string-match "^[0-9]+$" word) | |
(replace-string word | |
(format "%d" (+ amt (string-to-int word))) | |
nil (car bounds) (cdr bounds)) | |
(forward-char -1)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment