Skip to content

Instantly share code, notes, and snippets.

@d11wtq d11wtq/inc-number.el
Created Jun 22, 2013

Embed
What would you like to do?
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
You can’t perform that action at this time.