From: Juri Linkov <juri@linkov.net>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: master 4b5d04b: Use new macro debounce-reduce to make mouse scaling of images more responsive
Date: Wed, 27 Nov 2019 23:54:46 +0200 [thread overview]
Message-ID: <87d0dd0yu1.fsf@mail.linkov.net> (raw)
In-Reply-To: <jwvblsyq9u1.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Tue, 26 Nov 2019 22:32:01 -0500")
>>>> * lisp/emacs-lisp/timer.el (debounce, debounce-reduce): New macros.
>>> Please use proper prefixes for those names.
>> Maybe timer-debounce and timer-debounce-reduce.
>
> I guess so, tho now that I looked at it I have other questions/comments:
>
> - I don't see `debounce` used anywhere. Do we need it?
I prepared a patch that uses `debounce`, but then waited until resolving
the question of prefixes. But now I installed the patch in b31a966e88
and will add the prefixes afterwards.
> - Why is `debounce-reduce` a macro rather than a function?
In its initial versions that used `body` it needed to be a macro,
but now it can be a function indeed.
> - What is the advantage of wrapping a `debounce-reduce` around
> `image--change-size` instead of doing something like:
>
> (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")
> ;; Wait for a bit of idle-time before actually performing the change,
> ;; so as to batch together sequences of closely consecutive size changes.
> (run-with-idle-timer 0.3 nil
> #'image--change-size
> (if n
> (- 1 (/ (prefix-numeric-value n) 10.0))
> 0.8)))
This version doesn't discard a sequence of consecutive calls
where every call is a costly operation. For example, on slow hardware
every image resize takes about 1 sec. Thus when mouse-wheel
generates 5 events, this version will wait for the next idle time,
then will resize the image sequentially 5 times during 5 seconds.
Whereas `debounce-reduce` accumulates all mouse wheel events, and then
calls only one resize operation with the collected scaling factor.
next prev parent reply other threads:[~2019-11-27 21:54 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20191123222254.31152.57547@vcs0.savannah.gnu.org>
[not found] ` <20191123222259.56FE420BE9@vcs0.savannah.gnu.org>
2019-11-24 0:40 ` master 4b5d04b: Use new macro debounce-reduce to make mouse scaling of images more responsive Stefan Monnier
2019-11-26 22:10 ` Juri Linkov
2019-11-27 3:32 ` Stefan Monnier
2019-11-27 21:54 ` Juri Linkov [this message]
2019-11-27 22:55 ` Stefan Monnier
2019-11-27 23:59 ` Juri Linkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87d0dd0yu1.fsf@mail.linkov.net \
--to=juri@linkov.net \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.