Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 29 additions & 11 deletions emacs/tern.el
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
(require 'url)
(require 'url-http)

(defvar tern-docs-popup-buffer "*tern:docs*")
(defvar tern-type-popup-buffer "*tern:type*")
(defvar tern-known-port nil)
(defvar tern-server nil)
(defvar tern-explicit-port nil)
Expand All @@ -22,6 +24,17 @@
(defun tern-message (fmt &rest objects)
(apply 'message fmt objects))

(defun tern-popup-buffer (buffer-name text)
(pop-to-buffer
(with-current-buffer (get-buffer-create buffer-name)
(view-mode -1)
(setq buffer-read-only nil)
(erase-buffer)
(insert text)
(goto-char (point-min))
(view-mode +1)
(current-buffer))))

(defun tern-req (port doc c)
(let* ((url-mime-charset-string nil) ; Suppress huge, useless header
(url-request-method "POST")
Expand Down Expand Up @@ -495,7 +508,12 @@ list of strings, giving the binary name and arguments.")

(defun tern-get-type ()
(interactive)
(tern-run-query (lambda (data) (tern-message (or (cdr (assq 'type data)) "Not found")))
(tern-run-query (lambda (data)
(let ((type (cdr (assq 'type data))))
(cond (type
(tern-popup-buffer tern-type-popup-buffer type))
(t
(tern-message "Not found")))))
"type"
(point)))

Expand All @@ -504,20 +522,20 @@ list of strings, giving the binary name and arguments.")
(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))))
(tern-run-query (lambda (data)
(let ((url (cdr (assq 'url data))) (doc (cdr (assq 'doc data))))
(if (and tern-last-docs-url (equal url tern-last-docs-url))
(progn
(setf tern-last-docs-url nil)
(browse-url url))
(cond (doc
(setf tern-last-docs-url url)
(tern-message doc))
(tern-popup-buffer tern-docs-popup-buffer doc))
(url
(browse-url url))
(t (tern-message "Not found")))))
"documentation"
(point))))
(t (tern-message "Not found"))))))
`((type . "documentation") (docFormat . "full"))
(point)))

;; Connection management

Expand Down