How do I use a keyboard shortcut chords as a prefix anchor?

key-chord-mode

allows me to bind the simultaneous press of two keys to a command. This is great, but I would like the simultaneous pressing of a certain key combination to enter a mode in which an additional key (or keys) is expected, similar to what happens when I press C-c

or C-x

.

Basically, I would like to bind a function to something like ab l

or ab w

, where the rollover ab

behaves like a modifier, and l

or w

defines the final function to call.

How can i do this?

+3


source to share


1 answer


Although I'm not familiar with key-cord

in particular, the normal solution is to just replace the command with a key-card. From the doc:

21.8.1 Entering the key sequence

The command loop reads the key-sequence input at a time, causing the key-sequence reads. Lisp programs can call this function as well; for example, description-key uses it to read the key for description. - Function: read-key-sequence prompt & optional continue-echo dont-downcase-last switch-frame-ok command-loop

This function reads a key sequence and returns it as a string or vector. It keeps reading events until it has accumulated a complete

      

key sequence; that is, it is sufficient to specify the command without a prefix using the currently active keyboard layouts. (Remember that a key sequence that starts with a mouse event that is read using the buffer layouts into the window where the mouse was pointed, not the current buffer.)

You can create a prefix keymap by creating a new sparse layout and typing the keys into it:

(let (
          (sub-keymap (make-sparse-keymap))
          )
     (define-key sub-keymap "a" (message (lambda () (interactive) "hello world")))
     (define-key sub-keymap "b" (message (lambda () (interactive) "hello world"))))
     (global-set-key [C-f9] sub-keymap))

      



When you press [C-f9]

, you will be taken to the "sub-keyboard" and you can press "a" or "b" to see the results.

So, I would expect you to be able to achieve what you want by replacing the last line in my example with something like:

(key-chord-define-global "ab"   sub-keymap)

      

+3


source







All Articles