Skip to content

Commit

Permalink
Add customizable variable cider-cheatsheet-select-type
Browse files Browse the repository at this point in the history
  • Loading branch information
katomuso committed Jun 2, 2024
1 parent 208887c commit d43d89e
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions cider-cheatsheet.el
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ from ClojureDocs or any other function accepting a var as an argument."
function)
:package-version '(cider . "0.15.0"))

(defcustom cider-cheatsheet-select-type 'multi
"Controls how cheatsheet is displayed when using `cider-cheatsheet-select`.
If `multi`, then provide a multi-step selection process where you need to go
section by section until you find a var.
If `path`, then represent each completion candidate as a full path to a var."
:type '(choice (const multi)
(const path))
:package-version '(cider . "0.15.0"))

(defconst cider-cheatsheet-hierarchy
'(("Documentation"
("REPL"
Expand Down Expand Up @@ -583,25 +594,28 @@ This list is supposed to have the following format:
hierarchy))

;;;###autoload
(defun cider-cheatsheet-select (&optional flat)
(defun cider-cheatsheet-select ()
"Navigate cheatsheet sections and show documentation for selected var.
With a prefix argument FLAT, represent each candidate as a full path to var."
(interactive "P")
(if flat
(let* ((hierarchy (cider-cheatsheet--flatten-hierarchy cider-cheatsheet-hierarchy))
(paths (mapcar (lambda (sections) (string-join sections " > ")) hierarchy))
(path (completing-read "Select path: " paths))
(var (car (last (split-string path " > ")))))
(funcall cider-cheatsheet-default-action-function var))
(let ((hierarchy cider-cheatsheet-hierarchy))
(while (stringp (caar hierarchy))
(let* ((sections (mapcar #'car hierarchy))
(section (completing-read "Select section: " sections)))
(setq hierarchy (map-elt hierarchy section))))
(let* ((vars (seq-mapcat #'cider-cheatsheet--expand-vars hierarchy))
(var (completing-read "Select var: " vars)))
(funcall cider-cheatsheet-default-action-function var)))))
Navigates through a multi-step selection process or represents each candidate
as a full path to a var, depending on the value of `cider-cheatsheet-select-type'."
(interactive)
(cl-case cider-cheatsheet-select-type
(multi
(let ((hierarchy cider-cheatsheet-hierarchy))
(while (stringp (caar hierarchy))
(let* ((sections (mapcar #'car hierarchy))
(section (completing-read "Select section: " sections)))
(setq hierarchy (map-elt hierarchy section))))
(let* ((vars (seq-mapcat #'cider-cheatsheet--expand-vars hierarchy))
(var (completing-read "Select var: " vars)))
(funcall cider-cheatsheet-default-action-function var))))
(path
(let* ((hierarchy (cider-cheatsheet--flatten-hierarchy cider-cheatsheet-hierarchy))
(paths (mapcar (lambda (sections) (string-join sections " > ")) hierarchy))
(path (completing-read "Select path: " paths))
(var (car (last (split-string path " > ")))))
(funcall cider-cheatsheet-default-action-function var)))))

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

0 comments on commit d43d89e

Please sign in to comment.