GNU bug report logs -
#78714
30.1; failure binding keys to certain unicode characters
Previous Next
Reported by: John Holman <john.g.holman <at> gmail.com>
Date: Sat, 7 Jun 2025 11:48:01 UTC
Severity: normal
Tags: fixed
Found in version 30.1
Fixed in version 30.2
Done: Robert Pluim <rpluim <at> gmail.com>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
> However the same syntax fails for some characters (so far I've noticed this
> for \u00B0 to \u00B6 but there will be more) e.g
> after (define-key my-test-mode-map (kbd "a") "\u00B2") C-h k shows
Just never bind keys to strings. It doesn't do what you think it does.
Such strings are interpreted as "sequences of keyboard events" for
reasons of compatibility with the pre-GUI world where ASCII reigned
supreme. So it comes with weird baggage inherited from *many*
years ago.
Just say no.
If you want to bind a key to a keyboard macro, then use `kmacro`:
(define-key my-test-mode-map (kbd "a") (kmacro "\u00B2"))
`kmacro` also treats the string as a "sequence of keyboard events" but
expects this string to be written in a human-readable manner, i.e. the
same syntax output by `key-binding` or accepted as input by `key-parse`,
and it will often signal convenient errors when the format is unclear,
instead of silently behaving in odd ways.
Stefan
PS: IMO, we should deprecate the use of strings and arrays as "commands".
It's been made obsolete back in 2002 when `kmacro.el` was added
to Emacs. We keep it for backward compatibility, but it's just a source
of confusion. Before Emacs-29's `kmacro` macro it could still be
justified on the grounds that it was inconvenient to write
(define-key my-test-mode-map (kbd "a") (kmacro-lambda-form "\u00B2"))
(and it still didn't use the nicer `key-parse` syntax, and it printed to
something somewhat unpalatable), but nowadays `kmacro` is just
a better alternative.
This bug report was last modified 7 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.