Skip to content

Instantly share code, notes, and snippets.

@xuchunyang
Created October 4, 2015 05:25
Show Gist options
  • Save xuchunyang/bf7d4b9d6e78574cb7e6 to your computer and use it in GitHub Desktop.
Save xuchunyang/bf7d4b9d6e78574cb7e6 to your computer and use it in GitHub Desktop.
Increment number at point by 1.
(defun incf-at-point ()
"Increment number at point by 1."
(interactive)
(let ((number (number-at-point))
bounds beg end)
(if number
(progn
(setq bounds (bounds-of-thing-at-point 'sexp))
(setq beg (car bounds)
end (cdr bounds))
(let ((old-pt (point)))
(delete-region beg end)
(insert (number-to-string (1+ number)))
(goto-char old-pt)))
(user-error "No number found at point"))))
(bind-key "M-=" #'incf-at-point)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment