From c0aa1c736dca4d549e717ccc127a991d3a93002a Mon Sep 17 00:00:00 2001 From: James Bunton Date: Sat, 29 Apr 2017 02:42:00 +1000 Subject: [PATCH 1/2] Popup full documentation in a separate Emacs window --- emacs/tern.el | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/emacs/tern.el b/emacs/tern.el index 5c2a17de..0cc186a9 100644 --- a/emacs/tern.el +++ b/emacs/tern.el @@ -12,6 +12,7 @@ (require 'url) (require 'url-http) +(defvar tern-docs-popup-buffer "*tern:docs*") (defvar tern-known-port nil) (defvar tern-server nil) (defvar tern-explicit-port nil) @@ -22,6 +23,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") @@ -504,20 +516,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 From 76e14f5db82ac78c7cdcc7eaeb12f603df1fc387 Mon Sep 17 00:00:00 2001 From: James Bunton Date: Sat, 29 Apr 2017 02:55:46 +1000 Subject: [PATCH 2/2] Popup type definition in separate Emacs window --- emacs/tern.el | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/emacs/tern.el b/emacs/tern.el index 0cc186a9..3580d42d 100644 --- a/emacs/tern.el +++ b/emacs/tern.el @@ -13,6 +13,7 @@ (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) @@ -507,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)))