bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#59305: 29.0.50; keymap-global-set handling of string bindings differ


From: Robert Pluim
Subject: bug#59305: 29.0.50; keymap-global-set handling of string bindings different from global-set-key
Date: Tue, 22 Nov 2022 17:58:07 +0100

>>>>> On Wed, 16 Nov 2022 09:47:31 +0100, Robert Pluim <rpluim@gmail.com> said:

    Robert> 1. Change `kbd' to always return a vector even if the input is
    Robert> ascii-only, which makes [4] work

I tried that, and it seems to work, but I guess itʼs kind of
risky. Just what we need to see if people are testing the pre-test
properly 😸

    Robert> 2. Change `keymap-set' to convert ascii-only strings to the format 
in
    Robert> [5] or [6]. Probably just a call to `string-to-vector' is enough.

This is less invasive. Something like this:

diff --git a/lisp/keymap.el b/lisp/keymap.el
index eaeba96644..deb44844fb 100644
--- a/lisp/keymap.el
+++ b/lisp/keymap.el
@@ -61,7 +61,23 @@ keymap-set
   ;; If we're binding this key to another key, then parse that other
   ;; key, too.
   (when (stringp definition)
-    (keymap--check definition)
+    ;; For backwards compatibility, we want people to be able to say
+    ;; "hello" instead of forcing them to say "h e l l o", and to fix
+    ;; the common mistake of specifying a string with non-ascii
+    ;; characters, we convert to a vector instead.
+    (cond
+     ((let ((case-fold-search nil)) ;; no special chars or keywords
+             (not (string-match-p
+                   (rx (or " " "^" "<" ">" "-" "\\"
+                           "NUL" "RET" "TAB" "LFD"
+                           "ESC" "SPC" "DEL")))))
+      (setq definition (string-join (seq-split definition 1) " "))
+      (keymap--check definition))
+     ((string-match-p ;; non-ascii characters
+       "[[:nonascii:]]" definition)
+      (setq definition (string-to-vector definition)))
+     (t ;; kbd syntax
+      (keymap--check definition)))
     (setq definition (key-parse definition)))
   (define-key keymap (key-parse key) definition))


Robert
-- 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]