tags:

views:

863

answers:

6

It often occurs that a file buffer is modified (duh!). Before exiting, emacs asks whether to save the changes. Now it would be interesting to know what actually changed. Is there a way to find out?

+1  A: 

In this case I type undo to see the last change (usually some stray character which got typed in the wrong window, since I save early and often).

It would be nice if there were some other indication of the current changes, e.g. in the border like quick diff in Eclipse text editors.

starblue
And if the undo happens to undo an important change, you can just enter some character and run undo twice - thanks to Emacs's undo facility, which is more powerful than that in most editors.
Jouni K. Seppänen
+6  A: 

I use diff-buffer-with-file, and select the file that the buffer came from (which is the default anyway for the command... just hit enter).

You can also use highlight-changes-mode, though this won't track changes until you turn it on, so not so useful if you want to see what changed when you're closing a file that has not been in this mode :-)

Jarret Hardie
+16  A: 

As of Emacs 22.1 (at least), 'save-buffers-kill-emacs (the default binding for C-x C-c) prompts you for each unsaved buffer that has a file. Type a d when prompted to save and see the diff.

From the help documentation:

Save some modified file-visiting buffers.  Asks user about each one.
You can answer `y' to save, `n' not to save, `C-r' to look at the
buffer in question with `view-buffer' before deciding or `d' to
view the differences using `diff-buffer-with-file'.

If you look at the prompt, it should say something like:

Save file /path/to/file.txt? (y, n, !, ., q, C-r, d, or C-h)

Typing C-h gives you a little more verbose description (but d is what you are asking for):

Type SPC or `y' to save the current buffer;
DEL or `n' to skip the current buffer;
RET or `q' to give up on the save (skip all remaining buffers);
C-g to quit (cancel the whole command);
! to save all remaining buffers;
C-r to view this buffer;
d to view changes in this buffer;
or . (period) to save the current buffer and exit.
Trey Jackson
+6  A: 

You can have highlight-changes-mode enabled. It will display all changes in red. However it won't show you whitespace changes and will mark removals only with an red _. See also http://www.emacswiki.org/emacs/TrackChanges.

danielpoe
A: 

I use goto-chg for things like that. It's not perfect, but it always is enough to jog my memory about what change I made and promptly forgot about.

Joe Casadonte
A: 

I found this post about tracking changes by djcb most helpful regarding tracking changes in Emacs. The trick is to add the following to your .emacs:

;; higlight changes in documents
(global-highlight-changes-mode t)
(setq highlight-changes-visibility-initial-state nil); initially hide

and then toggle highlight-changes-visible-mode when you want to see what has changed.

jmn