Function: bibtex-search-backward-field

bibtex-search-backward-field is a byte-compiled function defined in bibtex.el.gz.

Signature

(bibtex-search-backward-field NAME &optional BOUND)

Documentation

Search backward to find a BibTeX field of name NAME.

If a syntactically correct field is found, return a pair containing the boundaries of the name and text parts of the field. The search is limited by the optional arg BOUND. If BOUND is t the search is limited by the beginning of the current entry. Do not move point.

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/bibtex.el.gz
(defun bibtex-search-backward-field (name &optional bound)
  "Search backward to find a BibTeX field of name NAME.
If a syntactically correct field is found, return a pair containing
the boundaries of the name and text parts of the field.  The search
is limited by the optional arg BOUND.  If BOUND is t the search is
limited by the beginning of the current entry.  Do not move point."
  (save-match-data
    (if (eq bound t)
        (setq bound (save-excursion (bibtex-beginning-of-entry))))
    (let ((name-part (concat ",[ \t\n]*\\(" name "\\)[ \t\n]*=[ \t\n]*"))
          (case-fold-search t) left right)
      (save-excursion
        ;; the parsing functions are not designed for parsing backwards :-(
        (when (search-backward "," bound t)
          (or (save-excursion
                (when (looking-at name-part)
                  (setq left (list (match-beginning 0) (match-beginning 1)
                                   (match-end 1)))
                  (goto-char (match-end 0))
                  (setq right (bibtex-parse-field-text))))
              (while (and (not right)
                          (re-search-backward name-part bound t))
                (setq left (list (match-beginning 0) (match-beginning 1)
                                 (match-end 1)))
                (save-excursion
                  (goto-char (match-end 0))
                  (setq right (bibtex-parse-field-text)))))
          (if right (cons left right)))))))