emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master b31a966: * lisp/image-mode.el: Resize image on window resizing (b


From: Juri Linkov
Subject: master b31a966: * lisp/image-mode.el: Resize image on window resizing (bug#32672)
Date: Wed, 27 Nov 2019 16:52:37 -0500 (EST)

branch: master
commit b31a966e88b1b4fbc8148fda47becd1d209a67fd
Author: Juri Linkov <address@hidden>
Commit: Juri Linkov <address@hidden>

    * 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.
---
 etc/NEWS           |  3 +++
 lisp/image-mode.el | 25 +++++++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index 8233328..db30450 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2623,6 +2623,9 @@ pointer is over.  To change this behaviour, you can 
customize the user
 option 'mouse-wheel-follow-mouse'.  Note that this will also affect
 scrolling.
 
+** Mouse scroll up and down with control key modifier also works on images
+where it scales the image under the mouse pointer.
+
 ---
 ** help-follow-symbol now signals 'user-error' if point (or the
 position pointed to by the argument POS) is not in a symbol.
diff --git a/lisp/image-mode.el b/lisp/image-mode.el
index db68646..09d7828 100644
--- a/lisp/image-mode.el
+++ b/lisp/image-mode.el
@@ -599,6 +599,10 @@ Key bindings:
 
   (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-change nil t)
+  (add-hook 'window-state-change-functions #'image--window-change nil t)
+  (add-hook 'window-selection-change-functions #'image--window-change nil t)
+
   (run-mode-hooks 'image-mode-hook)
   (let ((image (image-get-display-property))
        (msg1 (substitute-command-keys
@@ -856,6 +860,27 @@ Otherwise, display the image by calling `image-mode'."
           (get-buffer-window-list (current-buffer) 'nomini 'visible))
     (image-toggle-display-image)))
 
+(defvar image--window-change-function
+  (debounce 1.0
+    (lambda (window)
+      (when (window-live-p window)
+        (with-current-buffer (window-buffer)
+          (when (derived-mode-p 'image-mode)
+            (let ((spec (image-get-display-property)))
+              (when (eq (car-safe spec) 'image)
+                (let* ((image-width  (plist-get (cdr spec) :max-width))
+                       (image-height (plist-get (cdr spec) :max-height))
+                       (edges (window-inside-pixel-edges window))
+                       (window-width  (- (nth 2 edges) (nth 0 edges)))
+                       (window-height (- (nth 3 edges) (nth 1 edges))))
+                  (when (and image-width image-height
+                             (or (not (= image-width  window-width))
+                                 (not (= image-height window-height))))
+                    (image-toggle-display-image)))))))))))
+
+(defun image--window-change (window)
+  (funcall image--window-change-function window))
+
 
 ;;; Animated images
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]