Rens Oliemans <[email protected]> writes:

> Ah, I found something interesting. The \begin{lstlisting}[label=...]
> environment adds the label to the "listing" type, found in RefTeX when
> pressing 'l' for the Label Type prompt, I was used to that. In this
> case, however, the \lstinputlisting[label=...] label seems to be added
> to the "section" Label Type, found when pressing 's' or ' '. So I can
> find it with 'C-c ) RET SPACE' or 'C-c ) RET s'.

I admit this is also what I did, i.e., hitting ' ' for all labels and
not 'l', but you're right.  In theory, it should be enough to do this in
your init file:

--8<---------------cut here---------------start------------->8---
(setq reftex-label-alist
      '(("\\lstinputlisting[]{}" ?l "lst:" "~\\ref{%s}" 2
         (regexp "[Ll]isting"))))
--8<---------------cut here---------------end--------------->8---

But I couldn't get it working, can't tell why.

> Thanks, this helps a bunch!

You're welcome.

> I hadn't tried that yet since I was still mindlessly pressing 'l' to
> see the listing type labels. I might need to change my working method
> somewhat, since I usually press 'l' to see all listings, and now I
> might need to press ' ' and find the label in a bit more noise.

Yes, this is unfortunate, but I don't have a solution right now.

> Pressing SPACE errors and gives "[No match]", even though I can find
> it via (reftex-reference). So, the *RefTeX Select* buffer only occurs
> via 'C-c ) RET', or (reftex-reference), which seems different from
> you.

It seems you don't plug RefTeX into AUCTeX.

> This is all for Emacs version
>      
>      GNU Emacs 29.4 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.43, 
> cairo version 1.18.2)

Ok, thanks.

> I usually install auctex via straight.el, like this:
>
> (use-package auctex
>   :straight t
>   ...
>   :hook
>   (LaTeX-mode . reftex-mode))

Delete the last form and try something like this:

  (use-package reftex
    :hook
    ((LaTeX-mode Texinfo-mode) . turn-on-reftex)
    :custom
    (reftex-plug-into-AUCTeX t))

This should activate RefTeX properly inside AUCTeX.

> Hope this helps a bit. At least I can continue, reftex seems to find
> the listing label, I just assumed that it would add it to the listing
> type, but how could it know that via just the regexp? Thanks!

See above.

Best, Arash

Reply via email to