Function: bibtex-completion-at-point-function
bibtex-completion-at-point-function is a byte-compiled function
defined in bibtex.el.gz.
Signature
(bibtex-completion-at-point-function)
Documentation
Compute completion data for BibTeX mode.
For use with completion-at-point-functions.
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/bibtex.el.gz
(defun bibtex-completion-at-point-function ()
"Compute completion data for BibTeX mode.
For use with `completion-at-point-functions'."
(let ((pnt (point))
(case-fold-search t)
(beg (save-excursion
(re-search-backward "[ \t{\"]")
(forward-char)
(point)))
(end (point))
bounds name compl)
(save-excursion
(if (and (setq bounds (bibtex-enclosing-field nil t))
(>= pnt (bibtex-start-of-text-in-field bounds))
(<= pnt (bibtex-end-of-text-in-field bounds)))
(setq name (bibtex-name-in-field bounds t)
compl (cond ((string-equal-ignore-case name "crossref")
;; point is in crossref field
'crossref-key)
((string-equal-ignore-case name "month")
;; point is in month field
bibtex-predefined-month-strings)
;; point is in other field
(t (bibtex-strings))))
(bibtex-beginning-of-entry)
(cond ((setq bounds (bibtex-parse-string t))
;; point is inside a @String key
(cond ((and (>= pnt (nth 1 (car bounds)))
(<= pnt (nth 2 (car bounds))))
(setq compl 'string))
;; point is inside a @String field
((and (>= pnt (bibtex-start-of-text-in-string bounds))
(<= pnt (bibtex-end-of-text-in-string bounds)))
(setq compl (bibtex-strings)))))
;; point is inside a @Preamble field
((setq bounds (bibtex-parse-preamble))
(if (and (>= pnt (bibtex-start-of-text-in-string bounds))
(<= pnt (bibtex-end-of-text-in-string bounds)))
(setq compl (bibtex-strings))))
((and (looking-at bibtex-entry-maybe-empty-head)
;; point is inside a key
(or (and (match-beginning bibtex-key-in-head)
(>= pnt (match-beginning bibtex-key-in-head))
(<= pnt (match-end bibtex-key-in-head)))
;; or point is on empty key
(and (not (match-beginning bibtex-key-in-head))
(= pnt (match-end 0)))))
(setq compl 'key)))))
(cond ((eq compl 'key)
;; Key completion: no cleanup needed.
(list beg end
(lambda (s p a)
(let (completion-ignore-case)
(complete-with-action a (bibtex-global-key-alist) s p)))))
((eq compl 'crossref-key)
;; Crossref key completion.
(let* ((buf (current-buffer)))
(list beg end
(lambda (s p a)
(cond
((eq a 'metadata) '(metadata (category . bibtex-key)))
(t (let ((completion-ignore-case nil))
(complete-with-action
a (bibtex-global-key-alist) s p)))))
:exit-function (bibtex-complete-crossref-cleanup buf))))
((eq compl 'string)
;; String key completion: no cleanup needed.
(list beg end
(lambda (s p a)
(let ((completion-ignore-case t))
(complete-with-action a bibtex-strings s p)))))
(compl
;; String completion.
(list beg end
(lambda (s p a)
(cond
((eq a 'metadata) '(metadata (category . bibtex-string)))
(t (let ((completion-ignore-case t))
(complete-with-action a compl s p)))))
:exit-function (bibtex-complete-string-cleanup compl))))))