Function: reftex-all-used-citation-keys
reftex-all-used-citation-keys is a byte-compiled function defined in
reftex-cite.el.gz.
Signature
(reftex-all-used-citation-keys)
Documentation
Return a list of all citation keys used in document.
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/reftex-cite.el.gz
;;; 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))
(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:
"{\\([^}]+\\)}"))
;; Multicites: Match \MACRONAME(Global Pre)(Global Post)
(re2 (concat "\\\\"
(regexp-opt '("cites" "Cites"
"parencites" "Parencites"
"footcites" "footcitetexts"
"smartcites" "Smartcites"
"textcites" "Textcites"
"supercites"
"autocites" "Autocites"
"volcites" "Volcites"
"pvolcites" "Pvolcites"
"fvolcites" "Fvolcites"
"svolcites" "Svolcites"
"tvolcites" "Tvolcites"
"avolcites" "Avolcites"))
"\\(?:([^)]*)\\)\\{0,2\\}"))
;; For each key in list [prenote][postnote]{key}
(re3 (concat "\\(?:\\[[^]]*\\]\\)\\{0,2\\}"
"{\\([^}]+\\)}"))
file keys kk k)
(save-current-buffer
(while (setq file (pop files))
(set-buffer (reftex-get-file-buffer-force file 'mark))
(save-excursion
(save-restriction
(widen)
(goto-char (point-min))
(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))))))
;; And now search for citation lists:
(goto-char (point-min))
(while (re-search-forward re2 nil t)
;; Make sure we're not inside a comment:
(unless (save-match-data
(nth 4 (syntax-ppss)))
(while (progn
;; Ignore the value of
;; `reftex-allow-detached-macro-args' since we
;; expect a bigger number of args and detaching
;; them seems natural for line breaks:
(while (looking-at "[ \t\r\n]+\\|%.*\n")
(goto-char (match-end 0)))
(and (looking-at re3)
(goto-char (match-end 0))))
(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))