Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a case-sensitive keybinding in Emacs?

According to the Emacs' manual, modifier keys are case-insensitive due to "historical reasons".

Can I change this behaviour?

My goal is making M-a and M-A to mean different things.

Thanks!

like image 997
EuAndreh Avatar asked Jun 12 '14 05:06

EuAndreh


Video Answer


1 Answers

According to the manual,

A Control-modified alphabetical character is always considered case-insensitive: Emacs always treats C-A as C-a, C-B as C-b, and so forth. The reason for this is historical.

So you couldn't define them like:

(global-set-key (kbd "C-a") 'xxx)
(global-set-key (kbd "C-A") 'yyy)

but S- can be used for Shift, so:

(global-set-key (kbd "C-a") 'xxx)
(global-set-key (kbd "C-S-a") 'yyy)  ;; C-A

is OK. And

For all other modifiers, you can make the modified alphabetical characters case-sensitive when you customize Emacs. For instance, you could make M-a and M-A run different commands.

So you can define key-binding like this:

(global-set-key (kbd "M-a") 'xxx)
(global-set-key (kbd "M-A") 'yyy)
like image 129
songyuanyao Avatar answered Sep 20 '22 03:09

songyuanyao