Skip to content

Commit

Permalink
import auto-revert-buffers as-is from 24.5's autorevert.el
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsius committed Jan 26, 2016
1 parent e1696fb commit 21228fe
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions lisp/magit-autorevert.el
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,75 @@ This function calls the hook `magit-auto-revert-mode-hook'.")
(and magit-auto-revert-mode auto-revert-buffer-list)))
(auto-revert-buffers)))

(defun auto-revert-buffers ()
"Revert buffers as specified by Auto-Revert and Global Auto-Revert Mode.
Should `global-auto-revert-mode' be active all file buffers are checked.
Should `auto-revert-mode' be active in some buffers, those buffers
are checked.
Non-file buffers that have a custom `revert-buffer-function' and
`buffer-stale-function' are reverted either when Auto-Revert
Mode is active in that buffer, or when the variable
`global-auto-revert-non-file-buffers' is non-nil and Global
Auto-Revert Mode is active.
This function stops whenever there is user input. The buffers not
checked are stored in the variable `auto-revert-remaining-buffers'.
To avoid starvation, the buffers in `auto-revert-remaining-buffers'
are checked first the next time this function is called.
This function is also responsible for removing buffers no longer in
Auto-Revert mode from `auto-revert-buffer-list', and for canceling
the timer when no buffers need to be checked."
(save-match-data
(let ((bufs (if global-auto-revert-mode
(buffer-list)
auto-revert-buffer-list))
remaining new)
;; Partition `bufs' into two halves depending on whether or not
;; the buffers are in `auto-revert-remaining-buffers'. The two
;; halves are then re-joined with the "remaining" buffers at the
;; head of the list.
(dolist (buf auto-revert-remaining-buffers)
(if (memq buf bufs)
(push buf remaining)))
(dolist (buf bufs)
(if (not (memq buf remaining))
(push buf new)))
(setq bufs (nreverse (nconc new remaining)))
(while (and bufs
(not (and auto-revert-stop-on-user-input
(input-pending-p))))
(let ((buf (car bufs)))
(if (buffer-live-p buf)
(with-current-buffer buf
;; Test if someone has turned off Auto-Revert Mode in a
;; non-standard way, for example by changing major mode.
(if (and (not auto-revert-mode)
(not auto-revert-tail-mode)
(memq buf auto-revert-buffer-list))
(setq auto-revert-buffer-list
(delq buf auto-revert-buffer-list)))
(when (auto-revert-active-p)
;; Enable file notification.
(when (and auto-revert-use-notify buffer-file-name
(not auto-revert-notify-watch-descriptor))
(auto-revert-notify-add-watch))
(auto-revert-handler)))
;; Remove dead buffer from `auto-revert-buffer-list'.
(setq auto-revert-buffer-list
(delq buf auto-revert-buffer-list))))
(setq bufs (cdr bufs)))
(setq auto-revert-remaining-buffers bufs)
;; Check if we should cancel the timer.
(when (and (not global-auto-revert-mode)
(null auto-revert-buffer-list))
(cancel-timer auto-revert-timer)
(setq auto-revert-timer nil)))))

(custom-add-to-group 'magit 'auto-revert-check-vc-info 'custom-variable)

;;; magit-autorevert.el ends soon
Expand Down

0 comments on commit 21228fe

Please sign in to comment.