mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-02-04 14:40:54 -08:00
Enhance the auto-revert to avoid revert a buffer in short time
* lisp/autorevert.el (auto-revert--last-time): New defvar. (auto-revert-handler, auto-revert-notify-handler): Use it. * test/lisp/autorevert-tests.el (with-auto-revert-test): Set `auto-revert--lockout-interval' correctly.
This commit is contained in:
parent
80627a31c6
commit
545c54aea1
2 changed files with 17 additions and 6 deletions
|
|
@ -370,6 +370,9 @@ buffer.")
|
|||
"Non-nil when file has been modified on the file system.
|
||||
This has been reported by a file notification event.")
|
||||
|
||||
(defvar-local auto-revert--last-time nil
|
||||
"The last time of buffer was reverted.")
|
||||
|
||||
(defvar auto-revert-debug nil
|
||||
"Use for debug messages.")
|
||||
|
||||
|
|
@ -749,13 +752,17 @@ system.")
|
|||
;; Mark buffer modified.
|
||||
(setq auto-revert-notify-modified-p t)
|
||||
|
||||
;; Revert the buffer now if we're not locked out.
|
||||
;; Lock out the buffer
|
||||
(unless auto-revert--lockout-timer
|
||||
(auto-revert-handler)
|
||||
(setq auto-revert--lockout-timer
|
||||
(run-with-timer
|
||||
auto-revert--lockout-interval nil
|
||||
#'auto-revert--end-lockout buffer))))))))))
|
||||
#'auto-revert--end-lockout buffer))
|
||||
;; Revert it when first entry or it was reverted intervals ago
|
||||
(when (or (null auto-revert--last-time)
|
||||
(> (float-time (time-since auto-revert--last-time))
|
||||
auto-revert--lockout-interval))
|
||||
(auto-revert-handler))))))))))
|
||||
|
||||
(defun auto-revert--end-lockout (buffer)
|
||||
"End the lockout period after a notification.
|
||||
|
|
@ -801,7 +808,8 @@ This is an internal function used by Auto-Revert Mode."
|
|||
#'buffer-stale--default-function)
|
||||
t))))
|
||||
eob eoblist)
|
||||
(setq auto-revert-notify-modified-p nil)
|
||||
(setq auto-revert-notify-modified-p nil
|
||||
auto-revert--last-time (current-time))
|
||||
(when revert
|
||||
(when (and auto-revert-verbose
|
||||
(not (eq revert 'fast)))
|
||||
|
|
|
|||
|
|
@ -132,12 +132,15 @@ This expects `auto-revert--messages' to be bound by
|
|||
(error (message "%s" err) (signal (car err) (cdr err)))))))
|
||||
|
||||
(defmacro with-auto-revert-test (&rest body)
|
||||
`(let ((auto-revert-interval-orig auto-revert-interval))
|
||||
`(let ((auto-revert-interval-orig auto-revert-interval)
|
||||
(auto-revert--lockout-interval-orig auto-revert--lockout-interval))
|
||||
(unwind-protect
|
||||
(progn
|
||||
(customize-set-variable 'auto-revert-interval 0.1)
|
||||
(setq auto-revert--lockout-interval 0.05)
|
||||
,@body)
|
||||
(customize-set-variable 'auto-revert-interval auto-revert-interval-orig))))
|
||||
(customize-set-variable 'auto-revert-interval auto-revert-interval-orig)
|
||||
(setq auto-revert--lockout-interval auto-revert--lockout-interval-orig))))
|
||||
|
||||
(defun auto-revert-tests--write-file (text file time-delta &optional append)
|
||||
(write-region text nil file append 'no-message)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue