abo-abo / swiper

Ivy - a generic completion frontend for Emacs, Swiper - isearch with an overview, and more. Oh, man!
https://oremacs.com/swiper/
2.3k stars 338 forks source link

The problem of autocompletion with an incremental drop down menu for auctex based on ivy on Ubuntu 20.04. #2887

Closed hongyi-zhao closed 3 years ago

hongyi-zhao commented 3 years ago

On Ubuntu 20.04, I'm using latest git master version of Emacs/auctex/swiper, with the straight as the Emacs package manager. The auctex and swiper/ivy are bootstrapped as below via straight:

(straight-use-package
 `( auctex :type git :host nil :repo "https://git.savannah.gnu.org/git/auctex.git"
    :pre-build ,(pcase system-type
                (`berkeley-unix '("gmake"))
                (_ '(
                    ;("bash" "-c" "cd ~/.emacs.d/straight/repos/auctex")
                    ("./autogen.sh")
                    ("./configure")
                    ("make")
                    ("sudo" "make" "install"))))))

(load "auctex.el" nil t t) 
(load "preview-latex.el" nil t t)
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master nil)

(straight-use-package
 `( swiper :type git :host github :repo "abo-abo/swiper"
    :pre-build (
               ;("bash" "-c" "cd ~/.emacs.d/straight/repos/swiper")
               ;https://github.com/abo-abo/swiper/issues/2886#issuecomment-860562001
               ("make" "deps")
               ("make" "compile")
               )))

;(add-to-list 'load-path "~/.emacs.d/straight/repos/swiper/")
(require 'ivy)
(ivy-mode 1)
(setq ivy-use-virtual-buffers t)
(setq ivy-count-format "(%d/%d) ")                   

Then I test my above configurations with a minimal LaTeX file as shown below:

\documentclass{paper}
\usepackage{hyperref}
\begin{document}
   Some testings come here.
\end{document}

I find the following problems:

  1. The incremental drop down menu only won't be triggered at all, till I hit the macro completion shortcut, i.e., C-M-i.
  2. Some commands, say, `\href', will not be automatically completed at all, even when I hit the macro completion shortcut, i.e., C-M-i.

But TeXstudio doesn't have all the above-mentioned disadvantages, see the following screenshot taken from it for more detailed info.

image

basil-conto commented 3 years ago

The incremental drop down menu only won't be triggered at all, till I hit the macro completion shortcut, i.e., C-M-i.

That's expected. Ivy doesn't provide any automatic "drop down menus". For that there's e.g. company-mode: https://company-mode.github.io/

Some commands, say, `\href', will not be automatically completed at all, even when I hit the macro completion shortcut, i.e., C-M-i.

That probably means you haven't initialised/activated auctex properly. I'm not familiar with straight, but with the built-in package manager you would just M-x package-initialize RET to activate the auctex package if it's already installed.

Here's what I did:

  1. cat << EOF > /tmp/foo.tex
    \documentclass{paper}
    \usepackage{hyperref}
    \begin{document}
    some testings comes here.
    \end{document}
    EOF
  2. cd "$(mktemp -d)"
  3. HOME="$PWD" XDG_CONFIG_HOME="$PWD/.config" emacs -Q
  4. M-x package-install RET auctex RET
  5. M-x package-install RET ivy RET
  6. M-x ivy-mode RET
  7. C-x C-f /tmp/foo.tex RET
  8. C-s . RET RET \hr C-M-i

2021-06-14-123800_229x159_scrot

Since this issue doesn't seem related to Ivy, I'm closing it for now, but I'm still happy to answer questions if I can.

hongyi-zhao commented 3 years ago

That's expected. Ivy doesn't provide any automatic "drop down menus". For that there's e.g. company-mode: https://company-mode.github.io/

Thank you for letting me know this. I add the follownig code snippet into my ~/.emacs.d/init.el:

(use-package company)
(add-hook 'after-init-hook 'global-company-mode)

Now I obtain the same result with yours as shown below, but according to my try, the command to trigger the "drop-down menu" is like this: C-s . RET \hr C-M-i.

image

Furthermore, what I really want is that once I start typing commands, the incremental drop-down menu should be triggered automatically immediately and the candidate results should be narrowed as the input sequence increases without invoking the command used in step 8 over and over again. To summarize, below is the drop-down menu that is triggered when only one command character is entered, and it should be gradually and precisely filtered as the input sequence grows:

image

Can this be done?

Since this issue doesn't seem related to Ivy, I'm closing it for now, but I'm still happy to answer questions if I can.

Thank you for your sincere help and technical exquisite guidance.

Another thing I want to know is how to let Emacs show tooltip like the following given by TeXstudio:

image

Regards, HY

basil-conto commented 3 years ago

Can this be done?

That's what company-mode does, AFAIK. I don't use it, though, so I can't help you configure it, sorry.

Another thing I want to know is how to let Emacs show tooltip like the following given by TeXstudio:

Sorry, I'm not aware of any packages that currently do that. If there aren't any, maybe you can be the first to write one ;).

hongyi-zhao commented 3 years ago

That's what company-mode does,

Then, what's the relationship between company-mode and swiper/ivy?

I filed an issue here.

Sorry, I'm not aware of any packages that currently do that.

This seems to be the exact same thing being discussed here.

If there aren't any, maybe you can be the first to write one ;).

If so, maybe I really will do that someday ;-).

basil-conto commented 3 years ago

Then, what's the relationship between company-mode and swiper/ivy?

None, except for both being completion-related. Again, I'm not that familiar with company-mode, but AFAIK it supports different frontends and backends, so I guess Ivy could be used as a frontend and e.g. Counsel functions as backends, or something like that.

hongyi-zhao commented 3 years ago

Have you noticed my latest comments here? It seems to me that the LSP based solution maybe a preferable method over the tricks discussed here. However, TBF, I haven't achieved a feasible configuration based on this method so far.

basil-conto commented 3 years ago

It seems to me that the LSP based solution maybe a preferable method over the tricks discussed here.

Sure, whatever works for you.

I sometimes use the Eglot [1][2] LSP client with the Digestif [3] server.

I've yet to compare it to the TexLab [4] server, I guess because Debian's version of rustc is too old to compile it.

[1] https://elpa.gnu.org/devel/eglot.html [2] https://elpa.gnu.org/packages/eglot.html [3] https://github.com/astoff/digestif [4] https://github.com/latex-lsp/texlab

However, TBF, I haven't achieved a feasible configuration based on this method so far.

What have you tried? All I do after installing eglot, auctex, and digestif is:

(with-eval-after-load 'tex
  (define-key TeX-mode-map [remap TeX-complete-symbol] #'completion-at-point))

auctex changes the default binding of C-M-i to an auctex-specific completion command. Since I want eglot LSP-based completion, the snippet above restores the default binding of C-M-i.

Then when I visit a LaTeX file I just M-x eglot RET and everything works OOTB! :)

hongyi-zhao commented 3 years ago

Thank you for sharing valuable experience. I'll try it as soon as possible.

What have you tried?

I give a cursory look at some related packages, including digestif, texlab, lsp-mode[1], lsp-ivy, and spacemacs, but still can't figure out a workable setting from scratch. It seems to me that the lsp-mode is an indispensable component for this feature, but your above-mentioned configuration don't use it at all. This is a complicated configuration field for Emacs, my understanding is far less comprehensive enough.

[1] For lsp-mode relevant (La)TeX supporting capability, refer to the following instructions for more detailed info:

https://emacs-lsp.github.io/lsp-mode/page/lsp-tex/ https://emacs-lsp.github.io/lsp-mode/page/lsp-texlab/ https://emacs-lsp.github.io/lsp-mode/page/lsp-latex/

basil-conto commented 3 years ago

It seems to me that the lsp-mode is an indispensable component for this feature, but your above-mentioned configuration don't use it all.

That's because I use the simpler eglot from GNU ELPA (the official Emacs package archive) in place of the larger lsp-mode from MELPA (the popular community archive).

My understanding is that lsp-mode is quite capable and popular, but I always prefer solutions that are as built-in or integrated as possible, and eglot suits all my needs OOTB :). One day it may even be built into vanilla Emacs.

hongyi-zhao commented 3 years ago

Then when I visit a LaTeX file I just M-x eglot RET and everything works OOTB! :)

Wonderful. I have successfully completed the corresponding configuration according to your above guidance. I describe the detailed steps used by me as below:

  1. Install digestif according to the instruction here:
$ git clone https://github.com/astoff/digestif.git digestif.git
$ cd digestif.git/scripts
# Bootstrap digestif with the self-installing wrapper script.
$ ./digestif
# Place it in your $PATH
$ ln -sfr digestif ~/.local/bin
  1. For Emacs with the Eglot package relative configurations: installation and setting of Emacs, auctex, Eglot, and relevant packages through straight:
(straight-use-package
 `( auctex :type git :host nil :repo "https://git.savannah.gnu.org/git/auctex.git"
    :pre-build ,(pcase system-type
                (`berkeley-unix '("gmake"))
                (_ '(
                    ;("bash" "-c" "cd ~/.emacs.d/straight/repos/auctex")
                    ("./autogen.sh")
                    ("./configure")
                    ("make")
                    ("sudo" "make" "install"))))))

(load "auctex.el" nil t t) 
(load "preview-latex.el" nil t t)
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master nil)

(use-package company)
(add-hook 'after-init-hook 'global-company-mode)

(use-package yasnippet)
(require 'yasnippet)
(yas-reload-all)
(add-hook 'prog-mode-hook #'yas-minor-mode)

(use-package eglot)

; Based on my tries, whether the following settings are made or not will not affect the final use.
;(with-eval-after-load 'tex
;  (define-key TeX-mode-map [remap TeX-complete-symbol] #'completion-at-point))

Open some TeX document and enable Eglot (M-x eglot). Voilà! See the following screenshot for detailed info:

image

I also tried to test the Emacs with the lsp-mode package as described here but failed to trigger the completion at all. The settings used by me is shown below:

(use-package lsp-mode)
(use-package company-lsp)
(require 'company-lsp)
(push 'company-lsp company-backends)
(add-to-list 'company-lsp-filter-candidates '(digestif . nil))
astoff commented 3 years ago

auctex changes the default binding of C-M-i to an auctex-specific completion command.

This surely has a good historical reason to be so, but at this point AUCTeX should probably be providing a simple completion-at-point function instead...

astoff commented 3 years ago

I've yet to compare it to the TexLab [4] server, I guess because Debian's version of rustc is too old to compile it.

I've never done that comparison (I'm the author of Digestif), so I would be curious to know about your findings. TexLab is a much bigger project in terms of lines of code and dependencies, but I can't see that difference reflected in their feature list.

basil-conto commented 3 years ago

auctex changes the default binding of C-M-i to an auctex-specific completion command.

This surely has a good historical reason to be so,

Yes, namely that completion-at-point didn't always exist, IIUC.

but at this point AUCTeX should probably be providing a simple completion-at-point function instead...

It already does, which is why simply rebinding C-M-i works regardless of Eglot. See (info "(auctex) Completion").

I would be curious to know about your findings.

Okay, but don't hold your breath ;). I probably won't even bother trying to install TexLab until it's easier to do so on Debian, since Digestif already suits my (limited) LaTeX needs.

I can't see that difference reflected in their feature list.

Glad to hear I'm not missing out :). Thanks!