Load cus-start.
[bpt/emacs.git] / lisp / view.el
index 32c2285..bbc168b 100644 (file)
@@ -18,8 +18,9 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to
-;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
 
 ;;; Commentary:
 
 (make-variable-buffer-local 'view-mode)
 
 (defvar view-mode-auto-exit nil
-  "Non-nil means scrolling past the end of buffer exits View mode.")
+  "Non-nil means scrolling past the end of buffer exits View mode.
+Some commands, such as \\[view-file], set this to t locally;
+the only way to override that is to set it to nil using `view-mode-hook'.")
+
 (make-variable-buffer-local 'view-mode-auto-exit)
 
 (defvar view-old-buffer-read-only nil)
@@ -70,7 +74,9 @@ This is local in each buffer, once it is used.")
 (if view-mode-map
     nil
   (setq view-mode-map (make-keymap))
-  (suppress-keymap view-mode-map)
+  ;; We used to call suppress-keymap here, but that isn't good in a minor mode.
+  ;; Self-inserting characters will beep anyway, since the buffer is read-only,
+  ;; and we should not interfere with letters that serve as useful commands.
   (define-key view-mode-map "q" 'view-exit)
   (define-key view-mode-map "<" 'beginning-of-buffer)
   (define-key view-mode-map ">" 'end-of-buffer)
@@ -87,9 +93,8 @@ This is local in each buffer, once it is used.")
   (define-key view-mode-map "'" 'View-back-to-mark)
   (define-key view-mode-map "@" 'View-back-to-mark)  
   (define-key view-mode-map "x" 'exchange-point-and-mark)
-  (define-key view-mode-map "h" 'Helper-describe-bindings)
-  (define-key view-mode-map "?" 'Helper-describe-bindings)
-  (define-key view-mode-map (char-to-string help-char) 'Helper-help)
+  (define-key view-mode-map "h" 'describe-mode)
+  (define-key view-mode-map "?" 'describe-mode)
   (define-key view-mode-map "s" 'isearch-forward)
   (define-key view-mode-map "r" 'isearch-backward)
   (define-key view-mode-map "/" 'View-search-regexp-forward)
@@ -182,23 +187,19 @@ This command runs the normal hook `view-mode-hook'."
 ;;;###autoload
 (defun view-mode (&optional arg)
   "Toggle View mode.
-If you use this function to turn on View mode,
-\"exiting\" View mode does nothing except turn View mode off.
-The other way to turn View mode on is by calling
-`view-mode-enter'."
-  (interactive "P")
-  (setq view-mode
-       (if (null arg)
-           (not view-mode)
-         (> (prefix-numeric-value arg) 0)))
-  (force-mode-line-update))
+With a prefix argument, turn View mode on if the argument is >= zero
+and off if it is not.
+
+If you use this function to turn on View mode, then subsequently
+\"exiting\" View mode does nothing except turn View mode off.  The
+other way to turn View mode on is by calling `view-mode-enter';
+that is what Lisp programs usually use.
 
-(defun view-mode-enter (&optional prev-buffer action)
-  "Minor mode for viewing text but not editing it.
 Letters do not insert themselves.  Instead these commands are provided.
 Most commands take prefix arguments.  Commands dealing with lines
 default to \"scroll size\" lines (initially size of window).
 Search commands default to a repeat count of one.
+
 M-< or <       move to beginning of buffer.
 M-> or >       move to end of buffer.
 C-v or Space   scroll forward lines.
@@ -222,11 +223,21 @@ C-r or r  do reverse incremental search.
                  successful search and when jump to line to occurs.
                  The mark is set on jump to buffer start or end.
 ? or h         provide help message (list of commands).
-\\[Helper-help]                provides help (list of commands or description of a command).
+\\[help-command]               provides help (list of commands or description of a command).
 C-n            moves down lines vertically.
 C-p            moves upward lines vertically.
 C-l            recenters the screen.
-q              exit view-mode and return to previous buffer.
+q              exit view-mode and return to previous buffer."
+  (interactive "P")
+  (setq view-mode
+       (if (null arg)
+           (not view-mode)
+         (> (prefix-numeric-value arg) 0)))
+  (force-mode-line-update))
+
+(defun view-mode-enter (&optional prev-buffer action)
+  "Enter View mode, a Minor mode for viewing text but not editing it.
+See the function `view-mode' for more details.
 
 This function runs the normal hook `view-mode-hook'.
 
@@ -259,9 +270,9 @@ This function runs the normal hook `view-mode-hook'.
   (setq goal-column nil)
 
   (run-hooks 'view-mode-hook)
-  (message
+  (message "%s"
      (substitute-command-keys
-      "Type \\[Helper-help] for help, \\[Helper-describe-bindings] for commands, \\[view-exit] to quit.")))
+      "Type \\[help-command] for help, \\[describe-mode] for commands, \\[view-exit] to quit.")))
 \f
 (defun view-exit ()
   "Exit from view-mode.
@@ -340,8 +351,8 @@ Arg is number of lines to scroll."
        (scroll-up lines)))
     (cond ((pos-visible-in-window-p (point-max))
           (goto-char (point-max))
-          (recenter -1)
-          (message (substitute-command-keys
+          (message "%s"
+                   (substitute-command-keys
                     "End.  Type \\[view-exit] to quit viewing."))))
     (move-to-window-line -1)
     (beginning-of-line)))
@@ -379,7 +390,10 @@ Arg is number of lines to scroll."
 (defun View-search-regexp-forward (n regexp)
   "Search forward for Nth occurrence of REGEXP.
 Displays line found at center of window.  REGEXP is remembered for
-searching with \\[View-search-last-regexp-forward] and \\[View-search-last-regexp-backward].  Sets mark at starting position and pushes mark ring."
+searching with \\[View-search-last-regexp-forward] and \\[View-search-last-regexp-backward].  Sets mark at starting position and pushes mark ring.
+
+The variable `view-highlight-face' controls the face that is used
+for highlighting the match that is found."
   (interactive "p\nsSearch forward (regexp): ")
 ;;;(view-last-command 'View-search-last-regexp-forward n)
   (view-search n (if (equal regexp "") view-last-regexp regexp)))
@@ -387,7 +401,10 @@ searching with \\[View-search-last-regexp-forward] and \\[View-search-last-regex
 (defun View-search-regexp-backward (n regexp)
   "Search backward from window start for Nth instance of REGEXP.
 Displays line found at center of window.  REGEXP is remembered for
-searching with \\[View-search-last-regexp-forward] and \\[View-search-last-regexp-backward].  Sets mark at starting position and pushes mark ring."
+searching with \\[View-search-last-regexp-forward] and \\[View-search-last-regexp-backward].  Sets mark at starting position and pushes mark ring.
+
+The variable `view-highlight-face' controls the face that is used
+for highlighting the match that is found."
   (interactive "p\nsSearch backward (regexp): ")
   (View-search-regexp-forward (- n)
                              (if (equal regexp "") view-last-regexp regexp)))
@@ -395,16 +412,26 @@ searching with \\[View-search-last-regexp-forward] and \\[View-search-last-regex
 (defun View-search-last-regexp-forward (n)
   "Search forward from window end for Nth instance of last regexp.
 Displays line found at center of window.  Sets mark at starting position
-and pushes mark ring."
+and pushes mark ring.
+
+The variable `view-highlight-face' controls the face that is used
+for highlighting the match that is found."
   (interactive "p")
-  (View-search-regexp-forward n view-last-regexp))
+  (if view-last-regexp
+      (View-search-regexp-forward n view-last-regexp)
+    (error "No previous View-mode search")))
 
 (defun View-search-last-regexp-backward (n)
   "Search backward from window start for Nth instance of last regexp.
 Displays line found at center of window.  Sets mark at starting position and
-pushes mark ring."
+pushes mark ring.
+
+The variable `view-highlight-face' controls the face that is used
+for highlighting the match that is found."
   (interactive "p")
-  (View-search-regexp-backward n view-last-regexp))
+  (if view-last-regexp
+      (View-search-regexp-backward n view-last-regexp)
+    (error "No previous View-mode search")))
 
 (defun View-back-to-mark (&optional ignore)
   "Return to last mark set in View mode, else beginning of file.