[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [AUCTeX-devel] Automatic adding of label to optional argument

From: Mosè Giordano
Subject: Re: [AUCTeX-devel] Automatic adding of label to optional argument
Date: Wed, 18 Jan 2017 11:13:51 +0100

Hi Arash,

2017-01-17 14:13 GMT+01:00 Arash Esbati <address@hidden>:
> 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---

So are you transferring part of the job currently done by
`LaTeX-label' to `TeX-read-label'?  Asked just to understand what
you're doing, looks good anyway.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]