Allow to pause arbitrary hydras to the stack

* hydra.el (hydra-pause-resume): New command.
(hydra-pause-ring): New defvar. Stores the paused hydras.
(hydra-keyboard-quit): Set `hydra-curr-map' to nil, so it's possible to
determine if any hydra is active.
(hydra--clearfun): Ignore `hydra-pause-resume', since the hydra needs to
be active for `hydra-pause-resume'.

Fixes #135
master
Oleh Krehel 11 years ago
parent 1acd5f60cd
commit 1a13273ff0
  1. 43
      hydra.el

@ -116,18 +116,20 @@ warn: keep KEYMAP and issue a warning instead of running the command."
(defun hydra--clearfun () (defun hydra--clearfun ()
"Disable the current Hydra unless `this-command' is a head." "Disable the current Hydra unless `this-command' is a head."
(when (or (unless (eq this-command 'hydra-pause-resume)
(memq this-command '(handle-switch-frame keyboard-quit)) (when (or
(null overriding-terminal-local-map) (memq this-command '(handle-switch-frame
(not (or (eq this-command keyboard-quit))
(lookup-key hydra-curr-map (this-single-command-keys))) (null overriding-terminal-local-map)
(cl-case hydra-curr-foreign-keys (not (or (eq this-command
(warn (lookup-key hydra-curr-map (this-single-command-keys)))
(setq this-command 'hydra-amaranth-warn)) (cl-case hydra-curr-foreign-keys
(run (warn
t) (setq this-command 'hydra-amaranth-warn))
(t nil))))) (run
(hydra-disable))) t)
(t nil)))))
(hydra-disable))))
(defvar hydra--ignore nil (defvar hydra--ignore nil
"When non-nil, don't call `hydra-curr-on-exit'.") "When non-nil, don't call `hydra-curr-on-exit'.")
@ -409,6 +411,7 @@ Return DEFAULT if PROP is not in H."
(hydra-disable) (hydra-disable)
(cancel-timer hydra-timeout-timer) (cancel-timer hydra-timeout-timer)
(cancel-timer hydra-message-timer) (cancel-timer hydra-message-timer)
(setq hydra-curr-map nil)
(unless (and hydra--ignore (unless (and hydra--ignore
(null hydra--work-around-dedicated)) (null hydra--work-around-dedicated))
(if hydra-lv (if hydra-lv
@ -1060,6 +1063,22 @@ DOC defaults to TOGGLE-NAME split and capitalized."
0 0
i))))) i)))))
(defvar hydra-pause-ring (make-ring 10)
"Ring for paused hydras.")
(defun hydra-pause-resume ()
"Quit the current hydra and save it to the stack.
If there's no active hydra, pop one from the stack and call its body.
If the stack is empty, call the last hydra's body."
(interactive)
(cond (hydra-curr-map
(ring-insert hydra-pause-ring hydra-curr-body-fn)
(hydra-keyboard-quit))
((zerop (ring-length hydra-pause-ring))
(funcall hydra-curr-body-fn))
(t
(funcall (ring-remove hydra-pause-ring 0)))))
;; Local Variables: ;; Local Variables:
;; outline-regexp: ";;\\([;*]+ [^\s\t\n]\\|###autoload\\)\\|(" ;; outline-regexp: ";;\\([;*]+ [^\s\t\n]\\|###autoload\\)\\|("
;; indent-tabs-mode: nil ;; indent-tabs-mode: nil

Loading…
Cancel
Save