Skip to content

Commit d765ccf

Browse files
committed
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.
1 parent 6851394 commit d765ccf

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ integration.
1919
* [#664](https://github.com/clojure-emacs/cider/pull/664): New apropos support:
2020
search function/var names (bound to <kbd>C-c C-d a</kbd>) or documentation
2121
(bound to <kbd>C-c C-d A</kbd>).
22-
* You can open Grimoire's entry for a particular Clojure (built-in) symbol with
23-
`cider-grimoire` (<kbd>C-c C-d g</kbd>).
22+
* You can view Grimoire's entry for a particular Clojure (built-in) symbol in
23+
Emacs with `cider-grimoire` (<kbd>C-c C-d g</kbd>) or your default browser with
24+
`cider-grimoire-web` (<kbd>C-c C-d h</kbd>).
2425
* `cider-mode` now displays the namespace of the current buffer in the mode-line
2526
(as SLIME does).
2627

cider-interaction.el

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,8 @@ under point, prompts for a var."
14111411
(interactive "P")
14121412
(cider-read-symbol-name "Symbol: " 'cider-doc-lookup query))
14131413

1414+
(defconst cider-grimoire-url "http://grimoire.arrdem.com/")
1415+
14141416
(defun cider-grimoire-replace-special (name)
14151417
"Convert the dashes in NAME to a grimoire friendly format."
14161418
(->> name
@@ -1422,12 +1424,12 @@ under point, prompts for a var."
14221424
(defun cider-grimoire-url (name ns clojure-version)
14231425
"Generate a grimoire url from NAME, NS and CLOJURE-VERSION."
14241426
(let ((clojure-version (concat (substring clojure-version 0 4) "0"))
1425-
(base-url "http://grimoire.arrdem.com/"))
1427+
(base-url cider-grimoire-url))
14261428
(if name
14271429
(concat base-url clojure-version "/" ns "/" (cider-grimoire-replace-special name) "/")
14281430
(concat base-url clojure-version "/" ns "/"))))
14291431

1430-
(defun cider-grimoire-lookup (symbol)
1432+
(defun cider-grimoire-web-lookup (symbol)
14311433
"Look up the grimoire documentation for SYMBOL."
14321434
(-if-let (var-info (cider-var-info symbol))
14331435
(let ((name (cider-get-var-attr var-info "name"))
@@ -1436,9 +1438,38 @@ under point, prompts for a var."
14361438
(browse-url (cider-grimoire-url name ns (cider--clojure-version))))
14371439
(message "Symbol %s not resolved" symbol)))
14381440

1439-
(defun cider-grimoire (query)
1441+
(defun cider-grimoire-web (query)
14401442
"Open the grimoire documentation for QUERY in the default web browser."
14411443
(interactive "P")
1444+
(cider-read-symbol-name "Symbol: " 'cider-grimoire-web-lookup query))
1445+
1446+
(defun cider-grimoire-lookup (symbol)
1447+
"Look up the grimoire documentation for SYMBOL."
1448+
(-if-let (var-info (cider-var-info symbol))
1449+
(let ((name (cider-get-var-attr var-info "name"))
1450+
(ns (cider-get-var-attr var-info "ns"))
1451+
(url-request-method "GET")
1452+
(url-request-extra-headers `(("Content-Type" . "text/plain"))))
1453+
;; TODO: add a whitelist of supported namespaces
1454+
(url-retrieve (cider-grimoire-url name ns (cider--clojure-version))
1455+
(lambda (status)
1456+
(goto-char (point-min))
1457+
(re-search-forward "^$")
1458+
(delete-region (point-min) (point))
1459+
(delete-blank-lines)
1460+
(text-mode)
1461+
(cider-popup-buffer-mode +1)
1462+
(read-only-mode +1)
1463+
(pop-to-buffer (current-buffer))
1464+
(goto-char (point-min))
1465+
(when (get-buffer "*cider grimoire*")
1466+
(kill-buffer "*cider grimoire*"))
1467+
(rename-buffer "*cider grimoire*"))))
1468+
(message "Symbol %s not resolved" symbol)))
1469+
1470+
(defun cider-grimoire (query)
1471+
"Open the grimoire documentation for QUERY in a popup buffer."
1472+
(interactive "P")
14421473
(cider-read-symbol-name "Symbol: " 'cider-grimoire-lookup query))
14431474

14441475
(defun cider-apropos-doc (button)

cider-mode.el

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ entirely."
5959
(define-key map (kbd "C-c C-d a") 'cider-apropos)
6060
(define-key map (kbd "C-c C-d A") 'cider-apropos-documentation)
6161
(define-key map (kbd "C-c C-d g") 'cider-grimoire)
62+
(define-key map (kbd "C-c C-d h") 'cider-grimoire-web)
6263
(define-key map (kbd "C-c C-d j") 'cider-javadoc)
6364
(define-key map (kbd "C-c C-d d") 'cider-doc)
6465
(define-key map (kbd "C-M-x") 'cider-eval-defun-at-point)
@@ -122,6 +123,7 @@ entirely."
122123
["Display documentation" cider-doc]
123124
["Display JavaDoc" cider-javadoc]
124125
["Display Grimoire documentation" cider-grimoire]
126+
["Display Grimoire documentation in browser" cider-grimoire-web]
125127
["Inspect" cider-inspect]
126128
"--"
127129
["Run test" cider-test-run-test]

cider-repl.el

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,7 @@ ENDP) DELIM."
991991
(define-key map (kbd "C-c C-d a") 'cider-apropos)
992992
(define-key map (kbd "C-c C-d A") 'cider-apropos-documentation)
993993
(define-key map (kbd "C-c C-d g") 'cider-grimoire)
994+
(define-key map (kbd "C-c C-d h") 'cider-grimoire-web)
994995
(define-key map (kbd "C-c C-d d") 'cider-doc)
995996
(define-key map (kbd "C-c C-d j") 'cider-javadoc)
996997
(define-key map (kbd "C-c C-o") 'cider-repl-clear-output)
@@ -1038,6 +1039,7 @@ ENDP) DELIM."
10381039
["Display documentation" cider-doc]
10391040
["Display JavaDoc" cider-javadoc]
10401041
["Display Grimoire documentation" cider-grimoire]
1042+
["Display Grimoire documentation in browser" cider-grimoire-web]
10411043
["Inspect" cider-inspect]
10421044
"--"
10431045
["Set REPL ns" cider-repl-set-ns]

0 commit comments

Comments
 (0)