diff options
| author | Juri Linkov | 2019-11-30 23:16:03 +0200 |
|---|---|---|
| committer | Juri Linkov | 2019-11-30 23:16:03 +0200 |
| commit | d64ea182fb6e2bf3af8ac8a289e8029ded36407e (patch) | |
| tree | 0e7835bc8f2f2b62a64a1fed3f72871abf3ad611 /lisp/emacs-lisp/timer.el | |
| parent | 9ac78ef56c184b757f9866edc3092eb62e259c90 (diff) | |
| download | emacs-d64ea182fb6e2bf3af8ac8a289e8029ded36407e.tar.gz 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/emacs-lisp/timer.el')
| -rw-r--r-- | lisp/emacs-lisp/timer.el | 44 |
1 files changed, 0 insertions, 44 deletions
diff --git a/lisp/emacs-lisp/timer.el b/lisp/emacs-lisp/timer.el index 5fdf9a426a7..561cc70078f 100644 --- a/lisp/emacs-lisp/timer.el +++ b/lisp/emacs-lisp/timer.el | |||
| @@ -488,50 +488,6 @@ The argument should be a value previously returned by `with-timeout-suspend'." | |||
| 488 | If the user does not answer after SECONDS seconds, return DEFAULT-VALUE." | 488 | If the user does not answer after SECONDS seconds, return DEFAULT-VALUE." |
| 489 | (with-timeout (seconds default-value) | 489 | (with-timeout (seconds default-value) |
| 490 | (y-or-n-p prompt))) | 490 | (y-or-n-p prompt))) |
| 491 | |||
| 492 | (defmacro debounce (secs function) | ||
| 493 | "Call FUNCTION after SECS seconds have elapsed. | ||
| 494 | Postpone FUNCTION call until after SECS seconds have elapsed since the | ||
| 495 | last time it was invoked. On consecutive calls within the interval of | ||
| 496 | SECS seconds, cancel all previous calls that occur rapidly in quick succession, | ||
| 497 | and execute only the last call. This improves performance of event processing." | ||
| 498 | (declare (indent 1) (debug t)) | ||
| 499 | (let ((timer-sym (make-symbol "timer"))) | ||
| 500 | `(let (,timer-sym) | ||
| 501 | (lambda (&rest args) | ||
| 502 | (when (timerp ,timer-sym) | ||
| 503 | (cancel-timer ,timer-sym)) | ||
| 504 | (setq ,timer-sym | ||
| 505 | (run-with-timer | ||
| 506 | ,secs nil (lambda () | ||
| 507 | (apply ,function args)))))))) | ||
| 508 | |||
| 509 | (defmacro debounce-reduce (secs initial-state state-function function) | ||
| 510 | "Call FUNCTION after SECS seconds have elapsed. | ||
| 511 | Postpone FUNCTION call until after SECS seconds have elapsed since the | ||
| 512 | last time it was invoked. On consecutive calls within the interval of | ||
| 513 | SECS seconds, cancel all previous calls that occur rapidly in quick succession, | ||
| 514 | and execute only the last call. This improves performance of event processing. | ||
| 515 | |||
| 516 | STATE-FUNCTION can be used to accumulate the state on consecutive calls | ||
| 517 | starting with the value of INITIAL-STATE, and then execute the last call | ||
| 518 | with the collected state value." | ||
| 519 | (declare (indent 1) (debug t)) | ||
| 520 | (let ((timer-sym (make-symbol "timer")) | ||
| 521 | (state-sym (make-symbol "state"))) | ||
| 522 | `(let (,timer-sym (,state-sym ,initial-state)) | ||
| 523 | (lambda (&rest args) | ||
| 524 | (setq ,state-sym (apply ,state-function ,state-sym args)) | ||
| 525 | (when (timerp ,timer-sym) | ||
| 526 | (cancel-timer ,timer-sym)) | ||
| 527 | (setq ,timer-sym | ||
| 528 | (run-with-timer | ||
| 529 | ,secs nil (lambda () | ||
| 530 | (apply ,function (if (listp ,state-sym) | ||
| 531 | ,state-sym | ||
| 532 | (list ,state-sym))) | ||
| 533 | (setq ,state-sym ,initial-state)))))))) | ||
| 534 | |||
| 535 | 491 | ||
| 536 | (defconst timer-duration-words | 492 | (defconst timer-duration-words |
| 537 | (list (cons "microsec" 0.000001) | 493 | (list (cons "microsec" 0.000001) |