From 0b9e474953bbf5b9168821b7f86cf2a349aae511 Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Tue, 10 Sep 2002 16:48:52 +0000 Subject: [PATCH] (diff-buffer-with-file): Simplify. Don't signal an error if buffer has no file. Call sit-for after `diff' returns. --- lisp/files.el | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/lisp/files.el b/lisp/files.el index f86afe8d5d2..31d2b8762fa 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -2996,23 +2996,21 @@ After saving the buffer, this function runs `after-save-hook'." (defun diff-buffer-with-file (&optional buffer) "View the differences between BUFFER and its associated file. -This requires the external program \"diff\" to be in your `exec-path'." +This requires the external program `diff' to be in your `exec-path'." (interactive "bBuffer: ") - (setq buffer (get-buffer (or buffer (current-buffer)))) - (let ((buf-filename (buffer-file-name buffer))) - (unless buf-filename - (error "Buffer %s has no associated file" buffer)) - (let ((tempfile (make-temp-file "buffer-content-"))) - (unwind-protect - (progn - (with-current-buffer buffer - (save-restriction - (widen) - (write-region (point-min) (point-max) tempfile nil 'nomessage))) - (diff buf-filename tempfile nil t)) - (when (file-exists-p tempfile) - (delete-file tempfile))) - nil))) + (with-current-buffer (get-buffer (or buffer (current-buffer))) + (if (null buffer-file-name) + (message "Buffer %s has no associated file" (buffer-name)) + (let ((tempfile (make-temp-file "buffer-content-"))) + (unwind-protect + (save-restriction + (widen) + (write-region (point-min) (point-max) tempfile nil 'nomessage) + (diff buffer-file-name tempfile nil t) + (sit-for 0)) + (when (file-exists-p tempfile) + (delete-file tempfile))) + nil)))) (defvar save-some-buffers-action-alist '((?\C-r -- 2.39.5