Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d43d89e

Browse files
committedJun 2, 2024
Add customizable variable cider-cheatsheet-select-type
1 parent 208887c commit d43d89e

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed
 

‎cider-cheatsheet.el

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ from ClojureDocs or any other function accepting a var as an argument."
5757
function)
5858
:package-version '(cider . "0.15.0"))
5959

60+
(defcustom cider-cheatsheet-select-type 'multi
61+
"Controls how cheatsheet is displayed when using `cider-cheatsheet-select`.
62+
63+
If `multi`, then provide a multi-step selection process where you need to go
64+
section by section until you find a var.
65+
66+
If `path`, then represent each completion candidate as a full path to a var."
67+
:type '(choice (const multi)
68+
(const path))
69+
:package-version '(cider . "0.15.0"))
70+
6071
(defconst cider-cheatsheet-hierarchy
6172
'(("Documentation"
6273
("REPL"
@@ -583,25 +594,28 @@ This list is supposed to have the following format:
583594
hierarchy))
584595

585596
;;;###autoload
586-
(defun cider-cheatsheet-select (&optional flat)
597+
(defun cider-cheatsheet-select ()
587598
"Navigate cheatsheet sections and show documentation for selected var.
588599
589-
With a prefix argument FLAT, represent each candidate as a full path to var."
590-
(interactive "P")
591-
(if flat
592-
(let* ((hierarchy (cider-cheatsheet--flatten-hierarchy cider-cheatsheet-hierarchy))
593-
(paths (mapcar (lambda (sections) (string-join sections " > ")) hierarchy))
594-
(path (completing-read "Select path: " paths))
595-
(var (car (last (split-string path " > ")))))
596-
(funcall cider-cheatsheet-default-action-function var))
597-
(let ((hierarchy cider-cheatsheet-hierarchy))
598-
(while (stringp (caar hierarchy))
599-
(let* ((sections (mapcar #'car hierarchy))
600-
(section (completing-read "Select section: " sections)))
601-
(setq hierarchy (map-elt hierarchy section))))
602-
(let* ((vars (seq-mapcat #'cider-cheatsheet--expand-vars hierarchy))
603-
(var (completing-read "Select var: " vars)))
604-
(funcall cider-cheatsheet-default-action-function var)))))
600+
Navigates through a multi-step selection process or represents each candidate
601+
as a full path to a var, depending on the value of `cider-cheatsheet-select-type'."
602+
(interactive)
603+
(cl-case cider-cheatsheet-select-type
604+
(multi
605+
(let ((hierarchy cider-cheatsheet-hierarchy))
606+
(while (stringp (caar hierarchy))
607+
(let* ((sections (mapcar #'car hierarchy))
608+
(section (completing-read "Select section: " sections)))
609+
(setq hierarchy (map-elt hierarchy section))))
610+
(let* ((vars (seq-mapcat #'cider-cheatsheet--expand-vars hierarchy))
611+
(var (completing-read "Select var: " vars)))
612+
(funcall cider-cheatsheet-default-action-function var))))
613+
(path
614+
(let* ((hierarchy (cider-cheatsheet--flatten-hierarchy cider-cheatsheet-hierarchy))
615+
(paths (mapcar (lambda (sections) (string-join sections " > ")) hierarchy))
616+
(path (completing-read "Select path: " paths))
617+
(var (car (last (split-string path " > ")))))
618+
(funcall cider-cheatsheet-default-action-function var)))))
605619

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

0 commit comments

Comments
 (0)
Please sign in to comment.