[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

K.8 Other Search-and-Loop Commands

Here are some other commands that find matches for a regular expression. They all ignore case in matching, if the pattern contains no upper-case letters and case-fold-search is non-nil. Aside from occur, all operate on the text from point to the end of the buffer, or on the active region in Transient Mark mode.

M-x occur RET regexp RET
Display a list showing each line in the buffer that contains a match for regexp. To limit the search to part of the buffer, narrow to that part (see section AC.22 Narrowing). A numeric argument n specifies that n lines of context are to be displayed before and after each matching line.

The buffer `*Occur*' containing the output serves as a menu for finding the occurrences in their original context. Click Mouse-2 on an occurrence listed in `*Occur*', or position point there and type RET; this switches to the buffer that was searched and moves point to the original of the chosen occurrence.

M-x list-matching-lines
Synonym for M-x occur.

M-x how-many RET regexp RET
Print the number of matches for regexp that exist in the buffer after point. In Transient Mark mode, if the region is active, the command operates on the region instead.

M-x flush-lines RET regexp RET
Delete each line that contains a match for regexp, operating on the text after point. In Transient Mark mode, if the region is active, the command operates on the region instead.

M-x keep-lines RET regexp RET
Delete each line that does not contain a match for regexp, operating on the text after point. In Transient Mark mode, if the region is active, the command operates on the region instead.

You can also search multiple files under control of a tags table (see section W.2.6 Searching and Replacing with Tags Tables) or through Dired A command (see section AB.7 Operating on Files), or ask the grep program to do it (see section V.2 Searching with Grep under Emacs).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on April 2, 2002 using texi2html