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-backends
RET.
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)