135 |
(set (make-local-variable 'TeX-master) master) |
(set (make-local-variable 'TeX-master) master) |
136 |
(erase-buffer) |
(erase-buffer) |
137 |
(insert " MULTIPLE LABELS IN CURRENT DOCUMENT:\n") |
(insert " MULTIPLE LABELS IN CURRENT DOCUMENT:\n") |
138 |
(insert |
(insert |
139 |
" Move point to label and type `r' to run a query-replace on the label\n" |
" Move point to label and type `r' to run a query-replace on the label\n" |
140 |
" and its references. Type `q' to exit this buffer.\n\n") |
" and its references. Type `q' to exit this buffer.\n\n") |
141 |
(insert " LABEL FILE\n") |
(insert " LABEL FILE\n") |
193 |
(not (yes-or-no-p "Replacing all simple labels in multiple files is risky. Continue? "))) |
(not (yes-or-no-p "Replacing all simple labels in multiple files is risky. Continue? "))) |
194 |
(error "Abort")) |
(error "Abort")) |
195 |
;; Make the translation list |
;; Make the translation list |
196 |
(let* ((re-core (concat "\\(" |
(let* ((re-core (concat "\\(" |
197 |
(mapconcat 'cdr reftex-typekey-to-prefix-alist "\\|") |
(mapconcat 'cdr reftex-typekey-to-prefix-alist "\\|") |
198 |
"\\)")) |
"\\)")) |
199 |
(label-re (concat "\\`" re-core "\\([0-9]+\\)\\'")) |
(label-re (concat "\\`" re-core "\\([0-9]+\\)\\'")) |
200 |
(search-re (concat "[{,]\\(" re-core "\\([0-9]+\\)\\)[,}]")) |
(search-re (concat "[{,]\\(" re-core "\\([0-9]+\\)\\)[,}]")) |
227 |
(reftex-save-all-document-buffers) |
(reftex-save-all-document-buffers) |
228 |
|
|
229 |
;; First test to check for erros |
;; First test to check for erros |
230 |
(setq n (reftex-translate |
(setq n (reftex-translate |
231 |
files search-re translate-alist error-fmt 'test)) |
files search-re translate-alist error-fmt 'test)) |
232 |
|
|
233 |
;; Now the real thing. |
;; Now the real thing. |
234 |
(if (yes-or-no-p |
(if (yes-or-no-p |
235 |
(format "Replace %d items at %d places in %d files? " |
(format "Replace %d items at %d places in %d files? " |
236 |
(length translate-alist) n (length files))) |
(length translate-alist) n (length files))) |
237 |
(progn |
(progn |
249 |
|
|
250 |
(defun reftex-translate (files search-re translate-alist error-fmt test) |
(defun reftex-translate (files search-re translate-alist error-fmt test) |
251 |
;; In FILES, look for SEARCH-RE and replace match 1 of it with |
;; In FILES, look for SEARCH-RE and replace match 1 of it with |
252 |
;; its association in TRANSLATE-ALSIT. |
;; its association in TRANSLATE-ALSIT. |
253 |
;; If we do not find an association and TEST is non-nil, query |
;; If we do not find an association and TEST is non-nil, query |
254 |
;; to ignore the problematic string. |
;; to ignore the problematic string. |
255 |
;; If TEST is nil, it is ignored without query. |
;; If TEST is nil, it is ignored without query. |
256 |
;; Return the number of replacements. |
;; Return the number of replacements. |
257 |
(let ((n 0) file label match-data buf macro pos cell) |
(let ((n 0) file label match-data buf macro pos cell) |
277 |
(or (looking-at "\\\\ref") |
(or (looking-at "\\\\ref") |
278 |
(looking-at "\\\\[a-zA-Z]*ref\\(range\\)?[^a-zA-Z]") |
(looking-at "\\\\[a-zA-Z]*ref\\(range\\)?[^a-zA-Z]") |
279 |
(looking-at "\\\\ref[a-zA-Z]*[^a-zA-Z]") |
(looking-at "\\\\ref[a-zA-Z]*[^a-zA-Z]") |
280 |
(looking-at (format |
(looking-at (format |
281 |
reftex-find-label-regexp-format |
reftex-find-label-regexp-format |
282 |
(regexp-quote label))))) |
(regexp-quote label))))) |
283 |
;; OK, we should replace it. |
;; OK, we should replace it. |