Is there an emacs command to show the difference between a buffer and its file?
For example, I've made some edits to a buffer, forgotten what they were, and now I need to save the buffer to its file, but want to check what I have actually changed first.
A buffer is something in memory, a file resides on a hard disk.
If you wish to mark the buffer as visiting a different file and save it right away, use C-x C-w ( write-file ). This is equivalent to set-visited-file-name followed by C-x C-s , except that C-x C-w asks for confirmation if the file exists.
The command M-x diff compares two files, displaying the differences in an Emacs buffer named `*diff*' . It works by running the diff program, using options taken from the variable diff-switches . The value of diff-switches should be a string; the default is "-c" to specify a context diff.
Diff mode is a major mode used for the output of M-x diff and other similar commands. This kind of output is called a patch, because it can be passed to the patch command to automatically apply the specified changes. To select Diff mode manually, type M-x diff-mode .
diff-buffer-with-file
. I just googled for "emacs compare buffer file changed".
Another option is to hit C-x s
followed by d
. This also shows a diff between a buffer and its file.
Most useful if the buffer of interest is the only one that needs saving.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With