Skip to content

Instantly share code, notes, and snippets.

@d11wtq
Created June 22, 2013 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d11wtq/5836174 to your computer and use it in GitHub Desktop.
Save d11wtq/5836174 to your computer and use it in GitHub Desktop.
Vim-style increment/decrement numbers under the cursor, for Emacs.
;; 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