The big question is whether you want this behavior for kill-buffer
itself, which means not only when you call it interactively but for every use of it in existing Lisp code, or whether you want it only for interactive use.
I'll assume the latter. In that case, leave kill-buffer
alone, define your own command that does what you want, and remap the keys that are normally bound to kill-buffer
to your command:
(global-set-key [remap kill-buffer] 'my-kill-buffer)
For your my-kill-buffer
command, just check at the outset whether the buffer has been modified, and if so then launch ediff
for it.
To check whether it has been modified, use buffer-modified-p
.
To ediff
you would presumably want to grab the file (i.e., the buffer as saved), and diff it against the current, modified buffer. You might need to fiddle a bit to do that - I don't know of an existing ediff
command that does that.
But maybe all you really need is something like highlight-changes-mode
. See the Emacs manual, node Highlight Interactively
.
In other words, maybe all you need is to invoke highlight-changes-mode
if the buffer has been modified.