Skip to content

Commit 2b37d0f

Browse files
katomusobbatsov
authored andcommitted
Refactor cider-cheatsheet-select
1 parent 27245f3 commit 2b37d0f

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

cider-cheatsheet.el

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
(require 'cider-doc)
3232
(require 'cl-lib)
33+
(require 'map)
3334
(require 'seq)
3435

3536
(defconst cider-cheatsheet-hierarchy
@@ -548,24 +549,18 @@ This list is supposed to have the following format:
548549
(mapcar #'symbol-name vars)
549550
(mapcar (lambda (var) (format "%s/%s" ns var)) vars))))
550551

551-
(defun cider-cheatsheet--select-var (var-list)
552-
"Expand the symbols in VAR-LIST to fully-qualified var names.
553-
554-
The list can hold one or more lists inside - one per each namespace."
555-
(let ((namespaced-vars (seq-mapcat #'cider-cheatsheet--expand-vars var-list)))
556-
(cider-doc-lookup (completing-read "Select var: " namespaced-vars))))
557-
558552
;;;###autoload
559553
(defun cider-cheatsheet-select ()
560554
"Navigate cheatsheet sections and show documentation for selected var."
561555
(interactive)
562-
(let ((cheatsheet-data cider-cheatsheet-hierarchy))
563-
(while (stringp (caar cheatsheet-data))
564-
(let* ((sections (mapcar #'car cheatsheet-data))
565-
(sel-section (completing-read "Select cheatsheet section: " sections))
566-
(section-data (seq-find (lambda (elem) (equal (car elem) sel-section)) cheatsheet-data)))
567-
(setq cheatsheet-data (cdr section-data))))
568-
(cider-cheatsheet--select-var cheatsheet-data)))
556+
(let ((hierarchy cider-cheatsheet-hierarchy))
557+
(while (stringp (caar hierarchy))
558+
(let* ((sections (mapcar #'car hierarchy))
559+
(section (completing-read "Select section: " sections)))
560+
(setq hierarchy (map-elt hierarchy section))))
561+
(let* ((vars (seq-mapcat #'cider-cheatsheet--expand-vars hierarchy))
562+
(var (completing-read "Select var: " vars)))
563+
(cider-doc-lookup var))))
569564

570565
(cl-defun cider-cheatsheet--insert-hierarchy (hierarchy &optional (level 0))
571566
"Insert HIERARCHY with visual indentation for LEVEL."

0 commit comments

Comments
 (0)