Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Emacs key bindings to recognize capital letters?

Tags:

emacs

elisp

How do I get Emacs to recognize M-C (meta-shift-c) rather than translating it as m-c?

Currently when I do C-h k M-C I get: M-c (translated from M-C) runs the command capitalize-word.

How do I get it to NOT translate M-C to M-c?

like image 287
incandescentman Avatar asked Mar 03 '14 18:03

incandescentman


People also ask

How do I change case in Emacs?

To make all the letters in a word uppercase, position your cursor before the word and type M-u . To make all the words in a region uppercase, position your cursor before the region and set a mark. Then move your cursor below the region and type C-x C-u .

How do I type cm in Emacs?

C-M-\ requires all three keys to be held at the same time, not like C-M \ . So, in your case, that's Ctrl-Alt-\ all together.

What is RET key in Emacs?

"RET" is the Return key while emacs runs in a terminal. and run emacs in terminal, your keybinding will have no effect. But the problem is, by binding (kbd "RET") , you are also binding (kbd "C-m") , regardless you run emacs in terminal or GUI.


2 Answers

Just use modifier S (Shift) in your key binding. E.g.:

(global-set-key "\M-\S-c" 'foobar)

If there is nothing explicitly bound to the shifted key then Emacs automatically translates it to the unshifted key.

From the Elisp manual, node Key Sequence Input:

If an input character is upper-case (or has the shift modifier) and has no key binding, but its lower-case equivalent has one, then read-key-sequence' converts the character to lower case. Note thatlookup-key' does not perform case conversion in this way.

like image 123
Drew Avatar answered Sep 22 '22 06:09

Drew


To get Emacs to distinguish the two is very easy: add a binding for M-C. The translation from M-C to M-c happens as a fallback when no binding was found for M-C.

like image 33
Stefan Avatar answered Sep 24 '22 06:09

Stefan