company-auctex icon indicating copy to clipboard operation
company-auctex copied to clipboard

Doesn't obey `company-minimum-prefix-length`

Open Stebalien opened this issue 8 years ago • 9 comments

I reported this to at https://github.com/company-mode/company-mode/issues/578 but apparently this is an issue with company-auctex. Basically, if company-minimum-prefix-length is 2, typing \l and then backspacing should show no completions (there's only one prefix letter). However, with the company-auctex backend enabled, it completes every latex command.

After further investigation, it turns out that this package simply ignores company-minimum-prefix-length entirely. \l is completed (no backspacing) even if company-minimum-prefix-length is set to 3.

Stebalien avatar Sep 07 '16 15:09 Stebalien

I fixed it locally this way:

  (defun as/company-auctex-prefix (regexp)
    "Returns the prefix for matching given REGEXP."
    (and (derived-mode-p 'latex-mode)
         (when (looking-back regexp)
           (match-string-no-properties 1))))

  (advice-add 'company-auctex-prefix :override 'as/company-auctex-prefix)

The company-auctex-prefix should not return a pair, but just the prefix. The t part in the pair prevents the comparison to company-minimum-prefix-length.

brabalan avatar Feb 15 '17 15:02 brabalan

I tried the fix by @brabalan but it didn't help me. I still get completion for a single character, which is annoying when typing math symbols that usually only have one character. I had posted this originally as a spacemacs problem but I'm not sure where it belongs. In a tex file, typing n brings up the completions and using M-x company-diag as suggested in https://github.com/company-mode/company-mode/issues/578, it tells me it uses the company-dabbrev backend.

Emacs 25.2.2 (x86_64-pc-linux-gnu) of 2017-05-06 on lgw01-59
Company 0.9.4

company-backends: ((company-auctex-macros company-auctex-symbols company-auctex-environments :with company-yasnippet)
 (company-auctex-bibs :with company-yasnippet)
 (company-auctex-labels :with company-yasnippet)
 (company-dabbrev-code company-gtags company-etags company-keywords :with company-yasnippet)
 (company-files :with company-yasnippet)
 (company-dabbrev :with company-yasnippet))

Used backend: (company-dabbrev :with company-yasnippet)

Major mode: latex-mode
Prefix: "n"
Completions:
  "next"
  "node"
  "null"
...

Even if I type \tex, The info is that it uses dabbvrev.

Any ideas?

fredRos avatar Aug 10 '17 07:08 fredRos

I have the very same problem and would be grateful for any help.

ntor avatar Aug 31 '17 18:08 ntor

I have the same issue

JunnanZ avatar Sep 26 '17 13:09 JunnanZ

@fredRos this is exactly what I am also experiencing. company-minimum-prefix-length which defaults to 3 does not get respected in latex-mode with AUCtex.

Shourai avatar Oct 12 '17 10:10 Shourai

Apparently the problem is with auctex itself https://github.com/syl20bnr/spacemacs/issues/9388#issuecomment-346275072 because it sets a local variable company-minimum-prefix-length which overrides global settings of the length.

fredRos avatar Nov 22 '17 08:11 fredRos

As a workaround for the prefix length, I have this in my configuration.

  (eval-after-load "latex"
    '(add-hook 'LaTeX-mode-hook
               (lambda ()
                 (setq company-minimum-prefix-length 4))))

brabalan avatar Nov 23 '17 07:11 brabalan

Fixed in Git: http://git.savannah.gnu.org/cgit/auctex.git/commit/?id=b2571b6048928882903204553716b9ec19d3e15b

tsdh avatar Nov 23 '17 08:11 tsdh

Does the combination of #24 (thanks, @brabalan) and AUCTeX 12.1 fix this?

alexeyr avatar Feb 27 '18 07:02 alexeyr