AFAIK emacs does not support keyup/keydown
events, only keypressed
. An example of a consequence is that when we want to mark a region we have to first set a mark set-mark-command
and can then mark the region by moving around the point. While this is really an interesting feature as you don't have to hold a shift key pressed while marking the text, sometimes it would be desirable to have the same behavior like in other editors. This question is to understand why emacs doesn't support this feature and why this is considered better. Also is there an ideomatic approach how we could solve this in emacs?
-
6Emacs also works in a terminal, and key up/down events don't make sense in that environment. Quite likely, that is at least a historical reason why these events aren't supported. That doesn't mean they couldn't be supported though. I suspect nobody has seen a sufficiently pressing need to bother with it.– Harald Hanche-OlsenCommented Apr 2, 2015 at 8:43
-
1Okay that's a valid argument, though there are other features in emacs that only work in a graphical environment (fonts, mouse events, etc)– shaftCommented Apr 2, 2015 at 8:55
-
3I wrote some code that simulates key up/down events to preview a file on key down then close the preview buffer on key up, like the answer says it's hacky, but maybe it could be molded into something stable. emacs.stackexchange.com/questions/275/…– Jordon BiondoCommented Apr 2, 2015 at 13:12
-
3What "same behavior like in other editors" are you referring to [I don't use those other text editors]? The rest of the text seems to hint at "shift+movement to select", but that is already supported in Emacs.– StefanCommented Apr 2, 2015 at 14:10
-
5Though you're right these key events don't exist in Emacs, you should know that Emacs does support shift selection (if that's what inspired your question).– MalabarbaCommented Apr 2, 2015 at 16:23
1 Answer
As answered in comments for historical reason Emacs run in terminals and those devices are character oriented - you get byte sequence without any guarantee when this happen at keyboard.
Discussion also point that it is possible to implement this for graphical environment. But nobody interested in that.
Note that some programs like games or music software may use detailed info about when key pressed, how long, and when released but text editing have nothing common with these.
From manual (info "(elisp)Mouse Events")
:
Emacs supports four kinds of mouse events:
click events, drag events, button-down events, and motion events.
Hover event can be emulated by idle timer - analyzing thing at point after delay.
-
“… but text editing have nothing common with these.”—Emitting text on key-up events can be useful when implementing key chords (in the stenography-sense). That way you don’t have to rely on timeouts when implementing key chords. Just look at all the hoops that
key-chord
users have to jump through; anaylzing bigram frequencies, “I adjusted key-chord to sample my current typing frequency”, and so on. Commented Sep 8, 2020 at 16:30