diff options
author | Bozhidar Batsov <bozhidar@batsov.com> | 2014-08-02 16:43:36 +0300 |
---|---|---|
committer | Bozhidar Batsov <bozhidar@batsov.com> | 2014-08-02 16:43:36 +0300 |
commit | d765ccfe68ba9084ffb95d959c6b7d17ca441e77 (patch) | |
tree | 7136e0d1add76c7a0b8941321a526ab2c99c389f | |
parent | 6851394d59a7c6a98ed4968396616c809da6afa1 (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.
-rw-r--r-- | CHANGELOG.md | 5 | ||||
-rw-r--r-- | cider-interaction.el | 37 | ||||
-rw-r--r-- | cider-mode.el | 2 | ||||
-rw-r--r-- | cider-repl.el | 2 |
4 files changed, 41 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index f9bc2edd..4f30e456 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,8 +19,9 @@ integration. * [#664](https://github.com/clojure-emacs/cider/pull/664): New apropos support: search function/var names (bound to <kbd>C-c C-d a</kbd>) or documentation (bound to <kbd>C-c C-d A</kbd>). -* You can open Grimoire's entry for a particular Clojure (built-in) symbol with -`cider-grimoire` (<kbd>C-c C-d g</kbd>). +* You can view Grimoire's entry for a particular Clojure (built-in) symbol in +Emacs with `cider-grimoire` (<kbd>C-c C-d g</kbd>) or your default browser with +`cider-grimoire-web` (<kbd>C-c C-d h</kbd>). * `cider-mode` now displays the namespace of the current buffer in the mode-line (as SLIME does). 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) diff --git a/cider-mode.el b/cider-mode.el index 34f754f7..75d9fa39 100644 --- a/cider-mode.el +++ b/cider-mode.el @@ -59,6 +59,7 @@ entirely." (define-key map (kbd "C-c C-d a") 'cider-apropos) (define-key map (kbd "C-c C-d A") 'cider-apropos-documentation) (define-key map (kbd "C-c C-d g") 'cider-grimoire) + (define-key map (kbd "C-c C-d h") 'cider-grimoire-web) (define-key map (kbd "C-c C-d j") 'cider-javadoc) (define-key map (kbd "C-c C-d d") 'cider-doc) (define-key map (kbd "C-M-x") 'cider-eval-defun-at-point) @@ -122,6 +123,7 @@ entirely." ["Display documentation" cider-doc] ["Display JavaDoc" cider-javadoc] ["Display Grimoire documentation" cider-grimoire] + ["Display Grimoire documentation in browser" cider-grimoire-web] ["Inspect" cider-inspect] "--" ["Run test" cider-test-run-test] diff --git a/cider-repl.el b/cider-repl.el index 91ca0aeb..abbe9796 100644 --- a/cider-repl.el +++ b/cider-repl.el @@ -991,6 +991,7 @@ ENDP) DELIM." (define-key map (kbd "C-c C-d a") 'cider-apropos) (define-key map (kbd "C-c C-d A") 'cider-apropos-documentation) (define-key map (kbd "C-c C-d g") 'cider-grimoire) + (define-key map (kbd "C-c C-d h") 'cider-grimoire-web) (define-key map (kbd "C-c C-d d") 'cider-doc) (define-key map (kbd "C-c C-d j") 'cider-javadoc) (define-key map (kbd "C-c C-o") 'cider-repl-clear-output) @@ -1038,6 +1039,7 @@ ENDP) DELIM." ["Display documentation" cider-doc] ["Display JavaDoc" cider-javadoc] ["Display Grimoire documentation" cider-grimoire] + ["Display Grimoire documentation in browser" cider-grimoire-web] ["Inspect" cider-inspect] "--" ["Set REPL ns" cider-repl-set-ns] |