I recently upgraded to Emacs24, and a number of my custom keybindings broke as a result of it.
According to the fine manual, it is possible to make Emacs stop conflating function keys with their ASCII control codes (eg, it is possible to have C-m
and RET
bound to different things, or C-i
and TAB
, and so on). This has always been a large pet peeve of mine with Emacs, that such valuable "first level" keyboard shortcuts are wasted on things for which I already have dedicated keys on my keyboard. I want to bind them to different things, in my case, to 'modernize' the keybindings by mimicking gedit. In Emacs23, this was working beautifully:
(global-set-key (kbd "C-i") 'goto-line)
(global-set-key (kbd "C-m") 'comment-or-uncomment-region)
(global-set-key (kbd "C-d") 'kill-whole-line)
;; Fix some stuff broken by the above
(global-set-key [delete] 'delete-char)
(global-set-key (kbd "TAB") 'indent-for-tab-command)
(global-set-key (kbd "RET") 'newline)
Then, I upgraded to Emacs24 and it broke, kinda. It still "works" in the sense that C-m
certainly does one thing, and RET
does another, but the problem is that the return key no longer behaves properly in terminal mode or in the minibuffer. Instead of activating the command I've just typed, in both cases, the return key simply moves the cursor down to the next line and I'm left with no way of activating the commands I type in to either the minibuffer or the terminal.
Ironically, Emacs24 introduced a lot of changes to the behavior of deleting, and in the process they decoupled C-d
from DEL
so that it's actually now safe to bind C-d
to something without needing to bind DEL
back to the expected behavior, so it would be great if I could achieve similar "it just works" behavior for my return key, while C-m
is bound to something else.
So, I can envision two possible solutions to this problem. One might look like this:
(global-set-key (kbd "C-m") 'comment-or-uncomment-region)
(global-set-key (kbd "RET") 'do-what-i-expect-the-return-key-to-do-in-any-mode)
OR, something like this would be even nicer:
(setq decouple-ascii-control-codes-from-function-keys t)
But I'm not aware of any such variable or function that would help me out in this scenario.
I've made several unsuccessful attempts at using mode-hooks to restore the correct bindings in terminal and minibuffer modes, but I just can't seem to get anything to work. Help!
Thanks.
C-m
and not forC-i
. Eg,C-m
andRET
are successfully doing different actions, but then when I hit theTAB
key it does the action that I bound toC-i
instead. Any thoughts on why? I accepted your answer anyway though just becauseC-m
was the one I was struggling with; I already hadC-i
andTAB
working just withglobal-set-key
. – Telethermometer