karthink / consult-reftex

21 stars 3 forks source link

Feature Request: Allow `reftex-ref-style-alist` for references command candidates #1

Open Hugo-Heagren opened 2 years ago

Hugo-Heagren commented 2 years ago

First off, great package. This is such a great idea, and I'm really pleased to see people using consult-based interfaces for more stuff. And reftex's interface really needed an overhaul!

At the moment, the list of commands which can be used for references is hard-coded to \ref, \Ref, \eqr, \aut, \pag and \aut. This is non-ideal for a couple of reasons:

I think the solution is to parse and use reftex-ref-style-alist to provide the list. This (within reftex) has a well-established method for adding new items. It even organised with categorisation, so we could use a consult--multi based function to select the command. By definition, it also links up with reftex.

I'd be happy to submit a PR if you like this idea!

(I've been using this package for about a week, and I'm going of raise a fair few issues, mostly feature requests. Unless I explicitly say otherwise, you can assume I'm always happy to submit a PR for what I suggest.)

karthink commented 2 years ago

Hi @Hugo-Heagren, thanks for the interest!

I don't have time to work on this package right now, but I'll go through all your feature suggestions in the next few days and note some thoughts. PRs are welcome, but please hold off working on it until I have a chance to read through the suggestions carefully.

karthink commented 2 years ago

I think the solution is to parse and use reftex-ref-style-alist to provide the list.

Implemented partially in f11ead66. reftex-ref-style-alist is used to populate the list of reference styles. However the annotations are still hard coded. Reftex does not provide descriptions for each (at least I couldn't find any).

If you have a better idea of how to handle this, please let me know.

Hugo-Heagren commented 2 years ago

Thanks! I pulled the latest version but the commit broke it for me. It I try to insert a reference, I get a circular list error. This is because my reftex-ref-style-alist is circularly defined (I have no idea why...). Even stranger, this error only shows up the second time I run consult-reftex-insert-reference. Value shown below:

(("Default" t
  (("\\ref" 13)
   ("\\Ref" 82)
   ("\\footref" 110)
   ("\\pageref" 112)
   . #1=(("\\autoref" 97)
     ("\\autopageref" 117)
     . #2=(("\\cref" 99)
           ("\\Cref" 67)
           ("\\cpageref" 100)
           ("\\Cpageref" 68)
           . #1#))))
 ("Varioref" "varioref"
  (("\\vref" 118)
   ("\\Vref" 86)
   ("\\vpageref" 103)))
 ("Fancyref" "fancyref"
  (("\\fref" 102)
   ("\\Fref" 70)))
 ("Hyperref" "hyperref" #1#)
 ("Cleveref" "cleveref" #2#)
 ("AMSmath" "amsmath"
  (("\\eqref" 101))))

My reftex setup is also pretty orthodox, so I think this is probably not an unusual edge case:

(use-package reftex
  :after tex
  :hook (TeX-mode . turn-on-reftex)
  :custom
  (reftex-cite-format 'biblatex)
  (reftex-plug-into-AUCTeX t)
  (reftex-trust-label-prefix t))

I traced the errors a bit and the problem is in assigning reference in consult-reftex-insert-reference with this map:

(mapcar (lambda (style)
          (concat (car style) "{" label "}"))
        (consult-reftex-active-styles))

This is trying to map over the whole of a circular list, which of course is impossible. I'm not sure how it could be solved, but I thought I'd raise the issue.

karthink commented 2 years ago

This is because my reftex-ref-style-alist is circularly defined

Well I'm stumped.

This is trying to map over the whole of a circular list, which of course is impossible. I'm not sure how it could be solved, but I thought I'd raise the issue.

I'll try checking the reftex source to see how it's handled there.

karthink commented 2 years ago

The more I look into this, the more I'm convinced the circular list is an error. With a circularly defined reftex-ref-style-alist, I can't even get the built-in reftex-reference to work. Something's wrong.

Hugo-Heagren commented 2 years ago

The more I look into this, the more I'm convinced the circular list is an error. With a circularly defined reftex-ref-style-alist, I can't even get the built-in reftex-reference to work. Something's wrong.

Alright, that's good to know. I'll try to fix it at my end, and post a report if I do. Thanks!

swflint commented 6 months ago

I think it's the use of mapcan, which modifies the underlying structure (uses nconc) as determined by (reftex-ref-style-list), which may be the value of reftex-ref-style-alist. Fixing that seems to fix the problem on my end.