aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2020-12-19 22:19:18 +0200
committerJuri Linkov2020-12-19 22:19:18 +0200
commitb9edbaed01a91d5fc6235fc679d8e0cd827f6fa9 (patch)
treeb5c9c1eb9d0365a25a00f0f75f3ffea690472ad5
parent5fe04f6b0773279a46b0449f0c890af3a03fb649 (diff)
downloademacs-b9edbaed01a91d5fc6235fc679d8e0cd827f6fa9.tar.gz
emacs-b9edbaed01a91d5fc6235fc679d8e0cd827f6fa9.zip
* lisp/image-mode.el: Use one timer and lock for slow remote calls (bug#45256)
* lisp/image-mode.el (image-auto-resize-timer): New variable. (image--window-state-change): Cancel previous timer and remember new timer in image-auto-resize-timer. (image--window-state-change): New variable. (image-fit-to-window): When image-fit-to-window-lock is nil, call image-toggle-display-image ignoring 'remote-file-error'.
-rw-r--r--lisp/image-mode.el21
1 files changed, 18 insertions, 3 deletions
diff --git a/lisp/image-mode.el b/lisp/image-mode.el
index 032ebf38733..465bf867627 100644
--- a/lisp/image-mode.el
+++ b/lisp/image-mode.el
@@ -942,6 +942,9 @@ Otherwise, display the image by calling `image-mode'."
942 (get-buffer-window-list (current-buffer) 'nomini 'visible)) 942 (get-buffer-window-list (current-buffer) 'nomini 'visible))
943 (image-toggle-display-image))) 943 (image-toggle-display-image)))
944 944
945(defvar image-auto-resize-timer nil
946 "Timer for `image-auto-resize-on-window-resize' option.")
947
945(defun image--window-state-change (window) 948(defun image--window-state-change (window)
946 ;; Wait for a bit of idle-time before actually performing the change, 949 ;; Wait for a bit of idle-time before actually performing the change,
947 ;; so as to batch together sequences of closely consecutive size changes. 950 ;; so as to batch together sequences of closely consecutive size changes.
@@ -950,8 +953,14 @@ Otherwise, display the image by calling `image-mode'."
950 ;; consecutive calls happen without any redisplay between them, 953 ;; consecutive calls happen without any redisplay between them,
951 ;; the costly operation of image resizing should happen only once. 954 ;; the costly operation of image resizing should happen only once.
952 (when (numberp image-auto-resize-on-window-resize) 955 (when (numberp image-auto-resize-on-window-resize)
953 (run-with-idle-timer image-auto-resize-on-window-resize nil 956 (when image-auto-resize-timer
954 #'image-fit-to-window window))) 957 (cancel-timer image-auto-resize-timer))
958 (setq image-auto-resize-timer
959 (run-with-idle-timer image-auto-resize-on-window-resize nil
960 #'image-fit-to-window window))))
961
962(defvar image-fit-to-window-lock nil
963 "Lock for `image-fit-to-window' timer function.")
955 964
956(defun image-fit-to-window (window) 965(defun image-fit-to-window (window)
957 "Adjust size of image to display it exactly in WINDOW boundaries." 966 "Adjust size of image to display it exactly in WINDOW boundaries."
@@ -968,7 +977,13 @@ Otherwise, display the image by calling `image-mode'."
968 (when (and image-width image-height 977 (when (and image-width image-height
969 (or (not (= image-width window-width)) 978 (or (not (= image-width window-width))
970 (not (= image-height window-height)))) 979 (not (= image-height window-height))))
971 (image-toggle-display-image))))))))) 980 (unless image-fit-to-window-lock
981 (unwind-protect
982 (progn
983 (setq-local image-fit-to-window-lock t)
984 (ignore-error 'remote-file-error
985 (image-toggle-display-image)))
986 (setq image-fit-to-window-lock nil)))))))))))
972 987
973 988
974;;; Animated images 989;;; Animated images