branch: master commit f01c87e37c9646a3b32fbe1c390c6f94b8c153a8 Author: Oleh Krehel <ohwoeo...@gmail.com> Commit: Oleh Krehel <ohwoeo...@gmail.com>
Fix red heads not exiting temporarily * hydra.el (hydra--ignore): New defvar. (hydra-disable): Don't call :post unless `hydra--ignore' is nil. (hydra--make-defun): Temporarily disable transient map before calling the command. Fixes #109 --- hydra-test.el | 24 ++++++++++++++++++++++++ hydra.el | 40 +++++++++++++++++++++++----------------- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/hydra-test.el b/hydra-test.el index 267ccad..7d361e6 100644 --- a/hydra-test.el +++ b/hydra-test.el @@ -104,6 +104,8 @@ The body can be accessed via `hydra-error/body'. Call the head: `first-error'." (interactive) (hydra-default-pre) + (let ((hydra--ignore t)) + (hydra-keyboard-quit)) (condition-case err (progn (setq this-command @@ -138,6 +140,8 @@ The body can be accessed via `hydra-error/body'. Call the head: `next-error'." (interactive) (hydra-default-pre) + (let ((hydra--ignore t)) + (hydra-keyboard-quit)) (condition-case err (progn (setq this-command @@ -172,6 +176,8 @@ The body can be accessed via `hydra-error/body'. Call the head: `previous-error'." (interactive) (hydra-default-pre) + (let ((hydra--ignore t)) + (hydra-keyboard-quit)) (condition-case err (progn (setq this-command @@ -229,6 +235,8 @@ Call the head: `previous-error'." The body can be accessed via `hydra-error/body'." (interactive) (hydra-default-pre) + (let ((hydra--ignore nil)) + (hydra-keyboard-quit)) (when hydra-is-helpful (if hydra-lv (lv-message @@ -397,6 +405,8 @@ Call the head: `nil'." The body can be accessed via `hydra-toggle/body'." (interactive) (hydra-default-pre) + (let ((hydra--ignore nil)) + (hydra-keyboard-quit)) (when hydra-is-helpful (if hydra-lv (lv-message @@ -481,6 +491,8 @@ Call the head: `next-line'." (interactive) (hydra-default-pre) (set-cursor-color "#e52b50") + (let ((hydra--ignore t)) + (hydra-keyboard-quit)) (condition-case err (progn (setq this-command @@ -514,6 +526,8 @@ Call the head: `previous-line'." (interactive) (hydra-default-pre) (set-cursor-color "#e52b50") + (let ((hydra--ignore t)) + (hydra-keyboard-quit)) (condition-case err (progn (setq this-command @@ -568,6 +582,8 @@ The body can be accessed via `hydra-vi/body'." (interactive) (hydra-default-pre) (set-cursor-color "#e52b50") + (let ((hydra--ignore nil)) + (hydra-keyboard-quit)) (when hydra-is-helpful (if hydra-lv (lv-message @@ -651,6 +667,8 @@ The body can be accessed via `hydra-zoom/body'. Call the head: `(text-scale-set 0)'." (interactive) (hydra-default-pre) + (let ((hydra--ignore t)) + (hydra-keyboard-quit)) (condition-case err (call-interactively (function @@ -708,6 +726,8 @@ Call the head: `(text-scale-set 0)'." The body can be accessed via `hydra-zoom/body'." (interactive) (hydra-default-pre) + (let ((hydra--ignore nil)) + (hydra-keyboard-quit)) (when hydra-is-helpful (if hydra-lv (lv-message @@ -792,6 +812,8 @@ The body can be accessed via `hydra-zoom/body'. Call the head: `(text-scale-set 0)'." (interactive) (hydra-default-pre) + (let ((hydra--ignore t)) + (hydra-keyboard-quit)) (condition-case err (call-interactively (function @@ -849,6 +871,8 @@ Call the head: `(text-scale-set 0)'." The body can be accessed via `hydra-zoom/body'." (interactive) (hydra-default-pre) + (let ((hydra--ignore nil)) + (hydra-keyboard-quit)) (when hydra-is-helpful (if hydra-lv (lv-message diff --git a/hydra.el b/hydra.el index 970716f..e370dbc 100644 --- a/hydra.el +++ b/hydra.el @@ -120,6 +120,9 @@ warn: keep KEYMAP and issue a warning instead of running the command." (t nil))))) (hydra-disable))) +(defvar hydra--ignore nil + "When non-nil, don't call `hydra-curr-on-exit'") + (defun hydra-disable () "Disable the current Hydra." (remove-hook 'pre-command-hook 'hydra--clearfun) @@ -127,10 +130,11 @@ warn: keep KEYMAP and issue a warning instead of running the command." (with-selected-frame frame (when overriding-terminal-local-map (internal-pop-keymap hydra-curr-map 'overriding-terminal-local-map) - (when hydra-curr-on-exit - (let ((on-exit hydra-curr-on-exit)) - (setq hydra-curr-on-exit nil) - (funcall on-exit))))))) + (unless hydra--ignore + (when hydra-curr-on-exit + (let ((on-exit hydra-curr-on-exit)) + (setq hydra-curr-on-exit nil) + (funcall on-exit)))))))) (unless (fboundp 'internal-push-keymap) (defun internal-push-keymap (keymap symbol) @@ -563,25 +567,27 @@ BODY-AFTER-EXIT is added to the end of the wrapper." `(,(hydra--call-interactively cmd (cadr head)))))) (delq nil - `(,(when cmd + `((let ((hydra--ignore ,(not (eq (cadr head) 'body)))) + (hydra-keyboard-quit)) + ,(when cmd `(condition-case err ,(hydra--call-interactively cmd (cadr head)) ((quit error) (message "%S" err) (unless hydra-lv (sit-for 0.8))))) - (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) - ,(when body-foreign-keys - (list 'quote body-foreign-keys))) - ,body-after-exit - ,(when body-timeout - `(hydra-timeout ,body-timeout)))))))) + (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) + ,(when body-foreign-keys + (list 'quote body-foreign-keys))) + ,body-after-exit + ,(when body-timeout + `(hydra-timeout ,body-timeout)))))))) (defmacro hydra--make-funcall (sym) "Transform SYM into a `funcall' to call it."