@@ -599,6 +599,10 @@ Key bindings:
599
599
600
600
(add-hook 'change-major-mode-hook #'image-toggle-display-text nil t )
601
601
(add-hook 'after-revert-hook #'image-after-revert-hook nil t )
602
+ (add-hook 'window-size-change-functions #'image--window-change nil t )
603
+ (add-hook 'window-state-change-functions #'image--window-change nil t )
604
+ (add-hook 'window-selection-change-functions #'image--window-change nil t )
605
+
602
606
(run-mode-hooks 'image-mode-hook )
603
607
(let ((image (image-get-display-property ))
604
608
(msg1 (substitute-command-keys
@@ -856,6 +860,27 @@ Otherwise, display the image by calling `image-mode'."
856
860
(get-buffer-window-list (current-buffer ) 'nomini 'visible ))
857
861
(image-toggle-display-image )))
858
862
863
+ (defvar image--window-change-function
864
+ (debounce 1.0
865
+ (lambda (window )
866
+ (when (window-live-p window)
867
+ (with-current-buffer (window-buffer )
868
+ (when (derived-mode-p 'image-mode )
869
+ (let ((spec (image-get-display-property )))
870
+ (when (eq (car-safe spec) 'image )
871
+ (let* ((image-width (plist-get (cdr spec) :max-width ))
872
+ (image-height (plist-get (cdr spec) :max-height ))
873
+ (edges (window-inside-pixel-edges window))
874
+ (window-width (- (nth 2 edges) (nth 0 edges)))
875
+ (window-height (- (nth 3 edges) (nth 1 edges))))
876
+ (when (and image-width image-height
877
+ (or (not (= image-width window-width))
878
+ (not (= image-height window-height))))
879
+ (image-toggle-display-image )))))))))))
880
+
881
+ (defun image--window-change (window )
882
+ (funcall image--window-change-function window))
883
+
859
884
860
885
; ;; Animated images
861
886
0 commit comments