branch: master commit f3c4dd7a026e49110a280dba9e0173d86ecdf9d4 Author: Oleh Krehel <ohwoeo...@gmail.com> Commit: Oleh Krehel <ohwoeo...@gmail.com>
hydra.el (hydra--hint): allow duplicate functions in heads * hydra.el (hydra--hint): Duplicate functions will be concatenated. Example: (defhydra hydra-zoom (global-map "<f2>") "zoom" ("g" text-scale-increase "in") ("l" text-scale-decrease "out") ("0" (text-scale-set 0) "reset") ("1" (text-scale-set 0) :bind nil) ("2" (text-scale-set 0) :bind nil :color blue)) Here, the hint will be: "zoom: [g]: in, [l]: out, [0 1 2]: reset." And "2" will be colored blue. Fixes #26 --- hydra.el | 44 +++++++++++++++++++++++++++----------------- 1 files changed, 27 insertions(+), 17 deletions(-) diff --git a/hydra.el b/hydra.el index a1bc9e9..95a34af 100644 --- a/hydra.el +++ b/hydra.el @@ -214,23 +214,33 @@ Return DEFAULT if PROP is not in H." (defun hydra--hint (docstring heads body-color) "Generate a hint from DOCSTRING and HEADS and BODY-COLOR. It's intended for the echo area, when a Hydra is active." - (format "%s: %s." - docstring - (mapconcat - (lambda (h) - (format - (if (stringp (cl-caddr h)) - (concat "[%s]: " (cl-caddr h)) - "%s") - (propertize - (car h) 'face - (hydra--face h body-color)))) - (cl-remove-if - (lambda (x) - (and (> (length x) 2) - (null (cl-caddr x)))) - heads) - ", "))) + (let (alist) + (dolist (h heads) + (let ((val (assoc (cadr h) alist)) + (pstr (propertize (car h) 'face + (hydra--face h body-color)))) + (unless (and (> (length h) 2) + (null (cl-caddr h))) + (if val + (setf (cadr val) + (concat (cadr val) " " pstr)) + (push + (cons (cadr h) + (cons pstr + (and (stringp (cl-caddr h)) (cl-caddr h)))) + alist))))) + + (format "%s: %s." + docstring + (mapconcat + (lambda (x) + (format + (if (cdr x) + (concat "[%s]: " (cdr x)) + "%s") + (car x))) + (nreverse (mapcar #'cdr alist)) + ", ")))) (defun hydra-disable () "Disable the current Hydra."