Function: LaTeX-completion-candidates-key-val
LaTeX-completion-candidates-key-val is a byte-compiled function
defined in latex.el.
Signature
(LaTeX-completion-candidates-key-val KEY-VALS)
Documentation
Return completion candidates from KEY-VALS based on buffer position.
KEY-VALS is an alist of key-value pairs.
Source Code
;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/latex.el
(defun LaTeX-completion-candidates-key-val (key-vals)
"Return completion candidates from KEY-VALS based on buffer position.
KEY-VALS is an alist of key-value pairs."
(let ((end (point))
(func (lambda (kv &optional k)
(if k
(cadr (assoc k kv))
kv)))
beg key)
(save-excursion
(re-search-backward "[[{(<,=]" (line-beginning-position 0) t))
(if (string= (match-string 0) "=")
;; We have to look for a value:
(save-excursion
;; Matching the value is easy, just grab everything before the
;; '=' and ...
(re-search-backward "=\\([^=]*\\)" (line-beginning-position) t)
;; ... then move forward over any tabs and spaces:
(save-excursion
(forward-char)
(skip-chars-forward " \t" end)
(setq beg (point)))
;; Matching the key is less fun: `re-search-backward'
;; doesn't travel enough, so we have to use
;; `skip-chars-backward' and limit the search to the
;; beginning of the previous line:
(skip-chars-backward "^,[{<" (line-beginning-position 0))
;; Make sure we're not looking at a comment:
(when (looking-at-p (concat "[ \t]*" TeX-comment-start-regexp))
(forward-line))
;; Now pick up the key, if available:
(setq key (string-trim
(buffer-substring-no-properties (point)
(match-beginning 0))
"[ \t\n\r%]+" "[ \t\n\r%]+"))
;; This caters also for the case where nothing is typed yet:
(list beg end (completion-table-dynamic
(lambda (_)
(funcall func key-vals key)))
:exclusive 'no))
;; We have to look for a key:
(save-excursion
;; Find the beginning
(skip-chars-backward "^,[{<" (line-beginning-position 0))
;; Make sure we're not looking at a comment:
(when (looking-at-p (concat "[ \t]*" TeX-comment-start-regexp))
(forward-line))
;; Now go until the first char or number which would be the
;; start of the key:
(skip-chars-forward "^a-zA-Z0-9" end)
(setq beg (point))
;; This caters also for the case where nothing is typed yet:
(list beg end (completion-table-dynamic
(lambda (_)
(funcall func key-vals)))
:exclusive 'no)))))