comparison lisp/view.el @ 13122:05bae277596e

(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.
author Richard M. Stallman <rms@gnu.org>
date Thu, 05 Oct 1995 22:25:38 +0000
parents d7735534db86
children e712a11f25a0
comparison
equal deleted inserted replaced
13121:4efe8fac6854 13122:05bae277596e
50 (make-variable-buffer-local 'view-exit-action) 50 (make-variable-buffer-local 'view-exit-action)
51 (defvar view-return-here nil) 51 (defvar view-return-here nil)
52 (make-variable-buffer-local 'view-return-here) 52 (make-variable-buffer-local 'view-return-here)
53 (defvar view-exit-position nil) 53 (defvar view-exit-position nil)
54 (make-variable-buffer-local 'view-exit-position) 54 (make-variable-buffer-local 'view-exit-position)
55
56 (defvar view-overlay nil
57 "Overlay used to display where a search operation found its match.")
58 (make-variable-buffer-local 'view-overlay)
55 59
56 (or (assq 'view-mode minor-mode-alist) 60 (or (assq 'view-mode minor-mode-alist)
57 (setq minor-mode-alist 61 (setq minor-mode-alist
58 (cons '(view-mode " View") minor-mode-alist))) 62 (cons '(view-mode " View") minor-mode-alist)))
59 63
258 "Exit from view-mode. 262 "Exit from view-mode.
259 If you viewed an existing buffer, that buffer returns to its previous mode. 263 If you viewed an existing buffer, that buffer returns to its previous mode.
260 If you viewed a file that was not present in Emacs, its buffer is killed." 264 If you viewed a file that was not present in Emacs, its buffer is killed."
261 (interactive) 265 (interactive)
262 (setq view-mode nil) 266 (setq view-mode nil)
267 (delete-overlay view-overlay)
263 (force-mode-line-update) 268 (force-mode-line-update)
264 (cond (view-mode-auto-exit 269 (cond (view-mode-auto-exit
265 (setq buffer-read-only view-old-buffer-read-only) 270 (setq buffer-read-only view-old-buffer-read-only)
266 (setq view-mode-auto-exit nil) 271 (setq view-mode-auto-exit nil)
267 272
369 (defun View-search-regexp-forward (n regexp) 374 (defun View-search-regexp-forward (n regexp)
370 "Search forward for Nth occurrence of REGEXP. 375 "Search forward for Nth occurrence of REGEXP.
371 Displays line found at center of window. REGEXP is remembered for 376 Displays line found at center of window. REGEXP is remembered for
372 searching with \\[View-search-last-regexp-forward] and \\[View-search-last-regexp-backward]. Sets mark at starting position and pushes mark ring." 377 searching with \\[View-search-last-regexp-forward] and \\[View-search-last-regexp-backward]. Sets mark at starting position and pushes mark ring."
373 (interactive "p\nsSearch forward (regexp): ") 378 (interactive "p\nsSearch forward (regexp): ")
374 (if (> (length regexp) 0) 379 ;;;(view-last-command 'View-search-last-regexp-forward n)
375 (progn 380 (view-search n (if (equal regexp "") view-last-regexp regexp))))
376 ;(view-last-command 'View-search-last-regexp-forward n)
377 (view-search n regexp))))
378 381
379 (defun View-search-regexp-backward (n regexp) 382 (defun View-search-regexp-backward (n regexp)
380 "Search backward from window start for Nth instance of REGEXP. 383 "Search backward from window start for Nth instance of REGEXP.
381 Displays line found at center of window. REGEXP is remembered for 384 Displays line found at center of window. REGEXP is remembered for
382 searching with \\[View-search-last-regexp-forward] and \\[View-search-last-regexp-backward]. Sets mark at starting position and pushes mark ring." 385 searching with \\[View-search-last-regexp-forward] and \\[View-search-last-regexp-backward]. Sets mark at starting position and pushes mark ring."
383 (interactive "p\nsSearch backward (regexp): ") 386 (interactive "p\nsSearch backward (regexp): ")
384 (View-search-regexp-forward (- n) regexp)) 387 (View-search-regexp-forward (- n)
388 (if (equal regexp "") view-last-regexp regexp)))
385 389
386 (defun View-search-last-regexp-forward (n) 390 (defun View-search-last-regexp-forward (n)
387 "Search forward from window end for Nth instance of last regexp. 391 "Search forward from window end for Nth instance of last regexp.
388 Displays line found at center of window. Sets mark at starting position 392 Displays line found at center of window. Sets mark at starting position
389 and pushes mark ring." 393 and pushes mark ring."
415 (setq where (point)))) 419 (setq where (point))))
416 (if where 420 (if where
417 (progn 421 (progn
418 (push-mark) 422 (push-mark)
419 (goto-char where) 423 (goto-char where)
424 (if view-overlay
425 (move-overlay view-overlay (match-beginning 0) (match-end 0))
426 (setq view-overlay
427 (make-overlay (match-beginning 0) (match-end 0))))
428 (overlay-put view-overlay 'face 'highlight)
420 (beginning-of-line) 429 (beginning-of-line)
421 (recenter (/ (view-window-size) 2))) 430 (recenter (/ (view-window-size) 2)))
422 (message "Can't find occurrence %d of %s" times regexp) 431 (message "Can't find occurrence %d of %s" times regexp)
423 (sit-for 4)))) 432 (sit-for 4))))
424 433