Function: reftex-parse-bibtex-entry
reftex-parse-bibtex-entry is an autoloaded and byte-compiled function
defined in reftex-cite.el.gz.
Signature
(reftex-parse-bibtex-entry ENTRY &optional FROM TO RAW)
Documentation
Parse BibTeX ENTRY.
If ENTRY is nil then parse the entry in current buffer between FROM and TO. If RAW is non-nil, keep double quotes/curly braces delimiting fields.
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/reftex-cite.el.gz
;;;###autoload
(defun reftex-parse-bibtex-entry (entry &optional from to raw)
"Parse BibTeX ENTRY.
If ENTRY is nil then parse the entry in current buffer between FROM and TO.
If RAW is non-nil, keep double quotes/curly braces delimiting fields."
(let (alist key start field)
(save-excursion
(save-restriction
(if entry
(progn
(set-buffer (get-buffer-create " *RefTeX-scratch*"))
(fundamental-mode)
(set-syntax-table reftex-syntax-table-for-bib)
(erase-buffer)
(insert entry))
(widen)
(if (and from to) (narrow-to-region from to)))
(goto-char (point-min))
(if (re-search-forward "@\\(\\(?:\\w\\|\\s_\\)+\\)[ \t\n\r]*\
[{(][ \t\n\r]*\\([^ \t\n\r,]+\\)" nil t)
(setq alist
(list
(cons "&type" (downcase (reftex-match-string 1)))
(cons "&key" (reftex-match-string 2)))))
(while (re-search-forward "\\(\\(?:\\w\\|-\\)+\\)[ \t\n\r]*=[ \t\n\r]*"
nil t)
(setq key (downcase (reftex-match-string 1)))
(cond
((= (following-char) ?{)
(cond
(raw
(setq start (point))
(forward-char 1))
(t
(forward-char 1)
(setq start (point))
(condition-case nil
(up-list 1)
(error nil)))))
((= (following-char) ?\")
(cond
(raw
(setq start (point))
(forward-char 1))
(t
(forward-char 1)
(setq start (point))))
(while (and (search-forward "\"" nil t)
(= ?\\ (char-after (- (point) 2))))))
(t
(setq start (point))
(re-search-forward "[ \t]*[\n\r,}]" nil 1)))
;; extract field value, ignore trailing comma if in RAW mode
(let ((stop (if (and raw (not (= (char-after (1- (point))) ?,)))
(point)
(1- (point))) ))
(setq field (buffer-substring-no-properties start stop)))
;; remove extra whitespace
(while (string-match "[\n\t\r]\\|[ \t][ \t]+" field)
(setq field (replace-match " " nil t field)))
(push (cons key field) alist))))
alist))