branch: master
commit eb181fde0cf12f2c46c92fe753918a291cf3bea0
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
Call :post for :timeout
* hydra.el (hydra--make-defun): When both :timeout and :post are given,
if `hydra-timeout' runs out, it will call :post before
`hydra-keyboard-quit'.
(hydra-timeout): Update to call function if it's given. Always call
`hydra-keyboard-quit' afterwards.
For this example code:
(global-set-key
(kbd "C-c t")
(defhydra test-hydra-b
(:timeout 2.0 :post (message "test b quit"))
"test b"
("x" (message "x"))
("y" (message "y"))
("q" nil "quit")))
The message "test b quit" is issued:
- on "q"
- on "x" or "y", after one of them has started the timer, and the timer
ran out. The timer is set to 2.0 seconds, and is reset each time "x"
or "y" is pressed.
- not on a plain "C-c t"
Fixes #34
---
hydra.el | 13 +++++++++----
1 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/hydra.el b/hydra.el
index 2680f38..c5a74a2 100644
--- a/hydra.el
+++ b/hydra.el
@@ -610,7 +610,10 @@ OTHER-POST is an optional extension to the :post key of
BODY."
`(lambda () (hydra-cleanup)))))
,(or other-post
(when body-timeout
- `(hydra-timeout ,body-timeout))))))))))
+ (list 'hydra-timeout
+ body-timeout
+ (when body-post
+ (hydra--make-callable
body-post))))))))))))
(defun hydra-pink-fallback ()
"On intercepting a non-head, try to run it."
@@ -774,8 +777,7 @@ NAMES should be defined by `defhydradio' or similar."
"Timer for `hydra-timeout'.")
(defun hydra-timeout (secs &optional function)
- "In SECS seconds call FUNCTION.
-FUNCTION defaults to `hydra-disable'.
+ "In SECS seconds call FUNCTION, then `hydra-keyboard-quit'.
Cancel the previous `hydra-timeout'."
(cancel-timer hydra-timer)
(setq hydra-timer (timer-create))
@@ -783,7 +785,10 @@ Cancel the previous `hydra-timeout'."
(timer-relative-time (current-time) secs))
(timer-set-function
hydra-timer
- (or function #'hydra-keyboard-quit))
+ `(lambda ()
+ ,(when function
+ `(funcall ,function))
+ (hydra-keyboard-quit)))
(timer-activate hydra-timer))
;;* Macros