unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Andreas Politz <politza@fh-trier.de>
To: help-gnu-emacs@gnu.org
Subject: Re: automatic dired update
Date: Mon, 05 Jan 2009 11:15:36 +0100	[thread overview]
Message-ID: <1231150601.751645@arno.fh-trier.de> (raw)
In-Reply-To: <mailman.3996.1231148453.26697.help-gnu-emacs@gnu.org>

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



  parent reply	other threads:[~2009-01-05 10:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <91299a37-5cd2-4b3e-a7c3-381bdf7f69a5@q30g2000prq.googlegroups.com>
     [not found] ` <90548140-00a8-44f8-b8f0-6b4530f49933@v39g2000pro.googlegroups.com>
     [not found]   ` <ddd5bee8-c0ca-4cf6-8234-72ae447a362d@s1g2000prg.googlegroups.com>
2009-01-04 21:05     ` automatic dired update Xah Lee
2009-01-05  1:56       ` Drew Adams
2009-01-05  9:40         ` Paul R
2009-01-05 15:43           ` Drew Adams
     [not found]         ` <mailman.3996.1231148453.26697.help-gnu-emacs@gnu.org>
2009-01-05 10:15           ` Andreas Politz [this message]
2009-01-06 16:47             ` Andreas Politz
2009-01-06 22:27               ` Peter Dyballa
     [not found]               ` <mailman.4171.1231280855.26697.help-gnu-emacs@gnu.org>
2009-01-07  8:47                 ` Andreas Politz
2009-01-05 12:53       ` Michael Heerdegen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1231150601.751645@arno.fh-trier.de \
    --to=politza@fh-trier.de \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).