]> code.delx.au - gnu-emacs/blobdiff - lisp/view.el
(rmail-summary-get-new-mail): Don't call rmail-summary-goto-msg if msg is 0.
[gnu-emacs] / lisp / view.el
index 06f30a5bff634e537b2fc622ce141a1d1979e465..0823cc1e67b8e4052eaddc1814e595e843a7944a 100644 (file)
 
 ;;; Code:
 
+;;;###autoload
+(defvar view-highlight-face 'highlight
+   "*The overlay face used for highlighting the match found by View mode search.")
+
 (defvar view-mode nil "Non-nil if View mode is enabled.")
 (make-variable-buffer-local 'view-mode)
 
 (defvar view-exit-position nil)
 (make-variable-buffer-local 'view-exit-position)
 
+(defvar view-overlay nil
+  "Overlay used to display where a search operation found its match.
+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 '(view-mode " View") minor-mode-alist)))
@@ -78,9 +87,8 @@
   (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)
@@ -176,20 +184,13 @@ This command runs the normal hook `view-mode-hook'."
 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))
+`view-mode-enter'.
 
-(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.
@@ -213,11 +214,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'.
 
@@ -252,7 +263,7 @@ This function runs the normal hook `view-mode-hook'.
   (run-hooks 'view-mode-hook)
   (message
      (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.
@@ -260,6 +271,7 @@ If you viewed an existing buffer, that buffer returns to its previous mode.
 If you viewed a file that was not present in Emacs, its buffer is killed."
   (interactive)
   (setq view-mode nil)
+  (and view-overlay (delete-overlay view-overlay))
   (force-mode-line-update)
   (cond (view-mode-auto-exit
         (setq buffer-read-only view-old-buffer-read-only)
@@ -330,7 +342,6 @@ 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
                     "End.  Type \\[view-exit] to quit viewing."))))
     (move-to-window-line -1)
@@ -369,31 +380,42 @@ 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): ")
-  (if (> (length regexp) 0)
-      (progn
-       ;(view-last-command 'View-search-last-regexp-forward n)
-       (view-search n regexp))))
+;;;(view-last-command 'View-search-last-regexp-forward n)
+  (view-search n (if (equal regexp "") view-last-regexp regexp)))
 
 (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) regexp))
+  (View-search-regexp-forward (- n)
+                             (if (equal regexp "") view-last-regexp regexp)))
 
 (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))
 
 (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))
 
@@ -417,6 +439,11 @@ invocations return to earlier marks."
        (progn
          (push-mark)
          (goto-char where)
+         (if view-overlay
+             (move-overlay view-overlay (match-beginning 0) (match-end 0))
+           (setq view-overlay
+                 (make-overlay (match-beginning 0) (match-end 0))))
+         (overlay-put view-overlay 'face view-highlight-face)
          (beginning-of-line)
          (recenter (/ (view-window-size) 2)))
       (message "Can't find occurrence %d of %s" times regexp)