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

Failed to activate company-math and company-ispell when using eglot, texlab, and company. #708

Closed
hongyi-zhao opened this issue Jun 25, 2021 · 10 comments

Comments

@hongyi-zhao
Copy link

On Ubuntu 20.04, I use the self-compiled git master version of Emacs and the following configuration to do the testing:

;;Bootstrap straight
(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 5))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))
(straight-use-package 'use-package)
(setq straight-use-package-by-default t)


;Using AUCTeX from local Git repo without installation
;https://github.com/raxod502/straight.el/issues/800#issuecomment-862165317
(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" ,(straight--repos-dir "auctex"))
                    ("./autogen.sh")
                    ("./configure" "--without-texmf-dir" "--with-lispdir=.") 
                    ("make")
                    )))))

     (setq TeX-data-directory (straight--repos-dir "auctex")
           TeX-lisp-directory TeX-data-directory)                   
    
; Or set the following variable via custom-set-variables in the opened buffer by the following command.
; M-x describe-variable RET preview-TeX-style-dir RET
;`(preview-TeX-style-dir ,(concat ".:" (straight--repos-dir "auctex") "latex:"))
(setq preview-TeX-style-dir (concat ".:" (straight--repos-dir "auctex") "latex:"))

(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 eglot
  :hook 
  ((TeX-mode . eglot-ensure))
  :config
  ;  (setq eglot-confirm-server-initiated-edits nil)

  ;;; ensure we don't use digestif server, which is far less than texlab on features and characteristics.
  ;(delete (assoc '(tex-mode context-mode texinfo-mode bibtex-mode)
  ;               eglot-server-programs) eglot-server-programs)

  ;;; ensure texlab is set as the server.
  (add-to-list 'eglot-server-programs
             '((latex-mode tex-mode context-mode texinfo-mode bibtex-mode) . ("texlab"))))

(use-package company
  :hook
  (TeX-mode . company-mode)
  :custom
  ;https://github.com/company-mode/company-mode/issues/14#issuecomment-290261406
  ; Do not downcase the returned candidates automatically
  (company-dabbrev-downcase nil) 
  (company-idle-delay 0) 
  (company-minimum-prefix-length 1))

(use-package company-math)
(defun my-latex-mode-setup ()
  (setq-local company-math-allow-unicode-symbols-in-faces (quote (tex-math font-latex-math-face)))

  (setq-local company-backends
               (append '((company-math-symbols-latex
                          company-math-symbols-unicode
                          company-latex-commands 
                          company-capf
                          company-ispell
;                          company-abbrev
;                          company-bbdb
;                          company-dabbrev
;                          company-dabbrev-code
;                          company-files
;                          company-keywords
;                          company-semantic
                           ))
                       company-backends)))
(add-hook 'LaTeX-mode-hook 'my-latex-mode-setup)

But I find that the above configuration failed to activate the company-math and company-ispell for LaTeX environment, as shown below:

image

Any hints for this problem?

Regards,
HY

@dgutov
Copy link
Collaborator

dgutov commented Jun 25, 2021

Diag shows that company-backends is set to a different value: (company-capf).

Why? Probably because Eglot changes its value.

Try (add-to-list 'eglot-stay-out-of 'company).

@joaotavora
Copy link
Owner

Try (add-to-list 'eglot-stay-out-of 'company).

Yes, this is the correct action. Be aware you're now responsible for managing company-capf in the company-backends list, Eglot is no longer managing that part of the buffer for you.

@hongyi-zhao
Copy link
Author

Thanks a lot. I try to use the following configuration, and it really does the trick:

(use-package eglot
  :hook 
  ((TeX-mode . eglot-ensure))
  :config
  (add-to-list 'eglot-stay-out-of 'company)
  (add-to-list 'eglot-server-programs
             '((latex-mode tex-mode context-mode texinfo-mode bibtex-mode) . ("texlab"))))

image

@dgutov
Copy link
Collaborator

dgutov commented Jun 25, 2021

@joaotavora BTW, now that company-clang is behind company-capf in company-backends by default, you can probably remove this change of settings: Eglot should work well with the default config.

@joaotavora
Copy link
Owner

If you happen to use Eglot + other servers, this affects them too. Recently the C++/C modes clangd server had some problems where some Company backend would interfere with company-capf. I suppose they have been fixed.

@joaotavora
Copy link
Owner

ah, I was just commenting about that. I think it's safest to keep this for a while.

@hongyi-zhao
Copy link
Author

hongyi-zhao commented Jun 25, 2021

But I also found that some commands still couldn't be completed, as shown below.

The \bra command which is defined in braket package can't be completed:

image

The \href command which is defined in hyperref package can't be completed:

image

@joaotavora
Copy link
Owner

But I also find that there are some commands still can't be completed, as shown below.

I didn't have a change to comment on this, but it looks like you completely skipped the issue reporting template. If you wish an issue to be analysed, you may not do that. Open a new issue and describe everything accurately as requested. If you can't do that for one reason or another, it's better to open a new discussion item, as the template will advise.

@hongyi-zhao
Copy link
Author

hongyi-zhao commented Jun 25, 2021

Yep. This issue was created from a blank one. I opened a new issue.

@hongyi-zhao
Copy link
Author

hongyi-zhao commented Jun 27, 2021

Another problem is the above configuration can't do the partial match search, say, when I input \arrow, I want to see all the LaTeX commands which includes arrow in it.

Based on further tries, this feature is supplied by the following backends:

company-ispell  company-capf

But it seems that the first backend that provides the match results takes effect, so there is no way to achieve the aims I described here.

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

No branches or pull requests

3 participants