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

From: Daniel Colascione <[email-masked]>
Date: Fri, 28 Mar 2025 21:03:10 -0400

On March 28, 2025 8:40:36 PM EDT, "Elijah Gabe Pérez" <[email-masked]> wrote:
>Daniel Colascione <[email-masked]> writes:
>
>> The feature I'm proposing is higher-level than that.  For example, for
>> my personal use, I have something that sits in pre-redisplay-function
>> and scans all the windows for applying highlights based on current
>> buffer and window selection.  I should have written this thing using the
>> appropriate window configuration change hooks, but didn't, because I'm
>> lazy and my approach is fast enough for me.
>
>>     ;; Don't do this.
>
>>     (defun window-highlight--pre-redisplay (_window)
>>       (window-highlight--rescan-windows))
>
>>     (add-function :after pre-redisplay-function
>>        #'window-highlight--pre-redisplay))
>
>> What I'd have wanted instead is something like this:
>
>>   (run-when-changed
>>       (list (selected-window) (selected-frame) (frame-focus-state))
>>     #'window-highlight--rescan-windows)
>
>> Here, we'd run window-highlight--rescan-windows only when one of its
>> dependent conditions (e.g. selected frame) changed.  After any number of
>> window and frame changes, we'd run window-highlight--rescan-windows
>> *once*, immediately before its effects would become user-visible
>> (e.g. just before redisplay, or after commands), and we wouldn't re-run
>> it until one of its preconditions changed.
>
>Can your proposal also handle whether user moves cursor?
>
>Another reason why post-command-hook is used is mostly for run code
>when user moves cursor position.

I don't see why not? You could put (point) on your change list or something. I'm imagining that we just recognize forms in this list specially and add the appropriate low level hooks internally.

>post-command-hook would run code even if user/cursor is idle and even
>for every /(unrelated)/ function in background, which can lead to high
>resource consumption.

Yeah. Tragedy of the commons. Too many sheep grazing on the communal Emacs event loop.

>
>I think having alternatives like this for specific commands (or actions)
>could help reduce the use of post-command-hook.
>