2009-06-11

emacs keybinding notation

On Jun 11, 1:07 am, Nordlöw wrote:
> I am trying to set the key meta-¤ (to the left of % on my swedish
> keyboard) like follows:
>
> (global-set-key [(meta \¤)] 'regexpl-search-replace-list)
>
> but it doesn't work, nothing happens when I press the combination. Why
> is that when the following works:
> (global-set-key [(meta \&)] 'query-replace-regexp)
>
> Thanks in advance,
> Nordlöw

not sure what's the problem. I've switched to kbd notation for all my keybinding needs, because that way, you have a sure way to know what the notation would be like, by calling the command describe-key. In your case, perhaps try that.

I did notice some inconsistencies even with this, especially when defining a non alphanumeric key. Here's a little write up:

-----------
Note: A keypress-combination such as “Meta+Shift+2” can also be considered as “Meta+@”. So, in emacs, you might be thinking that both of these code: “(kbd "M-S-2")” and “(kbd "M-@")” will work. Actually, only the latter will work.

When writing a keybinding definition, for a key combination that involves “Meta+Shift+‹key›”, you must use a version without the shift key if possible. For keybinding involving “Ctrl+Shift+‹letter›”, you must use the "-S". Examples:

GOOD BAD Keystroke
(kbd "M-A") (kbd "M-S-a") Meta+Shift+a
(kbd "M-@") (kbd "M-S-2") Meta+Shift+2
(kbd "M-:") (kbd "M-S-;") Meta+Shift+;
(kbd "C-S-a") (kbd "C-A") Ctrl+Shift+a

A easy way to find out the proper syntax, is to call “Alt+x describe-key”, then type the keystroke.

Note also, that keys involving “Ctrl+Shift+‹key›” cannot be distinguished from “Ctrl+‹key›” when emacs runs in a text terminal (i.e. telnet/ssh). So, this means best to avoid any binding with both Control and Shift.

• How to Define Keyboard Shortcuts in Emacs
http://xahlee.org/emacs/keyboard_shortcuts.html

---------------

i reported the above as a bug sometimes late last year or this year, but i think it got dismissed.

emacs's has a keybinding notation hell. For detail, see the section “Representation of Keystrokes” near the bottom.

• The Confusion of Emacs's Keystroke Representation
http://xahlee.org/emacs/keystroke_rep.html

Xah
∑ http://xahlee.org/

No comments:

Post a Comment