reddit / emacs

Any reason not to rebind C-m nowadays?

BettaGeorge · 2022-04-07 12:54
For historical/compatibility/darkmagic reasons, the enter key behaves differently with a GUI than without one. All of its incarnations are usually sanely bound to do the same thing, as is "C-m". My question is, in 2022, do I face any (likely) issues if I rebind C-m to something I actually use? I mostly use emacs on X. Single-key shortcuts are rare, and I would like to use as many as possible without breaking anything. Thanks in advance!
ndamee · 2022-04-07 13:48
If you use emacs only on GUI then rebind it. I do. (define-key input-decode-map [?\C-m] [C-m]) (global-set-key (kbd "<C-m>") 'my-stuff) And look for other terminal bindings too (e.g. C-i) https://emacs.stackexchange.com/a/17510
BettaGeorge · 2022-04-07 14:12
I /mainly/ use it in X, but there are times when I have to drop into a tty. I would rather avoid having two separate configs. I guess a good compromise would be to just not do the rebind in tty. I'll wrap the whole thing to check for `display-graphic-p` first and put functionality in there that I can live without in a tty. Thank you for the link!
zuma0 · 2022-04-07 15:30
Interesting question. I prefer less finger travel so I've been trying to use C-m instead of return and C-\[ instead of escape. Sometimes C-i too.
zhyang11 · 2022-04-07 17:56
Checking `display-graphic-p` won't work for cases where you have a GUI window and tty window at the same time (through emacsclient) - maybe look up `tty-setup-hook` and `window-setup-hook`. Looks like the thing you want to do is to setup `input-decode-map` so that on tty `C-m` is mapped to `<enter>`. However this won't work for GUI window since now you can't differentiate `C-m` and `<enter>` now. Maybe you can tell the terminal emulator to send a different sequence on `C-m`, possibly using [CSI style encoding](http://www.leonerd.org.uk/hacks/fixterms/). TBH this all sounds like a mess.
Horrih · 2022-04-07 20:14
For a similar reason I wanted to use C-i as different from TAB I made it work both on gui and tty by doing some rebinding - on linux, my terminal emulator is konsole, in the settings you can rebind c-i to some other unused complicated binding you'll never use - on windows i did the same with powertoyz So basically my function was bound to 2 keys, one in gui mode the other for tty, both actuated by the same key binding
[deleted] · 2022-04-07 20:22
[deleted]
Phil-Hudson · 2022-04-08 10:47
I think you *can* make a conditional mapping in `input-decode-map` work using a function (untested): (defun my-ctrl-m (_ignored) (kbd (if (display-graphic-p (selected-frame)) "C-m" "<enter>"))) (define-key input-decode-map [?\C-m] #'my-ctrl-m)
papercatlol · 2022-04-08 21:49
Nah, you'll be fine. I've been using C-m as <Return> (while remapping <Return>) and remapped C-i and C-] for years without issues.