Quickly diff the changes made in the current buffer with its file

Update (23rd Jan 2010): Separated the key-assignment and  function definition.

A simple function to quickly do a diff of the current buffer contents with its underlying file. Very useful if the file has been changed outside (e.g., a log file).

;; Diff the current buffer with the file contents
(defun my-diff-current-buffer-with-disk ()
 "Compare the current buffer with it's disk file."
 (interactive)
 (diff-buffer-with-file (current-buffer)))
(global-set-key (kbd "C-c w") 'my-diff-current-buffer-with-disk)
Advertisements

7 thoughts on “Quickly diff the changes made in the current buffer with its file

  1. Binding to C-x = does have the semantic resonance with vc-diff’s key binding and is a good solution.

    Just a note of caution though – you do end up overwriting the default function which is to (a) either display the current cursor position or (b) with a prefix argument, describe the character under point.

    Admittedly, one probably does not have much use for either defaults under normal usage (though I did find myself using the second function (C-u C-x =) once in a while to find the font face being used).

    1. @Shawn Betts, you are right. This was a quick and dirty personal setting – but the disadvantage is that (a) the function is anonymous and (b) the key description via C-h k is essentially unusable.

      I have updated the tip to separate the function definition from the key assignment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s