From d43d89ef81b812418afafe7993110746d683584d Mon Sep 17 00:00:00 2001 From: Kato Muso Date: Sun, 2 Jun 2024 22:02:42 +0000 Subject: [PATCH] Add customizable variable cider-cheatsheet-select-type --- cider-cheatsheet.el | 48 +++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/cider-cheatsheet.el b/cider-cheatsheet.el index d2fc7fa20..d8d3bacf3 100644 --- a/cider-cheatsheet.el +++ b/cider-cheatsheet.el @@ -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" @@ -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."