Mercurial > emacs
comparison lisp/replace.el @ 1427:c49077849583
(occur): Always search entire buffer.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 18 Oct 1992 01:06:40 +0000 |
parents | ae5c412a32ec |
children | 787f816e1f4b |
comparison
equal
deleted
inserted
replaced
1426:67fd35416ba3 | 1427:c49077849583 |
---|---|
241 (defvar list-matching-lines-default-context-lines 0 | 241 (defvar list-matching-lines-default-context-lines 0 |
242 "*Default number of context lines to include around a `list-matching-lines' | 242 "*Default number of context lines to include around a `list-matching-lines' |
243 match. A negative number means to include that many lines before the match. | 243 match. A negative number means to include that many lines before the match. |
244 A positive number means to include that many lines both before and after.") | 244 A positive number means to include that many lines both before and after.") |
245 | 245 |
246 (defvar occur-whole-buffer nil | |
247 "If t, occur operates on whole buffer, otherwise occur starts from point. | |
248 default is nil.") | |
249 | |
250 (fset 'list-matching-lines 'occur) | 246 (fset 'list-matching-lines 'occur) |
251 | 247 |
252 (defun occur (regexp &optional nlines) | 248 (defun occur (regexp &optional nlines) |
253 "Show lines containing a match for REGEXP. If the global variable | 249 "Show all lines in the current buffer containing a match for REGEXP. |
254 `occur-whole-buffer' is non-nil, the entire buffer is searched, otherwise | 250 Interactively, REGEXP defaults to the last REGEXP |
255 search begins at point. Interactively, REGEXP defaults to the last REGEXP | |
256 used interactively with \\[occur]. | 251 used interactively with \\[occur]. |
257 | 252 |
258 If a match spreads across multiple lines, all those lines are shown. | 253 If a match spreads across multiple lines, all those lines are shown. |
259 | 254 |
260 Each line is displayed with NLINES lines before and after, or -NLINES | 255 Each line is displayed with NLINES lines before and after, or -NLINES |
274 (let ((first t) | 269 (let ((first t) |
275 (buffer (current-buffer)) | 270 (buffer (current-buffer)) |
276 (linenum 1) | 271 (linenum 1) |
277 (prevpos (point-min)) | 272 (prevpos (point-min)) |
278 (final-context-start (make-marker))) | 273 (final-context-start (make-marker))) |
279 (if (not occur-whole-buffer) | 274 ;;; (save-excursion |
280 (save-excursion | 275 ;;; (beginning-of-line) |
281 (beginning-of-line) | 276 ;;; (setq linenum (1+ (count-lines (point-min) (point)))) |
282 (setq linenum (1+ (count-lines (point-min) (point)))) | 277 ;;; (setq prevpos (point))) |
283 (setq prevpos (point)))) | |
284 (with-output-to-temp-buffer "*Occur*" | 278 (with-output-to-temp-buffer "*Occur*" |
285 (save-excursion | 279 (save-excursion |
286 (set-buffer standard-output) | 280 (set-buffer standard-output) |
287 (insert "Lines matching ") | 281 (insert "Lines matching ") |
288 (prin1 regexp) | 282 (prin1 regexp) |
292 (setq occur-nlines nlines) | 286 (setq occur-nlines nlines) |
293 (setq occur-pos-list ())) | 287 (setq occur-pos-list ())) |
294 (if (eq buffer standard-output) | 288 (if (eq buffer standard-output) |
295 (goto-char (point-max))) | 289 (goto-char (point-max))) |
296 (save-excursion | 290 (save-excursion |
297 (if occur-whole-buffer | 291 (beginning-of-buffer) |
298 (beginning-of-buffer)) | |
299 ;; Find next match, but give up if prev match was at end of buffer. | 292 ;; Find next match, but give up if prev match was at end of buffer. |
300 (while (and (not (= prevpos (point-max))) | 293 (while (and (not (= prevpos (point-max))) |
301 (re-search-forward regexp nil t)) | 294 (re-search-forward regexp nil t)) |
302 (goto-char (match-beginning 0)) | 295 (goto-char (match-beginning 0)) |
303 (beginning-of-line) | 296 (beginning-of-line) |