Subject: bug#76113: 29.4; Behavior of kmacro-bind-to-key (C-x C-k b)

From: [email-masked]
Date: Thu, 06 Feb 2025 17:06:40 -0500

I know this is a bug that I have found by not following the keybinding
standards of GNU Emacs.  Sequences of the type C-x C-k {UPPERCASE
LETTER} are _supposed_ to be reserved for user-defined key macros.  As
for why I would bind C-x C-k A to toggle-frame-fullscreen, in my initial
discovery of the bug it was bound to a function that I defined in my
.emacs/init.py file.

NOTE: When I say in my instructions "some other text", I literally typed
that phrase.

Start Emacs
In *scratch* buffer
Type F3
Type (global-set-key (kbd "C-x C-k A") 'toggle-frame-fullscreen)
Type F4
Type ESC x eval-buffer
Type C-x C-k A
Goes full-screen
Type F11
Goes back to previous size
Type C-x C-k b F11
Raises error message about current assignment of F11
THIS IS PROPER. (1)
Type no
Type C-x C-k b C-x C-k A
Raises error message about current assignment of C-x C-k A
THIS IS WHAT I EXPECT (2)
Type no
Type C-x C-k b A
FAILS to raise error message about current assignment of C-x C-k A
THIS I EXPECTED TO RAISE AN ERROR (3)
Type C-x C-k A
Types out (global-set-key (kbd "C-x C-k A") 'toggle-frame-fullscreen)
Which proves that actually was reassigned
Type F3
Type some other text
Type F4
Type C-x C-k b C-x C-k A
Raises error message about current assignment of C-x C-k A
THIS I DO NOT EXPECT (4)
Type no
Type C-x C-k b A
FAILS to raise error message about current assignment of C-x C-k A
THIS IS WHAT I EXPECT (5)
Type C-x C-k b A
Types some other text
END OF DEMONSTRATION

The documentation for kmacro-bind-to-key includes:
You can bind to any valid key sequence, but if you try to bind to
a key with an existing command binding, you will be asked for
confirmation whether to replace that binding.

But obviously you did intend for macros stored in C-x C-k {UPPERCASE
LETTER} to be replaced by other macros.  The behavior at point 5 is
exactly as I would expect, but is inconsistent with the behavior at
point 4.

Also, since at points 2 and 3, the key sequence C-x C-k A is bound to
something other than a keyboard macro, I personally want a warning*; but
in any event the behavior at 2 and 3 should be consistent.

*My expectations are that kmacro-bind-to-key give a warning on assigning
to a user-reserved key macro sequence when something other than a key
macro is bound to that key sequence, at the very least it should behave
the same whether it is given the key sequence in short or full form.

In GNU Emacs 29.4 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.33,
  cairo version 1.16.0) of 2024-10-24 built on fagricipni-A320M-S2H
Windowing system distributor 'The X.Org Foundation', version 
11.0.12101004
System Description: Linux Mint 21.3

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY
INOTIFY PDUMPER PNG RSVG SECCOMP SOUND THREADS TIFF TOOLKIT_SCROLL_BARS
X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB

Important settings:
   value of $LANG: en_US.UTF-8
   locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
   tooltip-mode: t
   global-eldoc-mode: t
   eldoc-mode: t
   show-paren-mode: t
   electric-indent-mode: t
   mouse-wheel-mode: t
   tool-bar-mode: t
   menu-bar-mode: t
   file-name-shadow-mode: t
   global-font-lock-mode: t
   font-lock-mode: t
   blink-cursor-mode: t
   line-number-mode: t
   indent-tabs-mode: t
   transient-mark-mode: (only . t)
   auto-composition-mode: t
   auto-encryption-mode: t
   auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message mailcap yank-media puny dired
dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg rfc6068
epg-config gnus-util mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util mail-prsvr mail-utils face-remap shortdoc text-property-search
help-fns radix-tree macros time-date subr-x cl-seq cl-extra help-mode
edmacro kmacro cl-loaddefs cl-lib rmc iso-transl tooltip cconv eldoc
paren electric uniquify ediff-hook vc-hooks lisp-float-type elisp-mode
mwheel term/x-win x-win term/common-win x-dnd tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu
timer select scroll-bar mouse jit-lock font-lock syntax font-core
term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads dbusbind inotify lcms2
dynamic-setting system-font-setting font-render-setting cairo
move-toolbar gtk x-toolkit xinput2 x multi-tty make-network-process
emacs)

Memory information:
((conses 16 50357 7387)
  (symbols 48 5632 0)
  (strings 32 15684 1800)
  (string-bytes 1 440206)
  (vectors 16 10519)
  (vector-slots 8 160957 12516)
  (floats 8 84 56)
  (intervals 56 284 0)
  (buffers 976 12))