Skip to content

Instantly share code, notes, and snippets.

@ruediger
Last active December 16, 2015 00:09
Show Gist options
  • Save ruediger/5345354 to your computer and use it in GitHub Desktop.
Save ruediger/5345354 to your computer and use it in GitHub Desktop.
renumber-offset
(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