aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1997-06-25 07:03:48 +0000
committerRichard M. Stallman1997-06-25 07:03:48 +0000
commit66d3a2b57f03e5f9c667ed1eba286b29222af37d (patch)
treea3297ac80460b22dc3cf2837a85c928eb96615b4
parent6c478ee2bd7b330ffe913ca6ef8182cf9b20a9e7 (diff)
downloademacs-66d3a2b57f03e5f9c667ed1eba286b29222af37d.tar.gz
emacs-66d3a2b57f03e5f9c667ed1eba286b29222af37d.zip
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.
-rw-r--r--lisp/view.el159
1 files changed, 94 insertions, 65 deletions
diff --git a/lisp/view.el b/lisp/view.el
index eeb02bbb824..68234cf4348 100644
--- a/lisp/view.el
+++ b/lisp/view.el
@@ -27,11 +27,11 @@
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:
@@ -48,7 +48,7 @@
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'.
@@ -60,20 +60,21 @@ 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.
64This variable is mainly intended to be temporarily set to non-nil by
65the F command in view-mode, but you can set it to t if you want the action
66for all scroll commands in view mode.")
64 67
65;;;###autoload
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.
68If nil, make an icon of the frame. If non-nil, delete the frame.") 70If 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.
73Commands that restore windows apply to all windows displaying buffer. 75Commands that restore windows when finished viewing a buffer, apply to all
74Buffer is removed from all windows displaying it, by using information in 76windows 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.")
@@ -103,15 +104,18 @@ If nil then the local value of this is initially set to half window size.")
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.
107Added to by view-mode-enter when entering View mode. 108This is local in each buffer being viewed.
108See RETURN-TO-ALIST argument of function `view-mode-exit' for format of 109It is added to by view-mode-enter when starting to view a buffer and
110subtracted from by view-mode-exit when finished viewing the buffer.
111
112See 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.
114nil or a function with one argument (a buffer) called at exit of view mode. 118This is local in each buffer being viewed.
115The \\[view-file] and \\[view-file-other-window] commands may set this to 119The \\[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)
@@ -430,10 +434,10 @@ If RETURN-TO is non-nil it is added as an element to the buffer local alist
430view-return-to-alist. 434view-return-to-alist.
431Save EXIT-ACTION in buffer local variable `view-exit-action'. 435Save EXIT-ACTION in buffer local variable `view-exit-action'.
432It should be either nil or a function that takes a buffer as argument. 436It should be either nil or a function that takes a buffer as argument.
433This function will called by `view-mode-exit'. 437This function will be called by `view-mode-exit'.
434 438
435RETURN-TO is either nil, meaning do nothing when exiting view mode, or 439RETURN-TO is either nil, meaning do nothing when exiting view mode, or
436 \(WINDOW OLD-WINDOW . OLD-BUF-INFO). 440it has the format (WINDOW OLD-WINDOW . OLD-BUF-INFO).
437WINDOW is a window used for viewing. 441WINDOW is a window used for viewing.
438OLD-WINDOW is nil or the window to select after viewing. 442OLD-WINDOW is nil or the window to select after viewing.
439OLD-BUF-INFO tells what to do with WINDOW when exiting. It is one of: 443OLD-BUF-INFO tells what to do with WINDOW when exiting. It is one of:
@@ -442,7 +446,7 @@ OLD-BUF-INFO tells what to do with WINDOW when exiting. It is one of:
4423) (OLD-BUFF START POINT) Display buffer OLD-BUFF with displayed text 4463) (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
445See the function `view-mode' for the commands of View mode. 449For list of all View commands, type H or h while viewing.
446 450
447This function runs the normal hook `view-mode-hook'." 451This function runs the normal hook `view-mode-hook'."
448 (if return-to 452 (if return-to
@@ -451,8 +455,8 @@ This function runs the normal hook `view-mode-hook'."
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 "\
@@ -464,32 +468,46 @@ RETURN-TO-ALIST, EXIT-ACTION and ALL-WIN determine what to do after
464exit. 468exit.
465EXIT-ACTION is nil or a function that is called with current buffer as 469EXIT-ACTION is nil or a function that is called with current buffer as
466argument. 470argument.
467RETURN-TO-ALIST is an alist that for some of the windows displaying the current 471RETURN-TO-ALIST is an alist that for some of the windows displaying the
468buffer, associate information on what to do with those windows. If ALL-WIN is 472current buffer, associate information on what to do with those windows.
469non-nil, then all windows on RETURN-TO-ALIST are restored to their old state. 473If ALL-WIN or the variable `view-exits-all-viewing-windows' is non-nil,
470If ALL-WIN is nil, then only the selected window is affected (if it is on 474then all windows on RETURN-TO-ALIST are restored to their old state.
471ALL-WIN). Each element has the format (WINDOW OLD-WINDOW . OLD-BUF-INFO) 475Otherwise only the selected window is affected (if it is on RETURN-TO-ALIST).
472where WINDOW is a window displaying the current buffer and OLD-BUF-INFO is 476
473information on what to do with WINDOW. OLD-BUF-INFO is one of: 477Elements of RETURN-TO-ALIST have the format (WINDOW OLD-WINDOW . OLD-BUF-INFO).
478WINDOW is a window displaying the current buffer.
479OLD-WINDOW is nil or a window to select after viewing.
480OLD-BUF-INFO is information on what to do with WINDOW and is one of:
4741) nil Do nothing. 4811) nil Do nothing.
4752) t Delete WINDOW or, if it is the only window, its frame. 4822) t Delete WINDOW or, if it is the only window, its frame.
4763) (OLD-BUF START POINT) Display buffer OLD-BUF with displayed text 4833) (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
478If one of the WINDOW in RETURN-TO-ALIST is the selected window and the 486If one of the WINDOW in RETURN-TO-ALIST is the selected window and the
479corresponding OLD-WINDOW is a live window, then select OLD-WINDOW." 487corresponding 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)))
@@ -504,16 +522,19 @@ corresponding OLD-WINDOW is a live window, then select OLD-WINDOW."
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 ()
@@ -525,8 +546,8 @@ corresponding OLD-WINDOW is a live window, then select OLD-WINDOW."
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."
@@ -711,10 +732,10 @@ See also `View-scroll-page-forward'."
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\".
713This is the number of lines which \\[View-scroll-page-forward] and 734This 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.
715sets \"page size\" to window height and scrolls forward that much, otherwise 736If LINES is omitted or = 0, sets \"page size\" to window height and
716scrolls forward LINES lines and sets \"page size\" to the minimum of window 737scrolls forward that much, otherwise scrolls forward LINES lines and sets
717height and the absolute value of LINES. 738\"page size\" to the minimum of window height and the absolute value of LINES.
718See also `View-scroll-page-forward'." 739See also `View-scroll-page-forward'."
719 (interactive "P") 740 (interactive "P")
720 (view-scroll-lines lines nil 741 (view-scroll-lines lines nil
@@ -784,13 +805,17 @@ invocations return to earlier marks."
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.
787Displays line found at center of window. REGEXP is remembered for searching 808
788with \\[View-search-last-regexp-forward] and \\[View-search-last-regexp-backward]. Sets mark at starting position and pushes mark ring. 809Displays line found at center of window. Sets mark at starting position and
789Characters @ or ! or combined as @! or !@ are special if entered at the 810pushes mark ring.
790beginning of REGEXP. They modify the search rather than become part of pattern 811
791searched for. @ means start search at the beginning of buffer. ! means search 812Characters @ and ! are special at the beginning of REGEXP. They modify
792for line that not contains match for pattern. If REGEXP only consist of these 813the search rather than become part of the pattern searched for.
793control 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.
816If REGEXP is empty or only consist of these control characters, then
817an earlier remembered REGEXP is used, otherwise REGEXP is remembered
818for use by later search commands.
794 819
795The variable `view-highlight-face' controls the face that is used 820The variable `view-highlight-face' controls the face that is used
796for highlighting the match that is found." 821for highlighting the match that is found."
@@ -799,13 +824,17 @@ for highlighting the match that is found."
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.
802Displays line found at center of window. REGEXP is remembered for searching 827
803with \\[View-search-last-regexp-forward] and \\[View-search-last-regexp-backward]. Sets mark at starting position and pushes mark ring. 828Displays line found at center of window. Sets mark at starting position and
804Characters @ or ! or combined as @! or !@ are special if entered at the 829pushes mark ring.
805beginning of REGEXP. They modify the search rather than become part of pattern 830
806searched for. @ means start search at the end of buffer. ! means search 831Characters @ and ! are special at the beginning of REGEXP. They modify
807for line that not contains match for pattern. If REGEXP only consist of these 832the search rather than become part of the pattern searched for.
808control 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.
835If REGEXP is empty or only consist of these control characters, then
836an earlier remembered REGEXP is used, otherwise REGEXP is remembered
837for use by later search commands.
809 838
810The variable `view-highlight-face' controls the face that is used 839The variable `view-highlight-face' controls the face that is used
811for highlighting the match that is found." 840for highlighting the match that is found."
@@ -833,7 +862,7 @@ for highlighting the match that is found."
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)