From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Robert Pluim Newsgroups: gmane.emacs.bugs 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 Message-ID: <87bk5wqjka.fsf@gmail.com> References: <87edu3cml8.fsf@gmail.com> <874junfonc.fsf@gmail.com> <87r0x1njll.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29641"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Lars Ingebrigtsen , 59305@debbugs.gnu.org To: Stefan Kangas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Apr 26 16:36:46 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1s0Mgw-0007XI-DS for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 26 Apr 2024 16:36:46 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s0Mgc-0004Fj-KG; Fri, 26 Apr 2024 10:36:27 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s0Mfy-000477-SA for bug-gnu-emacs@gnu.org; Fri, 26 Apr 2024 10:35:51 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s0Mfx-0005Oo-58 for bug-gnu-emacs@gnu.org; Fri, 26 Apr 2024 10:35:45 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s0MgF-0007pZ-6K for bug-gnu-emacs@gnu.org; Fri, 26 Apr 2024 10:36:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Robert Pluim Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 26 Apr 2024 14:36:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59305 X-GNU-PR-Package: emacs Original-Received: via spool by 59305-submit@debbugs.gnu.org id=B59305.171414210429510 (code B ref 59305); Fri, 26 Apr 2024 14:36:02 +0000 Original-Received: (at 59305) by debbugs.gnu.org; 26 Apr 2024 14:35:04 +0000 Original-Received: from localhost ([127.0.0.1]:38181 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s0MfE-0007fE-Fe for submit@debbugs.gnu.org; Fri, 26 Apr 2024 10:35:03 -0400 Original-Received: from mail-lj1-x22a.google.com ([2a00:1450:4864:20::22a]:47585) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s0MfA-0007dI-6E for 59305@debbugs.gnu.org; Fri, 26 Apr 2024 10:34:59 -0400 Original-Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2d8b2389e73so26495031fa.3 for <59305@debbugs.gnu.org>; Fri, 26 Apr 2024 07:34:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714142071; x=1714746871; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:from:to:cc:subject:date:message-id :reply-to; bh=x6xYN2NiRvz5zD4LY2cZ2LVUtf0/2Q9mexFmE2hIhjI=; b=Uqx2ULPNOrQ/5ys1LdF++8CKTSjWKPuBnVdDInPhtAiJFHg8JkGSekffAEk05Gbxti Km0cCk7dXpJS+HzRxDYcVH1LegrvhIfnw+M+ohFjc684HWnuWW//CjMxwL1jSCsb7HiA orAcm9Q7Glx+Vdi5akOqenXb20toFVxtiuErEerIaMtlwaHTKLXUlFWy5o/j1CmdfDmG evaO/ZC6UyYFHDNaOSnr6kO+ZdpqPla4NPaTC6jkDiMrTor8bRDpbE9qUGbsjLhB+1rJ 0k+/gzk7iO5p0MaEuIOvU9JJfK1+46WECVEF4mTTo6n4qAMvNxH1Z7xrqsuHhSx8jPuD Y4PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714142071; x=1714746871; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x6xYN2NiRvz5zD4LY2cZ2LVUtf0/2Q9mexFmE2hIhjI=; b=lBb/TGLF1LtO6FsM86rfPHRnMU7ZFFk7oOz7V/qzAsDMirGWtoDIncNf9i4ETEJ6eV psWEnlKVB7GG10Fnhn9NAdWs18anD0Z+WNXWv/Cdm5bap4gb8bpk8FiJ0WpUmVFiuZyZ X9UFDCGA37D6Kl5i7n1HWxOSB2PMOTg9nVf/7PElS7I5WlSn3pgnoiHuhfrSL8tIoHxx B/kNTx7clVzdLvBLqRUPtnY3ONTnJNqzb767cXSJWCANKDvpjRNYGVAD1r1CWtwRXLkb ne5wMf+485mokZkJByjMDfhNU8W+76dghakzOgAye99yV/X8kFl6xi8A2OZBzMIm5UcK m6Qw== X-Forwarded-Encrypted: i=1; AJvYcCW6vxWXDwPyjT+6m/DkfaberXerHPCTX5cXzfOwXybDfLJo3CIY4bKpUD0kjeXOLfcZXwUPxFvNKZAGTcIDPRYWScTrLLs= X-Gm-Message-State: AOJu0YzbGjJ5TNsRo3Esk/rlS4hBxmVT86phFHC77DimJrXMJFClp9Co i7wFN9TXzs7MbuLfpFPBF0o8kVCf6z2tNStYpId5JvuK5OKR5CU5y1hkwg== X-Google-Smtp-Source: AGHT+IGIwxIHu1d0rEqbUSuC9EUUqBqN+bFh+1hi3K0pOZ7FqJjPeIp7FNGijDAZj5Xi9oTuWzo5+w== X-Received: by 2002:a2e:a284:0:b0:2d8:5a5e:7c5e with SMTP id k4-20020a2ea284000000b002d85a5e7c5emr1680986lja.22.1714142071001; Fri, 26 Apr 2024 07:34:31 -0700 (PDT) Original-Received: from rltb ([82.66.8.55]) by smtp.gmail.com with ESMTPSA id jx6-20020a05600c578600b004185be4baefsm1507494wmb.0.2024.04.26.07.34.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 07:34:30 -0700 (PDT) In-Reply-To: <87r0x1njll.fsf@gmail.com> (Robert Pluim's message of "Thu, 15 Dec 2022 09:42:46 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:283992 Archived-At: >>>>> On Thu, 15 Dec 2022 09:42:46 +0100, Robert Pluim s= aid: 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 ent= ry) I was going to write 'Stefan why did you overwrite my patch', but it=CA=BCs me who didn=CA=BCt 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=CA=BCs just in Emacs=CA=BC code). I gu= ess we could add an 'always produce a vector' argument to `kbd', but perhaps just recommending `kmacro' is best, since it=CA=BCs a fairly niche usage. This is against emacs-29 Robert --=20 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-save-then-kill) @end example =20 - 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 =20 @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'. =20 +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'. =20 +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= ))