[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [AUCTeX-devel] Automatic adding of label to optional argument
From: |
Arash Esbati |
Subject: |
Re: [AUCTeX-devel] Automatic adding of label to optional argument |
Date: |
Tue, 17 Jan 2017 14:13:13 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.1.91 |
Arash Esbati <address@hidden> writes:
> One thing that occurred to me is `TeX-read-label' adds and empty label,
> i.e. only a prefix like "lst:" to `LaTeX-label-list' -- see below in the
> test doc for an example.
Following up myself, I think I have a solution for this. Borrowing some
code from RefTeX, `TeX-read-label' can be like this:
--8<---------------cut here---------------start------------->8---
(defun TeX-read-label (optional &optional prompt definition)
"snipped"
(let (label valid)
(while (not valid)
(setq label
(completing-read
(TeX-argument-prompt optional prompt "Key")
(LaTeX-label-list) nil nil TeX-read-label-prefix))
;; If we're defining a label, check if it's already defined and
;; ask user for confirmation, otherwise ask again
(cond ((and definition
(assoc label (LaTeX-label-list)))
(ding)
(when (y-or-n-p
(format-message "Label `%s' exists. Use anyway? " label))
(setq valid t)))
(t
(setq valid t))))
;; Only add a newly defined label to list of known one if it is
;; not empty and not equal to `TeX-read-label-prefix', if given
(when (and definition
(not (string-equal "" label))
(if TeX-read-label-prefix
(not (string-equal TeX-read-label-prefix label))
t))
(LaTeX-add-labels label))
;; Return label, can be empty string "", TeX-read-label-prefix
;; only like "fig:" or the real thing like "fig:foo"
label))
--8<---------------cut here---------------end--------------->8---
It works within `TeX-arg-label' and `LaTeX-label' when RefTeX is
disabled. Any comments welcome.
Best, Arash