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)
7 thoughts on “Quickly diff the changes made in the current buffer with its file”
I like to bind this to C-x =, since it’s similar to vc-diff, which is at C-x v =.
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).
It’s bad form to use an interactive lambda function in a key binding.
@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.
Mate, thanks a lot for this! have been searching for a way to do this for ages!