aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2019-11-27 23:52:29 +0200
committerJuri Linkov2019-11-27 23:52:29 +0200
commitb31a966e88b1b4fbc8148fda47becd1d209a67fd (patch)
tree77d43d0665a21f96479d4cd3840462ff32cf986c
parent2435f811b946ec54ab1da90aded52caddef977c8 (diff)
downloademacs-b31a966e88b1b4fbc8148fda47becd1d209a67fd.tar.gz
emacs-b31a966e88b1b4fbc8148fda47becd1d209a67fd.zip
* lisp/image-mode.el: Resize image on window resizing (bug#32672)
* lisp/image-mode.el (image--window-change): New function. (image--window-change-function): New variable. (image-mode--setup-mode): Add buffer-local hook image--window-change to window-size-change-functions, window-state-change-functions, window-selection-change-functions.
-rw-r--r--etc/NEWS3
-rw-r--r--lisp/image-mode.el25
2 files changed, 28 insertions, 0 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 8233328fa3c..db304508886 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2623,6 +2623,9 @@ pointer is over. To change this behaviour, you can customize the user
2623option 'mouse-wheel-follow-mouse'. Note that this will also affect 2623option 'mouse-wheel-follow-mouse'. Note that this will also affect
2624scrolling. 2624scrolling.
2625 2625
2626** Mouse scroll up and down with control key modifier also works on images
2627where it scales the image under the mouse pointer.
2628
2626--- 2629---
2627** help-follow-symbol now signals 'user-error' if point (or the 2630** help-follow-symbol now signals 'user-error' if point (or the
2628position pointed to by the argument POS) is not in a symbol. 2631position pointed to by the argument POS) is not in a symbol.
diff --git a/lisp/image-mode.el b/lisp/image-mode.el
index db6864649d0..09d7828047e 100644
--- a/lisp/image-mode.el
+++ b/lisp/image-mode.el
@@ -599,6 +599,10 @@ Key bindings:
599 599
600 (add-hook 'change-major-mode-hook #'image-toggle-display-text nil t) 600 (add-hook 'change-major-mode-hook #'image-toggle-display-text nil t)
601 (add-hook 'after-revert-hook #'image-after-revert-hook nil t) 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 (run-mode-hooks 'image-mode-hook) 606 (run-mode-hooks 'image-mode-hook)
603 (let ((image (image-get-display-property)) 607 (let ((image (image-get-display-property))
604 (msg1 (substitute-command-keys 608 (msg1 (substitute-command-keys
@@ -856,6 +860,27 @@ Otherwise, display the image by calling `image-mode'."
856 (get-buffer-window-list (current-buffer) 'nomini 'visible)) 860 (get-buffer-window-list (current-buffer) 'nomini 'visible))
857 (image-toggle-display-image))) 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;;; Animated images 885;;; Animated images
861 886