Function: bib-guess-or-prompt-for-label

bib-guess-or-prompt-for-label is a byte-compiled function defined in bib-cite.el.

Signature

(bib-guess-or-prompt-for-label)

Documentation

Guess from context, or prompt the user for a label command.

Source Code

;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/bib-cite.el
(defun bib-guess-or-prompt-for-label ()
  "Guess from context, or prompt the user for a label command."
  (save-excursion
    (if (not (looking-at "\\\\"))        ;If not on beginning of a command
             (re-search-backward "[\\]"
                                 (save-excursion (beginning-of-line)(point))
                                 t))
    (cond
     ((looking-at bib-ref-regexpc)   ;On \ref, looking for matching \label
      (let ((b (progn (search-forward "{" nil t)(forward-char -1)(point)))
            (e (progn (forward-sexp 1)(point))))
        (concat "\\\\label" (regexp-quote (buffer-substring b e)))))
     ((looking-at "\\\\label{")         ;On \label, looking for matching \ref
      (let ((b (progn (search-forward "{" nil t)(forward-char -1)(point)))
            (e (progn (forward-sexp 1)(point))))
        (concat  bib-ref-regexp (regexp-quote (buffer-substring b e)))))
     (t                                 ;Prompt the user
      (let* ((minibuffer-local-completion-map bib-label-prompt-map)
             (the-alist (create-alist-from-list
                         (cdr (reverse LaTeX-label-list))))
        ;;; LaTeX-label-list example:
        ;;;  '(("label3" "label4")("label1" "label2") nil)
        ;; so let's get rid of that nil part in embedded list.
             (the-name
              (completing-read "Label: " the-alist nil nil nil
                               'LaTeX-find-label-hist-alist)))
        (if (not (equal the-name ""))
            (concat "\\\\label{" (regexp-quote the-name) "}")
          ;; else try to get a \ref
          (setq the-name (completing-read "Ref: " the-alist nil nil nil
                                          'LaTeX-find-label-hist-alist))
          (if (not (equal the-name ""))
              (concat bib-ref-regexpc (regexp-quote the-name) "}")
            nil)))))))