vspinu / company-math

Completion back-ends for for math unicode symbols and latex tags
124 stars 8 forks source link

Some commands, say, `\bra`, can't be completed in math mode, while they can be completed in normal literal typesetting mode. #19

Open hongyi-zhao opened 3 years ago

hongyi-zhao commented 3 years ago

The testing configuration:

(use-package lsp-mode
 :hook
 (TeX-mode . lsp)
 :custom (lsp-prefer-capf t))

(use-package lsp-latex
  :straight (:host github :repo "ROCKTAKEY/lsp-latex"))

(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)
(use-package math-symbol-lists)
(use-package ac-math)
(use-package company-auctex)

;;https://www.emacswiki.org/emacs/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-math-disallow-unicode-symbols-in-faces nil)
  (setq-local company-math-allow-latex-symbols-in-faces nil)
;  (setq-local company-backends
;               (append '((company-math-symbols-latex company-math-symbols-unicode company-auctex-macros company-auctex-environments))
;                      company-backends)))

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

image image

Obviously, this is not the desired result.

Any hints for this problem?

Regards, HY

hongyi-zhao commented 3 years ago

Comment out the following two lines in the above configuration seems to solve this problem:

  (setq-local company-math-disallow-unicode-symbols-in-faces nil)
  (setq-local company-math-allow-latex-symbols-in-faces nil)

But some commands, say, \bra, can't be completed in math mode: image While they can be completed in text mode: image

vspinu commented 3 years ago
     (append '((company-math-symbols-latex company-math-symbols-unicode company-auctex-environments 
                          company-auctex-macros company-capf company-ispell company-latex-commands
                          company-abbrev company-bbdb company-dabbrev-code company-dabbrev
                          company-files company-keywords company-semantic
                         ))

This doens't seem right to me, but if it works for you ok. All those backends are triggered simultaneously. The point of company backends is that if the first ones don't find it, the following ones are triggered. company-math backends start with \ prefix, if there is no prefix they are not triggered.

But some commands, say, \bra, can't be completed in math mode:

Bra completion is not comming form company math. Probably from company-capf which triggers auctex completion and it looks in braket.sty file (just a guess). So it's not a company-math issue.

Comment out the following two lines in the above configuration seems to solve this problem:

Yes, you need to look at company-math custom variables and configure as you see fit.

hongyi-zhao commented 3 years ago

This doens't seem right to me, but if it works for you ok.

What's your working configuration?

vspinu commented 3 years ago

I do (add-to-list 'company-backends 'company-math-symbols-unicode) globally and

(setq-local company-backends
                (append '((company-math-symbols-latex
                           company-latex-commands))
                        company-backends))

In latex mode.

hongyi-zhao commented 3 years ago

If you want the normal human writing completion, the following backend should be appended to the list too:

company-ispell

But even so, there are still many commands that cannot be completed., as I've described here.