summaryrefslogtreecommitdiff
path: root/cider-interaction.el
diff options
context:
space:
mode:
authorBozhidar Batsov <bozhidar@batsov.com>2014-08-02 16:43:36 +0300
committerBozhidar Batsov <bozhidar@batsov.com>2014-08-02 16:43:36 +0300
commitd765ccfe68ba9084ffb95d959c6b7d17ca441e77 (patch)
tree7136e0d1add76c7a0b8941321a526ab2c99c389f /cider-interaction.el
parent6851394d59a7c6a98ed4968396616c809da6afa1 (diff)
Add the ability to display Grimoire documentation within Emacs
This uses the new Grimoire 0.3 API. The implementation is extremely basic at this point (and pretty crude), but the results are useful never-the-less.
Diffstat (limited to 'cider-interaction.el')
-rw-r--r--cider-interaction.el37
1 files changed, 34 insertions, 3 deletions
diff --git a/cider-interaction.el b/cider-interaction.el
index 6621c39a..8920d5f1 100644
--- a/cider-interaction.el
+++ b/cider-interaction.el
@@ -1411,6 +1411,8 @@ under point, prompts for a var."
(interactive "P")
(cider-read-symbol-name "Symbol: " 'cider-doc-lookup query))
+(defconst cider-grimoire-url "http://grimoire.arrdem.com/")
+
(defun cider-grimoire-replace-special (name)
"Convert the dashes in NAME to a grimoire friendly format."
(->> name
@@ -1422,12 +1424,12 @@ under point, prompts for a var."
(defun cider-grimoire-url (name ns clojure-version)
"Generate a grimoire url from NAME, NS and CLOJURE-VERSION."
(let ((clojure-version (concat (substring clojure-version 0 4) "0"))
- (base-url "http://grimoire.arrdem.com/"))
+ (base-url cider-grimoire-url))
(if name
(concat base-url clojure-version "/" ns "/" (cider-grimoire-replace-special name) "/")
(concat base-url clojure-version "/" ns "/"))))
-(defun cider-grimoire-lookup (symbol)
+(defun cider-grimoire-web-lookup (symbol)
"Look up the grimoire documentation for SYMBOL."
(-if-let (var-info (cider-var-info symbol))
(let ((name (cider-get-var-attr var-info "name"))
@@ -1436,9 +1438,38 @@ under point, prompts for a var."
(browse-url (cider-grimoire-url name ns (cider--clojure-version))))
(message "Symbol %s not resolved" symbol)))
-(defun cider-grimoire (query)
+(defun cider-grimoire-web (query)
"Open the grimoire documentation for QUERY in the default web browser."
(interactive "P")
+ (cider-read-symbol-name "Symbol: " 'cider-grimoire-web-lookup query))
+
+(defun cider-grimoire-lookup (symbol)
+ "Look up the grimoire documentation for SYMBOL."
+ (-if-let (var-info (cider-var-info symbol))
+ (let ((name (cider-get-var-attr var-info "name"))
+ (ns (cider-get-var-attr var-info "ns"))
+ (url-request-method "GET")
+ (url-request-extra-headers `(("Content-Type" . "text/plain"))))
+ ;; TODO: add a whitelist of supported namespaces
+ (url-retrieve (cider-grimoire-url name ns (cider--clojure-version))
+ (lambda (status)
+ (goto-char (point-min))
+ (re-search-forward "^$")
+ (delete-region (point-min) (point))
+ (delete-blank-lines)
+ (text-mode)
+ (cider-popup-buffer-mode +1)
+ (read-only-mode +1)
+ (pop-to-buffer (current-buffer))
+ (goto-char (point-min))
+ (when (get-buffer "*cider grimoire*")
+ (kill-buffer "*cider grimoire*"))
+ (rename-buffer "*cider grimoire*"))))
+ (message "Symbol %s not resolved" symbol)))
+
+(defun cider-grimoire (query)
+ "Open the grimoire documentation for QUERY in a popup buffer."
+ (interactive "P")
(cider-read-symbol-name "Symbol: " 'cider-grimoire-lookup query))
(defun cider-apropos-doc (button)