1

Since js2-mode does not have eldoc-mode support, I was wondering if I could get some similar functionality to js2-mode with the help of tern-mode.

tern-mode has a command tern-get-type which will return the type of the thing under cursor in the minibuffer. How can I get this command to run automatically when cursor is idle (preferably after a small delay)?

2
  • Not the same thing but close, have you looked at Helm Dash github.com/areina/helm-dash ? Sep 7, 2016 at 12:04
  • I already have the dash app for mac for browsing documentation. Yes, I did try out helm-dash, but eventually decided it's better to stick with dash app for mac instead. Sep 7, 2016 at 12:28

1 Answer 1

2

The right thing to do is to run this tern-get-type from eldoc-documentation-function. This way, eldoc-mode will take care of running it after a little delay etc...

I.e. maybe something like

(defun js2--eldoc-via-tern ()
  ...(tern-get-type..)...)

(add-hook 'js2-mode-hook
          (lambda ()
            (setq-local eldoc-documentation-function #'js2--eldoc-via-tern)))

You might even do that to js-mode rather than js2-mode (since nowadays js2-mode inherits from js-mode).

If/when it works, I suggest you submit it for inclusion in js(2)-mode, e.g. via M-x report-emacs-bug.

5
  • I'll try this out today.And is it okay to report this? Since not everyone who uses js2-mode will use tern-mode and this would cause a dependancy on tern-mode Sep 7, 2016 at 13:32
  • I don't guarantee that it will be accepted and integrated, but it's definitely worth submitting. The various different major modes should aim to merge rather than to diverge and re-invent the wheel.
    – Stefan
    Sep 7, 2016 at 13:35
  • I got this to work and reported this feature as a bug. Thanks for the help. Sep 7, 2016 at 13:59
  • @ChakravarthyRaghunandan Please post the working solution! Nov 4, 2018 at 10:51
  • @PhilHudson I use tern-mode with js2-mode now. So, it doesn't have the problem I mentioned in this old post. Nov 4, 2018 at 16:55

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.