Subject: bug#78180: 31.0.50; Since ab71699e5f2, global value of post-command-hook is useless

From: Ihor Radchenko <[email-masked]>
Date: Thu, 01 May 2025 08:44:01 +0000

Hi,

Before commit ab71699e5f2, global-eldoc-mode (enabled by default) did
nothing in most buffers and only activated when a given major mode
defined `eldoc-documentation-functions' (so that `eldoc--supported-p'
returns non-nil).

One can easily see this via
1. emacs -Q
2. C-x b *Messages* RET
3. M-: post-command-hook (nil)

After ab71699e5f2, `eldoc-documentation-functions' is no longer nil by
default, with immediate effect of *every single buffer* having
eldoc-mode enabled.

Enabling eldoc-mode itself is not a big deal. What is a big deal is the
fact that it is no longer possible to setup post-command-hook globally,
not just in current buffer, but also in all the future new buffers.
It is also not possible to setup transient hooks (self-removed upon
first execution) as long as current command ends up in different buffer.

(It was technically not exactly possible in the past as well, for
buffers holding their buffer-local post-command-hook value, but the
problem was less obvious as most buffers had post-command-hook set to
its default value)

The problem may affect:
1. Org mode (that's how I found the problem)
2. vcursor.el, vc.el, type-break.el, transient.el, xterm.el,
   scroll-all.el, global-reveal-mode, repeat-mode, gud.el, flymake,
   elisp-mode.el, and basically any other part of Emacs setting global
   default value of post-command-hook.

I do no think that ab71699e5f2 itself is doing anything wrong, but
rather that the design of post-command-hook is not ideal for its
purpose. The fact that we were able to get along with the current design
is by pure chance and the fact that most buffers did not set
buffer-local value of post-command-hook.

Maybe we should introduce post-command-global-hook that will be
evaluated in every single buffer and leave post-command-hook to be used
locally (maybe even rename it to post-command-local-hook for
clarity). Maybe similar for pre-command-hook.

In GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.49, cairo version 1.18.4) of 2025-04-29 built on localhost
Repository revision: 3a514005d153df429b0ed58ac64300296b9d5aac
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101016
System Description: Gentoo Linux
-- 
Ihor Radchenko // yantar92,
Org mode maintainer,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>