diff options
author | Juri Linkov <juri@linkov.net> | 2019-11-30 23:16:03 +0200 |
---|---|---|
committer | Juri Linkov <juri@linkov.net> | 2019-11-30 23:16:03 +0200 |
commit | d64ea182fb6e2bf3af8ac8a289e8029ded36407e (patch) | |
tree | 0e7835bc8f2f2b62a64a1fed3f72871abf3ad611 /lisp/image.el | |
parent | 9ac78ef56c184b757f9866edc3092eb62e259c90 (diff) | |
download | emacs-d64ea182fb6e2bf3af8ac8a289e8029ded36407e.tar.gz emacs-d64ea182fb6e2bf3af8ac8a289e8029ded36407e.tar.bz2 emacs-d64ea182fb6e2bf3af8ac8a289e8029ded36407e.zip |
Use run-with-idle-timer instead of debounce for responsive image scaling.
* lisp/emacs-lisp/timer.el (debounce, debounce-reduce): Revert macro addition.
https://lists.gnu.org/archive/html/emacs-devel/2019-11/msg01133.html
* lisp/image.el (image-increase-size, image-decrease-size):
Use run-with-idle-timer.
(image--change-size): Rename back from image--change-size-function.
* lisp/image-mode.el (image-mode--setup-mode): Remove hooks
window-size-change-functions and window-selection-change-functions (bug#32672)
(image-fit-to-window): Rename from image--window-change-function.
(image--window-state-change): Rename from image--window-change.
Use run-with-idle-timer.
Diffstat (limited to 'lisp/image.el')
-rw-r--r-- | lisp/image.el | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/lisp/image.el b/lisp/image.el index c4304782327..f4ed4e79fc0 100644 --- a/lisp/image.el +++ b/lisp/image.el @@ -1017,20 +1017,34 @@ has no effect." If N is 3, then the image size will be increased by 30%. The default is 20%." (interactive "P") - (funcall image--change-size-function - (if n - (1+ (/ (prefix-numeric-value n) 10.0)) - 1.2))) + ;; Wait for a bit of idle-time before actually performing the change, + ;; so as to batch together sequences of closely consecutive size changes. + ;; `image--change-size' just changes one value in a plist. The actual + ;; image resizing happens later during redisplay. So if those + ;; consecutive calls happen without any redisplay between them, + ;; the costly operation of image resizing should happen only once. + (run-with-idle-timer 0.3 nil + #'image--change-size + (if n + (1+ (/ (prefix-numeric-value n) 10.0)) + 1.2))) (defun image-decrease-size (&optional n) "Decrease the image size by a factor of N. If N is 3, then the image size will be decreased by 30%. The default is 20%." (interactive "P") - (funcall image--change-size-function - (if n - (- 1 (/ (prefix-numeric-value n) 10.0)) - 0.8))) + ;; Wait for a bit of idle-time before actually performing the change, + ;; so as to batch together sequences of closely consecutive size changes. + ;; `image--change-size' just changes one value in a plist. The actual + ;; image resizing happens later during redisplay. So if those + ;; consecutive calls happen without any redisplay between them, + ;; the costly operation of image resizing should happen only once. + (run-with-idle-timer 0.3 nil + #'image--change-size + (if n + (- 1 (/ (prefix-numeric-value n) 10.0)) + 0.8))) (defun image-mouse-increase-size (&optional event) "Increase the image size using the mouse." @@ -1065,16 +1079,12 @@ default is 20%." (plist-put (cdr image) :type 'imagemagick)) image)) -(defvar image--change-size-function - (debounce-reduce 0.3 1 - (lambda (state factor) - (* state factor)) - (lambda (factor) - (let* ((image (image--get-imagemagick-and-warn)) - (new-image (image--image-without-parameters image)) - (scale (image--current-scaling image new-image))) - (setcdr image (cdr new-image)) - (plist-put (cdr image) :scale (* scale factor)))))) +(defun image--change-size (factor) + (let* ((image (image--get-imagemagick-and-warn)) + (new-image (image--image-without-parameters image)) + (scale (image--current-scaling image new-image))) + (setcdr image (cdr new-image)) + (plist-put (cdr image) :scale (* scale factor)))) (defun image--image-without-parameters (image) (cons (pop image) |