guerrinha · 2022-07-20 02:16
I'm wonder why this is not a native thing?
[https://in.comum.org/smart-way-to-close-files.html](https://in.comum.org/smart-way-to-close-files.html)
DefiantAverage1 · 2022-07-20 03:11
I personally rely on git for most things I write. So, usually I just save the file, then check out the diff via git, if I need to
ilemming · 2022-07-20 03:28
bind a key to this:
```
(defun diff-current-buffer-with-file ()
(interactive)
(let ((buf (current-buffer)))
(with-current-buffer buf
(if buffer-file-name
(progn
(diff-buffer-with-file buf)
(select-window (get-buffer-window "*Diff*")))
(message "Buffer has no file!")))))
```
ieure · 2022-07-20 05:31
Not sure why you posted the code for a built-in function rather than its name.
guerrinha · 2022-07-20 15:41
The use case, is when you have a bunch of open buffers and start to kill them, and get surprised by Emacs asking you if you want to save or discard something you didn't know you have changed. In this case git will won't show the diff because is not saved.
\*edit\*
btw I use auto-commit for some org-files, so this is pretty handy.
ilemming · 2022-07-20 16:07
It's not built-in. This little fn uses built-in function, but it is slightly different. But sure, bind a key to `diff-buffer-with-file`, that works too.