Function: timeout--debounce-advice
timeout--debounce-advice is a byte-compiled function defined in
timeout.el.gz.
Signature
(timeout--debounce-advice &optional DELAY DEFAULT)
Documentation
Return a function that debounces its argument function.
For the meaning of DELAY see timeout-debounce.
The function returns immediately with value DEFAULT when called the first time. On future invocations, the result from the previous call is returned.
This is intended for use as function advice.
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/timeout.el.gz
(defun timeout--debounce-advice (&optional delay default)
"Return a function that debounces its argument function.
For the meaning of DELAY see `timeout-debounce'.
The function returns immediately with value DEFAULT when called the
first time. On future invocations, the result from the previous call is
returned.
This is intended for use as function advice."
(let ((debounce-timer nil)
(delay-value (or delay 0.50)))
(lambda (orig-fn &rest args)
"Debounce calls to this function."
(prog1 default
(if (timerp debounce-timer)
(progn
(cancel-timer debounce-timer)
(timer-set-time
debounce-timer (time-add nil (timeout--eval-value delay-value)))
(timer-activate debounce-timer))
(setq debounce-timer
(run-with-timer
(timeout--eval-value delay-value) nil
(lambda (buf)
(cancel-timer debounce-timer)
(setq debounce-timer nil)
(setq default
(if (buffer-live-p buf)
(with-current-buffer buf
(apply orig-fn args))
(apply orig-fn args))))
(current-buffer))))))))