-
-
Notifications
You must be signed in to change notification settings - Fork 645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an alternative way to display cider-cheatsheet-select
#3686
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
(require 'cl-lib) | ||
(require 'map) | ||
(require 'seq) | ||
(require 'subr-x) | ||
|
||
(defconst cider-cheatsheet-hierarchy | ||
'(("Documentation" | ||
|
@@ -549,18 +550,35 @@ This list is supposed to have the following format: | |
(mapcar #'symbol-name vars) | ||
(mapcar (lambda (var) (format "%s/%s" ns var)) vars)))) | ||
|
||
(defun cider-cheatsheet--flatten-hierarchy (hierarchy &optional sections) | ||
"Transform HIERARCHY to lists each representing a path with SECTIONS before var." | ||
(seq-mapcat (lambda (node) | ||
(if (stringp (car node)) | ||
(cider-cheatsheet--flatten-hierarchy (cdr node) (cons (car node) sections)) | ||
(mapcar (lambda (var) (reverse (cons var sections))) | ||
(cider-cheatsheet--expand-vars node)))) | ||
hierarchy)) | ||
|
||
;;;###autoload | ||
(defun cider-cheatsheet-select () | ||
"Navigate cheatsheet sections and show documentation for selected var." | ||
(interactive) | ||
(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))) | ||
(cider-doc-lookup var)))) | ||
(defun cider-cheatsheet-select (&optional flat) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps this can be a defcustom instead and you can use the prefix arg to invert whatever the value of the defcustom is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea! I've seen such a pattern a few times, but haven't thought about it this time. I planned to think about customizable variables later, so I will keep this in mind. |
||
"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 " > "))))) | ||
(cider-doc-lookup 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))) | ||
(cider-doc-lookup var))))) | ||
|
||
(cl-defun cider-cheatsheet--insert-hierarchy (hierarchy &optional (level 0)) | ||
"Insert HIERARCHY with visual indentation for LEVEL." | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In light of my last comment you can remove this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I actually use
string-join
fromsubr-x
, I think it will be okay to be explicit about it by requiring it.