[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
- [elpa] master updated (d183352 -> fddedd2), Oleh Krehel, 2015/05/01
- [elpa] master 8ded725 01/24: hydra.el (hydra--input-method-function): Move before first use, Oleh Krehel, 2015/05/01
- [elpa] master 8be0bff 02/24: hydra-examples.el: Add a defvar, Oleh Krehel, 2015/05/01
- [elpa] master 192c5b0 03/24: Allow heads to conditionally exit,
Oleh Krehel <=
- [elpa] master ad8def1 04/24: Match e.g. "C-d C-o" in docstring, Oleh Krehel, 2015/05/01
- [elpa] master f472834 05/24: hydra.el (hydra--format): Be non-greedy with width spec, Oleh Krehel, 2015/05/01
- [elpa] master 0b1b966 06/24: hydra.el (hydra-face-teal): Fixup doc, Oleh Krehel, 2015/05/01
- [elpa] master 1601991 07/24: Fix the regex once more and add test, Oleh Krehel, 2015/05/01
- [elpa] master c43e1cf 08/24: Add `lv-delete-window' function, Oleh Krehel, 2015/05/01
- [elpa] master b9d0687 09/24: Update `outline-regexp' and `indent-tabs-mode' file locals, Oleh Krehel, 2015/05/01
- [elpa] master 01248b1 10/24: Use one less ; for local vars, Oleh Krehel, 2015/05/01
- [elpa] master 00d2c0c 11/24: Add lv-force-update, Oleh Krehel, 2015/05/01
- [elpa] master 824f105 12/24: Optionally separate lv window and echo area using a thin line, Oleh Krehel, 2015/05/01
- [elpa] master dd02b16 13/24: .dir-locals.el: Add, Oleh Krehel, 2015/05/01