2

I'm using file-notify-add-watch from filenotify.el to watch a dired directory so it can revert when a file is modified within the directory. This generally works, but I've noticed that it only works sometimes when renaming a file. Code is here.

When I watch two directories (~/ and ~/readings, for example) and add a file test.txt to ~/, filenotify catches that and reverts the buffer. When I run mv test.txt readings, the event passed to the filenotify callback contains the sexp '((<desc>) renamed "~/readings/test.txt" "~/readings/test.txt"). When I move it back with mv readings/test.txt . (while in ~/), the event passed to the callback is '((<desc>) renamed "~/test.txt" "~/test.txt"). So it seems to be passing not the previous and the new file, but just two of the new file's path. This could be a bug, but I'm not sure. For easier reading (=> indicates the events passed to the callback within emacs):

$ echo hey > test.txt
=> ((32) created "~/test.txt")
=> ((32) changed "~/test.txt")
$ mv test.txt readings
=> ((34) created "~/readings/test.txt")
$ mv readings/test.txt .
=> ((32) renamed "~/test.txt" "~/test.txt")

I'm pretty sure this is a bug, but I wanted to make sure I wasn't using filenotify incorrectly. Adding the watch, I do:

(file-notify-add-watch
  (expand-file-name dired-directory)
  '(change attribute-change) #'my-callback)

Which returns 32 and 34, the two descriptors shown in the output above.

Is this a bug? Or is there some element of file-notify-add-watch I'm using incorrectly? I would expect mv <file> <folder> to create a rename notification with both the previous and current version, but it's not doing that. I'm using emacs 25.0.50 on linux with 'inotify as a file notification library.

  • I will check further whether it is an error in filenotify.el, but as first comment: since (a recent git checkout of) Emacs 25.0.50 you could also apply M-x auto-revert-mode on your dired buffer. – Michael Albinus Sep 4 '15 at 7:38
  • I didn't know that! I have global-auto-revert-mode turned on; would that do the same thing, or is the local auto-revert-mode required? It doesn't seem to be auto-reverting (which would effectively do everything my code is supposed to do). – cosmicexplorer Sep 4 '15 at 7:45
  • Huh, it does seem that the local auto-revert-mode is doing exactly that. I wonder why the global version doesn't do the same thing. – cosmicexplorer Sep 4 '15 at 7:47
  • 1
    See the doc of global-auto-revert-mode: Global Auto Revert mode is a global minor mode that reverts any buffer associated with a file when the file changes on disk. Use auto-revert-mode to revert a particular buffer. A dired buffer is not "associated with a file". – Michael Albinus Sep 4 '15 at 8:57
  • Oops, didn't catch that intricacy. If auto-revert-mode works, then I'll just use that instead of watching files manually; this behavior of filenotify is still strange though, I'll see if I can figure out what's happening. – cosmicexplorer Sep 4 '15 at 9:03
1

There was a problem in renaming of files over directory boundaries. Should be fixed now in filenotify.el. Pls try a recent rebuild of Emacs 25.0.50.

  • Using the method I tried above, the newest build seems to work! I'll just file an actual bug next time; I didn't here cause I wasn't sure if I was using it correctly. Thanks so much. – cosmicexplorer Sep 6 '15 at 21:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.