(w32_get_resource): Remove unused variable `ok'.
[bpt/emacs.git] / lisp / view.el
index 80c6207..c152383 100644 (file)
@@ -1,7 +1,7 @@
 ;;; view.el --- peruse file or buffer without editing
 
 ;; Copyright (C) 1985, 1989, 1994, 1995, 1997, 2000, 2001, 2002,
 ;;; view.el --- peruse file or buffer without editing
 
 ;; Copyright (C) 1985, 1989, 1994, 1995, 1997, 2000, 2001, 2002,
-;;   2003, 2004, 2005 Free Software Foundation, Inc.
+;;   2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: K. Shane Hartman
 ;; Maintainer: Inge Frick <inge@nada.kth.se>
 
 ;; Author: K. Shane Hartman
 ;; Maintainer: Inge Frick <inge@nada.kth.se>
@@ -11,7 +11,7 @@
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; is now controlled by the presence of a value in `view-return-to-alist'.
 (defcustom view-scroll-auto-exit nil
   "*Non-nil means scrolling past the end of buffer exits View mode.
 ;; is now controlled by the presence of a value in `view-return-to-alist'.
 (defcustom view-scroll-auto-exit nil
   "*Non-nil means scrolling past the end of buffer exits View mode.
-nil means attempting to scroll past the end of the buffer,
+A value of nil means attempting to scroll past the end of the buffer,
 only rings the bell and gives a message on how to leave."
   :type 'boolean
   :group 'view)
 
 (defcustom view-try-extend-at-buffer-end nil
 only rings the bell and gives a message on how to leave."
   :type 'boolean
   :group 'view)
 
 (defcustom view-try-extend-at-buffer-end nil
- "*Non-nil means try load more of file when reaching end of buffer.
+ "*Non-nil means try to load more of file when reaching end of buffer.
 This variable is mainly intended to be temporarily set to non-nil by
 the F command in view-mode, but you can set it to t if you want the action
 for all scroll commands in view mode."
 This variable is mainly intended to be temporarily set to non-nil by
 the F command in view-mode, but you can set it to t if you want the action
 for all scroll commands in view mode."
@@ -93,6 +93,12 @@ considered for restoring."
   :type 'boolean
   :group 'view)
 
   :type 'boolean
   :group 'view)
 
+(defcustom view-inhibit-help-message nil
+  "*Non-nil inhibits the help message shown upon entering View mode."
+  :type 'boolean
+  :group 'view
+  :version "22.1")
+
 ;;;###autoload
 (defvar view-mode nil
   "Non-nil if View mode is enabled.
 ;;;###autoload
 (defvar view-mode nil
   "Non-nil if View mode is enabled.
@@ -369,7 +375,8 @@ Use this argument instead of explicitly setting `view-exit-action'."
   ;; bindings instead of using the \\[] construction.  The reason for this
   ;; is that most commands have more than one key binding.
   "Toggle View mode, a minor mode for viewing text but not editing it.
   ;; bindings instead of using the \\[] construction.  The reason for this
   ;; is that most commands have more than one key binding.
   "Toggle View mode, a minor mode for viewing text but not editing it.
-With ARG, turn View mode on iff ARG is positive.
+With prefix argument ARG, turn View mode on if ARG is positive, otherwise
+turn it off.
 
 Emacs commands that do not change the buffer contents are available as usual.
 Kill commands insert text in kill buffers but do not delete.  Other commands
 
 Emacs commands that do not change the buffer contents are available as usual.
 Kill commands insert text in kill buffers but do not delete.  Other commands
@@ -432,13 +439,15 @@ p searches backward for last regular expression.
 \\[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.
 
 \\[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.
 
-The effect of \\[View-leave] , \\[View-quit] and \\[View-kill-and-leave] depends on how view-mode was entered.  If it was
-entered by view-file, view-file-other-window or view-file-other-frame
-\(\\[view-file], \\[view-file-other-window], \\[view-file-other-frame] or the dired mode v command), then \\[View-quit] will
-try to kill the current buffer.  If view-mode was entered from another buffer
-as is done by View-buffer, View-buffer-other-window, View-buffer-other frame,
-View-file, View-file-other-window or View-file-other-frame then \\[View-leave] , \\[View-quit] and \\[View-kill-and-leave]
-will return to that buffer.
+The effect of \\[View-leave], \\[View-quit] and \\[View-kill-and-leave] depends on how view-mode was entered.  If it was
+entered by view-file, view-file-other-window, view-file-other-frame, or
+\\[dired-view-file] \(\\[view-file], \\[view-file-other-window],
+\\[view-file-other-frame], or the Dired mode v command),
+then \\[View-quit] will try to kill the current buffer.
+If view-mode was entered from another buffer, by \\[view-buffer],
+\\[view-buffer-other-window], \\[view-buffer-other frame], \\[view-file],
+\\[view-file-other-window], or \\[view-file-other-frame],
+then \\[View-leave], \\[View-quit] and \\[View-kill-and-leave] will return to that buffer.
 
 Entry to view-mode runs the normal hook `view-mode-hook'."
   (interactive "P")
 
 Entry to view-mode runs the normal hook `view-mode-hook'."
   (interactive "P")
@@ -516,9 +525,10 @@ This function runs the normal hook `view-mode-hook'."
   (unless view-mode                    ; Do nothing if already in view mode.
     (view-mode-enable)
     (force-mode-line-update)
   (unless view-mode                    ; Do nothing if already in view mode.
     (view-mode-enable)
     (force-mode-line-update)
-    (message "%s"
-            (substitute-command-keys "\
-View mode: type \\[help-command] for help, \\[describe-mode] for commands, \\[View-quit] to quit."))))
+    (unless view-inhibit-help-message
+      (message "%s"
+              (substitute-command-keys "\
+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.
 \f
 (defun view-mode-exit (&optional return-to-alist exit-action all-win)
   "Exit View mode in various ways, depending on optional arguments.
@@ -874,7 +884,7 @@ If LINES is more than a window-full, only the last window-full is shown."
   (interactive "P")
   (let ((view-scroll-auto-exit nil)
        (view-try-extend-at-buffer-end t))
   (interactive "P")
   (let ((view-scroll-auto-exit nil)
        (view-try-extend-at-buffer-end t))
-    (view-scroll-lines lines nil view-page-size nil)))
+    (view-scroll-lines lines nil (view-page-size-default view-page-size) nil)))
 \f
 (defun View-search-regexp-forward (n regexp)
   "Search forward for first (or prefix Nth) occurrence of REGEXP in View mode.
 \f
 (defun View-search-regexp-forward (n regexp)
   "Search forward for first (or prefix Nth) occurrence of REGEXP in View mode.
@@ -980,27 +990,27 @@ for highlighting the match that is found."
               times (if no "no " "") regexp)
       (sit-for 4))))
 
               times (if no "no " "") regexp)
       (sit-for 4))))
 
+;; This is the dumb approach, looking at each line.  The original
+;; version of this function looked like it might have been trying to
+;; do something clever, but not succeeding:
+;; http://lists.gnu.org/archive/html/bug-gnu-emacs/2007-09/msg00073.html
 (defun view-search-no-match-lines (times regexp)
 (defun view-search-no-match-lines (times regexp)
-  ;; Search for the TIMESt occurrence of line with no match for REGEXP.
-  (let ((back (and (< times 0) (setq times (- times)) -1))
-       n)
-    (while (> times 0)
-      (save-excursion (beginning-of-line (if back (- times) (1+ times)))
-                     (setq n (point)))
-      (setq times
-           (cond
-            ((< (count-lines (point) n) times) -1) ; Not enough lines.
-            ((or (null (re-search-forward regexp nil t back))
-                 (if back (and (< (match-end 0) n)
-                               (> (count-lines (match-end 0) n) 1))
-                   (and (< n (match-beginning 0))
-                        (> (count-lines n (match-beginning 0)) 1))))
-             0)                        ; No match within lines.
-            (back (count-lines (max n (match-beginning 0)) (match-end 0)))
-            (t (count-lines (match-beginning 0) (min n (match-end 0))))))
-      (goto-char n))
-    (and (zerop times) (looking-at "^.*$"))))
-
+  "Search for the TIMESth occurrence of a line with no match for REGEXP.
+If such a line is found, return non-nil and set the match-data to that line.
+If TIMES is negative, search backwards."
+  (let ((step (if (>= times 0) 1
+                (setq times (- times))
+                -1)))
+    ;; Note that we do not check the current line.
+    (while (and (> times 0)
+                (zerop (forward-line step)))
+      ;; (forward-line 1) returns 0 on moving within the last line.
+      (if (eobp)
+          (setq times -1)
+        (or (re-search-forward regexp (line-end-position) t)
+            (setq times (1- times))))))
+  (and (zerop times)
+       (looking-at ".*")))
 
 (provide 'view)
 
 
 (provide 'view)