diff options
Diffstat (limited to 'lisp/textmodes/reftex-cite.el')
-rw-r--r-- | lisp/textmodes/reftex-cite.el | 52 |
1 files changed, 41 insertions, 11 deletions
diff --git a/lisp/textmodes/reftex-cite.el b/lisp/textmodes/reftex-cite.el index 26b14ebc79e..f3f95627af1 100644 --- a/lisp/textmodes/reftex-cite.el +++ b/lisp/textmodes/reftex-cite.el @@ -1116,10 +1116,10 @@ recommended for follow mode. It works OK for individual lookups." (setq bibtype (reftex-bib-or-thebib)) (cond ((eq bibtype 'bib) -; ((assq 'bib (symbol-value reftex-docstruct-symbol)) + ;; ((assq 'bib (symbol-value reftex-docstruct-symbol)) (setq bibfile-list (reftex-get-bibfile-list))) ((eq bibtype 'thebib) -; ((assq 'thebib (symbol-value reftex-docstruct-symbol)) + ;; ((assq 'thebib (symbol-value reftex-docstruct-symbol)) (setq bibfile-list (reftex-uniquify (mapcar #'cdr @@ -1142,8 +1142,35 @@ recommended for follow mode. It works OK for individual lookups." ;;; Global BibTeX file (defun reftex-all-used-citation-keys () + "Return a list of all citation keys used in document." (reftex-access-scan-info) - (let ((files (reftex-all-document-files)) file keys kk k) + ;; FIXME: multicites macros provided by biblatex + ;; are not covered in this function. + (let ((files (reftex-all-document-files)) + (re (concat "\\\\" + "\\(?:" + ;; biblatex volcite macros take these args: + ;; \volcite[prenote]{volume}[pages]{key} + ;; so cater for the first 3 args: + (regexp-opt '("volcite" "Volcite" + "pvolcite" "Pvolcite" + "fvolcite" "ftvolcite" + "svolcite" "Svolcite" + "tvolcite" "Tvolcite" + "avolcite" "Avolcite")) + "\\(?:\\[[^]]*\\]\\)?" + "{[^}]*}" + "\\(?:\\[[^]]*\\]\\)?" + "\\|" + ;; Other cite macros usually go like: + ;; \cite[prenote][postnote]{key} + ;; so cater for the optional args: + "\\(?:bibentry\\|[a-zA-Z]*[Cc]ite[a-zA-Z*]*\\)" + "\\(?:\\[[^]]*\\]\\)\\{0,2\\}" + "\\)" + ;; Now match the key: + "{\\([^}]+\\)}")) + file keys kk k) (save-current-buffer (while (setq file (pop files)) (set-buffer (reftex-get-file-buffer-force file 'mark)) @@ -1151,14 +1178,17 @@ recommended for follow mode. It works OK for individual lookups." (save-restriction (widen) (goto-char (point-min)) - (while (re-search-forward "\\(?:^\\|\\=\\)[^%\n\r]*?\\\\\\(bibentry\\|[a-zA-Z]*cite[a-zA-Z]*\\)\\(\\[[^]]*\\]\\)?{\\([^}]+\\)}" nil t) - (setq kk (match-string-no-properties 3)) - (while (string-match "%.*\n?" kk) - (setq kk (replace-match "" t t kk))) - (setq kk (split-string kk "[, \t\r\n]+")) - (while (setq k (pop kk)) - (or (member k keys) - (setq keys (cons k keys))))))))) + (while (re-search-forward re nil t) + ;; Make sure we're not inside a comment: + (unless (save-match-data + (nth 4 (syntax-ppss))) + (setq kk (match-string-no-properties 1)) + (while (string-match "%.*\n?" kk) + (setq kk (replace-match "" t t kk))) + (setq kk (split-string kk "[, \t\r\n]+")) + (while (setq k (pop kk)) + (or (member k keys) + (setq keys (cons k keys)))))))))) (reftex-kill-temporary-buffers) keys)) |