Skip to content

Commit 39275cb

Browse files
author
Bozhidar Batsov
committed
Add Grimoire integration
1 parent 1003085 commit 39275cb

File tree

5 files changed

+48
-0
lines changed

5 files changed

+48
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ 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-h a</kbd>) or documentation
2121
(bound to <kbd>C-c C-h d</kbd>).
22+
* You can open Grimoire's entry for a particular Clojure (built-in) symbol with
23+
`cider-grimoire` (<kbd>C-c C-h g</kbd>).
2224

2325
### Changes
2426

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ Keyboard shortcut | Description
562562
<kbd>C-c M-.</kbd> | Jump to the resource referenced by the string at point.
563563
<kbd>M-,</kbd> | Return to your pre-jump location.
564564
<kbd>M-TAB</kbd> | Complete the symbol at point.
565+
<kbd>C-c C-h g</kbd> | Lookup symbol in Grimoire.
565566
<kbd>C-c C-h a</kbd> | Apropos search for functions/vars.
566567
<kbd>C-c C-h d</kbd> | Apropos search for documentation.
567568

cider-interaction.el

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,38 @@ under point, prompts for a var."
14081408
(interactive "P")
14091409
(cider-read-symbol-name "Symbol: " 'cider-doc-lookup query))
14101410

1411+
(defun cider-grimoire-replace-dashes (name)
1412+
"Convert the dashes in NAME to a grimoire friendly format."
1413+
(setq name (if (string-match "\\`-" name)
1414+
(replace-match "DASH_" t t name)
1415+
name))
1416+
(setq name (if (string-match "-\\'" name)
1417+
(replace-match "_DASH" t t name)
1418+
name))
1419+
(replace-regexp-in-string "-" "_DASH_" name))
1420+
1421+
(defun cider-grimoire-url (name ns clojure-version)
1422+
"Generate a grimoire url from NAME, NS and CLOJURE-VERSION."
1423+
(let ((clojure-version (concat (substring clojure-version 0 4) "0"))
1424+
(base-url "http://grimoire.arrdem.com/"))
1425+
(if name
1426+
(concat base-url clojure-version "/" ns "/" (cider-grimoire-replace-dashes name) "/")
1427+
(concat base-url clojure-version "/" ns "/"))))
1428+
1429+
(defun cider-grimoire-lookup (symbol)
1430+
"Look up the grimoire documentation for SYMBOL."
1431+
(-if-let (var-info (cider-var-info symbol))
1432+
(let ((name (cider-get-var-attr var-info "name"))
1433+
(ns (cider-get-var-attr var-info "ns")))
1434+
;; TODO: add a whitelist of supported namespaces
1435+
(browse-url (cider-grimoire-url name ns (cider--clojure-version))))
1436+
(message "Symbol %s not resolved" symbol)))
1437+
1438+
(defun cider-grimoire (query)
1439+
"Open the grimoire documentation for QUERY in the default web browser."
1440+
(interactive "P")
1441+
(cider-read-symbol-name "Symbol: " 'cider-grimoire-lookup query))
1442+
14111443
(defun cider-apropos-doc (button)
14121444
"Display documentation for the symbol represented at BUTTON."
14131445
(cider-doc-lookup (button-get button 'apropos-symbol)))

cider-mode.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
(define-key map (kbd "M-TAB") 'complete-symbol)
4141
(define-key map (kbd "C-c C-h a") 'cider-apropos)
4242
(define-key map (kbd "C-c C-h d") 'cider-apropos-documentation)
43+
(define-key map (kbd "C-c C-h g") 'cider-grimoire)
4344
(define-key map (kbd "C-M-x") 'cider-eval-defun-at-point)
4445
(define-key map (kbd "C-c C-c") 'cider-eval-defun-at-point)
4546
(define-key map (kbd "C-x C-e") 'cider-eval-last-sexp)

test/cider-tests.el

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,3 +542,15 @@
542542
(ert-deftest test-cider--url-to-file ()
543543
(should (equal "/space test" (cider--url-to-file "file:/space%20test")))
544544
(should (equal "C:/space test" (cider--url-to-file "file:/C:/space%20test"))))
545+
546+
;;; grimoire tests
547+
(ert-deftest cider-grimoire-replace-dashes ()
548+
(should (equal (cider-grimoire-replace-dashes "defn-") "defn_DASH"))
549+
(should (equal (cider-grimoire-replace-dashes "-map-indexed") "DASH_map_DASH_indexed"))
550+
(should (equal (cider-grimoire-replace-dashes "-foo-bar-baz-") "DASH_foo_DASH_bar_DASH_baz_DASH")))
551+
552+
(ert-deftest cider-grimoire-url ()
553+
(should (equal "http://grimoire.arrdem.com/1.5.0/clojure.core/defn_DASH/"
554+
(cider-grimoire-url "defn-" "clojure.core" "1.5.1")))
555+
(should (equal "http://grimoire.arrdem.com/1.5.0/clojure.core/"
556+
(cider-grimoire-url nil "clojure.core" "1.5.1"))))

0 commit comments

Comments
 (0)