GNU bug report logs - #60867
29.0.60; keymap-set-after does not accept the AFTER=t argument

Previous Next

Package: emacs;

Reported by: Daniel Mendler <mail <at> daniel-mendler.de>

Date: Mon, 16 Jan 2023 18:21:01 UTC

Severity: normal

Tags: fixed

Found in version 29.0.60

Fixed in version 29.1

Done: Robert Pluim <rpluim <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


Message #20 received at 60867 <at> debbugs.gnu.org (full text, mbox):

From: Robert Pluim <rpluim <at> gmail.com>
To: Daniel Mendler <mail <at> daniel-mendler.de>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 60867 <at> debbugs.gnu.org
Subject: Re: bug#60867: 29.0.60; keymap-set-after does not accept the
 AFTER=t argument
Date: Thu, 19 Jan 2023 10:55:49 +0100
The nice thing about keymaps in Emacs is that everything is so
consistent :-).

The bare minimum to fix this bug:

diff --git c/lisp/keymap.el i/lisp/keymap.el
index 315eaab7560..2caaafabb94 100644
--- c/lisp/keymap.el
+++ i/lisp/keymap.el
@@ -186,6 +186,7 @@ keymap-set-after
   (declare (indent defun)
            (compiler-macro (lambda (form) (keymap--compile-check key) form)))
   (keymap--check key)
+  (when (eq after t) (setq after nil)) ; nil and t are treated the same
   (when after
     (keymap--check after))
   (define-key-after keymap (key-parse key) definition

However, `keymap-set' and `keymap-set-after' donʼt behave the same:

(let ((k (make-sparse-keymap)))
  (keymap-set k "a" "a")
  (keymap-set-after k "b" "b")
  k)

=> (keymap (97 . [97]) (98 . "b"))

so for consistency Iʼd want to put the following in emacs-29:

diff --git c/lisp/keymap.el i/lisp/keymap.el
index 315eaab7560..19faae5c493 100644
--- c/lisp/keymap.el
+++ i/lisp/keymap.el
@@ -188,6 +188,11 @@ keymap-set-after
   (keymap--check key)
   (when after
     (keymap--check after))
+  ;; If we're binding this key to another key, then parse that other
+  ;; key, too.
+  (when (stringp definition)
+    (keymap--check definition)
+    (setq definition (key-parse definition)))
   (define-key-after keymap (key-parse key) definition
     (and after (key-parse after))))

And of course the following for consistency for `keymap-lookup' as
well. I now firmly believe that the new keymap functions should use
`key-parse' and not `kbd'.

diff --git c/lisp/keymap.el i/lisp/keymap.el
index 315eaab7560..da71d48c86e 100644
--- c/lisp/keymap.el
+++ i/lisp/keymap.el
@@ -404,7 +404,7 @@ keymap-lookup
                    (symbolp value))
             (or (command-remapping value) value)
           value))
-    (key-binding (kbd key) accept-default no-remap position)))
+    (key-binding (key-parse key) accept-default no-remap position)))
 
 (defun keymap-local-lookup (keys &optional accept-default)
   "Return the binding for command KEYS in current local keymap only.

Eli, is this too much for emacs-29?

Robert
-- 




This bug report was last modified 2 years and 117 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.