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

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

Eli Zaretskii <[email-masked]> writes:

>> From: Daniel Mendler <[email-masked]>
>> Cc: Eli Zaretskii <[email-masked]>,  [email-masked],  Juri Linkov
>>  <[email-masked]>
>> Date: Thu, 27 Mar 2025 06:48:15 +0100
>> 
>> Elijah Gabe Pérez <[email-masked]> writes:
>> 
>> >> Would it be better to use an idle timer instead?  post-command-hook
>> >> tends to make Emacs sluggish.
>> >
>> > Yeah, that is that what worried me when i decided to use that hook.
>> >
>> > I've fixed the patch to use only idle-timer instead.
>> 
>> The problem with the idle timer is that it might not run immediately.
>
> That depends on the value of the SECS argument to run-with-idle-timer,
> doesn't it.

No, there is no guarantee that the idle timer will run soon enough after
the given time if Emacs stays busy.

>> However when the user changes the input method, overwrite mode or
>> similar, the users expects that the cursor reflects the change
>> immediately after the last key press and does not lag behind. Therefore
>> I think there is no alternative to the `post-command-hook'. It seems to
>> me that only a bunch of mode variables are checked and then
>> `cursor-type' is set. In CUA the cursor indicator is also updated in the
>> `post-command-hook'. So this should not be too costly?
>
> Sorry, I object to adding stuff to post-command-hook in these cases.
> Emacs becomes very sluggish, and we should avoid that as much as we
> can.

I see your point about sluggishness and I am very careful myself to not
enable modes which add expensive computations to the
`post-command-hook'. Nevertheless in this case using the
`post-command-hook' is the right thing, such that the `cursor-type' is
changed effective immediately, as had been done before in CUA, see
`cua--post-command-handler-1'. The computation in this case is not
expensive.

Daniel