Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reftex label candidates are not automatically refreshed #11

Open
atreyasha opened this issue Mar 15, 2021 · 8 comments · Fixed by #12 · May be fixed by #13
Open

Reftex label candidates are not automatically refreshed #11

atreyasha opened this issue Mar 15, 2021 · 8 comments · Fixed by #12 · May be fixed by #13

Comments

@atreyasha
Copy link
Collaborator

Hi @TheBB,

Quick question pertaining to a feature request. As of now, when I use company-reftex to search for label candidates, I notice that the selection of labels does not get updated after starting my emacs session. To overcome this I normally have to execute reftex-parse-all to manually refresh the selection of labels. Do you or others also experience this issue or is there some easy workaround?

I found this to be the relevant section of code:

;; Labels
(defun company-reftex-label-candidates (prefix)
"Find all label candidates matching PREFIX."
(reftex-access-scan-info)
(cl-loop for entry in (symbol-value reftex-docstruct-symbol)
if (and (stringp (car entry)) (string-prefix-p prefix (car entry)))
collect
(company-reftex-annotate (car entry) (cl-caddr entry))))

I noticed that the following edit on line 229 fixes the issue for me, and would be happy to submit a PR. WDYT?

;; Labels 
  
 (defun company-reftex-label-candidates (prefix) 
   "Find all label candidates matching PREFIX." 
   (reftex-access-scan-info)
   (reftex-parse-all) 
   (cl-loop for entry in (symbol-value reftex-docstruct-symbol) 
            if (and (stringp (car entry)) (string-prefix-p prefix (car entry))) 
            collect 
            (company-reftex-annotate (car entry) (cl-caddr entry)))) 
@TheBB
Copy link
Owner

TheBB commented Mar 16, 2021

So long as it doesn't turn into a performance sink, I don't mind.

@atreyasha
Copy link
Collaborator Author

atreyasha commented Mar 16, 2021

Will experiment to check how it affects performance. If it is fine then I will submit a PR.

atreyasha added a commit that referenced this issue Mar 24, 2021
This commit addresses issue #11 by calling `(reftex-parse-all)` before
searching for label candidates. This ensures that reftex parses all new
labels and loads them before searching using the input prefix
@atreyasha atreyasha linked a pull request Mar 24, 2021 that will close this issue
@atreyasha atreyasha self-assigned this Mar 24, 2021
@TobiasZawada
Copy link

TobiasZawada commented Sep 22, 2022

reftex-parse-all should be put into a customizable hook to make it optional or for replacing it with something better.

An example for a better solution would be to watch input files or compare their modification dates with those from the last scan.

See: https://emacs.stackexchange.com/questions/73745/company-reftex-slow-when-searching-for-labels

@atreyasha
Copy link
Collaborator Author

atreyasha commented Sep 22, 2022

Hi @TobiasZawada. Sorry to hear that #12 caused a performance sink for the OP in Emacs-StackExchange. I would be happy to collaborate on a PR to fix this new issue.

should be put into a customizable hook

This should be possible and fairly straight-forward to implement. As per here, there are two high-level functions for parsing either the current file or the (multifile) document. I could imagine this being part of the hook in our case and perhaps we could even remove the line containing (reftex-access-scan-info) since it is essentially being called twice.

An example for a better solution would be to watch input files or compare their modification dates with those from the last scan.

But before that, I would like to check if the performance sinks are mitigated by using the options specified here: https://www.gnu.org/software/auctex/manual/reftex/Optimizations.html? The descriptions of these options sound somewhat in the direction of your suggestion.

It would also be great if the OP could share a MWE to reproduce the performance sink here.

@atreyasha atreyasha reopened this Sep 23, 2022
@atreyasha atreyasha removed their assignment Sep 23, 2022
atreyasha added a commit that referenced this issue Oct 1, 2022
atreyasha added a commit that referenced this issue Oct 1, 2022
atreyasha added a commit that referenced this issue Oct 1, 2022
@atreyasha atreyasha linked a pull request Oct 1, 2022 that will close this issue
2 tasks
@atreyasha atreyasha linked a pull request Oct 1, 2022 that will close this issue
2 tasks
@atreyasha
Copy link
Collaborator Author

Hi @TobiasZawada. I created a PR (#13) to address the reported issue. Let me know if this and the aforementioned optimizations help with the performance sink.

@zhenhua-wang
Copy link

zhenhua-wang commented Nov 8, 2022

The easiest work-around for me is to perform rescan on save. In this way, we don't need to change company-reftex at all, so there won't be any performance issue.

@atreyasha
Copy link
Collaborator Author

@zhenhua-wang indeed that seems like the best solution. Could you share a snippet of the hook you use for this?

@zhenhua-wang
Copy link

@zhenhua-wang indeed that seems like the best solution. Could you share a snippet of the hook you use for this?

I didn't use hook for this. I simply rebind C-x C-s in reftex-mode-map to

 (defun zw/latex-rescan-on-save ()
    (interactive)
    (reftex-reset-mode)
    (save-buffer))

If you want, you can add-advice around the function save-buffer to achieve similar thing. I just don't want to perform mode checking every time I run save-buffer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants