Commit 4fe11426 authored by Richard M. Stallman's avatar Richard M. Stallman
Browse files

(View-search-regexp-forward, View-search-regexp-backward):

If arg is empty, use view-last-regexp.
(view-overlay): New variable, local in all buffers.
(view-search): Highlight the match using view-overlay.
(view-exit): Delete view-overlay.
parent 84c5c823
...@@ -53,6 +53,10 @@ ...@@ -53,6 +53,10 @@
(defvar view-exit-position nil) (defvar view-exit-position nil)
(make-variable-buffer-local 'view-exit-position) (make-variable-buffer-local 'view-exit-position)
(defvar view-overlay nil
"Overlay used to display where a search operation found its match.")
(make-variable-buffer-local 'view-overlay)
(or (assq 'view-mode minor-mode-alist) (or (assq 'view-mode minor-mode-alist)
(setq minor-mode-alist (setq minor-mode-alist
(cons '(view-mode " View") minor-mode-alist))) (cons '(view-mode " View") minor-mode-alist)))
...@@ -260,6 +264,7 @@ If you viewed an existing buffer, that buffer returns to its previous mode. ...@@ -260,6 +264,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." If you viewed a file that was not present in Emacs, its buffer is killed."
(interactive) (interactive)
(setq view-mode nil) (setq view-mode nil)
(delete-overlay view-overlay)
(force-mode-line-update) (force-mode-line-update)
(cond (view-mode-auto-exit (cond (view-mode-auto-exit
(setq buffer-read-only view-old-buffer-read-only) (setq buffer-read-only view-old-buffer-read-only)
...@@ -371,17 +376,16 @@ Arg is number of lines to scroll." ...@@ -371,17 +376,16 @@ Arg is number of lines to scroll."
Displays line found at center of window. REGEXP is remembered for 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."
(interactive "p\nsSearch forward (regexp): ") (interactive "p\nsSearch forward (regexp): ")
(if (> (length regexp) 0) ;;;(view-last-command 'View-search-last-regexp-forward n)
(progn (view-search n (if (equal regexp "") view-last-regexp regexp))))
;(view-last-command 'View-search-last-regexp-forward n)
(view-search n regexp))))
(defun View-search-regexp-backward (n regexp) (defun View-search-regexp-backward (n regexp)
"Search backward from window start for Nth instance of REGEXP. "Search backward from window start for Nth instance of REGEXP.
Displays line found at center of window. REGEXP is remembered for 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."
(interactive "p\nsSearch backward (regexp): ") (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) (defun View-search-last-regexp-forward (n)
"Search forward from window end for Nth instance of last regexp. "Search forward from window end for Nth instance of last regexp.
...@@ -417,6 +421,11 @@ invocations return to earlier marks." ...@@ -417,6 +421,11 @@ invocations return to earlier marks."
(progn (progn
(push-mark) (push-mark)
(goto-char where) (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 'highlight)
(beginning-of-line) (beginning-of-line)
(recenter (/ (view-window-size) 2))) (recenter (/ (view-window-size) 2)))
(message "Can't find occurrence %d of %s" times regexp) (message "Can't find occurrence %d of %s" times regexp)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment