|
32 | 32 | (require 'cl-lib) |
33 | 33 | (require 'map) |
34 | 34 | (require 'seq) |
| 35 | +(require 'subr-x) |
35 | 36 |
|
36 | 37 | (defconst cider-cheatsheet-hierarchy |
37 | 38 | '(("Documentation" |
@@ -549,18 +550,35 @@ This list is supposed to have the following format: |
549 | 550 | (mapcar #'symbol-name vars) |
550 | 551 | (mapcar (lambda (var) (format "%s/%s" ns var)) vars)))) |
551 | 552 |
|
| 553 | +(defun cider-cheatsheet--flatten-hierarchy (hierarchy &optional sections) |
| 554 | + "Transform HIERARCHY to lists each representing a path with SECTIONS before var." |
| 555 | + (seq-mapcat (lambda (node) |
| 556 | + (if (stringp (car node)) |
| 557 | + (cider-cheatsheet--flatten-hierarchy (cdr node) (cons (car node) sections)) |
| 558 | + (mapcar (lambda (var) (reverse (cons var sections))) |
| 559 | + (cider-cheatsheet--expand-vars node)))) |
| 560 | + hierarchy)) |
| 561 | + |
552 | 562 | ;;;###autoload |
553 | | -(defun cider-cheatsheet-select () |
554 | | - "Navigate cheatsheet sections and show documentation for selected var." |
555 | | - (interactive) |
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)))) |
| 563 | +(defun cider-cheatsheet-select (&optional flat) |
| 564 | + "Navigate cheatsheet sections and show documentation for selected var. |
| 565 | +
|
| 566 | +With a prefix argument FLAT, represent each candidate as a full path to var." |
| 567 | + (interactive "P") |
| 568 | + (if flat |
| 569 | + (let* ((hierarchy (cider-cheatsheet--flatten-hierarchy cider-cheatsheet-hierarchy)) |
| 570 | + (paths (mapcar (lambda (sections) (string-join sections " > ")) hierarchy)) |
| 571 | + (path (completing-read "Select path: " paths)) |
| 572 | + (var (car (last (split-string path " > "))))) |
| 573 | + (cider-doc-lookup var)) |
| 574 | + (let ((hierarchy cider-cheatsheet-hierarchy)) |
| 575 | + (while (stringp (caar hierarchy)) |
| 576 | + (let* ((sections (mapcar #'car hierarchy)) |
| 577 | + (section (completing-read "Select section: " sections))) |
| 578 | + (setq hierarchy (map-elt hierarchy section)))) |
| 579 | + (let* ((vars (seq-mapcat #'cider-cheatsheet--expand-vars hierarchy)) |
| 580 | + (var (completing-read "Select var: " vars))) |
| 581 | + (cider-doc-lookup var))))) |
564 | 582 |
|
565 | 583 | (cl-defun cider-cheatsheet--insert-hierarchy (hierarchy &optional (level 0)) |
566 | 584 | "Insert HIERARCHY with visual indentation for LEVEL." |
|
0 commit comments