Subject: bug#77224: [PATCH] New minor mode 'cursor-indicators-mode'

From: Daniel Mendler <[email-masked]>
Date: Thu, 27 Mar 2025 21:17:25 +0100

Eli Zaretskii <[email-masked]> writes:

>> From: Daniel Mendler <[email-masked]>
>> Cc: [email-masked],  [email-masked],  [email-masked]
>> Date: Thu, 27 Mar 2025 17:39:59 +0100
>> 
>> Eli Zaretskii <[email-masked]> writes:
>> 
>> > post-command-hook is run by the same loop that decides that Emacs is
>> > idle and runs timers, so the difference in practice should be very
>> > small if at all.
>> 
>> The `post-command-hook' is guaranteed to run after a command while the
>> idle timer is delayed until no new events are in the queue.
>
> No, the idle time is run immediately if there's no input.  Emacs
> doesn't wait or delay the timer.

We are saying the same thing here. Yes, if there is no input, the idle
timer will run immediately. But if the user continues typing and events
are in the queue, then the timer will not run for some time. A delay
also occurs when an asynchronous process runs and fills a buffer in the
background like the *compilation* buffer. Then the cursor update will
lag behind.

I am with you that one should not carelessly add `post-command-hooks'. I
use various modes which use `post-command-hooks', idle timers and
regular timers, each for their proper use case. For example
`post-command-hooks' lead to sluggishness if they were used for auto
completion, spell checking or help at point (like Eldoc). For such use
cases idle timers or regular timers are the better tool since they defer
the expensive computation of completion strings, talking to a language
server, completion backend or a spell checker.

Here we discuss changing only the color of the cursor, a much much less
complex operation. The `cursor-type' update and checking a few variables
to find the color is a cheap operation which will not lead to
sluggishness. If this were an expensive operation, I would look
elsewhere for places to optimize, but avoiding `post-command-hook' is
not the solution.

Daniel