Daniel Colascione <dancol@dancol.org> 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.
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.
I think having alternatives like this for specific commands (or actions)
could help reduce the use of post-command-hook.