1

I have just got ternjs up and running with js2-mode & company-mode in emacs and getting quite excited. The C-c C-d function to get the docs for a function from tern brings back quite a limited subset of information. I would love to learn lisp but find it confusing everytime I look at it.

Instead of showing the first line of a functions' comment block in the mini buffer what I would like to do is show the full document block in a split window that auto closes when exiting or on key press.

This is the function that gets the docs from tern

(defvar tern-last-docs-url nil)
(defun tern-get-docs ()
  (interactive)
  (if (and tern-last-docs-url (eq last-command 'tern-get-docs))
      (progn
        (browse-url tern-last-docs-url)
        (setf tern-last-docs-url nil))
    (tern-run-query (lambda (data)
                      (let ((url (cdr (assq 'url data))) (doc (cdr (assq 'doc data))))
                    (cond (doc
                           (setf tern-last-docs-url url)
                           (tern-message doc))
                  (url
                   (browse-url url))
                      (t (tern-message "Not found")))))
                "documentation"
                (point))))

But I dont have a clue where to start. I would like to debug and see what the url is - and test this outside of emacs to see firstly if tern actually returns the full docs.

If it does then I would like to open a split buffer and load the docs, and kill on keypress.

Anyone up for a mini lisp tutorial - breaking down how this works and perhaps instructions on how to do the above?

Actually I can see that all the full comment of the function is shown - I guess the only part I am seeking help with is how to open in a split window - and also I would like to include the additional jsDoc annotations such as @param {string} etc...

user2237076
  • 331
  • 3
  • 13
  • I would suggest starting by just adding a message immediately after `(lambda (data)` -- e.g., `(lambda (data) (message "%s" data) (let ((url ...` and then evaluate the revised function, then use it, and then check the `*Messages*` buffer to see what *data* looks like. – lawlist Jun 07 '16 at 19:38
  • Here is a sample split window insert stuff snippet: `(let ((buf (get-buffer-create "*foo*"))) (with-current-buffer buf (insert (format "%s" '(my list of stuff)))) (display-buffer buf t))` You may wish to consider putting something like that inside the `(lambda (data) ...)` statement where the value for `data` is valid. I take it `data` is a list, so that is why I used a list as an example. If the portion you are extracting from `data` is a string, then you can just use the string without the need for using `(format "%s" . . .)` – lawlist Jun 07 '16 at 21:16

0 Answers0