company-reftex
company-reftex copied to clipboard
Issues setting up company-reftex
Hi, This package seems awesome and I'd love to see it working but am having difficulty.
It seems the package is installed properly, but the appropriate functions are not called when \ref{ or \eqref{ are typed.
If I type M-x c-r-l at \ref{ I do see an autocomplete menu.
Any idea why the autocomplete is not 'auto' in my case?
To try and isolate the issue, I made a virtual machine instance and installed stock Debian 10.8 and got their default emacs (version is 26.1) Here is my .emacs
(require 'package)
(require 'reftex)
(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")
(add-to-list 'package-archives
'("melpa-stable" . "https://melpa.org/packages/") t)
(package-initialize)
(add-hook 'Latex-mode-hook 'turn-on-reftex)
(add-hook 'latex-mode-hook 'turn-on-reftex)
(custom-set-variables
'(package-selected-packages (quote (company-reftex company))))
(custom-set-faces)
(use-package company
:ensure t
:custom
(company-idle-delay 0.0)
:config (global-company-mode 1))
(eval-after-load "company"
'(add-to-list
'company-backends
'company-reftex-labels
'company-reftex-citations))
If someone could provide some tips or a minimal example of a working .emacs that would be very helpful. Thank you!
@thomasflynn918 I can try to help with this.
If I type M-x c-r-l at \ref{ I do see an autocomplete menu.
That would mean that company-reftex
works in general, so that seems good.
Any idea why the autocomplete is not 'auto' in my case?
My hunch is it could be due to company-minimum-prefix-length
. If it is set to the default value of 2
(I think), then you might need to type at least 2 characters after \ref{
or \eqref{
to have it automatically complete. Setting this value to 0
should theoretically work but could be annoying, but anw it seems this was already discussed here: https://emacs.stackexchange.com/questions/12441/is-it-possible-to-start-company-completion-without-a-prefix
Hi, I have facing the same issue with my implementation even with the 2 letter, I guess company-complete is not triggering company-reftex-label ? I have assigned a keybinding to company-complete.
People who experience this, please confirm that you've set the minimum prefix length to 0 as @atreyasha suggested.
I have facing the same issue with my implementation even with the 2 letter, I guess company-complete is not triggering company-reftex-label ? I have assigned a keybinding to company-complete.
@Sparsa do you see citation/label autocompletions when you manually execute company-complete
at the relevant point? If it does not, this would be a separate issue compared to @thomasflynn918 since they still can see an autocompletion menu, just that it is not automatically shown while typing.
In any case, I tested on my local setup and company-reftex
works just fine for me. I would recommend testing the \cite{
environment first rather than the \ref{
environment since the latter might erroneously show no atuocompletion due to reasons cited in #11.
People who experience this, please confirm that you've set the minimum prefix length to 0 as @atreyasha suggested.
I am fine with typing two characters, but for my case, even with two letters (or 4 or 6), it does not show up until I manually call Mx c-r-l.
Also, can anyone share the code about how you are adding this backend to the company-backend list?
(set (make-local-variable 'company-backends) '(company-math-symbols-latex
company-latex-commands company-reftex-labels
company-reftex-citations))
I am using something like this in LaTeX-mode-hook. I turned on company-mode globally, before that in my init.el.
Unfortunately I use spacemacs so I can't provide just a few lines responsible in my config. However, my company-diag
output shows:
company-backends: ((:separate company-reftex-labels company-reftex-citations)
(:separate company-auctex-symbols company-auctex-environments company-capf company-auctex-macros)
(company-semantic company-dabbrev-code company-gtags company-etags company-keywords)
company-files company-dabbrev)
In regards to specific elisp code, maybe something like this:
(setq-local company-backends
(append '((:separate company-reftex-labels company-reftex-citations))
company-backends))
BTW is the issue similar to the following?
https://emacs.stackexchange.com/questions/61065/cant-get-company-reftex-labels-to-work-properly
Yes, actually I think the problem was in the configuration itself, I was thinking of this company-backend as a list, but it can have a hierarchy, just like you have posted, I just made a group and now it works perfectly fine. Thank you for helping me. I am quoting the documentation from M-x customize-variable RET company-reftex-citations
================
An element of ‘company-backends’ can also be a list of backends. The
completions from backends in such groups are merged, but only from those
backends which return the same ‘prefix’.
If a backend command takes a candidate as an argument (e.g. ‘meta’), the
call is dispatched to the backend the candidate came from. In other
cases (except for ‘duplicates’ and ‘sorted’), the first non-nil value among
all the backends is returned.
The group can also contain keywords. Currently, ‘:with’ and ‘:separate’
keywords are defined. If the group contains keyword ‘:with’, the backends
listed after this keyword are ignored for the purpose of the ‘prefix’
command. If the group contains keyword ‘:separate’, the candidates that
come from different backends are sorted separately in the combined list.```
Awesome, glad to hear it worked. Yes company-backends
is IMO a complicated object and it requires some tweaking to get it to cooperate with other backends.
Sorry, emacs beginner here, just wanted to make sure that my solution is acceptable. I had the very same problem as @thomasflynn918 originally reported and @Sparsa used to have. Upon @atreyasha suggestion, I tried replacing
(setq company-backends
'((
company-capf
;; company-tabnine
company-bibtex
company-math-symbols-latex
company-latex-commands
company-math-symbols-unicode
company-reftex-labels
company-reftex-citations
company-yasnippet
company-files
company-ispell
company-dabbrev
)))
in https://emacs.stackexchange.com/a/61081/30026 with
(setq-local company-backends
(append '((:separate company-reftex-labels company-reftex-citations))
company-backends))
This worked great at first, but adding more backends to the list like
(setq-local company-backends
(append '((:separate company-math-symbols-latex company-latex-commands company-math-symbols-unicode company-reftex-labels company-reftex-citations))
company-backends))
made the old problem resurface. But appending backends as follows seems to work:
(setq-local company-backends
(append '((:separate company-math-symbols-latex company-math-symbols-unicode company-latex-commands))
company-backends))
(setq-local company-backends
(append '((:separate company-reftex-labels company-reftex-citations))
company-backends)))
Is this the way to go or is there a cleaner solution?
Hmm I am not sure why this happens, but good to know you found a solution that at least works. To diagnose the problem better, could you provide the following outputs after opening a tex
file or being in the latex-mode
major mode:
- Output of
M-x company-diag
with this in your configuration:
(setq-local company-backends
(append '((:separate company-math-symbols-latex
company-latex-commands
company-math-symbols-unicode
company-reftex-labels
company-reftex-citations))
company-backends))
- Output of
M-x company-diag
with this in your configuration:
(setq-local company-backends
(append '((:separate company-math-symbols-latex
company-math-symbols-unicode
company-latex-commands))
company-backends))
(setq-local company-backends
(append '((:separate company-reftex-labels
company-reftex-citations))
company-backends)))
- Could you check if using this in your
emacs
configuration works? I just reordered the backends.
(setq-local company-backends
(append '((:separate company-reftex-labels
company-reftex-citations
company-math-symbols-latex
company-latex-commands
company-math-symbols-unicode
))
company-backends))
- Are you using base
emacs
or a distribution?
Answers to these might help diagnose the situation better. My hunch is that there is some conflict between the backends, which results in problems when they are all chunked together. Perhaps this is why appending the backends with two separate commands helps.
Hmm I am not sure why this happens, but good to know you found a solution that at least works. To diagnose the problem better, could you provide the following outputs after opening a
tex
file or being in thelatex-mode
major mode:
Gladly! Hope you don't mind me using pastepin, the output is quite long and I couldn't find a collapsible code-block feature.
1. Output of `M-x company-diag` with this in your configuration:
(setq-local company-backends (append '((:separate company-math-symbols-latex company-latex-commands company-math-symbols-unicode company-reftex-labels company-reftex-citations)) company-backends))
https://pastebin.com/aCemrhgx (problem persists)
2. Output of `M-x company-diag` with this in your configuration:
(setq-local company-backends (append '((:separate company-math-symbols-latex company-math-symbols-unicode company-latex-commands)) company-backends)) (setq-local company-backends (append '((:separate company-reftex-labels company-reftex-citations)) company-backends)))
https://pastebin.com/DTEvAuAp (problem fixed)
3. Could you check if using this in your `emacs` configuration works? I just reordered the backends.
(setq-local company-backends (append '((:separate company-reftex-labels company-reftex-citations company-math-symbols-latex company-latex-commands company-math-symbols-unicode )) company-backends))
No, problem still exists.
4. Are you using base `emacs` or a distribution?
I am using GNU Emacs 26.3 in Ubuntu 20.04.2, which I think I installed using apt. I am running Emacs in the terminal via "/usr/bin/emacs -nw".
Answers to these might help diagnose the situation better. My hunch is that there is some conflict between the backends, which results in problems when they are all chunked together. Perhaps this is why appending the backends with two separate commands helps.
Good luck! I wish I could help but Emacs is not my forte. :-/
My bad, I should have mentioned I just needed everything except the completions; which is what makes the output so long.
But in any case, these outputs show that everything in the configuration is being reflected correctly in the company backends; which is a good first check. So indeed the problem is with the grouping of the backends. tl;dr I think your workaround makes sense and I would stick with it as long as it solves your problem.
Sorry I can't share anything useful from my configuration because I use an emacs
distribution. But if you notice the company-backends
in my setup, it also uses two different groups with the :separate
flag:
company-backends: ((:separate company-reftex-labels company-reftex-citations)
(:separate company-auctex-symbols company-auctex-environments company-capf company-auctex-macros)
(company-semantic company-dabbrev-code company-gtags company-etags company-keywords)
company-files company-dabbrev)
If you still feel like investigating further, I could recommend the following:
- Setup your
emacs
with a configuration that reproduces the problem - Open a
tex
file which should theoretically have citation or label candidates, or which showed these candidates when you used a configuration that fixes the problem - Type the relevant keyword such as
\cite{
or\ref{
and place your cursor one character after these keywords; eg.\cite{[cursor-here]
- Execute
M-x company-complete
- Immediately after, execute
M-x company-diag
The important output to look at would be on and after the Used backend
bit. This would tell you which backend was used in this step, what prefix it parsed and what completions it received.