Mercurial > emacs
comparison lisp/view.el @ 18448:7cf9cdba062d
Changed some documentation.
(view-exits-all-viewing-windows): Nev variable
replaces view-exit-all-windows-at-exit.
(view-exit-all-windows-at-exit): Variable deleted.
(view-mode-enter): Doesn't set view-exit-action if
argument exit-action is nil.
(view-mode-exit): Only restored windows are removed
from view-return-to-alist. Follow chains of old-windows.
Do not call replace-buffer-in-windows.
Call exit-action also when a window displays buffer.
(View-exit-and-edit): Now sets read-only by binding
view-old-buffer-read-only.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 25 Jun 1997 07:03:48 +0000 |
parents | 6f48844ce1a9 |
children | e272bd93c93c |
comparison
equal
deleted
inserted
replaced
18447:b7e01783be08 | 18448:7cf9cdba062d |
---|---|
25 ;;; Commentary: | 25 ;;; Commentary: |
26 | 26 |
27 ;; This package provides the `view' minor mode documented in the Emacs | 27 ;; This package provides the `view' minor mode documented in the Emacs |
28 ;; user's manual. | 28 ;; user's manual. |
29 ;; View mode entry and exit is done through the functions view-mode-enter | 29 ;; View mode entry and exit is done through the functions view-mode-enter |
30 ;; and view-mode-exit. Use these functions to enter or exit view-mode from | 30 ;; and view-mode-exit. Use these functions to enter or exit view-mode from |
31 ;; emacs lisp programs. | 31 ;; emacs lisp programs. |
32 ;; We use both view- and View- as prefix for symbols. View- is used as | 32 ;; We use both view- and View- as prefix for symbols. View- is used as |
33 ;; prefix for commands that have a key binding. view- is used for commands | 33 ;; prefix for commands that have a key binding. view- is used for commands |
34 ;; without key binding. The purpose of this is to make it easier for a | 34 ;; without key binding. The purpose of this is to make it easier for a |
35 ;; user to use command name completion. | 35 ;; user to use command name completion. |
36 | 36 |
37 ;;; Suggested key bindings: | 37 ;;; Suggested key bindings: |
38 ;; | 38 ;; |
39 ;; (define-key ctl-x-4-map "v" 'view-file-other-window) ; ^x4v | 39 ;; (define-key ctl-x-4-map "v" 'view-file-other-window) ; ^x4v |
46 | 46 |
47 ;;;###autoload | 47 ;;;###autoload |
48 (defvar view-highlight-face 'highlight | 48 (defvar view-highlight-face 'highlight |
49 "*The face used for highlighting the match found by View mode search.") | 49 "*The face used for highlighting the match found by View mode search.") |
50 | 50 |
51 ;; `view-mode-auto-exit' is replaced by the following global variable which | 51 ;; `view-mode-auto-exit' is replaced by the following option variable which |
52 ;; only says if scrolling past buffer end should leave view mode or not, it | 52 ;; only says if scrolling past buffer end should leave view mode or not, it |
53 ;; doesn't say if leaving view mode should restore windows or not. The latter | 53 ;; doesn't say if leaving view mode should restore windows or not. The latter |
54 ;; is now controlled by the presence of a value in `view-return-to-alist'. | 54 ;; is now controlled by the presence of a value in `view-return-to-alist'. |
55 ;;;###autoload | 55 ;;;###autoload |
56 (defvar view-scroll-auto-exit nil | 56 (defvar view-scroll-auto-exit nil |
58 nil means attempting to scroll past the end of the buffer, | 58 nil means attempting to scroll past the end of the buffer, |
59 only rings the bell and gives a message on how to leave.") | 59 only rings the bell and gives a message on how to leave.") |
60 | 60 |
61 ;;;###autoload | 61 ;;;###autoload |
62 (defvar view-try-extend-at-buffer-end nil | 62 (defvar view-try-extend-at-buffer-end nil |
63 "*Non-nil means try load more of file when reaching end of buffer.") | 63 "*Non-nil means try load more of file when reaching end of buffer. |
64 | 64 This variable is mainly intended to be temporarily set to non-nil by |
65 ;;;###autoload | 65 the F command in view-mode, but you can set it to t if you want the action |
66 for all scroll commands in view mode.") | |
67 | |
66 (defvar view-remove-frame-by-deleting nil | 68 (defvar view-remove-frame-by-deleting nil |
67 "*Determine how to remove a not needed frame. | 69 "*Determine how to View mode removes a frame no longer needed. |
68 If nil, make an icon of the frame. If non-nil, delete the frame.") | 70 If nil, make an icon of the frame. If non-nil, delete the frame.") |
69 | 71 |
70 ;;;###autoload | 72 ;;;###autoload |
71 (defvar view-exit-all-windows-at-exit nil | 73 (defvar view-exits-all-viewing-windows nil |
72 "*Non-nil means restore all windows displaying buffer. | 74 "*Non-nil means restore all windows used to view buffer. |
73 Commands that restore windows apply to all windows displaying buffer. | 75 Commands that restore windows when finished viewing a buffer, apply to all |
74 Buffer is removed from all windows displaying it, by using information in | 76 windows that display the buffer and have restore information in |
75 `view-return-to-alist' if that is available, otherwise by using | 77 `view-return-to-alist'.") |
76 `replace-buffer-in-windows'.") | |
77 | 78 |
78 ;;;###autoload | 79 ;;;###autoload |
79 (defvar view-mode nil "Non-nil if View mode is enabled.") | 80 (defvar view-mode nil "Non-nil if View mode is enabled.") |
80 ;;;###autoload | 81 ;;;###autoload |
81 (make-variable-buffer-local 'view-mode) | 82 (make-variable-buffer-local 'view-mode) |
101 | 102 |
102 (defvar view-last-regexp nil) | 103 (defvar view-last-regexp nil) |
103 (make-variable-buffer-local 'view-last-regexp) ; Global is better??? | 104 (make-variable-buffer-local 'view-last-regexp) ; Global is better??? |
104 | 105 |
105 (defvar view-return-to-alist nil | 106 (defvar view-return-to-alist nil |
106 "What to do with selected window and where to go when leaving View mode. | 107 "What to do with used windows and where to go when finished viewing buffer. |
107 Added to by view-mode-enter when entering View mode. | 108 This is local in each buffer being viewed. |
108 See RETURN-TO-ALIST argument of function `view-mode-exit' for format of | 109 It is added to by view-mode-enter when starting to view a buffer and |
110 subtracted from by view-mode-exit when finished viewing the buffer. | |
111 | |
112 See RETURN-TO-ALIST argument of function `view-mode-exit' for the format of | |
109 `view-return-to-alist'.") | 113 `view-return-to-alist'.") |
110 (make-variable-buffer-local 'view-return-to-alist) | 114 (make-variable-buffer-local 'view-return-to-alist) |
111 | 115 |
112 (defvar view-exit-action nil | 116 (defvar view-exit-action nil |
113 "\\<view-mode-map> | 117 "nil or a function with one argument (a buffer) called when finished viewing. |
114 nil or a function with one argument (a buffer) called at exit of view mode. | 118 This is local in each buffer being viewed. |
115 The \\[view-file] and \\[view-file-other-window] commands may set this to | 119 The \\[view-file] and \\[view-file-other-window] commands may set this to |
116 `kill-buffer'.") | 120 `kill-buffer'.") |
117 (make-variable-buffer-local 'view-exit-action) | 121 (make-variable-buffer-local 'view-exit-action) |
118 | 122 |
119 (defvar view-overlay nil | 123 (defvar view-overlay nil |
428 Enter View mode and set up exit from view mode depending on optional arguments. | 432 Enter View mode and set up exit from view mode depending on optional arguments. |
429 If RETURN-TO is non-nil it is added as an element to the buffer local alist | 433 If RETURN-TO is non-nil it is added as an element to the buffer local alist |
430 view-return-to-alist. | 434 view-return-to-alist. |
431 Save EXIT-ACTION in buffer local variable `view-exit-action'. | 435 Save EXIT-ACTION in buffer local variable `view-exit-action'. |
432 It should be either nil or a function that takes a buffer as argument. | 436 It should be either nil or a function that takes a buffer as argument. |
433 This function will called by `view-mode-exit'. | 437 This function will be called by `view-mode-exit'. |
434 | 438 |
435 RETURN-TO is either nil, meaning do nothing when exiting view mode, or | 439 RETURN-TO is either nil, meaning do nothing when exiting view mode, or |
436 \(WINDOW OLD-WINDOW . OLD-BUF-INFO). | 440 it has the format (WINDOW OLD-WINDOW . OLD-BUF-INFO). |
437 WINDOW is a window used for viewing. | 441 WINDOW is a window used for viewing. |
438 OLD-WINDOW is nil or the window to select after viewing. | 442 OLD-WINDOW is nil or the window to select after viewing. |
439 OLD-BUF-INFO tells what to do with WINDOW when exiting. It is one of: | 443 OLD-BUF-INFO tells what to do with WINDOW when exiting. It is one of: |
440 1) nil Do nothing. | 444 1) nil Do nothing. |
441 2) t Delete WINDOW or, if it is the only window, its frame. | 445 2) t Delete WINDOW or, if it is the only window, its frame. |
442 3) (OLD-BUFF START POINT) Display buffer OLD-BUFF with displayed text | 446 3) (OLD-BUFF START POINT) Display buffer OLD-BUFF with displayed text |
443 starting at START and point at POINT in WINDOW. | 447 starting at START and point at POINT in WINDOW. |
444 | 448 |
445 See the function `view-mode' for the commands of View mode. | 449 For list of all View commands, type H or h while viewing. |
446 | 450 |
447 This function runs the normal hook `view-mode-hook'." | 451 This function runs the normal hook `view-mode-hook'." |
448 (if return-to | 452 (if return-to |
449 (let ((entry (assq (car return-to) view-return-to-alist))) | 453 (let ((entry (assq (car return-to) view-return-to-alist))) |
450 (if entry (setcdr entry (cdr return-to)) | 454 (if entry (setcdr entry (cdr return-to)) |
451 (setq view-return-to-alist (cons return-to view-return-to-alist))))) | 455 (setq view-return-to-alist (cons return-to view-return-to-alist))))) |
452 (if view-mode ; Do nothing if already in view mode. | 456 (if view-mode ; Do nothing if already in view mode. |
453 nil | 457 nil |
454 (setq view-exit-action exit-action) | |
455 (view-mode-enable) | 458 (view-mode-enable) |
459 (if exit-action (setq view-exit-action exit-action)) | |
456 (force-mode-line-update) | 460 (force-mode-line-update) |
457 (message "%s" | 461 (message "%s" |
458 (substitute-command-keys "\ | 462 (substitute-command-keys "\ |
459 Type \\[help-command] for help, \\[describe-mode] for commands, \\[View-quit] to quit.")))) | 463 Type \\[help-command] for help, \\[describe-mode] for commands, \\[View-quit] to quit.")))) |
460 | 464 |
462 "Exit view-mode in various ways, depending on optional arguments. | 466 "Exit view-mode in various ways, depending on optional arguments. |
463 RETURN-TO-ALIST, EXIT-ACTION and ALL-WIN determine what to do after | 467 RETURN-TO-ALIST, EXIT-ACTION and ALL-WIN determine what to do after |
464 exit. | 468 exit. |
465 EXIT-ACTION is nil or a function that is called with current buffer as | 469 EXIT-ACTION is nil or a function that is called with current buffer as |
466 argument. | 470 argument. |
467 RETURN-TO-ALIST is an alist that for some of the windows displaying the current | 471 RETURN-TO-ALIST is an alist that for some of the windows displaying the |
468 buffer, associate information on what to do with those windows. If ALL-WIN is | 472 current buffer, associate information on what to do with those windows. |
469 non-nil, then all windows on RETURN-TO-ALIST are restored to their old state. | 473 If ALL-WIN or the variable `view-exits-all-viewing-windows' is non-nil, |
470 If ALL-WIN is nil, then only the selected window is affected (if it is on | 474 then all windows on RETURN-TO-ALIST are restored to their old state. |
471 ALL-WIN). Each element has the format (WINDOW OLD-WINDOW . OLD-BUF-INFO) | 475 Otherwise only the selected window is affected (if it is on RETURN-TO-ALIST). |
472 where WINDOW is a window displaying the current buffer and OLD-BUF-INFO is | 476 |
473 information on what to do with WINDOW. OLD-BUF-INFO is one of: | 477 Elements of RETURN-TO-ALIST have the format (WINDOW OLD-WINDOW . OLD-BUF-INFO). |
478 WINDOW is a window displaying the current buffer. | |
479 OLD-WINDOW is nil or a window to select after viewing. | |
480 OLD-BUF-INFO is information on what to do with WINDOW and is one of: | |
474 1) nil Do nothing. | 481 1) nil Do nothing. |
475 2) t Delete WINDOW or, if it is the only window, its frame. | 482 2) t Delete WINDOW or, if it is the only window, its frame. |
476 3) (OLD-BUF START POINT) Display buffer OLD-BUF with displayed text | 483 3) (OLD-BUF START POINT) Display buffer OLD-BUF with displayed text |
477 starting at START and point at POINT in WINDOW. | 484 starting at START and point at POINT in WINDOW. |
485 | |
478 If one of the WINDOW in RETURN-TO-ALIST is the selected window and the | 486 If one of the WINDOW in RETURN-TO-ALIST is the selected window and the |
479 corresponding OLD-WINDOW is a live window, then select OLD-WINDOW." | 487 corresponding OLD-WINDOW is a live window, then select OLD-WINDOW." |
488 (setq all-win | |
489 (and return-to-alist (or all-win view-exits-all-viewing-windows))) | |
480 (if view-mode ; Only do something if in view mode. | 490 (if view-mode ; Only do something if in view mode. |
481 (let* ((buffer (current-buffer)) | 491 (let* ((buffer (current-buffer)) |
482 window | 492 window |
483 (sel-old (assq (selected-window) return-to-alist)) | 493 (sel-old (assq (selected-window) return-to-alist)) |
484 (old-window (or (and sel-old (car (cdr sel-old))) | 494 (alist (cond |
485 (and all-win (selected-window)))) | 495 (all-win ; Try to restore all windows. |
486 (alist (if (setq all-win | 496 (append return-to-alist nil)) ; Copy. |
487 (or all-win view-exit-all-windows-at-exit)) | 497 (sel-old ; Only selected window. |
488 return-to-alist ; Try to restore all windows. | 498 (list sel-old)))) |
489 (and sel-old (list sel-old))))) ; Only selected window. | 499 (old-window (if sel-old (car (cdr sel-old))))) |
500 (if all-win ; Follow chains of old-windows. | |
501 (let ((c (length alist)) a) | |
502 (while (and (> c 0) ; Safety if mutually refering windows. | |
503 (or (not (window-live-p old-window)) | |
504 (eq buffer (window-buffer old-window))) | |
505 (setq a (assq old-window alist))) | |
506 (setq c (1- c)) | |
507 (setq old-window (car (cdr a)))) | |
508 (if (or (zerop c) (not (window-live-p old-window))) | |
509 (setq old-window (selected-window))))) | |
490 (view-mode-disable) | 510 (view-mode-disable) |
491 (setq view-exit-action nil | |
492 view-return-to-alist nil) | |
493 (while alist ; Restore windows with info. | 511 (while alist ; Restore windows with info. |
494 (if (and (window-live-p (setq window (car (car alist)))) | 512 (if (and (window-live-p (setq window (car (car alist)))) |
495 (eq buffer (window-buffer window))) | 513 (eq buffer (window-buffer window))) |
496 (let ((frame (window-frame window)) | 514 (let ((frame (window-frame window)) |
497 (old-buf-info (cdr (cdr (car alist))))) | 515 (old-buf-info (cdr (cdr (car alist))))) |
502 (set-window-buffer window (car old-buf-info)) ; old-buf | 520 (set-window-buffer window (car old-buf-info)) ; old-buf |
503 (set-window-start window (car (cdr old-buf-info))) | 521 (set-window-start window (car (cdr old-buf-info))) |
504 (set-window-point window (car (cdr (cdr old-buf-info))))) | 522 (set-window-point window (car (cdr (cdr old-buf-info))))) |
505 ((not (eq old-buf-info t)) nil) ; Not case 2, do nothing. | 523 ((not (eq old-buf-info t)) nil) ; Not case 2, do nothing. |
506 ((not (one-window-p t)) (delete-window)) | 524 ((not (one-window-p t)) (delete-window)) |
507 ((not (eq frame (next-frame))) ; Not the only frame, so | 525 ((not (eq frame (next-frame))) |
508 (if view-remove-frame-by-deleting (delete-frame frame) | 526 ;; Not the only frame, so can safely be removed. |
509 (iconify-frame frame)))))) ; can safely be removed. | 527 (if view-remove-frame-by-deleting |
528 (delete-frame frame) | |
529 (iconify-frame frame)))))) | |
530 (setq view-return-to-alist (delete (car alist) view-return-to-alist)) | |
510 (setq alist (cdr alist))) | 531 (setq alist (cdr alist))) |
511 (if (and return-to-alist view-exit-all-windows-at-exit) | |
512 (replace-buffer-in-windows buffer)) | |
513 (if (window-live-p old-window) ; still existing window | 532 (if (window-live-p old-window) ; still existing window |
514 (select-window old-window)) | 533 (select-window old-window)) |
515 (if (and exit-action (not (get-buffer-window buffer))) | 534 ; (if (and exit-action (not (get-buffer-window buffer))) |
516 (funcall exit-action buffer)) | 535 (if exit-action |
536 (progn (setq view-exit-action nil) | |
537 (funcall exit-action buffer))) | |
517 (force-mode-line-update)))) | 538 (force-mode-line-update)))) |
518 | 539 |
519 (defun View-exit () | 540 (defun View-exit () |
520 "Exit View mode but stay in current buffer." | 541 "Exit View mode but stay in current buffer." |
521 (interactive) | 542 (interactive) |
523 | 544 |
524 ;;;###autoload | 545 ;;;###autoload |
525 (defun View-exit-and-edit () | 546 (defun View-exit-and-edit () |
526 "Exit View mode and make the current buffer editable." | 547 "Exit View mode and make the current buffer editable." |
527 (interactive) | 548 (interactive) |
528 (view-mode-exit) | 549 (let ((view-old-buffer-read-only nil)) |
529 (setq buffer-read-only nil)) | 550 (view-mode-exit))) |
530 | 551 |
531 (defun View-leave () | 552 (defun View-leave () |
532 "Quit View mode and maybe switch buffers, but don't kill this buffer." | 553 "Quit View mode and maybe switch buffers, but don't kill this buffer." |
533 (interactive) | 554 (interactive) |
534 (view-mode-exit view-return-to-alist)) | 555 (view-mode-exit view-return-to-alist)) |
709 (view-scroll-lines lines t view-page-size nil)) | 730 (view-scroll-lines lines t view-page-size nil)) |
710 | 731 |
711 (defun View-scroll-page-forward-set-page-size (&optional lines) | 732 (defun View-scroll-page-forward-set-page-size (&optional lines) |
712 "Scroll forward LINES lines in View mode, setting the \"page size\". | 733 "Scroll forward LINES lines in View mode, setting the \"page size\". |
713 This is the number of lines which \\[View-scroll-page-forward] and | 734 This is the number of lines which \\[View-scroll-page-forward] and |
714 \\[View-scroll-page-backward] scroll by default. If LINES is omitted or = 0, | 735 \\[View-scroll-page-backward] scroll by default. |
715 sets \"page size\" to window height and scrolls forward that much, otherwise | 736 If LINES is omitted or = 0, sets \"page size\" to window height and |
716 scrolls forward LINES lines and sets \"page size\" to the minimum of window | 737 scrolls forward that much, otherwise scrolls forward LINES lines and sets |
717 height and the absolute value of LINES. | 738 \"page size\" to the minimum of window height and the absolute value of LINES. |
718 See also `View-scroll-page-forward'." | 739 See also `View-scroll-page-forward'." |
719 (interactive "P") | 740 (interactive "P") |
720 (view-scroll-lines lines nil | 741 (view-scroll-lines lines nil |
721 (setq view-page-size (view-page-size-default lines)) | 742 (setq view-page-size (view-page-size-default lines)) |
722 nil)) | 743 nil)) |
782 (pop-mark) | 803 (pop-mark) |
783 (view-recenter)) | 804 (view-recenter)) |
784 | 805 |
785 (defun View-search-regexp-forward (n regexp) | 806 (defun View-search-regexp-forward (n regexp) |
786 "Search forward for first (or prefix Nth) occurrence of REGEXP in View mode. | 807 "Search forward for first (or prefix Nth) occurrence of REGEXP in View mode. |
787 Displays line found at center of window. REGEXP is remembered for searching | 808 |
788 with \\[View-search-last-regexp-forward] and \\[View-search-last-regexp-backward]. Sets mark at starting position and pushes mark ring. | 809 Displays line found at center of window. Sets mark at starting position and |
789 Characters @ or ! or combined as @! or !@ are special if entered at the | 810 pushes mark ring. |
790 beginning of REGEXP. They modify the search rather than become part of pattern | 811 |
791 searched for. @ means start search at the beginning of buffer. ! means search | 812 Characters @ and ! are special at the beginning of REGEXP. They modify |
792 for line that not contains match for pattern. If REGEXP only consist of these | 813 the search rather than become part of the pattern searched for. |
793 control characters, then an earlier remembered REGEXP is used. | 814 @ means search all the buffer i.e. start search at the beginning of buffer. |
815 ! means search for a line that contains no match for the pattern. | |
816 If REGEXP is empty or only consist of these control characters, then | |
817 an earlier remembered REGEXP is used, otherwise REGEXP is remembered | |
818 for use by later search commands. | |
794 | 819 |
795 The variable `view-highlight-face' controls the face that is used | 820 The variable `view-highlight-face' controls the face that is used |
796 for highlighting the match that is found." | 821 for highlighting the match that is found." |
797 (interactive "p\nsSearch forward (regexp): ") | 822 (interactive "p\nsSearch forward (regexp): ") |
798 (view-search n regexp)) | 823 (view-search n regexp)) |
799 | 824 |
800 (defun View-search-regexp-backward (n regexp) | 825 (defun View-search-regexp-backward (n regexp) |
801 "Search backward for first (or prefix Nth) occurrence of REGEXP in View mode. | 826 "Search backward for first (or prefix Nth) occurrence of REGEXP in View mode. |
802 Displays line found at center of window. REGEXP is remembered for searching | 827 |
803 with \\[View-search-last-regexp-forward] and \\[View-search-last-regexp-backward]. Sets mark at starting position and pushes mark ring. | 828 Displays line found at center of window. Sets mark at starting position and |
804 Characters @ or ! or combined as @! or !@ are special if entered at the | 829 pushes mark ring. |
805 beginning of REGEXP. They modify the search rather than become part of pattern | 830 |
806 searched for. @ means start search at the end of buffer. ! means search | 831 Characters @ and ! are special at the beginning of REGEXP. They modify |
807 for line that not contains match for pattern. If REGEXP only consist of these | 832 the search rather than become part of the pattern searched for. |
808 control characters, then an earlier remembered REGEXP is used. | 833 @ means search all the buffer i.e. start search at the end of buffer. |
834 ! means search for a line that contains no match for the pattern. | |
835 If REGEXP is empty or only consist of these control characters, then | |
836 an earlier remembered REGEXP is used, otherwise REGEXP is remembered | |
837 for use by later search commands. | |
809 | 838 |
810 The variable `view-highlight-face' controls the face that is used | 839 The variable `view-highlight-face' controls the face that is used |
811 for highlighting the match that is found." | 840 for highlighting the match that is found." |
812 (interactive "p\nsSearch backward (regexp): ") | 841 (interactive "p\nsSearch backward (regexp): ") |
813 (view-search (- n) regexp)) | 842 (view-search (- n) regexp)) |
831 for highlighting the match that is found." | 860 for highlighting the match that is found." |
832 (interactive "p") | 861 (interactive "p") |
833 (view-search (- n) nil)) | 862 (view-search (- n) nil)) |
834 | 863 |
835 (defun view-search (times regexp) | 864 (defun view-search (times regexp) |
836 ;; This function does the job for all the view-search commands. | 865 ;; This function does the job for all the View-search- commands. |
837 (let (where no end ln) | 866 (let (where no end ln) |
838 (cond | 867 (cond |
839 ((and regexp (> (length regexp) 0) | 868 ((and regexp (> (length regexp) 0) |
840 (or (not (memq (string-to-char regexp) '(?! ?@))) | 869 (or (not (memq (string-to-char regexp) '(?! ?@))) |
841 (progn | 870 (progn |