2

When I enter "pars" in Emacs js-mode buffer and type tern-ac-complete, I get the desired result: list of completion candidates + the documentation next to the candidate.

However, I cannot get Tern completion to be triggered automatically. The ac-auto-start is set to 3 and the auto-complete works as expected for other cases (my dictionary file, the words I already typed in, jquery-doc, etc.)

katspaugh
  • 17,449
  • 11
  • 66
  • 103
  • Can you post your `tern` configuration please? –  Jan 21 '14 at 12:44
  • If you are thinking about my .emacs file, here it is: (add-hook 'js-mode-hook (lambda () (tern-mode t))) (eval-after-load 'tern '(progn (require 'tern-auto-complete) (tern-ac-setup))) – Darko Draskovic Jan 21 '14 at 13:00

4 Answers4

1

You should try company-mode with the third-party company-tern.

It starts completion automatically with no problems.

Dmitry
  • 3,625
  • 2
  • 30
  • 28
  • +1. Here's my Emacs Prelude snippet: ```(global-company-mode +1) (eval-after-load 'company '(add-to-list 'company-backends 'company-tern))``` – opyate May 04 '16 at 09:27
0

The issue is that tern does not provide an ac-source yet. From the comments in tern-auto-complete.el

This program does not provide an ac-source for arbitrary timing yet.

0

Call function 'edebug-defun for function 'ac-start of auto-complete.el, and follow call trace to figure out what causes this problem.

In my case, variable 'ac-use-dictionary-as-stop-words was t and having many words on my auto completion dictionary, so auto-complete was aborted.

tern.el          : Version: 0.0.1
auto-complete.el : Version: 1.4.0 

line. 1559 (ac-abort)) ;; <= This was called!!!

$ node --version # v0.11.13-pre (on Linux)
displayname
  • 663
  • 8
  • 9
0

This happens because tern-emacs has to request completions from tern-server (an async operation). Only when the server returns it goes on to call auto-complete with the tern sources only.

I fixed it by advising auto-complete to wait for tern request if a custom variable is set to t. This way you can get tern completions to show in your normal auto-complete workflow.

Here is the pull request (or just the diff) I made to the tern repo.

I'm adding this here in case someone stumbles here through search as i did.