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 Comments on “Quickly diff the changes made in the current buffer with its file”

  1. Ian Eure says:

    I like to bind this to C-x =, since it’s similar to vc-diff, which is at C-x v =.

  2. evolve75 says:

    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).

  3. Shawn Betts says:

    It’s bad form to use an interactive lambda function in a key binding.

    • evolve75 says:

      @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.

  4. Mate, thanks a lot for this! have been searching for a way to do this for ages!


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