emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] master 192c5b0 03/24: Allow heads to conditionally exit


From: Oleh Krehel
Subject: [elpa] master 192c5b0 03/24: Allow heads to conditionally exit
Date: Fri, 01 May 2015 14:27:08 +0000

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

    Allow heads to conditionally exit
    
    * hydra.el (hydra-deactivate): New defvar.
    (hydra-set-transient-map): When `hydra-deactivate' is set, quit.
    (hydra-disable): Make sure that `hydra-deactivate' is reset back to nil.
    
    Fixes #115
    
    Example: zoom in at most 5 times, then quit.
    
    (defvar hydra-zoom-amount 1)
    
    (defhydra hydra-zoom (global-map "<f2>")
      "zoom"
      ("g"
       (if (>= hydra-zoom-amount 5)
           (progn
             (setq hydra-zoom-amount 1)
             (setq hydra-deactivate t))
         (cl-incf hydra-zoom-amount)
         (call-interactively 'text-scale-increase))
       "in")
      ("l" text-scale-decrease "out"))
---
 hydra.el |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/hydra.el b/hydra.el
index 89254b6..fdd3847 100644
--- a/hydra.el
+++ b/hydra.el
@@ -88,6 +88,10 @@
 (defvar hydra-curr-foreign-keys nil
   "The current :foreign-keys behavior.")
 
+(defvar hydra-deactivate nil
+  "If a Hydra head sets this to t, exit the Hydra even if the
+  head wasn't designated for exiting.")
+
 (defun hydra-set-transient-map (keymap on-exit &optional foreign-keys)
   "Set KEYMAP to the highest priority.
 
@@ -99,11 +103,13 @@ that isn't in KEYMAP is called:
 nil: deactivate KEYMAP and run the command.
 run: keep KEYMAP and run the command.
 warn: keep KEYMAP and issue a warning instead of running the command."
-  (setq hydra-curr-map keymap)
-  (setq hydra-curr-on-exit on-exit)
-  (setq hydra-curr-foreign-keys foreign-keys)
-  (add-hook 'pre-command-hook 'hydra--clearfun)
-  (internal-push-keymap keymap 'overriding-terminal-local-map))
+  (if hydra-deactivate
+      (hydra-keyboard-quit)
+    (setq hydra-curr-map keymap)
+    (setq hydra-curr-on-exit on-exit)
+    (setq hydra-curr-foreign-keys foreign-keys)
+    (add-hook 'pre-command-hook 'hydra--clearfun)
+    (internal-push-keymap keymap 'overriding-terminal-local-map)))
 
 (defun hydra--clearfun ()
   "Disable the current Hydra unless `this-command' is a head."
@@ -128,6 +134,7 @@ warn: keep KEYMAP and issue a warning instead of running 
the command."
 
 (defun hydra-disable ()
   "Disable the current Hydra."
+  (setq hydra-deactivate nil)
   (remove-hook 'pre-command-hook 'hydra--clearfun)
   (dolist (frame (frame-list))
     (with-selected-frame frame



reply via email to

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