Function: bibtex-find-text-internal

bibtex-find-text-internal is a byte-compiled function defined in bibtex.el.gz.

Signature

(bibtex-find-text-internal &optional NOERROR SUBFIELD COMMA)

Documentation

Find text part of current BibTeX field or entry head.

Return list (NAME START-TEXT END-TEXT END STRING-CONST) with field name or entry type, start and end of text, and end of field or entry head. STRING-CONST is a flag which is non-nil if current subfield delimited by # is a BibTeX string constant. Return value is nil if field or entry head are not found. If optional arg NOERROR is non-nil, an error message is suppressed if text is not found. If optional arg SUBFIELD is non-nil START-TEXT and END-TEXT correspond to the current subfield delimited by #. Optional arg COMMA is as in bibtex-enclosing-field.

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/bibtex.el.gz
(defun bibtex-find-text-internal (&optional noerror subfield comma)
  "Find text part of current BibTeX field or entry head.
Return list (NAME START-TEXT END-TEXT END STRING-CONST) with field name
or entry type, start and end of text, and end of field or entry head.
STRING-CONST is a flag which is non-nil if current subfield delimited by #
is a BibTeX string constant.  Return value is nil if field or entry head
are not found.
If optional arg NOERROR is non-nil, an error message is suppressed
if text is not found.  If optional arg SUBFIELD is non-nil START-TEXT
and END-TEXT correspond to the current subfield delimited by #.
Optional arg COMMA is as in `bibtex-enclosing-field'."
  (save-excursion
    (let ((pnt (point))
          (bounds (bibtex-enclosing-field comma t))
          (case-fold-search t)
          name start-text end-text end failure done no-sub string-const)
      (bibtex-beginning-of-entry)
      (cond (bounds
             (setq name (bibtex-name-in-field bounds t)
                   start-text (bibtex-start-of-text-in-field bounds)
                   end-text (bibtex-end-of-text-in-field bounds)
                   end (bibtex-end-of-field bounds)))
            ;; @String
            ((setq bounds (bibtex-parse-string t))
             (if (<= pnt (bibtex-end-of-string bounds))
                 (setq name "@String" ;; not a field name!
                       start-text (bibtex-start-of-text-in-string bounds)
                       end-text (bibtex-end-of-text-in-string bounds)
                       end (bibtex-end-of-string bounds))
               (setq failure t)))
            ;; @Preamble
            ((setq bounds (bibtex-parse-preamble))
             (if (<= pnt (bibtex-end-of-string bounds))
                 (setq name "@Preamble" ;; not a field name!
                       start-text (bibtex-start-of-text-in-string bounds)
                       end-text (bibtex-end-of-text-in-string bounds)
                       end (bibtex-end-of-string bounds))
               (setq failure t)))
            ;; BibTeX head
            ((looking-at bibtex-entry-maybe-empty-head)
             (goto-char (match-end 0))
             (if comma (save-match-data
                         (re-search-forward "\\=[ \t\n]*," nil t)))
             (if (<= pnt (point))
                 (setq name (match-string-no-properties bibtex-type-in-head)
                       start-text (or (match-beginning bibtex-key-in-head)
                                 (match-end 0))
                       end-text (or (match-end bibtex-key-in-head)
                               (match-end 0))
                       end end-text
                       no-sub t) ; subfields do not make sense
               (setq failure t)))
            (t (setq failure t)))
      (when (and subfield (not failure))
        (setq failure no-sub)
        (unless failure
          (goto-char start-text)
          (while (not done)
            (if (or (prog1 (looking-at bibtex-field-const)
                      (setq end-text (match-end 0)
                            string-const t))
                    (prog1 (setq bounds (bibtex-parse-field-string))
                      (setq end-text (cdr bounds)
                            string-const nil)))
                (progn
                  (if (and (<= start-text pnt) (<= pnt end-text))
                      (setq done t)
                    (goto-char end-text))
                  (if (looking-at "[ \t\n]*#[ \t\n]*")
                      (setq start-text (goto-char (match-end 0)))))
              (setq done t failure t)))))
      (cond ((not failure)
             (list name start-text end-text end string-const))
            ((and no-sub (not noerror))
             (user-error "Not on text part of BibTeX field"))
            ((not noerror) (user-error "Not on BibTeX field"))))))