Subject: Re: bug#32850: 27.0.50; window-swap-states doesn't swap window prev/next-buffers

From: martin rudalics <[email-masked]>
Date: Thu, 25 Oct 2018 08:04:16 +0200

>> (save-window-excursion
 >>    (set-window-configuration configuration)
 >>    (window-state-get nil t))
 >
 > Is it really a good solution for serialization of tens of window configurations?
 > Is such code suitable to be placed to desktop.el?

Which problems do you see in practice?  I have no idea about the
internals of desktop.  If you mean that the windows' states have to be
saved too often - maybe to a backup file and as such converted from
configurations to states - we can, whenever desktop is active save a
configuration immediately to a state whenever it is stored somewhere.
That is, add some hook when a window configuration shall be saved to a
register and that register should be considered writable and saved
somewhere.  Is it that what you mean?

 > While testing without let-binding window-configuration-change-hook to nil,
 > window-configuration-change-hook was called 50 times, observable with:
 >
 > (add-hook 'window-configuration-change-hook
 >            (lambda () (message "window-configuration-change-hook called")))
 >
 > when let-bound to nil, these hooks are not called.

Obviously so.  The 'window-configuration-change-hook' mechanism is
extraordinarily dumb.

 > But after let-binding window-size-change-functions to nil,
 > and testing with
 >
 > (add-hook 'window-size-change-functions
 >            (lambda (_) (message "window-size-change-functions called")))
 >
 > window-size-change-functions is still called once.
 > I don't understand why.

'window-size-change-functions' is called by the redisplay mechanism
when it detects that at least one window has changed size.  This may
well happen outside the scope of the let binding.  If it happens when
restoring the initial configuration which should be identical to the
final one, you would have to investigate: Which window changed size
and why.  Maybe the minibuffer window is involved.

martin