Function: reftex-renumber-simple-labels
reftex-renumber-simple-labels is an autoloaded, interactive and
byte-compiled function defined in reftex-global.el.gz.
Signature
(reftex-renumber-simple-labels)
Documentation
Renumber all simple labels in the document to make them sequentially.
Simple labels are the ones created by RefTeX, consisting only of the
prefix and a number. After the command completes, all these labels will
have sequential numbers throughout the document. Any references to
the labels will be changed as well. For this, RefTeX looks at the
arguments of any macros which either start or end in the string ref.
This command should be used with care, in particular in multifile
documents. You should not use it if another document refers to this
one with the xr package.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/reftex-global.el.gz
;;;###autoload
(defun reftex-renumber-simple-labels ()
"Renumber all simple labels in the document to make them sequentially.
Simple labels are the ones created by RefTeX, consisting only of the
prefix and a number. After the command completes, all these labels will
have sequential numbers throughout the document. Any references to
the labels will be changed as well. For this, RefTeX looks at the
arguments of any macros which either start or end in the string `ref'.
This command should be used with care, in particular in multifile
documents. You should not use it if another document refers to this
one with the `xr' package."
(interactive)
;; Rescan the entire document
(reftex-access-scan-info 1)
;; Get some insurance
(if (and (reftex-is-multi)
(not (yes-or-no-p "Replacing all simple labels in multiple files is risky. Continue? ")))
(error "Abort"))
;; Make the translation list
(let* ((re-core (concat "\\("
(mapconcat #'cdr reftex-typekey-to-prefix-alist "\\|")
"\\)"))
(label-re (concat "\\`" re-core "\\([0-9]+\\)\\'"))
(search-re (concat "[{,]\\(" re-core "\\([0-9]+\\)\\)[,}]"))
(error-fmt "Undefined label or reference %s. Ignore and continue? ")
(label-numbers-alist (mapcar (lambda (x) (cons (cdr x) 0))
reftex-typekey-to-prefix-alist))
(files (reftex-all-document-files))
(list (symbol-value reftex-docstruct-symbol))
translate-alist n entry label new-label nr-cell changed-sequence)
(while (setq entry (pop list))
(when (and (stringp (car entry))
(string-match label-re (car entry)))
(setq label (car entry)
nr-cell (assoc (match-string 1 (car entry))
label-numbers-alist))
(if (assoc label translate-alist)
(error "Duplicate label %s" label))
(setq new-label (concat (match-string 1 (car entry))
(int-to-string (incf (cdr nr-cell)))))
(push (cons label new-label) translate-alist)
(or (string= label new-label) (setq changed-sequence t))))
(unless changed-sequence
(error "Simple labels are already in correct sequence"))
(reftex-ensure-write-access (reftex-all-document-files))
;; Save all document buffers before this operation
(reftex-save-all-document-buffers)
;; First test to check for errors.
(setq n (reftex-translate
files search-re translate-alist error-fmt 'test))
;; Now the real thing.
(if (yes-or-no-p
(format "Replace %d items at %d places in %d files? "
(length translate-alist) n (length files)))
(progn
(let ((inhibit-quit t)) ;; Do not disturb...
(reftex-translate
files search-re translate-alist error-fmt nil)
(setq quit-flag nil))
(if (and (reftex-is-multi)
(yes-or-no-p "Save entire document? "))
(reftex-save-all-document-buffers))
;; Rescan again...
(reftex-access-scan-info 1)
(message "Done replacing simple labels."))
(message "No replacements done"))))