[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 9c68e0a 68/72: Add :timeout option to hydra body
From: |
Oleh Krehel |
Subject: |
[elpa] master 9c68e0a 68/72: Add :timeout option to hydra body |
Date: |
Fri, 06 Mar 2015 13:04:25 +0000 |
branch: master
commit 9c68e0af394ab742419779e2a1df894cbbfd8fcb
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Add :timeout option to hydra body
* hydra.el (hydra--make-defun): Call `hydra-timeout' with :timeout if
it's given.
(hydra-timer): New var to hold the timer.
(hydra-timeout): New function to call `hydra-keyboard-quit' with delay.
(hydra-keyboard-quit): Cancel `hydra-timeout' timer.
Re #34.
---
hydra.el | 24 ++++++++++++++++++++++--
1 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/hydra.el b/hydra.el
index 46465c8..308de99 100644
--- a/hydra.el
+++ b/hydra.el
@@ -370,6 +370,7 @@ BODY is the second argument to `defhydra'"
(interactive)
(hydra-disable)
(hydra-cleanup)
+ (cancel-timer hydra-timer)
nil)
(defun hydra-disable ()
@@ -552,7 +553,8 @@ OTHER-POST is an optional extension to the :post key of
BODY."
(format "%s\n\nCall the head: `%S'." doc (cadr head))
doc))
(hint (intern (format "%S/hint" name)))
- (body-color (hydra--body-color body)))
+ (body-color (hydra--body-color body))
+ (body-timeout (plist-get body :timeout)))
`(defun ,name ()
,doc
(interactive)
@@ -585,7 +587,9 @@ OTHER-POST is an optional extension to the :post key of
BODY."
body-post)
`(lambda () (hydra-cleanup) ,body-post)
`(lambda () (hydra-cleanup)))))
- ,other-post)))))))
+ ,(or other-post
+ (when body-timeout
+ `(hydra-timeout ,body-timeout))))))))))
(defun hydra-pink-fallback ()
"On intercepting a non-head, try to run it."
@@ -744,6 +748,22 @@ NAMES should be defined by `defhydradio' or similar."
(dolist (n names)
(set n (aref (get n 'range) 0))))
+(defvar hydra-timer (timer-create)
+ "Timer for `hydra-timeout'.")
+
+(defun hydra-timeout (secs &optional function)
+ "In SECS seconds call FUNCTION.
+FUNCTION defaults to `hydra-disable'.
+Cancel the previous `hydra-timeout'."
+ (cancel-timer hydra-timer)
+ (setq hydra-timer (timer-create))
+ (timer-set-time hydra-timer
+ (timer-relative-time nil secs))
+ (timer-set-function
+ hydra-timer
+ (or function #'hydra-keyboard-quit))
+ (timer-activate hydra-timer))
+
;;* Macros
;;** defhydra
;;;###autoload
- [elpa] master 55682e7 57/72: Improve handling of heads with duplicate cmd, (continued)
- [elpa] master 55682e7 57/72: Improve handling of heads with duplicate cmd, Oleh Krehel, 2015/03/06
- [elpa] master 7de26d0 64/72: Add `hydra-repeat': hydra-specific `repeat', Oleh Krehel, 2015/03/06
- [elpa] master f231dc0 55/72: Simplify the hint part of each head, Oleh Krehel, 2015/03/06
- [elpa] master 764f4b6 67/72: hydra.el (hydra--format): Amend key regex, Oleh Krehel, 2015/03/06
- [elpa] master 8e90037 65/72: Add some features for generating tables, Oleh Krehel, 2015/03/06
- [elpa] master 3040f45 61/72: hydra.el (hydra--format): Amend key regex, Oleh Krehel, 2015/03/06
- [elpa] master e1e2e3e 69/72: lv.el (lv-window): Bind `golden-ratio-mode' to nil, Oleh Krehel, 2015/03/06
- [elpa] master 8dec3cd 70/72: Allow for a %s(test) spec in docstring, Oleh Krehel, 2015/03/06
- [elpa] master 9fc928b 63/72: hydra.el (hydra--format): Amend key regex, Oleh Krehel, 2015/03/06
- [elpa] master 989ed95 53/72: Rename compat toggle - :nonheads -> :foreign-keys, Oleh Krehel, 2015/03/06
- [elpa] master 9c68e0a 68/72: Add :timeout option to hydra body,
Oleh Krehel <=
- [elpa] master e342c33 71/72: hydra-ox.el: Emulate org-mode export dispatch, Oleh Krehel, 2015/03/06
- [elpa] master 6d6bbd4 62/72: hydra.el (hydra-key-format-spec): set default to "%s", Oleh Krehel, 2015/03/06
- [elpa] master 26c3fee 60/72: Remove hydra-exit, Oleh Krehel, 2015/03/06
- [elpa] master 41f98bd 66/72: Don't wrap `hydra-repeat', Oleh Krehel, 2015/03/06
- [elpa] master 3222b0c 72/72: Merge commit 'e342c330807fdd09adba974611122d1c95bdf07d' from hydra, Oleh Krehel, 2015/03/06