Recently, I have tried setting up a JS development environment and part of that process has been configuring company-mode for autocompletion duties - but I'm having some issues triggering auto completion. First - here's the file I use to configure company mode:

(use-package yasnippet
  :ensure t
  :diminish yas-minor-mode
  (setq yas-snippet-dirs (append yas-snippet-dirs
  (yas-global-mode 1))

(use-package company
  :ensure t
  :diminish company-mode
  (add-to-list 'company-backends 'company-elisp)
  (add-to-list 'company-backends 'company-yasnippet)
  (add-to-list 'company-backends 'company-dabbrev)
  (add-to-list 'company-backends 'company-dabbrev-code)
  (add-to-list 'company-backends 'company-etags)
  (setq company-auto-complete nil
        company-tooltip-flip-when-above t
        company-minimum-prefix-length 2
        company-tooltip-limit 10
        company-idle-delay 0.5)
  (global-company-mode 1))
;;  (add-hook 'prog-mode-hook 'company-mode))

(use-package helm-company
  :ensure t
    (define-key company-mode-map (kbd "C-:") 'helm-company)
    (define-key company-active-map (kbd "C-:") 'helm-company)))

(use-package company-tern
  :ensure t
  (add-to-list 'company-backends 'company-tern))

(use-package tern
  :ensure t
  :defer t
  :diminish tern-mode
    (add-hook 'js2-mode-hook 'tern-mode)))

(provide 'init-autocompletion)

Now, let's say I'm working in a...Coffeescript file - and it has something like this:

foo = 
  addTwo: (a) ->
    a + 2
  addThree: (a) ->
    a + 3

then later on in that file I start typing:


I would hope that company would kick in and offer addTwo/Three as candidates - but I got nada!

I ran company-diag - and I get this:

Emacs 24.5.1 (x86_64-apple-darwin14.4.0) of 2015-07-13 on MFT-A018.local
Company 0.9.0-cvs

company-backends: (company-tern company-etags company-dabbrev-code company-yasnippet company-elisp company-bbdb company-nxml company-css company-eclim company-semantic company-clang company-xcode company-cmake company-capf
              (company-dabbrev-code company-gtags company-etags company-keywords)
              company-oddmuse company-files company-dabbrev)

Used backend: company-etag

and a whole bunch of completion candidates - none of which are foo.addTwo/Three

can anyone offer any advice on how to get company-mode working?

  • Does tern support CoffeeScript? I don't think it does ATM.
    – PythonNut
    Commented Aug 12, 2015 at 15:28
  • no, but shouldn't dabbrev or dabbrev-code offer some candidates?
    – sunwukung
    Commented Aug 12, 2015 at 16:44

1 Answer 1


company-backends is a variable defined in company.el.

Documentation: The list of active back-ends (completion engines).

Only one back-end is used at a time. The choice depends on the order of the items in this list, and on the values they return in response to the ‘prefix’ command (see below). But a back-end can also be a "grouped" one (see below).

Grouped back-ends:

An element of company-backends can also itself be a list of back-ends, then it's considered to be a "grouped" back-end.

When possible, commands taking a candidate as an argument are dispatched to the back-end it came from. In other cases, the first non-nil value among all the back-ends is returned.

The latter is the case for the prefix command. But if the group contains the keyword :with, the back-ends after it are ignored for this command.

The completions from back-ends in a group are merged (but only from those that return the same prefix).


For some reason, company-etags thinks it's handling completion for the current buffer. Since it comes earlier in the list than company-dabbrev-code, it gets priority.

One way to handle this is to use mode-hooks to force the backend list to match what you'd like.

Another way is to throw a set of backends into a group. Members of a group do not block each other, so as long as company-dabbrev-code is in the first group it will always be active. This has its drawbacks too (performance, for example), and you will have to weigh between the two.

I use a sort of hybrid combination of the two. Unfortunately, my setup uses a lot of macro magic so it doesn't really make sense on its own.

EDIT: Here's a solution for CoffeeScript:

(add-hook 'coffee-mode
  (lambda ()
    (setq company-backends '(company-dabbrev-code))))
  • Apparently, the author of the question has a TAGS file in that project. So company-etags indeed thinks it should be used. Since it is in the beginning of company-backends for some reason (as opposed to the default configuration), nothing else gets used.
    – Dmitry
    Commented Aug 12, 2015 at 19:37
  • in all honesty, I have just thrown some completion backends in there that I thought might work - I come from Sublime/Vim where this isn't really an issue - so it's a little hard for me to grok at this stage. @PythonNut - could you show me an example of how you might start dabbrev-code for a specific mode?
    – sunwukung
    Commented Aug 12, 2015 at 19:51
  • 1
    @sunwukung does the edit help?
    – PythonNut
    Commented Aug 12, 2015 at 22:06

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.