Subject: bug#78582: 30.1; which-key-mode overwrites custom key bindings

From: Stefan Monnier <[email-masked]>
Date: Mon, 02 Jun 2025 10:11:16 -0400

> doc.c:
>   310 static void
>   311 reread_doc_file (Lisp_Object file)
>   312 {
>   313   if (NILP (file))
>   314     Fsnarf_documentation (Vdoc_file_name);
>   315   else
>   316     save_match_data_load (file, Qt, Qt, Qt, Qnil);
>   317 }
>
> Secondly, doc strings can point to loaddefs.el
>
>   (function-documentation 'rectangle-mark-mode)
>    => ("loaddefs.elc" . 1059343)

AFAICT the problem you describe is not specific to `loaddefs.el`.
The same thing can happen with any file that has a `global-set-key` call
at top-level.

This reloading business is supposed to happen only if the in-memory
doc-string-reference is out-of-sync with the installed files, presumably
because you're running Emacs "in place" and the files have changed in
the mean time.

If that's indeed your situation, then "all is well": the problem you're
seeing is "on purpose".  You can fix it by removing the above reloading
mechanism (in exchange for being unable to see the docstring in those
cases where the reloading would be needed).

I tend to see this every once in a while where `C-x C-c` (which
I normally rebind to a less-drastic operation) gets redefined
to its default binding because `files.elc` gets reloaded.  🙂

Maybe we should try and work harder to make such reloading more harmless
(e.g. replace the `define-key/global-set-key`s with functions which do
nothing if the key is already bound?), but it's an issue that affects
only those people who hack on the code of the very Emacs they're
running, so it's not super-high priority.

        Stefan