Mercurial > emacs
comparison lisp/view.el @ 79831:8b17197a6be3
(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.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Sat, 12 Jan 2008 17:16:20 +0000 |
parents | 9cd51e20e318 |
children | 2be6cb49457d |
comparison
equal
deleted
inserted
replaced
79830:7d66f0e4630b | 79831:8b17197a6be3 |
---|---|
236 (setq minor-mode-map-alist | 236 (setq minor-mode-map-alist |
237 (cons (cons 'view-mode view-mode-map) minor-mode-map-alist))) | 237 (cons (cons 'view-mode view-mode-map) minor-mode-map-alist))) |
238 | 238 |
239 ;;; Commands that enter or exit view mode. | 239 ;;; Commands that enter or exit view mode. |
240 | 240 |
241 (defun kill-buffer-if-not-modified (buf) | |
242 "Like `kill-buffer', but does nothing if the buffer is modified." | |
243 (let ((buf (or (bufferp buf) (get-buffer buf)))) | |
244 (and buf (not (buffer-modified-p buf)) | |
245 (kill-buffer buf)))) | |
246 | |
241 ;;;###autoload | 247 ;;;###autoload |
242 (defun view-file (file) | 248 (defun view-file (file) |
243 "View FILE in View mode, returning to previous buffer when done. | 249 "View FILE in View mode, returning to previous buffer when done. |
244 Emacs commands editing the buffer contents are not available; instead, | 250 Emacs commands editing the buffer contents are not available; instead, |
245 a special set of commands (mostly letters and punctuation) | 251 a special set of commands (mostly letters and punctuation) |
256 (get major-mode 'mode-class)) | 262 (get major-mode 'mode-class)) |
257 'special) | 263 'special) |
258 (progn | 264 (progn |
259 (switch-to-buffer buffer) | 265 (switch-to-buffer buffer) |
260 (message "Not using View mode because the major mode is special")) | 266 (message "Not using View mode because the major mode is special")) |
261 (view-buffer buffer (and (not had-a-buf) 'kill-buffer))))) | 267 (view-buffer buffer (and (not had-a-buf) 'kill-buffer-if-not-modified))))) |
262 | 268 |
263 ;;;###autoload | 269 ;;;###autoload |
264 (defun view-file-other-window (file) | 270 (defun view-file-other-window (file) |
265 "View FILE in View mode in another window. | 271 "View FILE in View mode in another window. |
266 When done, return that window to its previous buffer, and kill the | 272 When done, return that window to its previous buffer, and kill the |
277 (unless (file-exists-p file) (error "%s does not exist" file)) | 283 (unless (file-exists-p file) (error "%s does not exist" file)) |
278 (let ((had-a-buf (get-file-buffer file)) | 284 (let ((had-a-buf (get-file-buffer file)) |
279 (buf-to-view (find-file-noselect file))) | 285 (buf-to-view (find-file-noselect file))) |
280 (view-buffer-other-window buf-to-view nil | 286 (view-buffer-other-window buf-to-view nil |
281 (and (not had-a-buf) | 287 (and (not had-a-buf) |
282 (not (buffer-modified-p buf-to-view)) | 288 'kill-buffer-if-not-modified)))) |
283 'kill-buffer)))) | |
284 | 289 |
285 ;;;###autoload | 290 ;;;###autoload |
286 (defun view-file-other-frame (file) | 291 (defun view-file-other-frame (file) |
287 "View FILE in View mode in another frame. | 292 "View FILE in View mode in another frame. |
288 When done, kill the buffer visiting FILE if unmodified and if it wasn't | 293 When done, kill the buffer visiting FILE if unmodified and if it wasn't |
300 (unless (file-exists-p file) (error "%s does not exist" file)) | 305 (unless (file-exists-p file) (error "%s does not exist" file)) |
301 (let ((had-a-buf (get-file-buffer file)) | 306 (let ((had-a-buf (get-file-buffer file)) |
302 (buf-to-view (find-file-noselect file))) | 307 (buf-to-view (find-file-noselect file))) |
303 (view-buffer-other-frame buf-to-view nil | 308 (view-buffer-other-frame buf-to-view nil |
304 (and (not had-a-buf) | 309 (and (not had-a-buf) |
305 (not (buffer-modified-p buf-to-view)) | 310 'kill-buffer-if-not-modified)))) |
306 'kill-buffer)))) | |
307 | 311 |
308 | 312 |
309 ;;;###autoload | 313 ;;;###autoload |
310 (defun view-buffer (buffer &optional exit-action) | 314 (defun view-buffer (buffer &optional exit-action) |
311 "View BUFFER in View mode, returning to previous buffer when done. | 315 "View BUFFER in View mode, returning to previous buffer when done. |