Created
October 4, 2015 05:25
-
-
Save xuchunyang/bf7d4b9d6e78574cb7e6 to your computer and use it in GitHub Desktop.
Increment number at point by 1.
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
(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