Created
November 27, 2009 13:58
-
-
Save gongo/244029 to your computer and use it in GitHub Desktop.
バッファ内で、カーソルの位置にある数字列をインクリメント(もしくは引数に指定した数字を加算)する
This file contains 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 increment-string-as-number (number) | |
"Replace progression string of the position of the cursor | |
by string that added NUMBER. | |
Interactively, NUMBER is the prefix arg. | |
examle: | |
At the cursor string \"12\" | |
M-x increment-string-as-number ;; replaced by \"13\" | |
C-u 10 M-x increment-string-as-number ;; replaced by \"22\" | |
At the cursor string \"-12\" | |
M-x increment-string-as-number ;; replaced by \"-11\" | |
C-u 100 M-x increment-string-as-number ;; replaced by \"88\"" | |
(interactive "P") | |
(let ((col (current-column)) | |
(p (if (integerp number) number 1))) | |
(skip-chars-backward "-0123456789") | |
(or (looking-at "-?[0123456789]+") | |
(error "No number at point")) | |
(replace-match | |
(number-to-string (+ p (string-to-number (match-string 0))))) | |
(move-to-column col))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment