7

How can I configure Emacs to update a buffer's file association when the file is renamed externally?

In Textmate, I can open a file "foo.txt", use a different program to rename the file to "bar.txt", and Textmate automatically notices that the file was renamed. The new filename is displayed in the Textmate's window title, and editing and saving the file writes the changes to "bar.txt".

In Emacs, if I open a file "foo.txt" then use a different program to rename the file to "bar.txt", Emacs' buffer is still associated with "foo.txt". Editing and saving the file writes the file back to "foo.txt", but I would like it to write the file to "bar.txt" (I would also like the buffer name to change to "bar.txt", and for revert-buffer to read the file from "bar.txt").

2
  • 2
    Perhaps you can file a feature request against auto-revert-mode.
    – PythonNut
    Sep 9, 2015 at 2:00
  • This separation of buffers from filenames on disk is an essential part of emacs flexibility, a flexibility that comes with great benefit when editing remote files. That is why the emacs tutorial spends a lot of time upfront describing the difference between buffers and files. However if you want a custom behavior, look into file notification extensions.
    – Emacs User
    Sep 9, 2015 at 7:19

1 Answer 1

1

If you want to implement this yourself, then I imagine you need to utilise the Notifications on File Changes functionality (provided that one of the requisite libraries is supported on your OS).

C-hig (elisp) File Notifications RET

6
  • IIUC, Textmate runs on OS X. There is no file notification library for Emacs available these days. Integration of kqueue has been discussed, but nobody has implemented yet. Sep 9, 2015 at 7:18
  • @MichaelAlbinus what about inotify? I believe magit-filenotify uses something based on that.
    – suvayu
    Sep 9, 2015 at 8:58
  • 1
    Inotify support is integrated in Emacs, so there's no problem on GNU/Linux systems. But I suppose somebody, who wants Textmate features, runs her Emacs instance on OS X. Sep 9, 2015 at 9:32
  • Ah, indeed! This is on OS X.
    – suvayu
    Sep 9, 2015 at 12:05
  • 1
    Well, perfect timing! Yesterday I've merged some local work into the Emacs development version, which provides kqueue support on *BSD and OS X. File notification shall work now also on OS X! Nov 26, 2015 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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