1

In my Emacs configuration for JavaScript/ JS2-mode, specifically .js buffer in node:

(1) company-tern and ELDoc are NOT working properly.

For eg. when I type 'console.l', 'log' does not pop up, rather 'let' alone pops up

(2) When opening the buffer, a message pop ups, "There is no ELDoc support in this buffer"

My key Emacs configurations, for this:

Company:

(use-package company
  :ensure t
  :config (global-company-mode t)
  (progn
    (setq company-idle-delay 0)
    (setq company-minimum-prefix-length 1)
    (setq company-etags-everywhere '(html-mode web-mode js-mode js2-mode nxml-mode))

tern:

(use-package tern
  :ensure t
  :config
  (progn
    (autoload 'tern-mode "tern.el" nil t)
    (add-hook 'js-mode-hook (lambda () (tern-mode t)))
    (add-hook 'js2-mode-hook (lambda () (tern-mode t)))))

company-tern:

(use-package company-tern   
  :ensure t   
  :config   
    (with-eval-after-load 'company 'tern    
      '(add-to-list 'company-backends 'company-tern)))

ELDoc:

(global-eldoc-mode 1)
(add-hook 'js2-mode-hook 'eldoc-mode)
(add-hook 'js-mode-hook 'eldoc-mode)

Can some one help me to sort out what I am doing wrong?

tom_kp
  • 81
  • 4

1 Answers1

1

ElDoc

When eldoc-mode is enabled it checks whether eldoc-documentation-function is defined in current buffer. If not - it messages "There is no ElDoc support in this buffer" and exits.
Neither of these modes supports ElDoc, i.e. doesn't implement eldoc-documentation-function.

Company

When new characters are typed, company after each command checks for a possibility to complete it.
If company triggers a completion process, it loops over each member of company-backends list:

(add-to-list 'company-backends 'company-tern)

So completion depends on which company backend first is able to return some completion.
BTW, add-to-list is quoted in your setup.

That company looping over all backends can be avoided:

M-x company-tern calls only tern backend at point.(try it first)

Or, instead of adding company-tern to company-backends list, it can be assigned to a variable:
company-backend (notice there's no "s" in the end). This variable is provided by company for "manual override" cases, it means - use only one this backend.
It's a buffer local variable, so it should be assigned inside javascript mode hooks:

(setq company-backend company-tern)
yPhil
  • 963
  • 5
  • 22
  • 1
    Thanks **Alexandr Karbivnichiy**: (1) I agree with your answer that there is **no ELDoc** support for `company-tern`. (2) Re: **company**, I had to _quote_ `add-to-list` to get pop up of 'console' when typing **c**. And, `(setq company-backend company-term)` idea did not work for me. – tom_kp Jan 17 '19 at 16:35
  • So inside of a Javascript buffer, what is the value of ‘company-backends’? – InHarmsWay Feb 14 '19 at 11:30