How can I get Emacs to revert all unchanged buffer

2019-01-30 13:47发布

Often, when I switch branches in git, if the files are open in emacs, then emacs asks if I want to revert them (as it thinks they've changed on disk) even though the contents are identical.

Firstly I'd like to find a way for emacs to not ask me about it at all if the contents on disk are identical to those in the buffer.

Secondly I'd like a command that reverted (without query) all my open buffers that have no unsaved changes, and queried me about those that do have unsaved changes.

Alternatively, I'd be open to suggestions about other solutions, ways of working, etc I could try. I'm fairly happy writing emacs-lisp if people can give me pointers on where to start.

PS I'm using Aquamacs on OSX if that matters.

Edit:

Well, I've found the revbuffs package to be pretty much what I need. Certainly enough to stop me wanting to try and write anything new myself. (I mapped revbuffs to Cmd-R which works quite nicely. Kind of similar to Cmd-R in other Mac apps).

Global-auto-revert mode would have been a perfectly fine solution, and I wish I could choose two answers. I prefer revbuffs simply because of a, possibly irrational, feeling of wanting to be in control of what happens.

I'd kind of guessed that if I accessed git from within emacs, then it could probably be handled easier, but I currently prefer accessing git through the commandline. (I haven't quite been using emacs long enough to make it my operating system). I will investigate magit a little more thoroughly though.

Edit2:

I've been using magit for a year now and can highly recommend it for dealing with git from within emacs. However I still use revbuffs whenever I do a rebase outside of emacs.

3条回答
家丑人穷心不美
2楼-- · 2019-01-30 14:05

Magit package do this automatically, when you activate magit-ionotify-mode (inotify need emacs 24.4 on linux). Its description you can find here.

查看更多
Root(大扎)
3楼-- · 2019-01-30 14:24

Perhaps you'd like the global auto-revert mode. Try running global-auto-revert-mode and if you like it you can add (global-auto-revert-mode) to your ~/.emacs file.

查看更多
SAY GOODBYE
4楼-- · 2019-01-30 14:28

Try the revbufs package:

revbufs.el is a tiny Emacs package that safely reverts your buffers when you have files being edited both in Emacs and via external tools (e.g., code generators such as Jomtool)...

查看更多
登录 后发表回答