Subject: Re: 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 18:23:49 +0000

Eli Zaretskii <[email-masked]> writes:

>> rather that pretty much every single buffer will have a buffer-local
>> value that is shadowing the global value set by add-hook without LOCAL
>> arg.
>
> But only for the eldoc hook, right?  Because if not, I still don't
> understand what you are saying.

Sorry, but I do not understand your question.

>> Although, I now tested things more rigorously, and post-command-hook
>> does get evaluated, despite the above. So, I clearly miss something
>> about how and in which context post-command-hook is evaluated.
>
> May I suggest that you first describe the actual problem you bumped
> into?

The problem is rather simple - some of Org's tests make an assumption
that the value of `post-command-hook' is its global value in Org
buffers. It is no longer the case after ab71699e5f2.

When I was investigating the test failures, I thought that the problem
might be much more far-reaching than a simple test breaking. That's why
this bug report, and not the trivial fix of the tests.

>> 4. Create a new buffer C-x b new RET
>> 5. M-: post-command-hook RET
>>    
>>    (eldoc-schedule-timer t)   
>
> So the problem is that buffer-local hooks now have
> eldoc-schedule-timer added?  Is that the only problem?  And if so, why
> is it a problem?  Surely, there are gazillion of use cases in Emacs
> where many buffers have buffer-local post-command-hook different from
> the global value; why is it a problem in this case (or in all those
> cases)?

Well. First, I thought that it is a problem because presence of
buffer-local value preventing globally added hooks to be executed. It is
not a problem (for some reason I don't fully understand).

What else _might_ be a problem (but I am a bit lost in how things work
here) is direct invocations of (run-hooks 'post-command-hook) from
Elisp: in ert-x.el, gnus-msg.el, org-mouse.el. AFAIU, such calls will
only execute buffer-local post-comman-hook, not global. Maybe I miss
something.

-- 
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>