Subject: bug#66022: 30.0.50; kmacro overwriting global keybindings

From: Gerd Möllmann <[email-masked]>
Date: Mon, 18 Sep 2023 16:42:17 +0200

Gerd Möllmann <[email-masked]> writes:

> Stefan Monnier <[email-masked]> writes:
>
>>> I don't remember doing that, but I'll try to reproduce this somehow.  I
>>> tried it just now with a simple recipe but that didn't trigger the
>>> checks in my init.el.  Have to read the code that does that reloading, I
>>> guess.
>>
>> grep 'Fload (' src/*.c
>>
>> should get you started.
>
> Caught the sucker :-).  I think your intuition was right.

Here's the backtrace from the second watchdog, the one watching loaddefs
being loaded

Debugger entered: nil
  (if my-debug-on-loaddefs (debug) (setq my-debug-on-loaddefs t))
  my-debug-on-loaddefs()
  (lambda nil (my-debug-on-loaddefs))()
  eval-after-load-helper("/Applications/Emacs.app/Contents/Resources/lisp/lo...")
  run-hook-with-args(eval-after-load-helper "/Applications/Emacs.app/Contents/Resources/lisp/lo...")
  do-after-load-evaluation("/Applications/Emacs.app/Contents/Resources/lisp/lo...")
  documentation(duplicate-dwim)
  which-key--propertize-description("duplicate-dwim" nil nil nil "duplicate-dwim")
  which-key--format-and-replace((("C-c #" . "embark-act") ("C-c &" . "prefix") ("C-c d" . "duplicate-dwim") ("C-c g" . "my-grab-bag") ("C-c k" . "lambda") ("C-c m" . "magit-file-dispatch") ("C-c o" . "mode-line-other-buffer") ("C-c v" . "prefix") ("C-c C-b" . "elisp-byte-compile-buffer") ("C-c C-e" . "elisp-eval-region-or-buffer") ("C-c C-f" . "elisp-byte-compile-file") ("C-c C-k" . "lambda") ("C-c C-o" . "mode-line-other-buffer") ("C-c <tab>" . "company-complete")) nil)
  which-key--get-bindings([3] nil nil)
  which-key--create-buffer-and-show([3])
  which-key--update()
  apply(which-key--update nil)
  timer-event-handler([t 0 1 0 t which-key--update nil idle 0 nil])

and here is the code I have in my init.el

(defun my-watch-f2 (&rest args)
  (when (eq (car args) global-map)
    (let ((key (cl-second args)))
      (when (and (vectorp key) (eq (aref key 0) 'f2))
	(debug)))))

(add-hook 'after-init-hook
	  (lambda ()
	    (add-function :after (symbol-function 'define-key) #'my-watch-f2)))

(defvar my-debug-on-loaddefs nil)

(defun my-debug-on-loaddefs ()
  (if my-debug-on-loaddefs
      (debug)
    (setq my-debug-on-loaddefs t)))

(with-eval-after-load 'loaddefs
  (my-debug-on-loaddefs))