Description
Example hydra that causes the problem:
(defhydra hydra-example ()
"Example"
("s" some-fn "Some function" :exit t))
Hydra will create a function called hydra-example/some-fn-and-exit.
When you call this function directly, without executing hydra-example/body first, key-chord no longer works after the function finishes.
Normally I wouldn't call the function directly but I'm using multiple cursors and hydra-example/body is bound to a key-chord.
Steps I follow:
- Let's say I have 3 cursors.
- Then I use the key-chord to start the hydra.
- Multiple cursors asks me if I want to execute hydra/example/body for each cursor. I say no.
- I pick "s" to execute the hydra-example/some-fn-and-exit function.
- Multiple cursors asks me if I want to execute hydra-example/some-fn-and-exit for each cursor. I say yes.
- Multiple cursors executes hydra-example/some-fn-and-exit multiple times and now key-chords no longer work.
Just executing hydra-example/some-fn-and-exit directly will reproduce it as well.
I've been looking into it and it seems the problem lies within hydra-disable. When the generated hydra function is called directly it seems that overriding-terminal-local-map isn't set. This means the #'hydra--imf function is never removed and the key-chord function isn't restored.
I tried redefining the hydra-disable function and replacing overriding-terminal-local-map with t. Key-chord kept working fine after redefining it.
(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
(when overriding-terminal-local-map
(internal-pop-keymap hydra-curr-map 'overriding-terminal-local-map)
(unless hydra--ignore
(if (fboundp 'remove-function)
(remove-function input-method-function #'hydra--imf)
(when hydra--input-method-function
(setq input-method-function hydra--input-method-function)
(setq hydra--input-method-function nil)))
(when hydra-curr-on-exit
(let ((on-exit hydra-curr-on-exit))
(setq hydra-curr-on-exit nil)
(funcall on-exit))))))))
Is this a problem with hydra or can I solve this in a different way?