31

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?

tshepang
  • 12,111
  • 21
  • 91
  • 136

6 Answers6

30

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
  • 73,529
  • 11
  • 197
  • 229
17

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
  • 95,172
  • 10
  • 132
  • 126
9

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
  • 3,756
  • 23
  • 18
2

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
  • 889
  • 1
  • 8
  • 25
1

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
  • 55,348
  • 14
  • 97
  • 151
  • 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 Mar 09 '09 at 15:24
0

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
  • 15,888
  • 11
  • 45
  • 57