Subject: bug#20943: 25.0.50; Dired buffers are not always auto-reverted

From: Mark Karpov <[email-masked]>
Date: Thu, 09 Jul 2015 21:30:10 +0600

> We need to come up with a way of telling auto-revert that although the
> buffer was modified by the commands you mentioned, it's okay to revert
> it.  Can you suggest a change along those lines?

I propose two changes:

1. In ‘auto-revert-handler’, autorevert modified files if current buffer
is a Dired buffer:

(defun auto-revert-handler ()
  "Revert current buffer, if appropriate.
This is an internal function used by Auto-Revert Mode."
  (when (or auto-revert-tail-mode
            (eq major-mode dired-mode)
            (not (buffer-modified-p)))
    ...))

This removes «freezing» of modified buffers (‘auto-revert-buffer’ is
only called when auto-revert mode is enabled right? this should not
affect users who don't use auto-revert). This is what I currently
use. Control flow goes into body of ‘when’ and for Dired buffers this
boils down to conditions that check if current buffer is stale, and if
it is, then the function revert it.

2. To eliminate adverse effects (reordering of files because of
auto-revert mode), we need to write down all functions (commands) that
can insert new elements out of order in Dired buffer, then at the end of
every such a command, add:

(when auto-revert-mode
  (revert-buffer nil t t)) ;; not sure about the collection of args

This should be done only for Dired-specific commands (that are used only
in Dired mode, if there is uncertainty, add additional condition to test
that current major mode is ‘dired-mode’), of course.

In principle, a macro can be written for this set of functions, but I
don't think it's a good idea for Elisp, given such limited use case.

The only thing I cannot do myself from this is form full list of
functions that should call ‘revert-buffer’ when ‘auto-revert-mode’ is
enabled. You should be able to do it better than me.

These functions should contain reverting code in themselves because
‘auto-revert-handler’ cannot help here — its period is too long.

Maybe I don't see some corner cases? If you disagree with this plan,
let's discuss it.