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.
<left>
todelete-backwards-char
, if I accidentally press another key, it kicks me out of that 'mode' and I would have toC-d
again to use<left>
again. Ideally, as long asC-d
is held down, I can press whichever keys I want and all the unbound ones do nothing but the bound ones (like<left>
) do what they are bound to do. I'll make an edit to make this a little more clear.xmodmap -pm
to see them), but I don't know if you can define more or how to do so if possible. Other environments will differ. All these are questions for another site (possibly SuperUser SE).hydra
is no different from the behaviour withrepeat-mode
. This is not surprising ... Below the hood, they are doing the same / similar things. One key difference ishydra
is NOT part ofEmacs
and has to be installed separately, butrepeat-mode
comes withEmacs
.