[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 60ce256 41/45: Add an idle message timeout option
From: |
Oleh Krehel |
Subject: |
[elpa] master 60ce256 41/45: Add an idle message timeout option |
Date: |
Thu, 16 Apr 2015 12:45:56 +0000 |
branch: master
commit 60ce25698b90b388cb1332137c85a504bc09ed77
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Add an idle message timeout option
* hydra.el (hydra-keyboard-quit): Update.
(hydra--make-defun): Update.
(hydra-timeout-timer): Rename from `hydra-timer'.
(hydra-message-timer): New defvar.
(hydra-idle-message): New defun.
(hydra-timeout): Update.
Small example:
(defhydra hydra-zoom (:idle 1.0)
"zoom"
("g" text-scale-increase "in")
("l" text-scale-decrease "out"))
(global-set-key (kbd "<f2> g") 'hydra-zoom/body)
With this code, `hydra-zoom/body' will display the hint not immediately
but after 1.0 seconds. If you manage to exit the hydra by then, the hint
will not be displayed. Other functions will display the hint
immediately.
Fixes #108
---
hydra.el | 47 +++++++++++++++++++++++++++++++++++------------
1 files changed, 35 insertions(+), 12 deletions(-)
diff --git a/hydra.el b/hydra.el
index 0ce5e44..d81ac2a 100644
--- a/hydra.el
+++ b/hydra.el
@@ -369,7 +369,8 @@ Return DEFAULT if PROP is not in H."
"Quitting function similar to `keyboard-quit'."
(interactive)
(hydra-disable)
- (cancel-timer hydra-timer)
+ (cancel-timer hydra-timeout-timer)
+ (cancel-timer hydra-message-timer)
(when hydra--input-method-function
(setq input-method-function hydra--input-method-function)
(setq hydra--input-method-function nil))
@@ -550,7 +551,8 @@ BODY-AFTER-EXIT is added to the end of the wrapper."
doc))
(hint (intern (format "%S/hint" name)))
(body-foreign-keys (hydra--body-foreign-keys body))
- (body-timeout (plist-get body :timeout)))
+ (body-timeout (plist-get body :timeout))
+ (body-idle (plist-get body :idle)))
`(defun ,name ()
,doc
(interactive)
@@ -576,10 +578,12 @@ BODY-AFTER-EXIT is added to the end of the wrapper."
(message "%S" err)
(unless hydra-lv
(sit-for 0.8)))))
- (when hydra-is-helpful
- (if hydra-lv
- (lv-message (eval ,hint))
- (message (eval ,hint))))
+ ,(if (and body-idle (eq (cadr head) 'body))
+ `(hydra-idle-message ,body-idle ,hint)
+ `(when hydra-is-helpful
+ (if hydra-lv
+ (lv-message (eval ,hint))
+ (message (eval ,hint)))))
(hydra-set-transient-map
,keymap
(lambda () (hydra-keyboard-quit) ,body-before-exit)
@@ -705,23 +709,42 @@ NAMES should be defined by `defhydradio' or similar."
(dolist (n names)
(set n (aref (get n 'range) 0))))
-(defvar hydra-timer (timer-create)
+(defvar hydra-timeout-timer (timer-create)
"Timer for `hydra-timeout'.")
+(defvar hydra-message-timer (timer-create)
+ "Timer for the hint.")
+
+(defun hydra-idle-message (secs hint)
+ "In SECS seconds display HINT."
+ (cancel-timer hydra-message-timer)
+ (setq hydra-message-timer (timer-create))
+ (timer-set-time hydra-message-timer
+ (timer-relative-time (current-time) secs))
+ (timer-set-function
+ hydra-message-timer
+ (lambda ()
+ (when hydra-is-helpful
+ (if hydra-lv
+ (lv-message (eval hint))
+ (message (eval hint))))
+ (cancel-timer hydra-message-timer)))
+ (timer-activate hydra-message-timer))
+
(defun hydra-timeout (secs &optional function)
"In SECS seconds call FUNCTION, then function `hydra-keyboard-quit'.
Cancel the previous `hydra-timeout'."
- (cancel-timer hydra-timer)
- (setq hydra-timer (timer-create))
- (timer-set-time hydra-timer
+ (cancel-timer hydra-timeout-timer)
+ (setq hydra-timeout-timer (timer-create))
+ (timer-set-time hydra-timeout-timer
(timer-relative-time (current-time) secs))
(timer-set-function
- hydra-timer
+ hydra-timeout-timer
`(lambda ()
,(when function
`(funcall ,function))
(hydra-keyboard-quit)))
- (timer-activate hydra-timer))
+ (timer-activate hydra-timeout-timer))
;;* Macros
;;;###autoload
- [elpa] master 19cc1be 21/45: Use `unwind-protect' for :after-exit, (continued)
- [elpa] master 19cc1be 21/45: Use `unwind-protect' for :after-exit, Oleh Krehel, 2015/04/16
- [elpa] master 986226f 18/45: Simplify `keyboard-quit', Oleh Krehel, 2015/04/16
- [elpa] master 51e7753 19/45: Alias :post to :before-exit, and add :after-exit, Oleh Krehel, 2015/04/16
- [elpa] master 3d7d8c7 20/45: Add basic error handling, Oleh Krehel, 2015/04/16
- [elpa] master 684f8a2 39/45: Add integration test for red hydras temporarily exiting, Oleh Krehel, 2015/04/16
- [elpa] master d3d435d 25/45: Finalize head inheritance, Oleh Krehel, 2015/04/16
- [elpa] master b2c9ea6 36/45: README.md: Update intro, Oleh Krehel, 2015/04/16
- [elpa] master d678cc0 34/45: Work around `overriding-terminal-local-map' being terminal-local, Oleh Krehel, 2015/04/16
- [elpa] master d6e00ed 33/45: README.md: Add video demo link, Oleh Krehel, 2015/04/16
- [elpa] master 97c9b9b 32/45: Move `this-command' setter, Oleh Krehel, 2015/04/16
- [elpa] master 60ce256 41/45: Add an idle message timeout option,
Oleh Krehel <=
- [elpa] master 99b2aea 35/45: hydra.el (hydra--format): Match alnum for the "_..._" syntax, Oleh Krehel, 2015/04/16
- [elpa] master f01c87e 38/45: Fix red heads not exiting temporarily, Oleh Krehel, 2015/04/16
- [elpa] master f972634 45/45: Merge commit '742d66a63e86ac740e610faa5abba97e7f8ad5c2' from hydra, Oleh Krehel, 2015/04/16
- [elpa] master aeaabd3 42/45: hydra.el (defhydra): Re-throw a caught error when debug-on-error, Oleh Krehel, 2015/04/16
- [elpa] master 742d66a 44/45: hydra.el: Bump version, Oleh Krehel, 2015/04/16
- [elpa] master 09b63b5 43/45: Don't re-activate key chords too early, Oleh Krehel, 2015/04/16
- [elpa] master cab5a73 37/45: README.md: Update `hydra-zoom/body', Oleh Krehel, 2015/04/16
- [elpa] master 00aef59 40/45: hydra.el (hydra--format): Fix "s-t" issue, Oleh Krehel, 2015/04/16