Subject: bug#32672: 27.0.50; image resize on window resizing

From: Juri Linkov <[email-masked]>
Date: Sun, 09 Sep 2018 18:54:27 +0300

Like dynamically reformatting Man-mode buffers on window resizing in bug#32536
it would be useful to do the same for image-mode.  By default, when an image
is visited, it gets resized to fit into the window.  But on window shrinking,
parts of the image become truncated, and on window enlarging too much of
empty space is wasted since the image is not zoomed.

This patch relies on improvements in bug#32637.

diff --git a/lisp/image-mode.el b/lisp/image-mode.el
index 19fa28d440..9c7199ba9e 100644
--- a/lisp/image-mode.el
+++ b/lisp/image-mode.el
@@ -574,6 +574,7 @@ image-mode
 
 	(add-hook 'change-major-mode-hook 'image-toggle-display-text nil t)
 	(add-hook 'after-revert-hook 'image-after-revert-hook nil t)
+	(add-hook 'window-size-change-functions 'image-window-size-change nil t)
 	(run-mode-hooks 'image-mode-hook)
 	(let ((image (image-get-display-property))
 	      (msg1 (substitute-command-keys
@@ -822,6 +823,17 @@ image-after-revert-hook
           (get-buffer-window-list (current-buffer) 'nomini 'visible))
     (image-toggle-display-image)))
 
+(defun image-window-size-change (frame)
+  (walk-windows (lambda (window)
+                  (when (or (/= (window-pixel-width-before-size-change window)
+                                (window-pixel-width window))
+                            (/= (window-pixel-height-before-size-change window)
+                                (window-pixel-height window)))
+                    (with-current-buffer (window-buffer window)
+                      (when (derived-mode-p 'image-mode)
+                        (image-after-revert-hook)))))
+                'nomini frame))
+
 
 ;;; Animated images