From: Robert Pluim <rpluim@gmail.com>
To: Stefan Kangas <stefankangas@gmail.com>
Cc: Lars Ingebrigtsen <larsi@gnus.org>, 59305@debbugs.gnu.org
Subject: bug#59305: 29.0.50; keymap-global-set handling of string bindings different from global-set-key
Date: Fri, 26 Apr 2024 16:34:29 +0200 [thread overview]
Message-ID: <87bk5wqjka.fsf@gmail.com> (raw)
In-Reply-To: <87r0x1njll.fsf@gmail.com> (Robert Pluim's message of "Thu, 15 Dec 2022 09:42:46 +0100")
>>>>> On Thu, 15 Dec 2022 09:42:46 +0100, Robert Pluim <rpluim@gmail.com> said:
Robert> Then perhaps we should just change the docstrings and manual to
Robert> explain that binding a key to a string of characters should use
Robert> `kmacro' (since `kbd' is not the right thing for ASCII-only entry)
I was going to write 'Stefan why did you overwrite my patch', but itʼs
me who didnʼt follow up :-)
Changing `kbd' to always return a vector, attractive as it is to the
purist in me, falls foul of existing code that expects eg `(kbd
"RET")' to return a string (and thatʼs just in Emacsʼ code). I guess
we could add an 'always produce a vector' argument to `kbd', but
perhaps just recommending `kmacro' is best, since itʼs a fairly niche
usage.
This is against emacs-29
Robert
--
diff --git c/doc/emacs/custom.texi i/doc/emacs/custom.texi
index 4bd78f3ce83..d59440e203d 100644
--- c/doc/emacs/custom.texi
+++ i/doc/emacs/custom.texi
@@ -1933,8 +1933,38 @@ Init Rebinding
(keymap-global-set "<mouse-2>" 'mouse-save-then-kill)
@end example
- Language and coding systems may cause problems with key bindings for
-non-@acronym{ASCII} characters. @xref{Init Non-ASCII}.
+@cindex binding key to string
+ Key sequences can also be bound directly to Lisp strings rather than
+commands. Such strings are written using the same syntax as key
+sequences. For example, to bind @kbd{C-c h} to the string
+@samp{hello}:
+
+@example
+(keymap-global-set "C-c h" "h e l l o")
+@end example
+
+ Since this is somewhat cumbersome to write, the convenience function
+@code{kmacro} can be used instead:
+
+@example
+(keymap-global-set "C-c h" (kmacro "hello"))
+@end example
+
+ Non-@acronym{ASCII} characters can be specified directly in the
+string. To bind to e.g. @samp{ol@U{00E1}}, use:
+
+@example
+(keymap-global-set "C-c h" (kmacro "ol@U{00E1}"))
+@end example
+
+ However, be aware that language and coding systems may cause
+problems with key bindings for non-@acronym{ASCII} characters.
+@xref{Init Non-ASCII}. It may thus be better to use the following
+instead:
+
+@example
+(keymap-global-set "C-c h" (kmacro "ol\u00E1"))
+@end example
@findex global-set-key
@findex define-key
diff --git c/lisp/keymap.el i/lisp/keymap.el
index 4bdf65d39fa..592a9fd89ab 100644
--- c/lisp/keymap.el
+++ i/lisp/keymap.el
@@ -84,6 +84,9 @@ keymap-global-set
If COMMAND is a string (which can only happen when this function is
called from Lisp), it must satisfy `key-valid-p'.
+The `kmacro' convenience function converts a simple string of
+characters to an equivalent form that is acceptable for COMMAND.
+
Note that if KEY has a local binding in the current buffer,
that local binding will continue to shadow any global binding
that you make with this function."
@@ -108,6 +111,9 @@ keymap-local-set
If COMMAND is a string (which can only happen when this function is
called from Lisp), it must satisfy `key-valid-p'.
+The `kmacro' convenience function converts a simple string of
+characters to an equivalent form that is acceptable for COMMAND.
+
The binding goes in the current buffer's local keymap, which in most
cases is shared with all other buffers in the same major mode."
(declare (compiler-macro (lambda (form) (keymap--compile-check key) form))
next prev parent reply other threads:[~2024-04-26 14:34 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-16 8:47 bug#59305: 29.0.50; keymap-global-set handling of string bindings different from global-set-key Robert Pluim
2022-11-22 16:58 ` Robert Pluim
2022-11-25 0:14 ` Stefan Kangas
2022-11-25 8:01 ` Robert Pluim
2022-11-25 8:25 ` Stefan Kangas
2022-12-15 8:42 ` Robert Pluim
2024-04-26 14:34 ` Robert Pluim [this message]
2024-05-02 9:01 ` Eli Zaretskii
2024-05-02 13:13 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-06 10:03 ` Robert Pluim
2024-05-06 13:24 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-06 14:34 ` Robert Pluim
2024-05-06 15:20 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bk5wqjka.fsf@gmail.com \
--to=rpluim@gmail.com \
--cc=59305@debbugs.gnu.org \
--cc=larsi@gnus.org \
--cc=stefankangas@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).