I want C-d
to act as a kind of modifier for the <left>
and <right>
arrow keys in a similar way to how Shift
is a modifier that allows letters to be capitalized.
Shift Analogy
- When I press
a
I geta
- When I hold
Shift
and then pressa
I getA
- When I hold
Shift
and then holda
I getAAAA...
Goal
- while
C-d
is held down,<left>
and<right>
function asdelete-backwards-char
anddelete-char
respectively. - while
C-d
is held down, if<left>
(or<right>
) is also held down, then repeatedly calldelete-backwards-char
(ordelete-char
).
In other words, I want C-d
to act as a sort of "delete-modifier" so that as long as C-d
is held, I can press <left>
and <right>
to delete backwards and forwards. Note If C-d
is not being held down, <left>
and <right>
should have their default behavior (moving backward and forward one character).
One of my perceived road-blocks is mentioned in the emacs manual on the topic of modifier keys:
Although only the Control and Meta modifier keys are commonly used, Emacs supports three other modifier keys. These are called Super, Hyper, and Alt.
I've had a terrible time in the past trying to get Super
and Hyper
to work correctly on any of (much less across) my computers, but even if I could get them working properly, I don't think these will be enough; if I use Super
to act as the "delete-modifier", then I only have room for one or maybe two more before I've run out of the default modifiers emacs has to offer.
If I wanted (in addition to a "delete-modifier") a "search-modifier" that allowed me to hold down C-s
and then use <left>
and <right>
to search backwards and forwards, then Super
and Hyper
would have their hands full.
I want to make extensive use of this type of functionality, and I really want to believe that if the computer games I played as a child could implement something like it, then a tool as praised for its customizability as emacs could do the same, but so far the consensus among people I ask is that they do not really know if its even possible to implement this kind of functionality.
Edit
The closest I can get on my own is to use hydra
:
(global-unset-key (kbd "C-d"))
(defhydra hydra-delete (global-map "C-d")
"delete"
("C-<left>" delete-backward-char)
("C-<right>" delete-char))
The problem with this is that if I accidentally press any key other than <left>
and <right>
after holding down C-d
, I'll be kicked out of this 'deletion' mode, and the only way to step back in is hold down C-d
again. In practice this behavior is a lot less natural than the modifier functionality of the Shift
key.
Ideally, if I hold down C-d
, as long as C-d
is held down, <left>
and <right>
do what they are bound to do, but if a key is not bound to anything, pressing it while C-d
is held down does nothing.