3

This is something that's been bothering me for a while. I think I've configured company-mode backends wrong as I'm also getting company backends when inside comments.

Here is my company-mode config file. And here is an example of how I enable company-mode for specific major modes using a local variable for company-backends and adding that to the major mode hook. Like so:-

    (defun my-racer-mode-hook ()
      (set (make-local-variable 'company-backends)
           '((company-capf company-files company-yasnippet))))
    (add-hook 'racer-mode-hook 'my-racer-mode-hook)

I configure other major modes very similarly to the snippet above. But, I feel I did a mistake somewhere that's making company-yasnippet to pop up in the comments also. Can someone please point out where I did wrong ?

EDIT: I get completion from all backends inside the comments, not just company-yasnippet. Sorry for the confusion.

  • Try adding :with before company-yasnippet. – Dmitry Oct 28 '16 at 8:57
  • Hi, take a look at the edited question now. and Adding :with still gets me completions in the comments – Chakravarthy Raghunandan Oct 28 '16 at 11:17
  • What is your version of Emacs? – Dmitry Oct 28 '16 at 14:36
  • 25.1-1. running on mac os el capitan – Chakravarthy Raghunandan Oct 28 '16 at 17:25
  • 1
    Umm it happens with every major made that has company enabled :( I've no idea how to fix this annoyance – Chakravarthy Raghunandan Oct 28 '16 at 19:08
1

Each backend decides whether it works in the given context.

  • company-yasnippet works everywhere (you can counteract this using the keyword :with).
  • company-files works where it sees a beginning of an existing file name.
  • company-capf works where one of the elements in completion-at-point-functions says it works.

Since around 25.1, elisp-completion-at-point refuses to operate inside strings and comments (except when following a backtick, to complete symbol references).

You should probably open an issue at emacs-racer and ask for racer-complete-at-point to behave similarly.

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.