[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master eb181fd 23/28: Call :post for :timeout

From: Oleh Krehel
Subject: [elpa] master eb181fd 23/28: Call :post for :timeout
Date: Sun, 22 Mar 2015 16:34:47 +0000

branch: master
commit eb181fde0cf12f2c46c92fe753918a291cf3bea0
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    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-timeout): Update to call function if it's given. Always call
    `hydra-keyboard-quit' afterwards.
    For this example code:
     (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 
                                   `(lambda () (hydra-cleanup)))))
                       ,(or other-post
                            (when body-timeout
-                             `(hydra-timeout ,body-timeout))))))))))
+                             (list 'hydra-timeout
+                                   body-timeout
+                                   (when body-post
+                                     (hydra--make-callable 
 (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))
-   (or function #'hydra-keyboard-quit))
+   `(lambda ()
+      ,(when function
+             `(funcall ,function))
+      (hydra-keyboard-quit)))
   (timer-activate hydra-timer))
 ;;* Macros

reply via email to

[Prev in Thread] Current Thread [Next in Thread]