Additional modifier keys in emacs?

I recently modified the Emacs setup, but I ran into a problem that was starting to annoy me. I would like to be able to enter additional modifiers, such as keys. What I'm trying to do to make everything clearer is when I am in standby mode (which does not accept text input, so regular letters can bounce). I would like that when I hold the letter s and press j or l , the cursor moves to the next and previous line of the directory, respectively. Efficient execution of the s key acts as a modifier.

I have considered using s modifiers such as super or hyper , but they are all used for global things. Is it possible? if not, then this is a shame.

Edit:

There seems to be some confusion with what I need. If I define a normal key sequence like

(define-key map (kbd "sj") 'dired-next-dirline)

Then I have to constantly press s every time before pressing j to go to the next line of the directory. This is not what I'm looking for (so as not to get angry: P) I want s act as a modifier, where I can keep the s key pressed and keep pressing j to move along the lines.

Hope I made this clearer. Thanks.

+4
source share
4 answers

I delved into the code and came up with this. It binds sj to my-dired-next-dirline , but right after you do this, just j enough to do it again. Any other key resets the time reference.

Note that the set-temporary-overlay-map function was added in Emacs 24.2, which at the time of this writing was not yet released, so you will need to build Emacs from git .

 (defun my-dired-next-dirline () (interactive) (dired-next-dirline 1) (set-temporary-overlay-map (let ((map (make-sparse-keymap))) (define-key map [?j] 'my-dired-next-dirline) map) nil)) (eval-after-load "dired" '(progn (let ((prefix-map (make-sparse-keymap))) (define-key prefix-map "j" 'my-dired-next-dirline) (define-key dired-mode-map "s" prefix-map)))) 
+3
source

Key chords may be what you are looking for.

+2
source

If the key chords are not what you are looking for (as you suggested in the comment to answer Tom ), then you seem to need a simple define-key that uses a key sequence. i.e.

 (define-key dired-mode-map (kbd "sj") 'dired-previous-line) 

This has the disadvantage of disabling the original functionality of the s key, but you can restore this to the sequence s - s , I suppose.

+1
source

This question precedes it, but the Hydra package allows you to do this and more.

https://github.com/abo-abo/hydra

See examples here: https://github.com/abo-abo/hydra/blob/master/hydra-examples.el and here https://github.com/abo-abo/hydra/blob/master/hydra- test.el

The wiki also has more useful examples https://github.com/abo-abo/hydra/wiki/Hydras-by-Topic

Hydra initially had only a rather opaque metaphorical syntax, which made it pretty difficult to get started. I don’t know why such a bizarre two-layer metaphor from flowers to mythical stories and monsters with many heads, β€œdefeated”, was used to describe functions that essentially:

  • follow the action and stay in key mode (effectively what you ask for). (so-called blue hydra)
  • perform the action and close the key mode (a red hydra)

etc.

Fortunately, a more literal syntax was added in February 2015, check the tests to see the color and literal syntax side by side. (also this is commit https://github.com/abo-abo/hydra/commit/0a3cc60f5856eb4a38204b9075d67d058ba56bef )

See also this article by the author. http://oremacs.com/2015/02/02/colorful-hydrae/

+1
source

All Articles