I have been modifying my Emacs setup quite alot recently but I reached a problem which is starting to annoy me. I would like to be able to introduce additional modifier like keys. What I am trying to do, to make things clearer, is when I am in dired-mode (which doesn't accept textual input so normal letters can be rebound) I would like it so that when I hold down the letter s
and press j
or l
the cursor moves to the next and previous directory line respectively. Effectively making the s
key act like a modifier.
I have looked into making the s
apply a modifier such as super
or hyper
but those are all used for global things. Is this possible? if not then that's a shame.
Edit:
There seems to be some confusion with what I'm after. If I define a normal key sequence such as
(define-key map (kbd "s j") 'dired-next-dirline)
Then I have to keep pressing the s
key every time before I press j
to move to the next directory line. This is not what I am looking for (not to sound angry :P) I want s
to act like a modifier where I can keep the s
key held down and keep tapping j
to move down the lines.
I hope I have made this more clear. Thanks.
I dug around in the code and came up with this. It binds s j
to my-dired-next-dirline
, but right after you've done that, just j
is enough to do it again. Any other key resets the temporary binding.
Note that the function set-temporary-overlay-map
was added in Emacs 24.2, which at the time of this writing hasn't been released yet, so you'll 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))))
Key chords may be what you are looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With