Skip to content

Instantly share code, notes, and snippets.

@tripleee
Created June 10, 2015 12:10
Show Gist options
  • Save tripleee/bb3036c8575adc945f0b to your computer and use it in GitHub Desktop.
Save tripleee/bb3036c8575adc945f0b to your computer and use it in GitHub Desktop.
Simple Emacs function to renumber tables in a document
(defun renumber-tables (n m)
"Renumber remaining tables starting with index N, adjust by M.
For example, `(renumber-tables 3 -1)` will renumber \"Table 3\" to
\"Table 2\", \"Table 4\" to \"Table 3\", etc."
(interactive "NStart at: \nNAdjust: ")
(save-excursion
(save-match-data
(while (re-search-forward "Table \\([1-9][0-9]*\\)" nil t)
(let ((i (string-to-number (match-string-no-properties 1))))
(when (>= i n)
(replace-match (format "Table %i" (+ i m))) ))) )))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment