branch: master commit 2eddb832a0a737e78b33525bdf18629ec62933ff Author: Oleh Krehel <ohwoeo...@gmail.com> Commit: Oleh Krehel <ohwoeo...@gmail.com>
hydra-test.el (hydra-format): New test * hydra.el (hydra-fontify-head-greyscale): New defun. Usable as `hydra-fontify-head-function'. --- hydra-test.el | 26 ++++++++++++++++++++++++++ hydra.el | 9 +++++++++ 2 files changed, 35 insertions(+), 0 deletions(-) diff --git a/hydra-test.el b/hydra-test.el index 7b3d24b..fe02d6d 100644 --- a/hydra-test.el +++ b/hydra-test.el @@ -673,6 +673,32 @@ The body can be accessed via `hydra-vi/body'." ("l" text-scale-decrease "out") ("q" nil "quit")))))) +(ert-deftest hydra-format () + (should (equal + (let ((hydra-fontify-head-function + 'hydra-fontify-head-greyscale)) + (hydra--format + 'hydra-toggle + nil + " +_a_ abbrev-mode: %`abbrev-mode +_d_ debug-on-error: %`debug-on-error +_f_ auto-fill-mode: %`auto-fill-function +" '(("a" abbrev-mode nil) + ("d" toggle-debug-on-error nil) + ("f" auto-fill-mode nil) + ("g" golden-ratio-mode nil) + ("t" toggle-truncate-lines nil) + ("w" whitespace-mode nil) + ("q" nil "quit")))) + '(concat (format " +% 3s abbrev-mode: %S +% 3s debug-on-error: %S +% 3s auto-fill-mode: %S +" "{a}" abbrev-mode "{d}" debug-on-error "{f}" auto-fill-function) "[[q]]: quit")))) + + + (provide 'hydra-test) ;;; hydra-test.el ends here diff --git a/hydra.el b/hydra.el index ace2552..5ea4640 100644 --- a/hydra.el +++ b/hydra.el @@ -354,6 +354,15 @@ NAME, BODY, DOCSTRING and HEADS are parameters to `defhydra'." HEAD's binding is returned as a string with a colored face." (propertize (car head) 'face (hydra--face head body))) +(defun hydra-fontify-head-greyscale (head body) + "Produce a pretty string from HEAD and BODY. +HEAD's binding is returned as a string wrapped with [] or {}." + (let ((color (hydra--head-color head body))) + (format + (if (eq color 'blue) + "[%s]" + "{%s}") (car head)))) + (defun hydra-fontify-head (head body) "Produce a pretty string from HEAD and BODY." (funcall (or hydra-fontify-head-function 'hydra-fontify-head-default)