16

Setup:

GUI version GNU Emacs 25.0.50.1 (x86_64-w64-mingw32) of 2015-07-25 on KAEL

Compiled from EmacsW64.

, using the latest version of from MELPA

Windows 7 x64 bit.

Situation:

For example, I'm typing in the buffer foobarsentence.

And then start a new line below that, and typing fooba, I expected to get foobarsentence suggested from the Company popup completion window. But there is no foobarsentence.

I found it out from another answer that I could use company-dabbrev`` for that, bound, M-/. But I couldn't figure out how I could 'feed' the suggestions from company-dabbrev into the popup-window. I made a screencast gif to made my question clear.

enter image description here

As you can see, M-/ calls company-dabbrev. But I would like to see that suggested in the company completion popup. It surprised me this is not by default.

Any suggestion in order to 'feed' the suggestions from company-dabbrev to company popup window?

1
  • What major-mode is this?
    – PythonNut
    Commented Sep 1, 2015 at 22:30

1 Answer 1

35

Here is how completion in company works (I am simplifying a bit; a more detailed description can be found in documentation of company-backends C-hvcompany-backendsRET.

You have a list of backends (completion engines) which company should try to provide completion at point. Company tries each of these backends one after the another, and the first one that returns any candidates is used for completion; the rest of the backends are ignored. So by default, only one backend is used at a time.

In your case (you seem in emacs-lisp-mode), emacs-lisp backend is returning candidates for completion, so company-dabbrev is never used by company for completion; hence, you never get foobarsentence in completion. So, you might want to change company-backends so that company-dabbrev comes before company-elisp (or company-capf in recent emacsen). But I guess that is not what you want, since that would reverse the current situation and you will not get completions from emacs-lisp backend (in which case, read on).

Company provides a way to merge completions from multiple sources using what it calls grouped backends. Usually, the members of company-backends are individual backends, but it can also be a list of backends; in which case, the completion from the backends are merged provided they return same prefix or the text to be completed (please see documentation of company-backends for detailed description).

So, if you want to merge completions from company-elisp (on recent emacsen company-capf is used) and company-dabbrev, simply do this:

(add-to-list 'company-backends '(company-capf company-dabbrev))

Additionally, you can merge different backends using the :with keyword

(add-to-list 'company-backends '(company-capf :with company-dabbrev))

This is different from the previous example using a list of backends without :with, since company will use only the backends before :with for determining the prefix (the text to be completed). This implies that the candidates from backends after :with will be ignored by company, irrespective of whether the backends return a prefix or no, if none of the backends before :with return a prefix.

You might want to set this locally in emacs-lisp buffer (I prefer doing so).

3
  • @wasamasa thanks for the feedback, edited my answer to mention :with Commented Sep 3, 2015 at 17:54
  • 1
    Sir, you deserve my vote. I really enjoyed your explaination, and learned things about Company. Thanks for that.
    – ReneFroger
    Commented Sep 3, 2015 at 20:22
  • Glad I could help Commented Sep 4, 2015 at 1:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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