diff options
author | Bozhidar Batsov <bozhidar@batsov.com> | 2018-01-30 01:13:06 +0700 |
---|---|---|
committer | Bozhidar Batsov <bozhidar@batsov.com> | 2018-01-30 01:13:06 +0700 |
commit | a433741df98c5b583ba79beb6d8c69149bd55683 (patch) | |
tree | 2a4b265cab0b51da6b934515808708be35bac7f6 /cider-cheatsheet.el | |
parent | 4e0458a9d165f8f9ec5c3f388112ec5fe468a45f (diff) |
Implement a basic interface for the Clojure Cheatsheet
It's based entirely on completing-read, which means it would look
nice with various minibuffer completion systems.
Down the road it'd be nice to do something like the ns browser
for the cheatsheet as well.
Diffstat (limited to 'cider-cheatsheet.el')
-rw-r--r-- | cider-cheatsheet.el | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/cider-cheatsheet.el b/cider-cheatsheet.el index 0b40f779..36fbe4d8 100644 --- a/cider-cheatsheet.el +++ b/cider-cheatsheet.el @@ -28,6 +28,9 @@ ;;; Code: +(require 'cider-doc) +(require 'seq) + (defconst cider-cheatsheet-hierarchy '(("Primitives" ("Numbers" @@ -508,6 +511,44 @@ Note that some Clojure symbols appear in more than once. This is entirely intentional. For instance, `map` belongs in the sections on collections and transducers.") +(defun cider-cheatsheet--expand-vars (list) + "Expand the symbols in LIST to fully-qualified var names. + +This list is supposed to have the following format: + + (my-ns var1 var2 var3)" + (let ((ns (car list)) + (vars (cdr list))) + (if (eq ns :special) + (mapcar #'symbol-name vars) + (mapcar (lambda (var) (format "%s/%s" ns var)) vars)))) + +(defun cider-cheatsheet--select-var (var-list) + "Expand the symbols in VAR-LIST to fully-qualified var names. + +The list can hold one or more lists inside - one per each namespace." + (let ((namespaced-vars (seq-mapcat #'cider-cheatsheet--expand-vars + (seq-remove (lambda (list) + (eq (car list) :url)) + var-list)))) + (cider-doc-lookup (completing-read "Select var: " namespaced-vars)))) + +;;;###autoload +(defun cider-cheatsheet () + "Navigate `cider-cheatsheet-hierarchy' with `completing-read'. + +When you make it to a Clojure var its doc buffer gets displayed." + (interactive) + (let ((section nil) + (cheatsheet-data cider-cheatsheet-hierarchy)) + (while (stringp (caar cheatsheet-data)) + (let* ((sections (seq-filter #'stringp (mapcar #'car cheatsheet-data))) + (sel-section (completing-read "Select cheatsheet section: " sections)) + (section-data (seq-find (lambda (elem) (equal (car elem) sel-section)) cheatsheet-data))) + (setq section sel-section) + (setq cheatsheet-data (cdr section-data)))) + (cider-cheatsheet--select-var cheatsheet-data))) + (provide 'cider-cheatsheet) ;;; cider-cheatsheet.el ends here |