[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: |
Mon, 16 Jan 2017 01:40:16 +0100 |
Hi Arash,
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)
> "Insert a label for NAME at point.
> The optional TYPE argument can be either environment or section:
> in the former case this function looks up `LaTeX-label-alist' to
> choose which prefix to use for the label, in the latter case
> `LaTeX-section-label' will be looked up instead. If TYPE is nil,
> you will be always prompted for a label, with an empty default
> prefix.
>
> If `LaTeX-label-function' is a valid function, LaTeX label will
> transfer the job to this function.
>
> If the optional NO-INSERT is non-nil, only the label is returned
> and no insertion happens. Otherwise the inserted label is
> returned, nil if it is empty."
> (let ((TeX-read-label-prefix
> (cond
> ((eq type 'environment)
> (cdr (assoc name LaTeX-label-alist)))
> ((eq type 'section)
> (if (assoc name LaTeX-section-list)
> (if (stringp LaTeX-section-label)
> LaTeX-section-label
> (and (listp LaTeX-section-label)
> (cdr (assoc name LaTeX-section-label))))
> ""))
> ((null type)
> "")
> (t
> nil)))
> label)
> (when (symbolp TeX-read-label-prefix)
> (setq TeX-read-label-prefix (symbol-value TeX-read-label-prefix)))
> (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'.
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.
> ;; Use completing-read as we do with `C-c C-m \label RET'
> (setq label (TeX-read-label t "What label" t))
> ;; No label or empty string entered?
> (if (or (string= TeX-read-label-prefix label)
> (string= "" label))
> (setq label nil)
> ;; <change>
> ;; If NO-INSERT, return only the label for further
> ;; utilization, otherwise insert \label{label} in the buffer
> (if no-insert
> label
> (insert TeX-esc "label" TeX-grop label TeX-grcl)))
> ;; </change>
> (if label
> (progn
> (LaTeX-add-labels label)
> label)
> nil)))))
Maybe I'm missing something also here, but I think that
--8<---------------cut here---------------start------------->8---
(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)
--8<---------------cut here---------------end--------------->8---
can be safely replaced by
--8<---------------cut here---------------start------------->8---
(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
--8<---------------cut here---------------end--------------->8---
because `label' is the return value of `completing-read', which, up to
the best of my knowledge, always returns a string.
Bye,
Mosè