Last active
December 16, 2015 00:09
-
-
Save ruediger/5345354 to your computer and use it in GitHub Desktop.
renumber-offset
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 renumber-offset (&optional offset regex subexp) | |
"Add OFFSET to any number matching REGEXP. | |
If OFFSET is nil then 1 is chosen. | |
If REGEXP is nil then only numbers at the beginning of line are replaced. | |
SUBEXP can be used to give the number of the subexp of REGEX." | |
(interactive "p") | |
(setq offset (or offset 1)) | |
(setq regex (or regex "^[[:digit:]]+")) | |
(save-excursion | |
(goto-char (point-min)) | |
(while (re-search-forward "^[[:digit:]]+" nil t) | |
(replace-match (number-to-string | |
(+ offset (string-to-number | |
(match-string-no-properties (or subexp 0))))) | |
nil t nil subexp)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment