diff options
| -rw-r--r-- | lisp/view.el | 103 |
1 files changed, 55 insertions, 48 deletions
diff --git a/lisp/view.el b/lisp/view.el index 61c1ddf9a00..e6024601679 100644 --- a/lisp/view.el +++ b/lisp/view.el | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | ;;; view.el --- peruse file or buffer without editing. | 1 | ;;; view.el --- peruse file or buffer without editing. |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1985, 1989, 1994, 1995, 1997 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1985, 1989, 1994, 1995, 1997, 2000 |
| 4 | ;; Free Software Foundation, Inc. | ||
| 4 | 5 | ||
| 5 | ;; Author: K. Shane Hartman | 6 | ;; Author: K. Shane Hartman |
| 6 | ;; Maintainer: Inge Frick <inge@nada.kth.se> | 7 | ;; Maintainer: Inge Frick <inge@nada.kth.se> |
| @@ -182,7 +183,7 @@ This is local in each buffer, once it is used.") | |||
| 182 | (define-key map "m" 'point-to-register) | 183 | (define-key map "m" 'point-to-register) |
| 183 | (define-key map "'" 'register-to-point) | 184 | (define-key map "'" 'register-to-point) |
| 184 | (define-key map "x" 'exchange-point-and-mark) | 185 | (define-key map "x" 'exchange-point-and-mark) |
| 185 | (define-key map "@" 'View-back-to-mark) | 186 | (define-key map "@" 'View-back-to-mark) |
| 186 | (define-key map "." 'set-mark-command) | 187 | (define-key map "." 'set-mark-command) |
| 187 | (define-key map "%" 'View-goto-percent) | 188 | (define-key map "%" 'View-goto-percent) |
| 188 | ; (define-key map "G" 'View-goto-line-last) | 189 | ; (define-key map "G" 'View-goto-line-last) |
| @@ -217,7 +218,7 @@ This is local in each buffer, once it is used.") | |||
| 217 | (define-key map "1" 'digit-argument) | 218 | (define-key map "1" 'digit-argument) |
| 218 | (define-key map "0" 'digit-argument) | 219 | (define-key map "0" 'digit-argument) |
| 219 | (define-key map "H" 'describe-mode) | 220 | (define-key map "H" 'describe-mode) |
| 220 | (define-key map "?" 'describe-mode) ; Maybe do as less instead? | 221 | (define-key map "?" 'describe-mode) ; Maybe do as less instead? See above. |
| 221 | (define-key map "h" 'describe-mode) | 222 | (define-key map "h" 'describe-mode) |
| 222 | map)) | 223 | map)) |
| 223 | 224 | ||
| @@ -228,7 +229,7 @@ This is local in each buffer, once it is used.") | |||
| 228 | ;;; Commands that enter or exit view mode. | 229 | ;;; Commands that enter or exit view mode. |
| 229 | 230 | ||
| 230 | ;;;###autoload | 231 | ;;;###autoload |
| 231 | (defun view-file (file-name) | 232 | (defun view-file (file) |
| 232 | "View FILE in View mode, returning to previous buffer when done. | 233 | "View FILE in View mode, returning to previous buffer when done. |
| 233 | Emacs commands editing the buffer contents are not available; instead, | 234 | Emacs commands editing the buffer contents are not available; instead, |
| 234 | a special set of commands (mostly letters and punctuation) | 235 | a special set of commands (mostly letters and punctuation) |
| @@ -238,12 +239,12 @@ For list of all View commands, type H or h while viewing. | |||
| 238 | 239 | ||
| 239 | This command runs the normal hook `view-mode-hook'." | 240 | This command runs the normal hook `view-mode-hook'." |
| 240 | (interactive "fView file: ") | 241 | (interactive "fView file: ") |
| 241 | (let ((had-a-buf (get-file-buffer file-name))) | 242 | (let ((had-a-buf (get-file-buffer file))) |
| 242 | (view-buffer (find-file-noselect file-name) | 243 | (view-buffer (find-file-noselect file) |
| 243 | (and (not had-a-buf) 'kill-buffer)))) | 244 | (and (not had-a-buf) 'kill-buffer)))) |
| 244 | 245 | ||
| 245 | ;;;###autoload | 246 | ;;;###autoload |
| 246 | (defun view-file-other-window (file-name) | 247 | (defun view-file-other-window (file) |
| 247 | "View FILE in View mode in another window. | 248 | "View FILE in View mode in another window. |
| 248 | Return that window to its previous buffer when done. | 249 | Return that window to its previous buffer when done. |
| 249 | Emacs commands editing the buffer contents are not available; instead, | 250 | Emacs commands editing the buffer contents are not available; instead, |
| @@ -254,12 +255,12 @@ For list of all View commands, type H or h while viewing. | |||
| 254 | 255 | ||
| 255 | This command runs the normal hook `view-mode-hook'." | 256 | This command runs the normal hook `view-mode-hook'." |
| 256 | (interactive "fIn other window view file: ") | 257 | (interactive "fIn other window view file: ") |
| 257 | (let ((had-a-buf (get-file-buffer file-name))) | 258 | (let ((had-a-buf (get-file-buffer file))) |
| 258 | (view-buffer-other-window (find-file-noselect file-name) nil | 259 | (view-buffer-other-window (find-file-noselect file) nil |
| 259 | (and (not had-a-buf) 'kill-buffer)))) | 260 | (and (not had-a-buf) 'kill-buffer)))) |
| 260 | 261 | ||
| 261 | ;;;###autoload | 262 | ;;;###autoload |
| 262 | (defun view-file-other-frame (file-name) | 263 | (defun view-file-other-frame (file) |
| 263 | "View FILE in View mode in another frame. | 264 | "View FILE in View mode in another frame. |
| 264 | Maybe delete other frame and/or return to previous buffer when done. | 265 | Maybe delete other frame and/or return to previous buffer when done. |
| 265 | Emacs commands editing the buffer contents are not available; instead, | 266 | Emacs commands editing the buffer contents are not available; instead, |
| @@ -270,13 +271,13 @@ For list of all View commands, type H or h while viewing. | |||
| 270 | 271 | ||
| 271 | This command runs the normal hook `view-mode-hook'." | 272 | This command runs the normal hook `view-mode-hook'." |
| 272 | (interactive "fIn other frame view file: ") | 273 | (interactive "fIn other frame view file: ") |
| 273 | (let ((had-a-buf (get-file-buffer file-name))) | 274 | (let ((had-a-buf (get-file-buffer file))) |
| 274 | (view-buffer-other-frame (find-file-noselect file-name) nil | 275 | (view-buffer-other-frame (find-file-noselect file) nil |
| 275 | (and (not had-a-buf) 'kill-buffer)))) | 276 | (and (not had-a-buf) 'kill-buffer)))) |
| 276 | 277 | ||
| 277 | 278 | ||
| 278 | ;;;###autoload | 279 | ;;;###autoload |
| 279 | (defun view-buffer (buffer-name &optional exit-action) | 280 | (defun view-buffer (buffer &optional exit-action) |
| 280 | "View BUFFER in View mode, returning to previous buffer when done. | 281 | "View BUFFER in View mode, returning to previous buffer when done. |
| 281 | Emacs commands editing the buffer contents are not available; instead, | 282 | Emacs commands editing the buffer contents are not available; instead, |
| 282 | a special set of commands (mostly letters and punctuation) | 283 | a special set of commands (mostly letters and punctuation) |
| @@ -292,13 +293,12 @@ Use this argument instead of explicitly setting `view-exit-action'." | |||
| 292 | 293 | ||
| 293 | (interactive "bView buffer: ") | 294 | (interactive "bView buffer: ") |
| 294 | (let ((undo-window (list (window-buffer) (window-start) (window-point)))) | 295 | (let ((undo-window (list (window-buffer) (window-start) (window-point)))) |
| 295 | (switch-to-buffer buffer-name) | 296 | (switch-to-buffer buffer) |
| 296 | (view-mode-enter (cons (selected-window) (cons nil undo-window)) | 297 | (view-mode-enter (cons (selected-window) (cons nil undo-window)) |
| 297 | exit-action))) | 298 | exit-action))) |
| 298 | 299 | ||
| 299 | ;;;###autoload | 300 | ;;;###autoload |
| 300 | (defun view-buffer-other-window | 301 | (defun view-buffer-other-window (buffer &optional not-return exit-action) |
| 301 | (buffer-name &optional not-return exit-action) | ||
| 302 | "View BUFFER in View mode in another window. | 302 | "View BUFFER in View mode in another window. |
| 303 | Return to previous buffer when done, unless optional NOT-RETURN is non-nil. | 303 | Return to previous buffer when done, unless optional NOT-RETURN is non-nil. |
| 304 | Emacs commands editing the buffer contents are not available; instead, | 304 | Emacs commands editing the buffer contents are not available; instead, |
| @@ -320,17 +320,16 @@ Use this argument instead of explicitly setting `view-exit-action'." | |||
| 320 | (cons (selected-window) | 320 | (cons (selected-window) |
| 321 | (if (eq win (selected-window)) | 321 | (if (eq win (selected-window)) |
| 322 | t ; Has to make new window. | 322 | t ; Has to make new window. |
| 323 | (list | 323 | (list |
| 324 | (window-buffer win) ; Other windows old buffer. | 324 | (window-buffer win) ; Other windows old buffer. |
| 325 | (window-start win) | 325 | (window-start win) |
| 326 | (window-point win))))))) | 326 | (window-point win))))))) |
| 327 | (switch-to-buffer-other-window buffer-name) | 327 | (switch-to-buffer-other-window buffer) |
| 328 | (view-mode-enter (and return-to (cons (selected-window) return-to)) | 328 | (view-mode-enter (and return-to (cons (selected-window) return-to)) |
| 329 | exit-action))) | 329 | exit-action))) |
| 330 | 330 | ||
| 331 | ;;;###autoload | 331 | ;;;###autoload |
| 332 | (defun view-buffer-other-frame | 332 | (defun view-buffer-other-frame (buffer &optional not-return exit-action) |
| 333 | (buffer-name &optional not-return exit-action) | ||
| 334 | "View BUFFER in View mode in another frame. | 333 | "View BUFFER in View mode in another frame. |
| 335 | Return to previous buffer when done, unless optional NOT-RETURN is non-nil. | 334 | Return to previous buffer when done, unless optional NOT-RETURN is non-nil. |
| 336 | Emacs commands editing the buffer contents are not available; instead, | 335 | Emacs commands editing the buffer contents are not available; instead, |
| @@ -347,7 +346,7 @@ Use this argument instead of explicitly setting `view-exit-action'." | |||
| 347 | (interactive "bView buffer in other frame: \nP") | 346 | (interactive "bView buffer in other frame: \nP") |
| 348 | (let ((return-to | 347 | (let ((return-to |
| 349 | (and (not not-return) (cons (selected-window) t)))) ; Old window. | 348 | (and (not not-return) (cons (selected-window) t)))) ; Old window. |
| 350 | (switch-to-buffer-other-frame buffer-name) | 349 | (switch-to-buffer-other-frame buffer) |
| 351 | (view-mode-enter (and return-to (cons (selected-window) return-to)) | 350 | (view-mode-enter (and return-to (cons (selected-window) return-to)) |
| 352 | exit-action))) | 351 | exit-action))) |
| 353 | 352 | ||
| @@ -357,7 +356,7 @@ Use this argument instead of explicitly setting `view-exit-action'." | |||
| 357 | ;; bindings instead of using the \\[] construction. The reason for this | 356 | ;; bindings instead of using the \\[] construction. The reason for this |
| 358 | ;; is that most commands have more than one key binding. | 357 | ;; is that most commands have more than one key binding. |
| 359 | "Toggle View mode, a minor mode for viewing text but not editing it. | 358 | "Toggle View mode, a minor mode for viewing text but not editing it. |
| 360 | With arg, turn View mode on iff arg is positive. | 359 | With ARG, turn View mode on iff ARG is positive. |
| 361 | 360 | ||
| 362 | Emacs commands that do not change the buffer contents are available as usual. | 361 | Emacs commands that do not change the buffer contents are available as usual. |
| 363 | Kill commands insert text in kill buffers but do not delete. Other commands | 362 | Kill commands insert text in kill buffers but do not delete. Other commands |
| @@ -376,14 +375,18 @@ Digits provide prefix arguments. | |||
| 376 | \\[beginning-of-buffer] move to the beginning of buffer. | 375 | \\[beginning-of-buffer] move to the beginning of buffer. |
| 377 | > move to the end of buffer. | 376 | > move to the end of buffer. |
| 378 | \\[View-scroll-to-buffer-end] scroll so that buffer end is at last line of window. | 377 | \\[View-scroll-to-buffer-end] scroll so that buffer end is at last line of window. |
| 379 | SPC scroll forward prefix (default \"page size\") lines. | 378 | SPC scroll forward \"page size\" lines. |
| 380 | DEL scroll backward prefix (default \"page size\") lines. | 379 | With prefix scroll forward prefix lines. |
| 381 | \\[View-scroll-page-forward-set-page-size] like \\[View-scroll-page-forward] except prefix sets \"page size\". | 380 | DEL scroll backward \"page size\" lines. |
| 382 | \\[View-scroll-page-backward-set-page-size] like \\[View-scroll-page-backward] except prefix sets \"page size\". | 381 | With prefix scroll backward prefix lines. |
| 383 | \\[View-scroll-half-page-forward] scroll forward (and if prefix set) \"half page size\" lines. | 382 | \\[View-scroll-page-forward-set-page-size] like \\[View-scroll-page-forward] but with prefix sets \"page size\" to prefix. |
| 384 | \\[View-scroll-half-page-backward] scroll backward (and if prefix set) \"half page size\" lines. | 383 | \\[View-scroll-page-backward-set-page-size] like \\[View-scroll-page-backward] but with prefix sets \"page size\" to prefix. |
| 385 | RET, LFD scroll forward prefix (default one) line(s). | 384 | \\[View-scroll-half-page-forward] scroll forward \"half page size\" lines. With prefix, sets |
| 386 | y scroll backward prefix (default one) line(s). | 385 | \"half page size\" to prefix lines and scrolls forward that much. |
| 386 | \\[View-scroll-half-page-backward] scroll backward \"half page size\" lines. With prefix, sets | ||
| 387 | \"half page size\" to prefix lines and scrolls backward that much. | ||
| 388 | RET, LFD scroll forward one line. With prefix scroll forward prefix line(s). | ||
| 389 | y scroll backward one line. With prefix scroll backward prefix line(s). | ||
| 387 | \\[View-revert-buffer-scroll-page-forward] revert-buffer if necessary and scroll forward. | 390 | \\[View-revert-buffer-scroll-page-forward] revert-buffer if necessary and scroll forward. |
| 388 | Use this to view a changing file. | 391 | Use this to view a changing file. |
| 389 | \\[what-line] prints the current line number. | 392 | \\[what-line] prints the current line number. |
| @@ -415,12 +418,12 @@ p searches backward for last regular expression. | |||
| 415 | \\[View-kill-and-leave] quit View mode, kill current buffer and go back to other buffer. | 418 | \\[View-kill-and-leave] quit View mode, kill current buffer and go back to other buffer. |
| 416 | 419 | ||
| 417 | The effect of \\[View-leave] , \\[View-quit] and \\[View-kill-and-leave] depends on how view-mode was entered. If it was | 420 | The effect of \\[View-leave] , \\[View-quit] and \\[View-kill-and-leave] depends on how view-mode was entered. If it was |
| 418 | entered by view-file, view-file-other-window or view-file-other-frame (\\[view-file], | 421 | entered by view-file, view-file-other-window or view-file-other-frame |
| 419 | \\[view-file-other-window], \\[view-file-other-frame] or the dired mode v command), then \\[View-quit] will try to kill the | 422 | \(\\[view-file], \\[view-file-other-window], \\[view-file-other-frame] or the dired mode v command), then \\[View-quit] will |
| 420 | current buffer. If view-mode was entered from another buffer as is done by | 423 | try to kill the current buffer. If view-mode was entered from another buffer |
| 421 | View-buffer, View-buffer-other-window, View-buffer-other frame, View-file, | 424 | as is done by View-buffer, View-buffer-other-window, View-buffer-other frame, |
| 422 | View-file-other-window or View-file-other-frame then \\[view-leave] , \\[view-quit] and \\[view-kill-and-leave] will return | 425 | View-file, View-file-other-window or View-file-other-frame then \\[View-leave] , \\[View-quit] and \\[View-kill-and-leave] |
| 423 | to that buffer. | 426 | will return to that buffer. |
| 424 | 427 | ||
| 425 | Entry to view-mode runs the normal hook `view-mode-hook'." | 428 | Entry to view-mode runs the normal hook `view-mode-hook'." |
| 426 | (interactive "P") | 429 | (interactive "P") |
| @@ -478,7 +481,7 @@ OLD-BUF-INFO tells what to do with WINDOW when exiting. It is one of: | |||
| 478 | 2) t Delete WINDOW or, if it is the only window, its frame. | 481 | 2) t Delete WINDOW or, if it is the only window, its frame. |
| 479 | 3) (OLD-BUFF START POINT) Display buffer OLD-BUFF with displayed text | 482 | 3) (OLD-BUFF START POINT) Display buffer OLD-BUFF with displayed text |
| 480 | starting at START and point at POINT in WINDOW. | 483 | starting at START and point at POINT in WINDOW. |
| 481 | 4) quit-window Do quit-window in WINDOW. | 484 | 4) quit-window Do `quit-window' in WINDOW. |
| 482 | 485 | ||
| 483 | For list of all View commands, type H or h while viewing. | 486 | For list of all View commands, type H or h while viewing. |
| 484 | 487 | ||
| @@ -511,10 +514,10 @@ WINDOW is a window displaying the current buffer. | |||
| 511 | OLD-WINDOW is nil or a window to select after viewing. | 514 | OLD-WINDOW is nil or a window to select after viewing. |
| 512 | OLD-BUF-INFO is information on what to do with WINDOW and is one of: | 515 | OLD-BUF-INFO is information on what to do with WINDOW and is one of: |
| 513 | 1) nil Do nothing. | 516 | 1) nil Do nothing. |
| 514 | 2) t Delete WINDOW or, if it is the only window, its frame. | 517 | 2) t Delete WINDOW and, if it is the only window, its frame. |
| 515 | 3) (OLD-BUF START POINT) Display buffer OLD-BUF with displayed text | 518 | 3) (OLD-BUF START POINT) Display buffer OLD-BUF with displayed text |
| 516 | starting at START and point at POINT in WINDOW. | 519 | starting at START and point at POINT in WINDOW. |
| 517 | 4) quit-window Do quit-window in WINDOW. | 520 | 4) quit-window Do `quit-window' in WINDOW. |
| 518 | 521 | ||
| 519 | If one of the WINDOW in RETURN-TO-ALIST is the selected window and the | 522 | If one of the WINDOW in RETURN-TO-ALIST is the selected window and the |
| 520 | corresponding OLD-WINDOW is a live window, then select OLD-WINDOW." | 523 | corresponding OLD-WINDOW is a live window, then select OLD-WINDOW." |
| @@ -522,7 +525,7 @@ corresponding OLD-WINDOW is a live window, then select OLD-WINDOW." | |||
| 522 | (and return-to-alist (or all-win view-exits-all-viewing-windows))) | 525 | (and return-to-alist (or all-win view-exits-all-viewing-windows))) |
| 523 | (if view-mode ; Only do something if in view mode. | 526 | (if view-mode ; Only do something if in view mode. |
| 524 | (let* ((buffer (current-buffer)) | 527 | (let* ((buffer (current-buffer)) |
| 525 | window | 528 | window notlost |
| 526 | (sel-old (assq (selected-window) return-to-alist)) | 529 | (sel-old (assq (selected-window) return-to-alist)) |
| 527 | (alist (cond | 530 | (alist (cond |
| 528 | (all-win ; Try to restore all windows. | 531 | (all-win ; Try to restore all windows. |
| @@ -543,6 +546,7 @@ corresponding OLD-WINDOW is a live window, then select OLD-WINDOW." | |||
| 543 | (or view-no-disable-on-exit | 546 | (or view-no-disable-on-exit |
| 544 | (view-mode-disable)) | 547 | (view-mode-disable)) |
| 545 | (while alist ; Restore windows with info. | 548 | (while alist ; Restore windows with info. |
| 549 | (setq notlost nil) | ||
| 546 | (if (and (window-live-p (setq window (car (car alist)))) | 550 | (if (and (window-live-p (setq window (car (car alist)))) |
| 547 | (eq buffer (window-buffer window))) | 551 | (eq buffer (window-buffer window))) |
| 548 | (let ((frame (window-frame window)) | 552 | (let ((frame (window-frame window)) |
| @@ -555,19 +559,22 @@ corresponding OLD-WINDOW is a live window, then select OLD-WINDOW." | |||
| 555 | (set-window-start window (car (cdr old-buf-info))) | 559 | (set-window-start window (car (cdr old-buf-info))) |
| 556 | (set-window-point window (car (cdr (cdr old-buf-info))))) | 560 | (set-window-point window (car (cdr (cdr old-buf-info))))) |
| 557 | ((eq old-buf-info 'quit-window) | 561 | ((eq old-buf-info 'quit-window) |
| 558 | (quit-window)) ; Not case 2, do nothing. | 562 | (quit-window)) ; Case 4. |
| 559 | ((not (eq old-buf-info t)) nil) ; Not case 2, do nothing. | 563 | ((not (eq old-buf-info t)) nil) ; Not case 2, do nothing. |
| 560 | ((not (one-window-p t)) (delete-window)) | 564 | ((not (one-window-p t)) (delete-window)) |
| 561 | ((not (eq frame (next-frame))) | 565 | ((not (eq frame (next-frame))) |
| 562 | ;; Not the only frame, so can safely be removed. | 566 | ;; Not the only frame, so can safely be removed. |
| 563 | (if view-remove-frame-by-deleting | 567 | (if view-remove-frame-by-deleting |
| 564 | (delete-frame frame) | 568 | (delete-frame frame) |
| 569 | (setq notlost t) ; Keep the window. See below. | ||
| 565 | (iconify-frame frame)))))) | 570 | (iconify-frame frame)))))) |
| 566 | ;; Altering view-return-to-alist causes trouble when | 571 | ;; If a frame is removed by iconifying it, then the window is not |
| 567 | ;; the user deiconifies the frame, then types q again. | 572 | ;; really lost. In this case we keep the entry in |
| 568 | ;; If we leave view-return-to-alist unchanged, that | 573 | ;; view-return-to-alist so that if the user deiconifies the frame |
| 569 | ;; iconifies the frame again, as expected. | 574 | ;; and then press q, then the frame is iconified again. |
| 570 | ;;; (setq view-return-to-alist (delete (car alist) view-return-to-alist)) | 575 | (unless notlost |
| 576 | (setq view-return-to-alist | ||
| 577 | (delete (car alist) view-return-to-alist))) | ||
| 571 | (setq alist (cdr alist))) | 578 | (setq alist (cdr alist))) |
| 572 | (if (window-live-p old-window) ; still existing window | 579 | (if (window-live-p old-window) ; still existing window |
| 573 | (select-window old-window)) | 580 | (select-window old-window)) |
| @@ -766,7 +773,7 @@ If LINES is more than a window-full, only the last window-full is shown." | |||
| 766 | (interactive "P") | 773 | (interactive "P") |
| 767 | (view-scroll-lines lines nil view-page-size nil)) | 774 | (view-scroll-lines lines nil view-page-size nil)) |
| 768 | 775 | ||
| 769 | (defun View-scroll-page-backward (&optional lines) | 776 | (defun View-scroll-page-backward (&optional lines) |
| 770 | "Scroll \"page size\" or prefix LINES lines backward in View mode. | 777 | "Scroll \"page size\" or prefix LINES lines backward in View mode. |
| 771 | See also `View-scroll-page-forward'." | 778 | See also `View-scroll-page-forward'." |
| 772 | (interactive "P") | 779 | (interactive "P") |
| @@ -862,7 +869,7 @@ for use by later search commands. | |||
| 862 | 869 | ||
| 863 | The variable `view-highlight-face' controls the face that is used | 870 | The variable `view-highlight-face' controls the face that is used |
| 864 | for highlighting the match that is found." | 871 | for highlighting the match that is found." |
| 865 | (interactive "p\nsSearch forward (regexp): ") | 872 | (interactive "p\nsSearch forward (regexp): ") |
| 866 | (view-search n regexp)) | 873 | (view-search n regexp)) |
| 867 | 874 | ||
| 868 | (defun View-search-regexp-backward (n regexp) | 875 | (defun View-search-regexp-backward (n regexp) |