help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: automatic dired update


From: Andreas Politz
Subject: Re: automatic dired update
Date: Mon, 05 Jan 2009 11:15:36 +0100
User-agent: Mozilla-Thunderbird 2.0.0.17 (X11/20081018)

Paul R wrote:
Does anyone know how to make dired auto-refresh? For example, i have
a dired buffer of dir xyz buried somewhere. Then, i renamed some
files in OS's Desktop. Then, when i switch to dir xyz in emacs,
i wish to see the updated list without me having to type g to
refresh. originally i thought just some hook... something like
(add-hook 'dired-load-hook 'revert-buffer)

but when actually trying to do it, apparently not that simple.
I thought it must be some function or variable that tells me when
buffer display is switched or updated... can't locate it.

Drew> Good question. To use a hook to call `dired-revert', you need to
Drew> find a hook that represents the "change" in interaction state that
Drew> you make when you "switch" to the dired buffer. I'm not sure what
Drew> hook that might be.

That would only work if the dired buffer is not currently displayed when
the change happen.

I think a real solution would be to use FS notifications systems. I know
of inotify ( http://en.wikipedia.org/wiki/Inotify ) for linux but
I suspect such systems exist for most widely used systems. That would be
a very good addition to emacs.

Drew> You could use a timer or, say, `display-time-hook' to do it
Drew> periodically, but that's a sledge hammer.

As a temporary solution, a combination of :
 - refresh display on "buffer gets diplayed" event
and
 - refresh diplay every N seconds if buffer is already displayed
could provide the wanted effect.

Anybody aware of inotify-and-the-likes integration effort to emacs ?




(defvar dired-file-modification-hash (make-hash-table :test 'equal))

(defun maybe-revert-dired-buffers ()
  (walk-windows
   #'(lambda (win)
       (with-selected-window win
         (when (eq major-mode 'dired-mode)
           (let ((mod (gethash default-directory dired-file-modification-hash)))
             (unless (and mod
                          (equal mod (nth 5 (file-attributes 
default-directory))))
               (setq mod (nth 5 (file-attributes default-directory)))
               (puthash default-directory mod dired-file-modification-hash)
               (dired-revert))))))
   'no-mini 'all-frames))

(run-with-idle-timer 1 t 'maybe-revert-dired-buffers)

This is polling the filesystem, plus I don't know if it is working
on win32.

-ap



reply via email to

[Prev in Thread] Current Thread [Next in Thread]