]> code.delx.au - gnu-emacs/blobdiff - lisp/view.el
(popup-dialog-box): Don't quote nil and t in docstrings.
[gnu-emacs] / lisp / view.el
index 32bd23b449fcc17a4ac5c95e67a2db1ff79322ec..cf9db5293393386e2524d06f158419f7019b8452 100644 (file)
@@ -1,10 +1,11 @@
-;;; view.el --- peruse file or buffer without editing.
+;;; view.el --- peruse file or buffer without editing
 
-;; Copyright (C) 1985, 1989, 1994, 1995, 1997, 2000
+;; Copyright (C) 1985, 1989, 1994, 1995, 1997, 2000, 2001
 ;;   Free Software Foundation, Inc.
 
 ;; Author: K. Shane Hartman
 ;; Maintainer: Inge Frick <inge@nada.kth.se>
+;; Keywords: files
 
 ;; This file is part of GNU Emacs.
 
@@ -42,7 +43,7 @@
 ;;
 ;; You could also bind view-file, view-buffer, view-buffer-other-window and
 ;; view-buffer-other-frame to keys.
-
+\f
 ;;; Code:
 
 (defgroup view nil
   :group 'wp
   :group 'editing)
 
-(defcustom view-read-only nil
-  "*Non-nil means buffers visiting files read-only, do it in view mode."
-  :type 'boolean
-  :group 'view)
-
 (defcustom view-highlight-face 'highlight
    "*The face used for highlighting the match found by View mode search."
    :type 'face
@@ -109,13 +105,16 @@ functions that enable or disable view mode.")
   "Normal hook run when starting to view a buffer or file."
   :type 'hook
   :group 'view)
-
+\f
 (defvar view-old-buffer-read-only nil)
 (make-variable-buffer-local 'view-old-buffer-read-only)
 
 (defvar view-old-Helper-return-blurb)
 (make-variable-buffer-local 'view-old-Helper-return-blurb)
 
+;; Just to avoid warnings.
+(defvar Helper-return-blurb)
+
 (defvar view-page-size nil
   "Default number of lines to scroll by View page commands.
 If nil then the local value of this is initially set to window size.")
@@ -157,15 +156,14 @@ that use View mode automatically.")
 This is local in each buffer, once it is used.")
 (make-variable-buffer-local 'view-overlay)
 
-(or (assq 'view-mode minor-mode-alist)
-    (setq minor-mode-alist
-         (cons (list 'view-mode
-                     (propertize " View"
-                                 'help-echo "mouse-2: exit View mode"
-                                 'local-map (make-mode-line-mouse2-map
-                                             #'view-mode)))
-               minor-mode-alist)))
-
+(unless (assq 'view-mode minor-mode-alist)
+  (setq minor-mode-alist
+       (cons (list 'view-mode
+                   (propertize " View"
+                               'local-map mode-line-minor-mode-keymap
+                               'help-echo "mouse-3: minor mode menu"))
+             minor-mode-alist)))
+\f
 ;; Define keymap inside defvar to make it easier to load changes.
 ;; Some redundant "less"-like key bindings below have been commented out.
 (defvar view-mode-map
@@ -230,7 +228,7 @@ This is local in each buffer, once it is used.")
 (or (assq 'view-mode minor-mode-map-alist)
     (setq minor-mode-map-alist
          (cons (cons 'view-mode view-mode-map) minor-mode-map-alist)))
-
+\f
 ;;; Commands that enter or exit view mode.
 
 ;;;###autoload
@@ -354,7 +352,7 @@ Use this argument instead of explicitly setting `view-exit-action'."
     (switch-to-buffer-other-frame buffer)
     (view-mode-enter (and return-to (cons (selected-window) return-to))
                     exit-action)))
-
+\f
 ;;;###autoload
 (defun view-mode (&optional arg)
   ;; In the following documentation string we have to use some explicit key
@@ -413,12 +411,14 @@ r do reverse incremental search.
 \\     searches backward for regular expression, starting before current page.
 \\[View-search-last-regexp-forward]    searches forward for last regular expression.
 p      searches backward for last regular expression.
-\\[View-quit]  quit View mode, trying to restore window and buffer to previous state.
+\\[View-quit]  quit View mode, restoring this window and buffer to previous state.
          \\[View-quit] is the normal way to leave view mode.
 \\[View-exit]  exit View mode but stay in current buffer.  Use this if you started
          viewing a buffer (file) and find out you want to edit it.
-\\[View-exit-and-edit] exit View mode and make the current buffer editable.
-\\[View-quit-all]      quit View mode, trying to restore windows and buffer to previous state.
+         This command restores the previous read-only status of the buffer.
+\\[View-exit-and-edit] exit View mode, and make the current buffer editable
+         even if it was not editable before entry to View mode.
+\\[View-quit-all]      quit View mode, restoring all windows to previous state.
 \\[View-leave] quit View mode and maybe switch buffers, but don't kill this buffer.
 \\[View-kill-and-leave]        quit View mode, kill current buffer and go back to other buffer.
 
@@ -436,12 +436,11 @@ Entry to view-mode runs the normal hook `view-mode-hook'."
               (if (> (prefix-numeric-value arg) 0) view-mode (not view-mode)))
     (if view-mode (view-mode-disable)
       (view-mode-enable))))
-
+\f
 (defun view-mode-enable ()
   "Turn on View mode."
   ;; Always leave view mode before changing major mode.
   ;; This is to guarantee that the buffer-read-only variable is restored.
-  (make-local-hook 'change-major-mode-hook)
   (add-hook 'change-major-mode-hook 'view-mode-disable nil t)
   (setq view-mode t
        view-page-size (view-page-size-default view-page-size)
@@ -509,8 +508,8 @@ This function runs the normal hook `view-mode-hook'."
     (force-mode-line-update)
     (message "%s"
             (substitute-command-keys "\
-Type \\[help-command] for help, \\[describe-mode] for commands, \\[View-quit] to quit."))))
-
+View mode: type \\[help-command] for help, \\[describe-mode] for commands, \\[View-quit] to quit."))))
+\f
 (defun view-mode-exit (&optional return-to-alist exit-action all-win)
   "Exit View mode in various ways, depending on optional arguments.
 RETURN-TO-ALIST, EXIT-ACTION and ALL-WIN determine what to do after exit.
@@ -595,7 +594,7 @@ corresponding OLD-WINDOW is a live window, then select OLD-WINDOW."
          (setq view-exit-action nil)
          (funcall exit-action buffer))
        (force-mode-line-update))))
-
+\f
 (defun View-exit ()
   "Exit View mode but stay in current buffer."
   (interactive)
@@ -632,7 +631,7 @@ previous state and go to previous buffer or window."
   "Quit View mode, kill current buffer and return to previous buffer."
   (interactive)
   (view-mode-exit view-return-to-alist (or view-exit-action 'kill-buffer) t))
-
+\f
 
 ;;; Some help routines.
 
@@ -699,7 +698,7 @@ Also set the mark at the position where point was."
 ;    (goto-char (point-max))
 ;    (beginning-of-line))
 ;  (view-recenter))
-  
+
 (defun View-goto-line (&optional line)
   "Move to first (or prefix LINE) line in View mode.
 Display is centered at LINE.
@@ -709,14 +708,16 @@ Also set the mark at the position where point was."
   (goto-line line)
   (view-recenter))
 
-(defun View-scroll-to-buffer-end ()
-  "Scroll backward or forward so that buffer end is at last line of window."
+(defun View-back-to-mark (&optional ignore)
+  "Return to last mark set in View mode, else beginning of file.
+Display that line at the center of the window.
+This command pops the mark ring, so that successive
+invocations return to earlier marks."
   (interactive)
-  (let ((p (if (pos-visible-in-window-p (point-max)) (point))))
-    (goto-char (point-max))
-    (recenter -1)
-    (and p (goto-char p))))
-
+  (goto-char (or (mark t) (point-min)))
+  (pop-mark)
+  (view-recenter))
+\f
 (defun view-scroll-lines (lines backward default maxdefault)
   ;; This function does the job for all the scrolling commands.
   ;; Scroll forward LINES lines.  If BACKWARD is true scroll backwards.
@@ -775,6 +776,14 @@ Also set the mark at the position where point was."
                (if view-scroll-auto-exit "\\[View-scroll-page-forward]"
                  "\\[View-quit]")))
     (message "End of buffer")))
+\f
+(defun View-scroll-to-buffer-end ()
+  "Scroll backward or forward so that buffer end is at last line of window."
+  (interactive)
+  (let ((p (if (pos-visible-in-window-p (point-max)) (point))))
+    (goto-char (point-max))
+    (recenter -1)
+    (and p (goto-char p))))
 
 (defun View-scroll-page-forward (&optional lines)
   "Scroll \"page size\" or prefix LINES lines forward in View mode.
@@ -791,7 +800,7 @@ If LINES is more than a window-full, only the last window-full is shown."
 See also `View-scroll-page-forward'."
   (interactive "P")
   (view-scroll-lines lines t view-page-size nil))
-  
+
 (defun View-scroll-page-forward-set-page-size (&optional lines)
   "Scroll forward LINES lines in View mode, setting the \"page size\".
 This is the number of lines which \\[View-scroll-page-forward] and
@@ -855,17 +864,7 @@ If LINES is more than a window-full, only the last window-full is shown."
   (let ((view-scroll-auto-exit nil)
        (view-try-extend-at-buffer-end t))
     (view-scroll-lines lines nil view-page-size nil)))
-
-(defun View-back-to-mark (&optional ignore)
-  "Return to last mark set in View mode, else beginning of file.
-Display that line at the center of the window.
-This command pops the mark ring, so that successive
-invocations return to earlier marks."
-  (interactive)
-  (goto-char (or (mark t) (point-min)))
-  (pop-mark)
-  (view-recenter))
-            
+\f
 (defun View-search-regexp-forward (n regexp)
   "Search forward for first (or prefix Nth) occurrence of REGEXP in View mode.