mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-02-16 09:14:18 +00:00
Evaluate result on first call to throttled func in timeout.el
* lisp/emacs-lisp/timeout.el (timeout--throttle-advice) (timeout-throttled-func): Replace 'prog1' with 'progn' to return the evaluated value of 'result' (bug#79979). This will capture the correct return value the first time a throttled function is called. Previously, it would return nil on the very first call. (timeout-debounce, timeout-throttle, timeout-throttled-func) (timeout-debounced-func): Add the autoload cookie.
This commit is contained in:
parent
d8870cc102
commit
24e5505705
1 changed files with 13 additions and 6 deletions
|
|
@ -82,7 +82,7 @@ This is intended for use as function advice."
|
|||
(result))
|
||||
(lambda (orig-fn &rest args)
|
||||
"Throttle calls to this function."
|
||||
(prog1 result
|
||||
(progn
|
||||
(unless (and throttle-timer (timerp throttle-timer))
|
||||
(setq result (apply orig-fn args))
|
||||
(setq throttle-timer
|
||||
|
|
@ -90,7 +90,8 @@ This is intended for use as function advice."
|
|||
(timeout--eval-value timeout-value) nil
|
||||
(lambda ()
|
||||
(cancel-timer throttle-timer)
|
||||
(setq throttle-timer nil)))))))))
|
||||
(setq throttle-timer nil)))))
|
||||
result))))
|
||||
|
||||
(defun timeout--debounce-advice (&optional delay default)
|
||||
"Return a function that debounces its argument function.
|
||||
|
|
@ -122,6 +123,7 @@ This is intended for use as function advice."
|
|||
(apply orig-fn args))))
|
||||
(current-buffer))))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun timeout-debounce (func &optional delay default)
|
||||
"Debounce FUNC by making it run DELAY seconds after it is called.
|
||||
|
||||
|
|
@ -143,6 +145,7 @@ returned."
|
|||
'((name . debounce)
|
||||
(depth . -99)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun timeout-throttle (func &optional throttle)
|
||||
"Make FUNC run no more frequently than once every THROTTLE seconds.
|
||||
|
||||
|
|
@ -159,6 +162,7 @@ previous successful call is returned."
|
|||
'((name . throttle)
|
||||
(depth . -98)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun timeout-throttled-func (func &optional throttle)
|
||||
"Return a throttled version of function FUNC.
|
||||
|
||||
|
|
@ -182,7 +186,7 @@ previous successful call is returned."
|
|||
"\n\nThrottle calls to this function"))
|
||||
(interactive (advice-eval-interactive-spec
|
||||
(cadr (interactive-form func))))
|
||||
(prog1 result
|
||||
(progn
|
||||
(unless (and throttle-timer (timerp throttle-timer))
|
||||
(setq result (apply func args))
|
||||
(setq throttle-timer
|
||||
|
|
@ -190,14 +194,15 @@ previous successful call is returned."
|
|||
(timeout--eval-value throttle-value) nil
|
||||
(lambda ()
|
||||
(cancel-timer throttle-timer)
|
||||
(setq throttle-timer nil)))))))
|
||||
(setq throttle-timer nil)))))
|
||||
result))
|
||||
;; NON-INTERACTIVE version
|
||||
(lambda (&rest args)
|
||||
(:documentation
|
||||
(concat
|
||||
(documentation func)
|
||||
"\n\nThrottle calls to this function"))
|
||||
(prog1 result
|
||||
(progn
|
||||
(unless (and throttle-timer (timerp throttle-timer))
|
||||
(setq result (apply func args))
|
||||
(setq throttle-timer
|
||||
|
|
@ -205,8 +210,10 @@ previous successful call is returned."
|
|||
(timeout--eval-value throttle-value) nil
|
||||
(lambda ()
|
||||
(cancel-timer throttle-timer)
|
||||
(setq throttle-timer nil))))))))))
|
||||
(setq throttle-timer nil)))))
|
||||
result)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun timeout-debounced-func (func &optional delay default)
|
||||
"Return a debounced version of function FUNC.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue