[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#32672: 27.0.50; image resize on window resizing
From: |
Juri Linkov |
Subject: |
bug#32672: 27.0.50; image resize on window resizing |
Date: |
Fri, 21 Sep 2018 02:15:45 +0300 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu) |
>> But the problem is that the buffer-local hook will have such idiomatic code:
>>
>> (with-current-buffer (window-buffer window)
>> ...
>
> Where does 'window' come from? At the time 'buffer-list-update-hook'
> gets called, there's no guarantee that the buffer whose local hook
> runs is even shown in a window.
Thank you, now it's possible to finish this feature,
it gets 'window' using get-buffer-window-list:
diff --git a/lisp/image-mode.el b/lisp/image-mode.el
index 19fa28d440..3355ee6109 100644
--- a/lisp/image-mode.el
+++ b/lisp/image-mode.el
@@ -574,6 +574,9 @@ 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 (debounce
'image-size-window-change 1) nil t)
+ (add-hook 'buffer-list-update-hook 'image-size-buffer-change nil t)
+
(run-mode-hooks 'image-mode-hook)
(let ((image (image-get-display-property))
(msg1 (substitute-command-keys
@@ -822,6 +826,42 @@ image-after-revert-hook
(get-buffer-window-list (current-buffer) 'nomini 'visible))
(image-toggle-display-image)))
+(defun image-size-window-change (&optional frame)
+ (let (buffers)
+ (walk-windows (lambda (window)
+ (with-current-buffer (window-buffer window)
+ (when (derived-mode-p 'image-mode)
+ (push (current-buffer) buffers))))
+ 'nomini (or frame 'visible))
+ (mapc (lambda (buffer) (image-size-buffer-change buffer))
+ (delq nil (delete-dups buffers)))))
+
+(defun image-size-buffer-change (&optional buffer)
+ (with-current-buffer (or buffer (current-buffer))
+ (when (derived-mode-p 'image-mode)
+ (let* ((spec (image-get-display-property))
+ (spec (and (eq (car-safe spec) 'image) spec))
+ (max-width (plist-get (cdr spec) :max-width))
+ (max-height (plist-get (cdr spec) :max-height))
+ (windows (and (or max-width max-height)
+ (get-buffer-window-list
+ (current-buffer) 'nomini 'visible)))
+ min-width min-height min-window)
+ (mapc (lambda (window)
+ (let* ((edges (window-inside-pixel-edges window))
+ (width (- (nth 2 edges) (nth 0 edges)))
+ (height (- (nth 3 edges) (nth 1 edges))))
+ (setq min-width (if min-width (min min-width width)
width))
+ (setq min-height (if min-height (min min-height height)
height))
+ (when (and (= min-width width)
+ (= min-height height))
+ (setq min-window window))))
+ windows)
+ (when (or (and min-width max-width (not (= min-width max-width)))
+ (and min-height max-height (not (= min-height max-height))))
+ (with-selected-window min-window
+ (image-toggle-display-image)))))))
+
;;; Animated images
- bug#32672: 27.0.50; image resize on window resizing, (continued)
- bug#32672: 27.0.50; image resize on window resizing, Juri Linkov, 2018/09/13
- bug#32672: 27.0.50; image resize on window resizing, martin rudalics, 2018/09/14
- bug#32672: 27.0.50; image resize on window resizing, Juri Linkov, 2018/09/15
- bug#32672: 27.0.50; image resize on window resizing, martin rudalics, 2018/09/16
- bug#32672: 27.0.50; image resize on window resizing, Juri Linkov, 2018/09/16
- bug#32672: 27.0.50; image resize on window resizing, martin rudalics, 2018/09/17
- bug#32672: 27.0.50; image resize on window resizing, Juri Linkov, 2018/09/17
- bug#32672: 27.0.50; image resize on window resizing, martin rudalics, 2018/09/19
- bug#32672: 27.0.50; image resize on window resizing, Juri Linkov, 2018/09/19
- bug#32672: 27.0.50; image resize on window resizing, martin rudalics, 2018/09/20
- bug#32672: 27.0.50; image resize on window resizing,
Juri Linkov <=
- bug#32672: 27.0.50; image resize on window resizing, martin rudalics, 2018/09/21
- bug#32672: 27.0.50; image resize on window resizing, Juri Linkov, 2018/09/22
- bug#32672: 27.0.50; image resize on window resizing, martin rudalics, 2018/09/23
- bug#32672: 27.0.50; image resize on window resizing, Juri Linkov, 2018/09/23
- bug#32672: 27.0.50; image resize on window resizing, martin rudalics, 2018/09/24
- bug#32672: 27.0.50; image resize on window resizing, Eli Zaretskii, 2018/09/24
- bug#32672: 27.0.50; image resize on window resizing, martin rudalics, 2018/09/24
- bug#32672: 27.0.50; image resize on window resizing, Eli Zaretskii, 2018/09/24
- bug#32672: 27.0.50; image resize on window resizing, martin rudalics, 2018/09/24
- bug#32672: 27.0.50; image resize on window resizing, Eli Zaretskii, 2018/09/24