[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: Arash Esbati
Subject: Re: [AUCTeX-devel] Automatic adding of label to optional argument
Date: Mon, 16 Jan 2017 23:00:08 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.91

Hi Mosè,

Mosè Giordano <address@hidden> writes:

> 2017-01-13 16:09 GMT+01:00 Arash Esbati <address@hidden>:
>> --8<---------------cut here---------------start------------->8---
>> (defun LaTeX-label (name &optional type no-insert)
>> [...]
>>     (when TeX-read-label-prefix
>>       (if (and (boundp 'LaTeX-label-function)
>>                LaTeX-label-function
>>                (fboundp LaTeX-label-function))
>>           (setq label (funcall LaTeX-label-function name))
> The no-insert argument should be passed to the function and the
> docstring of `LaTeX-label-function' updated accordingly.  This is a
> breaking change, but I guess that for vast majority of users this
> variable is either nil or points to `reftex-label'.

Thanks!  Yes, I can do that once we have it all together.  I also agree

    (and (boundp 'LaTeX-label-function)

is not necessary.

> I suspect this function is starting to show the signs of aging.  This
> `label' variable is not used after the function enters this branch, I
> can't see why there is this is the `setq'.  `reftex-label' takes care
> of adding the inserted label to the list of labels, so I think this
> variable is not needed at all in the rest of function.


    (funcall LaTeX-label-function name)

does the job and this is not needed

    (setq label (funcall LaTeX-label-function name))

>>         ;; Use completing-read as we do with `C-c C-m \label RET'
>>         (setq label (TeX-read-label t "What label" t))

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.

> Maybe I'm missing something also here, but I think that
> (if (or (string= TeX-read-label-prefix label)
>     (string= "" label))
>     (setq label nil)
>   (insert TeX-esc "label" TeX-grop label TeX-grcl))
> (if label
>     (progn
>       (LaTeX-add-labels label)
>       label)
>   nil)
> can be safely replaced by
> (if (or (string= TeX-read-label-prefix label)
>     (string= "" label))
>     (setq label nil)
>   (insert TeX-esc "label" TeX-grop label TeX-grcl)
>   (LaTeX-add-labels label))
> label
> because `label' is the return value of `completing-read', which, up to
> the best of my knowledge, always returns a string.


As where we started, I have added a function `LaTeX-env-label-as-keyval'
to listings.el and also `LaTeX-label' as discussed above for testing.
`LaTeX-env-label-as-keyval' seems to do the job.  It does the job for
the `lstlisting' as part of `LaTeX-env-args' and for a sample env
LstListing in its own function.  As for another test, I also wrote a
style file for breqn.sty to test the function -- both attached.

--8<---------------cut here---------------start------------->8---



Eval this first:
(add-to-list 'LaTeX-label-alist '("lstlisting" . "lst:") t)
(add-to-list 'LaTeX-label-alist '("LstListing" . "lst:") t)
  '(("LstListing" ?l "lst:" "~\\ref{%s}" nil (regexp "[Ll]isting"))))

Copy this:   aboveskip=4pt,caption={Some caption}

\begin{lstlisting}[aboveskip=4pt,caption={Some caption},label={lst:1}]{}{}{}{}{}
Yank `aboveskip=4pt, caption ={Some caption}' when asked for key=vals.
label is appended.

Only with `aboveskip=4pt'

Test with envs from breqn:
  [label={eq:1}] is inserted automatically
where ,label={eq:2} is appended.

Eval the next 2 lines and simply hit RET when `(Optional) What label:' appears

(setq LaTeX-label-function nil)
(LaTeX-label "lstlisting" 'environment)

Now eval (LaTeX-label-list) which contains ("lst:").
--8<---------------cut here---------------end--------------->8---

Any comments welcome.

Best, Arash

Attachment: listings.el
Description: application/emacs-lisp

Attachment: breqn.el
Description: application/emacs-lisp

reply via email to

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