From c59571c7222511fdd0b0b33bb19155e732bee8e4 Mon Sep 17 00:00:00 2001 From: jao Date: Mon, 22 Mar 2021 19:04:14 +0000 Subject: properly recursive embark action indicator (ah, the riches) --- consult.org | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/consult.org b/consult.org index 027e60d..7dcf80b 100644 --- a/consult.org +++ b/consult.org @@ -202,16 +202,22 @@ (setq jao-embark--excluded '(embark-collect-snapshot embark-collect-live embark-export - embark-become embark-isearch nil)) + embark-keymap-help embark-become embark-isearch nil)) - (defun jao-embark--bind-desc (descs x) + (defun jao-embark--key-str (k) + (if (numberp k) (single-key-description k) (key-description k))) + + (defun jao-embark--bind-desc (descs x prefix) (let ((k (car x)) (c (cdr x))) - (cond ((memq c jao-embark--excluded) descs) + (cond ((keymapp c) + (let ((cds (jao-embark--keymap-descs c (jao-embark--key-str k)))) + (cons (max (or (car cds) 0) (or (car descs) 0)) + (cons (max (or (cadr cds) 0) (or (cadr descs) 0)) + (append (cddr descs) (cddr cds)))))) + ((memq c jao-embark--excluded) descs) ((symbolp c) - (let* ((desc (if (numberp k) - (single-key-description k) - (key-description k))) - (desc (format "%s" desc)) + (let* ((desc (jao-embark--key-str k)) + (desc (format "%s%s" (or prefix "") desc)) (doc (car (split-string (or (ignore-errors (documentation c)) "") "\n"))) @@ -219,10 +225,11 @@ (cons (max (length desc) (car descs)) (cons (max (length fun) (cadr descs)) (cons (list desc fun doc) (cddr descs)))))) - (t descs)))) + (t (message "i've skipped %S" x) descs)))) - (defun jao-embark--keymap-descs (k) - (seq-reduce #'jao-embark--bind-desc (cdr (keymap-canonicalize k)) '(0 0))) + (defun jao-embark--keymap-descs (k prefix) + (seq-reduce `(lambda (descs x) (jao-embark--bind-desc descs x ,prefix)) + (cdr (keymap-canonicalize k)) '(0 0))) (defun jao-embark--dstr (d) (let ((s (cadr d))) (if (string-prefix-p "embark" s) "" s))) @@ -232,7 +239,7 @@ (read-only-mode -1) (setq-local cursor-type nil) (delete-region (point-min) (point-max)) - (let* ((descs (jao-embark--keymap-descs keymap)) + (let* ((descs (jao-embark--keymap-descs keymap "")) (fmt (format "%%-%ds %%-%ds %%s\n" (cadr descs) (car descs)))) (seq-each (lambda (desc) (insert (format fmt @@ -240,7 +247,7 @@ (propertize (car desc) 'face 'embark-keybinding) (propertize (caddr desc) 'face 'italic)))) (seq-sort-by 'jao-embark--dstr 'string-greaterp (cddr descs)))) - (if target (insert (format "Action for '%s'" target)) (delete-char -1)) + (if target (insert (format "\nAction for '%s'" target)) (delete-char -1)) (read-only-mode 1) (let ((display-buffer-alist (append display-buffer-alist jao-embark--default-display))) -- cgit v1.2.3