7

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!

EuAndreh
  • 578
  • 3
  • 16
  • As far as I am aware, they are only treated as being case-insensitive if there is only one key definition. If you create two -- i.e., one lower-case key definition and one upper-case key definition, then they are no longer treated as being case-insensitive. Using the method you seek is very common. E.g., `(global-set-key [?\s-m] 'minimize)` and `(global-set-key [?\s-M] 'maximize)` – lawlist Jun 12 '14 at 05:37

1 Answers1

8

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)
songyuanyao
  • 169,198
  • 16
  • 310
  • 405
  • I do this quite often, actually. It does mean calling out in the doc for my code, however, that `C-A` is aka `C-S-a` (or vice versa). Emacs itself always uses the latter notation, with the explicit Shift modifier. – Drew Jun 12 '14 at 13:51