Subject: bug#24240: 25.1.50; window-state-put, image-mode and window scrolling

From: martin rudalics <[email-masked]>
Date: Wed, 17 Aug 2016 10:30:26 +0200

>> We'd need a variable, say ‘window-inhibit-configuration-change-hook’.
 >
 > inhibit-window-configuration-change-hook ?

We can abuse ‘frame-after-make-frame’.  Try the attached, completely
untested patch.

BTW I just noticed that we still run ‘window-configuration-change-hook’
in far too many cases.  I'll have to remove it from ‘window-resize’,
‘window--resize-mini-window’, ‘adjust-window-trailing-edge’ and
‘balance-windows’.

 > The problem is, that it does work when edebugging it.  Anyway, I think I've
 > found the problem: It's the call to set-window-start, which in my
 > understanding forces the next redraw to scroll the window, thus
 > negating image-modes work.

Would my patch work around that?

martin
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -5620,21 +5620,29 @@ window-state-put
 	;; minimum possible state.  But such configurations hardly make
 	;; sense anyway.
 	(error "Window %s too small to accommodate state" window)
-      (setq state (cdr state))
-      (setq window-state-put-list nil)
-      ;; Work on the windows of a temporary buffer to make sure that
-      ;; splitting proceeds regardless of any buffer local values of
-      ;; `window-size-fixed'.  Release that buffer after the buffers of
-      ;; all live windows have been set by `window--state-put-2'.
-      (with-temp-buffer
-	(set-window-buffer window (current-buffer))
-	(window--state-put-1 state window nil totals pixelwise)
-	(window--state-put-2 ignore pixelwise))
-      (while window-state-put-stale-windows
-	(let ((window (pop window-state-put-stale-windows)))
-	  (when (eq (window-deletable-p window) t)
-	    (delete-window window))))
-      (window--check frame))))
+
+
+      (unwind-protect
+          (progn
+            (frame-after-make-frame frame nil)
+            (setq state (cdr state))
+            (setq window-state-put-list nil)
+            ;; Work on the windows of a temporary buffer to make sure that
+            ;; splitting proceeds regardless of any buffer local values of
+            ;; `window-size-fixed'.  Release that buffer after the buffers of
+            ;; all live windows have been set by `window--state-put-2'.
+            (with-temp-buffer
+              (set-window-buffer window (current-buffer))
+              (window--state-put-1 state window nil totals pixelwise)
+              (window--state-put-2 ignore pixelwise))
+            (while window-state-put-stale-windows
+              (let ((window (pop window-state-put-stale-windows)))
+                (when (eq (window-deletable-p window) t)
+                  (delete-window window)))))
+        (frame-after-make-frame frame t)
+        (prog1
+            (window--check frame)
+          (run-window-configuration-change-hook frame))))))
 
 (defun display-buffer-record-window (type window buffer)
   "Record information for window used by `display-buffer'.