all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: automatic dired update
       [not found]   ` <ddd5bee8-c0ca-4cf6-8234-72ae447a362d@s1g2000prg.googlegroups.com>
@ 2009-01-04 21:05     ` Xah Lee
  2009-01-05  1:56       ` Drew Adams
  2009-01-05 12:53       ` Michael Heerdegen
  0 siblings, 2 replies; 9+ messages in thread
From: Xah Lee @ 2009-01-04 21:05 UTC (permalink / raw
  To: help-gnu-emacs

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.

Thanks.

  Xah
∑ http://xahlee.org/

☄

On Dec 31 2008, 7:16 pm, "Russ P." <Russ.Paie...@gmail.com> wrote:
> On Dec 31, 3:07 am,XahLee<xah...@gmail.com> wrote:
>
>
>
> > On Dec 30, 3:20 pm, "Russ P." <Russ.Paie...@gmail.com> wrote:
>
> > > Wouldn't it be nice if dired automatically updated every time it is
> > > "viewed" rather than requiring the user to type "g"?
>
> > > Also, I find that the columns in dired get misaligned, and I need to
> > > type "g" to get them realigned. Has that ever been fixed? Thanks.
>
> > you could set a hook so that whenever you switch to dired mode, it
> > gets updated.
>
> > Let us know if you need the code.
>
> > Perhaps this should be dired's option it emacs customization.
>
> >  Xah
> > ∑http://xahlee.org/
>
> > ☄
>
> Yes, I would like to get the code. Thanks.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: automatic dired update
  2009-01-04 21:05     ` automatic dired update Xah Lee
@ 2009-01-05  1:56       ` Drew Adams
  2009-01-05  9:40         ` Paul R
       [not found]         ` <mailman.3996.1231148453.26697.help-gnu-emacs@gnu.org>
  2009-01-05 12:53       ` Michael Heerdegen
  1 sibling, 2 replies; 9+ messages in thread
From: Drew Adams @ 2009-01-05  1:56 UTC (permalink / raw
  To: 'Xah Lee', help-gnu-emacs

> 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.

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

Seems like you want something that kicks in whenever a particular window gets
the focus, but I don't know of such a hook. `window-configuratino-change-hook'
is probably not what you want, but maybe take a look.

I think `change-major-mode-hook' won't do it, because that's only when the
current buffer's mode changes.

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

`first-change-hook' would presumably kick in for any change you made in Dired -
you might look at that.

`menu-bar-update-hook' kicks in whenever the menu-bar is updated - which is
quite often - another sledge hammer.

If you always switch buffers/windows with the mouse, maybe
`mouse-leave-buffer-hook' would help.

You could perhaps advise the commands you typically use to switch to the Dired
buffer/window (`switch-to-buffer' or whatever), so they check for `dired-mode'
and DTRT, but again, that's a bit of a sledge hammer.

I'm probably not thinking clearly right now, but I don't see anything obvious as
an elegant solution; sorry. But it's a good question. Maybe someone else has a
good answer.






^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: automatic dired update
  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>
  1 sibling, 1 reply; 9+ messages in thread
From: Paul R @ 2009-01-05  9:40 UTC (permalink / raw
  To: help-gnu-emacs

>> 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 ?

-- 
  Paul




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: automatic dired update
       [not found]         ` <mailman.3996.1231148453.26697.help-gnu-emacs@gnu.org>
@ 2009-01-05 10:15           ` Andreas Politz
  2009-01-06 16:47             ` Andreas Politz
  0 siblings, 1 reply; 9+ messages in thread
From: Andreas Politz @ 2009-01-05 10:15 UTC (permalink / raw
  To: help-gnu-emacs

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



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: automatic dired update
  2009-01-04 21:05     ` automatic dired update Xah Lee
  2009-01-05  1:56       ` Drew Adams
@ 2009-01-05 12:53       ` Michael Heerdegen
  1 sibling, 0 replies; 9+ messages in thread
From: Michael Heerdegen @ 2009-01-05 12:53 UTC (permalink / raw
  To: help-gnu-emacs

`auto-revert-mode' is designed to work for dired, too! Simply call it
from `dired-mode-hook'.

It is quite relyable and does what you want without additional
configuration.

Unfortunately, there are still some problems with this. For example,
actions like `dired-to-copy' cause the buffer-modified flag of the
target buffer to be set, which prevents later auto-reverting. There was
a discussion in gnu.emacs.bug about this; I hope the emacs developers
will find a better solution for Gnu Emacs 23.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: automatic dired update
  2009-01-05  9:40         ` Paul R
@ 2009-01-05 15:43           ` Drew Adams
  0 siblings, 0 replies; 9+ messages in thread
From: Drew Adams @ 2009-01-05 15:43 UTC (permalink / raw
  To: 'Paul R', help-gnu-emacs

> >> 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 
> Drew> state that you make when you "switch" to the dired buffer.
> Drew> I'm not sure what hook that might be.
> 
> That would only work if the dired buffer is not currently 
> displayed when the change happen.

That's why I put "switch" in quotes. It wasn't clear what the OP meant by
"switch to dir". I include the possibility that he includes the possibility of
changing focus to an existing Dired window.

My point was that, depending on what is meant by "switch", it's not obvious what
hook might help.






^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: automatic dired update
  2009-01-05 10:15           ` Andreas Politz
@ 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>
  0 siblings, 2 replies; 9+ messages in thread
From: Andreas Politz @ 2009-01-06 16:47 UTC (permalink / raw
  To: help-gnu-emacs


d_zman@hotmail.com wrote:
 > If I add this to my lisp scripts called out in .emacs it doesn't
 > work.  If I load your lisp script by itself, it does.  How can I have
 > it load with my other lisp scipts, is there line I can add to
 > my .emacs file?
 >

I don't know why it's not working, but as someone mentioned in this
thread I was reinventing wheels. Use auto-revert-mode instead :

(add-to-list 'dired-mode-hook 'auto-revert-mode)

-ap

 >> (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- Hide quoted text -
 >>
 >> - Show quoted text -
 >
 >



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: automatic dired update
  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>
  1 sibling, 0 replies; 9+ messages in thread
From: Peter Dyballa @ 2009-01-06 22:27 UTC (permalink / raw
  To: Andreas Politz; +Cc: help-gnu-emacs


Am 06.01.2009 um 17:47 schrieb Andreas Politz:

> (add-to-list 'dired-mode-hook 'auto-revert-mode)

Why do you use add-to-list? The usual use would be add-hook ...  
Doesn't add-to-list need an existing list before it can be altered?

--
Mit friedvollen Grüßen

   Pete

Klingon function calls do not have "parameters" - they have  
"arguments"- and they ALWAYS WIN THEM.





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: automatic dired update
       [not found]               ` <mailman.4171.1231280855.26697.help-gnu-emacs@gnu.org>
@ 2009-01-07  8:47                 ` Andreas Politz
  0 siblings, 0 replies; 9+ messages in thread
From: Andreas Politz @ 2009-01-07  8:47 UTC (permalink / raw
  To: help-gnu-emacs

Peter Dyballa wrote:
> 
> Am 06.01.2009 um 17:47 schrieb Andreas Politz:
> 
>> (add-to-list 'dired-mode-hook 'auto-revert-mode)
> 
> Why do you use add-to-list? The usual use would be add-hook ... Doesn't 
> add-to-list need an existing list before it can be altered?
>

It's lisps fault. I am thinking the whole time about lists.

-ap

> -- 
> Mit friedvollen Grüßen
> 
>   Pete
> 


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2009-01-07  8:47 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [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
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

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.