Re: window-buffer-change-functions & window-size-change-functions

Stéphane Marks <[email protected]> Tue, 30 Jun 2026 15:58:52 +0200
Newsgroups gmane.emacs.help
Message-ID <CAN+1HbpxiLDQgnqSh5=j-4APWBvkBuWb5YzOuSM6-UubfqqN9Q@mail.gmail.com>
On Tue, Jun 30, 2026 at 2:16 PM Joost Kremers <[email protected]>
wrote:

> Hi all,
>
> The docs state that `window-size-change-functions` "is run when a 'window
> size change' has been detected which means that a window was created,
> assigned another buffer, or changed its total size or that of its text
> area". Is there a way to separate out these various cases?
>
> I'm looking specifically for a way to distinguish the case where a new
> buffer is displayed in a window from the case where a window size is
> changed. Going by the names, `window-size-change-functions` and
> `window-buffer-change-functions` seem to allow me to do that, but
> apparently the former is also called upon buffer-change.
>

Consider using a window-buffer-change-functions function: after ensuring
the object is a window (it can be called with a frame as you probably
know), call window-old-buffer with the window and if it reports the same
buffer as window-buffer does, then it's not a new buffer for that window.
If you want to exclude minibuffer window changes, call
active-minibuffer-window to see if the selected window is associated with a
minibuffer.

(lambda (object)
  (when (and (window-live-p object)
             (eq (window-old-buffer object)
                 (window-buffer object)))
    ;; ...
    ))

-Stéphane