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?

  • What major-mode is this? – PythonNut Sep 1 '15 at 22:30
up vote 18 down vote accepted

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) company should try to provide completion at point. Company tries each of this backend one after the another and the first one that returns any candidates is used for completion and 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 and so company-dabbrev is never used by company for completion and 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 source 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 example 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 the none of the backends before :with return a prefix.

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

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

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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