branch: externals/timeout commit f5bbedf20ad18289e629babf36382f44958366c2 Author: Karthik Chikmagalur <karthikchikmaga...@gmail.com> Commit: Karthik Chikmagalur <karthikchikmaga...@gmail.com>
README: Update with new function descriptions * README.org (To use this library:) * timeout.el: Fix usage in commentary --- README.org | 13 +++++++++++++ timeout.el | 12 ++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/README.org b/README.org index 3b664aed0e..b5b3dc0020 100644 --- a/README.org +++ b/README.org @@ -32,3 +32,16 @@ By default a debounced function returns =nil= at call time. To change this, run #+begin_src emacs-lisp (timeout-debounce! 'func 0.5 'some-return-value) #+end_src + +Instead of advising =func=, you can also create new throttled or debounced versions of it with =timeout-throttle= and =timeout-debounce=: + +#+begin_src emacs-lisp +(timeout-throttle 'func 2.0) +(timeout-debounce 'func 0.5) +#+end_src + +These return anonymous functions which you can bind to a symbol with =defalias= or =fset=: +#+begin_src emacs-lisp +(defalias 'throttled-func (timeout-throttle 'func 2.0)) +(fset 'throttled-func (timeout-throttle 'func 2.0)) +#+end_src diff --git a/timeout.el b/timeout.el index 161955e5e6..49a1d11d72 100644 --- a/timeout.el +++ b/timeout.el @@ -30,20 +30,20 @@ ;; (ii) does not provide customization options to limit how often it runs, ;; ;; To throttle a function FUNC to run no more than once every 2 seconds, run -;; (timeout-throttle! func 2.0) +;; (timeout-throttle! 'func 2.0) ;; ;; To debounce a function FUNC to run after a delay of 0.3 seconds, run -;; (timeout-debounce! func 0.3) +;; (timeout-debounce! 'func 0.3) ;; ;; To create a new throttled or debounced version of FUNC instead, run ;; -;; (timeout-throttle func 2.0) -;; (timeout-debounce func 0.3) +;; (timeout-throttle 'func 2.0) +;; (timeout-debounce 'func 0.3) ;; ;; You can bind this via fset or defalias: ;; -;; (defalias 'throttled-func (timeout-throttle func 2.0)) -;; (fset 'throttled-func (timeout-throttle func 2.0)) +;; (defalias 'throttled-func (timeout-throttle 'func 2.0)) +;; (fset 'throttled-func (timeout-throttle 'func 2.0)) ;; ;; The interactive spec and documentation of FUNC is carried over to the new ;; function.