I really love
key-chord.el. It's become an integral part of my workflow, but sometimes I wish I could have them in the minibuffer (for things like evil-search). Specifically, I'd like
jj to exit out of
evil-search and move down a line. Is this possible?
I know I can hack together a command that acts as both a prefix and a command (see this SO question), so I could bind
j to a self inserting command, and
jj to my special command. How would I be able to break the event loop after a specified idle time? I do type
jj once in a blue moon, and I'd still like the flexibility of a timeout.
Is there any other way which I am unaware of to achieve what I want?
Origionally, this question was about the minibuffer in general.
key-chord.el seems to work fine with
minibuffer-local-map. It does not, however, work with
isearch-mode-map. Binding a command to a single regular key like
j does work in isearch. This is what I'm trying to solve.
I have found a solution which manually reproduces the behaviour of key-chord.el.
(defun isearch-exit-chord-worker (&optional arg) (interactive "p") (execute-kbd-macro (kbd "<backspace> <return>"))) (defun isearch-exit-chord (arg) (interactive "p") (isearch-printing-char) (unless (fboundp 'smartrep-read-event-loop) (require 'smartrep)) (run-at-time 0.3 nil 'keyboard-quit) (condition-case e (smartrep-read-event-loop '(("j" . isearch-exit-chord-worker) ("k" . isearch-exit-chord-worker))) (quit nil))) ;; example bindings (define-key isearch-mode-map "j" 'isearch-exit-chord) (define-key isearch-mode-map "k" 'isearch-exit-chord)
This approach actually has several advantages over
- It does not use an input method, so you can use a different input method in conjunction with this.
- The first character is shown immediately, and retracted if it is incorrect, while
key-chord.elonly shows it after a delay.