Function: bibtex-parse-keys
bibtex-parse-keys is a byte-compiled function defined in bibtex.el.gz.
Signature
(bibtex-parse-keys &optional ABORTABLE VERBOSE)
Documentation
Set bibtex-reference-keys to the keys used in the whole buffer.
Find both entry keys and crossref entries. If ABORTABLE is non-nil abort
on user input. If VERBOSE is non-nil give messages about progress.
Return alist of keys if parsing was completed, aborted otherwise.
If bibtex-parse-keys-fast is non-nil, use fast but simplified algorithm
for parsing BibTeX keys. If parsing fails, try to set this variable to nil.
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/bibtex.el.gz
(defun bibtex-parse-keys (&optional abortable verbose)
"Set `bibtex-reference-keys' to the keys used in the whole buffer.
Find both entry keys and crossref entries. If ABORTABLE is non-nil abort
on user input. If VERBOSE is non-nil give messages about progress.
Return alist of keys if parsing was completed, `aborted' otherwise.
If `bibtex-parse-keys-fast' is non-nil, use fast but simplified algorithm
for parsing BibTeX keys. If parsing fails, try to set this variable to nil."
(if (eq major-mode 'bibtex-mode)
(let (ref-keys crossref-keys)
(save-excursion
(save-match-data
(if verbose
(bibtex-progress-message
(concat (buffer-name) ": parsing reference keys")))
(catch 'userkey
(goto-char (point-min))
(if bibtex-parse-keys-fast
(let ((case-fold-search t)
(re (concat bibtex-entry-head "\\|"
",[ \t\n]*crossref[ \t\n]*=[ \t\n]*"
"\\(\"[^\"]*\"\\|{[^}]*}\\)[ \t\n]*[,})]")))
(while (re-search-forward re nil t)
(if (and abortable (input-pending-p))
;; user has aborted by typing a key: return `aborted'
(throw 'userkey 'aborted))
(cond ((match-end 3)
;; This is a crossref.
(let ((key (buffer-substring-no-properties
(1+ (match-beginning 3)) (1- (match-end 3)))))
(unless (assoc key crossref-keys)
(push (list key) crossref-keys))))
;; We probably have a non-bibtex file.
((not (match-beginning bibtex-type-in-head))
(throw 'userkey nil))
;; only keys of known entries
((assoc-string (bibtex-type-in-head)
bibtex-entry-alist t)
;; This is an entry.
(let ((key (bibtex-key-in-head)))
(unless (assoc key ref-keys)
(push (cons key t) ref-keys)))))))
(let (;; ignore @String entries because they are handled
;; separately by `bibtex-parse-strings'
(bibtex-sort-ignore-string-entries t)
bounds)
(bibtex-map-entries
(lambda (key _beg end)
(if (and abortable
(input-pending-p))
;; user has aborted by typing a key: return `aborted'
(throw 'userkey 'aborted))
(if verbose (bibtex-progress-message))
(unless (assoc key ref-keys)
(push (cons key t) ref-keys))
(if (and (setq bounds (bibtex-search-forward-field "crossref" end))
(setq key (bibtex-text-in-field-bounds bounds t))
(not (assoc key crossref-keys)))
(push (list key) crossref-keys))))))
(dolist (key crossref-keys)
(unless (assoc (car key) ref-keys) (push key ref-keys)))
(if verbose
(bibtex-progress-message 'done))
;; successful operation --> return `bibtex-reference-keys'
(setq bibtex-reference-keys (nreverse ref-keys))))))))