Search code examples
emacsrevertdired

How to enable `dired-auto-revert-buffer` only for Dired buffers without inserted subdirs?


Enabling global-auto-revert-mode is a wonderful way to develop/debug with another tool. Changes made to the file on disk are mirrored back in the corresponding emacs buffer.

dired-auto-revert-buffer makes the same possible for dired buffers, but if reverting dired buffers is enabled, it becomes impossible to use recursive directories. They take too long to reload.

How can I enable dired-auto-revert-buffer for dired buffers that have run neither insertion (dired-maybe-insert-subdir) nor, especially, recursive insertion?


Solution

  • Good question. Perhaps someone else will have a better idea, but as far as I can see, you will need to set dired-auto-revert-buffer to a function (not to t) that returns non-nil only when there are no inserted subdirs.

    This should do the trick:

    (setq dired-auto-revert-buffer  (lambda (_dir) (null (cdr dired-subdir-alist))))
    

    But keep in mind that dired-auto-revert-buffer has an effect only when you "revisit" an existing Dired buffer. It is not enough, for example, to just reselect its window or make its buffer current. If you use C-x d to revisit it, then it will be auto-reverted if it has no inserted subdirs.