diff --git a/lisp/emacs-lisp/timeout.el b/lisp/emacs-lisp/timeout.el index 2b90650f02a..7529d4bc0a4 100644 --- a/lisp/emacs-lisp/timeout.el +++ b/lisp/emacs-lisp/timeout.el @@ -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.