branch: master commit 1d378c6887f4ad2f7d4797274e98f020e56f375b Author: Oleh Krehel <ohwoeo...@gmail.com> Commit: Oleh Krehel <ohwoeo...@gmail.com>
Allow to set hydra verbosity * hydra.el (hydra--make-defun): Rewrite `hydra-show-hint' arglist. The hydra name should also be passed. (hydra-set-property): New defun. (hydra-show-hint): Add `caller' arg - the name of the hydra. It can be used as a key in `hydra-props-alist'. (hydra-idle-message): Add arg. * hydra-test.el: Update tests. --- hydra-test.el | 39 +++++++++++++++++++++++++++------------ hydra.el | 35 ++++++++++++++++++++++++++--------- 2 files changed, 53 insertions(+), 21 deletions(-) diff --git a/hydra-test.el b/hydra-test.el index 1c14c70..88d12a8 100644 --- a/hydra-test.el +++ b/hydra-test.el @@ -130,7 +130,8 @@ Call the head: `first-error'." (message "%S" err) (unless hydra-lv (sit-for 0.8)))) (hydra-show-hint - hydra-error/hint) + hydra-error/hint + (quote hydra-error)) (hydra-set-transient-map hydra-error/keymap (lambda nil @@ -164,7 +165,8 @@ Call the head: `next-error'." (message "%S" err) (unless hydra-lv (sit-for 0.8)))) (hydra-show-hint - hydra-error/hint) + hydra-error/hint + (quote hydra-error)) (hydra-set-transient-map hydra-error/keymap (lambda nil @@ -198,7 +200,8 @@ Call the head: `previous-error'." (message "%S" err) (unless hydra-lv (sit-for 0.8)))) (hydra-show-hint - hydra-error/hint) + hydra-error/hint + (quote hydra-error)) (hydra-set-transient-map hydra-error/keymap (lambda nil @@ -234,7 +237,8 @@ The body can be accessed via `hydra-error/body'." (setq hydra-curr-body-fn (quote hydra-error/body))) (hydra-show-hint - hydra-error/hint) + hydra-error/hint + (quote hydra-error)) (hydra-set-transient-map hydra-error/keymap (lambda nil @@ -410,7 +414,8 @@ The body can be accessed via `hydra-toggle/body'." (setq hydra-curr-body-fn (quote hydra-toggle/body))) (hydra-show-hint - hydra-toggle/hint) + hydra-toggle/hint + (quote hydra-toggle)) (hydra-set-transient-map hydra-toggle/keymap (lambda nil @@ -511,7 +516,9 @@ Call the head: `next-line'." ((quit error) (message "%S" err) (unless hydra-lv (sit-for 0.8)))) - (hydra-show-hint hydra-vi/hint) + (hydra-show-hint + hydra-vi/hint + (quote hydra-vi)) (hydra-set-transient-map hydra-vi/keymap (lambda nil @@ -544,7 +551,9 @@ Call the head: `previous-line'." ((quit error) (message "%S" err) (unless hydra-lv (sit-for 0.8)))) - (hydra-show-hint hydra-vi/hint) + (hydra-show-hint + hydra-vi/hint + (quote hydra-vi)) (hydra-set-transient-map hydra-vi/keymap (lambda nil @@ -582,7 +591,9 @@ The body can be accessed via `hydra-vi/body'." (hydra-keyboard-quit) (setq hydra-curr-body-fn (quote hydra-vi/body))) - (hydra-show-hint hydra-vi/hint) + (hydra-show-hint + hydra-vi/hint + (quote hydra-vi)) (hydra-set-transient-map hydra-vi/keymap (lambda nil @@ -683,7 +694,8 @@ Call the head: `(text-scale-set 0)'." (message "%S" err) (unless hydra-lv (sit-for 0.8)))) (hydra-show-hint - hydra-zoom/hint) + hydra-zoom/hint + (quote hydra-zoom)) (hydra-set-transient-map hydra-zoom/keymap (lambda nil @@ -725,7 +737,8 @@ The body can be accessed via `hydra-zoom/body'." (setq hydra-curr-body-fn (quote hydra-zoom/body))) (hydra-show-hint - hydra-zoom/hint) + hydra-zoom/hint + (quote hydra-zoom)) (hydra-set-transient-map hydra-zoom/keymap (lambda nil @@ -826,7 +839,8 @@ Call the head: `(text-scale-set 0)'." (message "%S" err) (unless hydra-lv (sit-for 0.8)))) (hydra-show-hint - hydra-zoom/hint) + hydra-zoom/hint + (quote hydra-zoom)) (hydra-set-transient-map hydra-zoom/keymap (lambda nil @@ -868,7 +882,8 @@ The body can be accessed via `hydra-zoom/body'." (setq hydra-curr-body-fn (quote hydra-zoom/body))) (hydra-show-hint - hydra-zoom/hint) + hydra-zoom/hint + (quote hydra-zoom)) (hydra-set-transient-map hydra-zoom/keymap (lambda nil diff --git a/hydra.el b/hydra.el index 14d275e..67b1cb5 100644 --- a/hydra.el +++ b/hydra.el @@ -768,8 +768,8 @@ BODY-AFTER-EXIT is added to the end of the wrapper." (unless hydra-lv (sit-for 0.8))))) ,(if (and body-idle (eq (cadr head) 'body)) - `(hydra-idle-message ,body-idle ,hint) - `(hydra-show-hint ,hint)) + `(hydra-idle-message ,body-idle ,hint ',name) + `(hydra-show-hint ,hint ',name)) (hydra-set-transient-map ,keymap (lambda () (hydra-keyboard-quit) ,body-before-exit) @@ -779,11 +779,28 @@ BODY-AFTER-EXIT is added to the end of the wrapper." ,(when body-timeout `(hydra-timeout ,body-timeout)))))))) -(defun hydra-show-hint (hint) - (when hydra-is-helpful - (if hydra-lv - (lv-message (eval hint)) - (message (eval hint))))) +(defvar hydra-props-alist nil) + +(defun hydra-set-property (name key val) + (let ((entry (assoc name hydra-props-alist)) + plist) + (when (null entry) + (add-to-list 'hydra-props-alist (list name)) + (setq entry (assoc name hydra-props-alist))) + (setq plist (cdr entry)) + (setcdr entry (plist-put plist key val)))) + +(defun hydra-show-hint (hint caller) + (let ((verbosity (plist-get (cdr (assoc caller hydra-props-alist)) + :verbosity))) + (cond ((eq verbosity 0)) + ((eq verbosity 1) + (message (eval hint))) + (t + (when hydra-is-helpful + (if hydra-lv + (lv-message (eval hint)) + (message (eval hint)))))))) (defmacro hydra--make-funcall (sym) "Transform SYM into a `funcall' to call it." @@ -914,7 +931,7 @@ NAMES should be defined by `defhydradio' or similar." (dolist (n names) (set n (aref (get n 'range) 0)))) -(defun hydra-idle-message (secs hint) +(defun hydra-idle-message (secs hint name) "In SECS seconds display HINT." (cancel-timer hydra-message-timer) (setq hydra-message-timer (timer-create)) @@ -923,7 +940,7 @@ NAMES should be defined by `defhydradio' or similar." (timer-set-function hydra-message-timer (lambda () - (hydra-show-hint hint) + (hydra-show-hint hint name) (cancel-timer hydra-message-timer))) (timer-activate hydra-message-timer))