I would like to be able to prevent company mode from automatically suggesting a specific backend (namely company-dabbrev) when in a specific mode (using text-mode-hook), however I don't want want to remove this backend from company-backends as I still want to include to get its completions when I manually invoke company-complete-common-or-cycle.

So, how would I go about excluding a backend from autocompleting on text input without excluding it entirely from company-backends?

(The motivation for this is that I find autocompletion on arbitrary words I'm typing in a text document distracting, but I do want to keep autocompletions such as latex environments, as these are quite handy. I do however sometimes want manual autocompletion for when I'm typing a long word that I've forgotten how to spell, but I know I've typed before.)


see https://github.com/company-mode/company-mode/issues/112 @dgutov comment.

Make the company-dabbrev the last element in company-backends. completion of previous backends will block company-dabbrev.

I usually place company-ispell at the beginning of the company-backends in text-mode-hook which blocks other backends in most cases.

If your want to remove/add backends instead of tweaking the priority of backends.

(defun company-my-setup ()
  (when (boundp 'company-backends)
    (make-local-variable 'company-backends)
    ;; remove
    (setq company-backends (delete 'company-dabbrev company-backends))
    ;; add
    (add-to-list 'company-backends 'company-dabbrev)

(add-hook 'latex-major-mode-hook 'company-my-setup)
| improve this answer | |
  • I'm not sure I see how tweaking the priority of backends can achieve this. Say I'm typing the word "hello", I don't want any backend to succeed for any portion of the word, so none should succeed, and consequently, none will block company-dabbrev when placed at the end. – nedned Feb 22 '16 at 6:37
  • And the other strategy, it seems like this still doesn't selectively remove the backends for the context of completing a half-typed word but not for calling something with say company-complete? Maybe I'm missing something. – nedned Feb 22 '16 at 6:41
  • 1
    I updated the last code snippet , just delete/add 'company-dabbrev. If you want to turn off all backends, (setq company-backends nil) – chen bin Feb 22 '16 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.