Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I don't need saving. How to keep Emacs buffers in sync with files?

Tags:

emacs

autosave

I want to have all my file buffers always synchronized with the file content on disk. Is is possible? (preferably as a mode)

If you think it is unsafe, than I will just say that emacs undo + git is more than enough for me and I find explicit saving and reverting (if other program changes the file) obsolete safety feature.

like image 615
Łukasz Lew Avatar asked Oct 31 '09 21:10

Łukasz Lew


People also ask

How do you save a buffer in Emacs?

To save the file you are editing, type C-x C-s or select Save Buffer from the Files menu.

What is auto reverting?

One use of Auto Revert mode is to “tail” a file such as a system log, so that changes made to that file by other programs are continuously displayed. To do this, just move the point to the end of the buffer, and it will stay there as the file contents change.

What is the command to write buffer to a specified file?

If you wish to mark the buffer as visiting a different file and save it right away, use C-x C-w ( write-file ). This is equivalent to set-visited-file-name followed by C-x C-s , except that C-x C-w asks for confirmation if the file exists.

Which key combination in emacs can be used to save your changes?

Quit, cancel, open, save, save as: C-x C-c : Quit Emacs. C-g : Cancel the current action (use when there's part of a key sequence showing in the minibuffer and you want out) C-x C-f : Open a file (whether or not it already exists) C-x C-s : Save a file.


2 Answers

To bring it all together:

If you want auto-saving to be done in the visited file rather than in a separate auto-save file, set the variable auto-save-visited-file-name to a non-nil value. In this mode, there is no real difference between auto-saving and explicit saving.

http://www.gnu.org/software/emacs/manual/html_node/emacs/Auto-Save-Files.html#Auto-Save-Files

This makes your auto-saves go into the file you are working on, and not an external one.

Then you can set auto-save-interval to 1, and enable global-auto-revert-mode and you're all set.

I think that does it for you...

like image 163
Paul McMillan Avatar answered Oct 17 '22 09:10

Paul McMillan


Set the "auto-save-interval" to 1. That will save after each character you type. It will save to the "save" file, rather than the actual file, but your work will be protected.

Another option is this: http://www.litchie.net/programs/real-auto-save.html

like image 31
divegeek Avatar answered Oct 17 '22 09:10

divegeek