# HG changeset patch # User Eli Zaretskii # Date 1200158180 0 # Node ID 8b17197a6be31079dfc6ee80fc8f2d942ef0cd4a # Parent 7d66f0e4630bcd667d0757368c2daa8c29994719 (view-file-other-window, view-file-other-frame): Fix last change. (kill-buffer-if-not-modified): New function. (view-file): Don't kill the buffer if it is modified. diff -r 7d66f0e4630b -r 8b17197a6be3 lisp/view.el --- a/lisp/view.el Sat Jan 12 14:15:35 2008 +0000 +++ b/lisp/view.el Sat Jan 12 17:16:20 2008 +0000 @@ -238,6 +238,12 @@ ;;; Commands that enter or exit view mode. +(defun kill-buffer-if-not-modified (buf) + "Like `kill-buffer', but does nothing if the buffer is modified." + (let ((buf (or (bufferp buf) (get-buffer buf)))) + (and buf (not (buffer-modified-p buf)) + (kill-buffer buf)))) + ;;;###autoload (defun view-file (file) "View FILE in View mode, returning to previous buffer when done. @@ -258,7 +264,7 @@ (progn (switch-to-buffer buffer) (message "Not using View mode because the major mode is special")) - (view-buffer buffer (and (not had-a-buf) 'kill-buffer))))) + (view-buffer buffer (and (not had-a-buf) 'kill-buffer-if-not-modified))))) ;;;###autoload (defun view-file-other-window (file) @@ -279,8 +285,7 @@ (buf-to-view (find-file-noselect file))) (view-buffer-other-window buf-to-view nil (and (not had-a-buf) - (not (buffer-modified-p buf-to-view)) - 'kill-buffer)))) + 'kill-buffer-if-not-modified)))) ;;;###autoload (defun view-file-other-frame (file) @@ -302,8 +307,7 @@ (buf-to-view (find-file-noselect file))) (view-buffer-other-frame buf-to-view nil (and (not had-a-buf) - (not (buffer-modified-p buf-to-view)) - 'kill-buffer)))) + 'kill-buffer-if-not-modified)))) ;;;###autoload