Function: reftex-extract-bib-entries-from-thebibliography

reftex-extract-bib-entries-from-thebibliography is a byte-compiled function defined in reftex-cite.el.gz.

Signature

(reftex-extract-bib-entries-from-thebibliography FILES)

Documentation

Extract bib-entries from the egin{thebibliography} environment.

Parsing is not as good as for the BibTeX database stuff. The environment should be located in FILES.

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/reftex-cite.el.gz
;; Parse the bibliography environment
(defun reftex-extract-bib-entries-from-thebibliography (files)
  "Extract bib-entries from the \begin{thebibliography} environment.
Parsing is not as good as for the BibTeX database stuff.
The environment should be located in FILES."
  (let* (start end buf entries re re-list file default)
    (unless files
      (error "Need file name to find thebibliography environment"))
    (while (setq file (pop files))
      (setq buf (reftex-get-file-buffer-force
                 file (not reftex-keep-temporary-buffers)))
      (unless buf
        (error "No such file %s" file))
      (message "Scanning thebibliography environment in %s" file)

      (with-current-buffer buf
	(save-excursion
	  (save-restriction
	    (widen)
	    (goto-char (point-min))
	    (while (re-search-forward
		    "\\(\\`\\|[\n\r]\\)[ \t]*\\\\begin{thebibliography}" nil t)
	      (beginning-of-line 2)
	      (setq start (point))
	      (if (re-search-forward
		   "\\(\\`\\|[\n\r]\\)[ \t]*\\\\end{thebibliography}" nil t)
		  (progn
		    (beginning-of-line 1)
		    (setq end (point))))
	      (when (and start end)
		(setq entries
		      (append entries
			      (mapcar #'reftex-parse-bibitem
				      (delete ""
					      (split-string
					       (buffer-substring-no-properties
						start end)
					       "[ \t\n\r]*\\\\bibitem[ \t]*\
\\(\\[[^]]*]\\)*[ \t]*"))))))
	      (goto-char end))))))
    (unless entries
      (error "No bibitems found"))

    ;; Read a regexp, completing on known citation keys.
    (setq default (regexp-quote (reftex-get-bibkey-default)))
    (setq re-list (reftex--query-search-regexps default))

    (if (or (null re-list ) (equal re-list '("")))
        (setq re-list (list default)))

    (if (string-match "\\`[ \t]*\\'" (car re-list))
        (error "Empty regular expression"))

    (while (and (setq re (pop re-list)) entries)
      (setq entries
            (delq nil (mapcar
                       (lambda (x)
                         (if (string-match re (cdr (assoc "&entry" x)))
                             x nil))
                       entries))))
    (setq entries
          (mapcar
            (lambda (x)
              (push (cons "&formatted" (reftex-format-bibitem x)) x)
              (push (reftex-get-bib-field "&key" x) x)
              x)
           entries))

    entries))