math0ne
math0ne

Reputation: 762

What's the best Find in File mode for EMACS?

What's the best package for finding a string in multiple files in EMACS. I know about grep and such but I would like something that is a little smoother to operate.

Upvotes: 4

Views: 1075

Answers (5)

Drew
Drew

Reputation: 30699

Depends what you mean by find a string. As others have mentioned, grep is very good at what it does. I use it all the time, everyday.

But if your "string" is, say, a sequence of words within a sentence (which can be multi-line), then grep might not be what you want.

Another tool for searching across multiple files or buffers (or bookmarks) is Icicles search. The general idea is that it first parses the files into search contexts according to some definition (e.g. a regexp), and then it searches for matches to your current minibuffer input (changing the search hits dynamically as you edit your input).

Whereas grep always uses lines as search contexts, with Icicles search you are not limited in how you define the contexts to search. The contexts need not partition (exhaust) the file; they can cover as much or as little of the file text as you want.

Among other possibilities, you can use Emacs thing-at-point definitions for various kinds of THING as the search contexts. For example, you can use command icicles-search-thing with sentence as the THING type, to use sentences as the search contexts.

Or you can use character-property zones as search contexts: search all zones that are font-locked with a given set of faces, for instance. There are many possibilities.

http://www.emacswiki.org/emacs/Icicles_-_Search_Commands%2c_Overview

Upvotes: 0

Dave L.
Dave L.

Reputation: 11238

As an alternative, I find dired-modehelpful, especially when used with either dired-mark-files-regexp (%m) or dired-mark-files-containing-regexp to select what should be searched and then dired-do-search (A).

Upvotes: 0

quodlibetor
quodlibetor

Reputation: 8433

Dired mode also lets you do a search through marked files with the dired-do-search function.

And ibuffer lets you do emacs' generic isearch through a bunch of buffers using the awkward key sequence M-s a C-s.

Upvotes: 0

ZungBang
ZungBang

Reputation: 409

Just in case you haven't read it already - there's lots of relevant tips over at the EmacsWiki GrepMode page.

Upvotes: 2

kovan
kovan

Reputation: 770

There are three builtin functions for grepping in Emacs: grep, find-grep (or grep-find) and rgrep.

The first two work by letting the user edit the grep command line directly. I usually use the third, rgrep, from "recursive grep". It's a little friendlier, as it prompts the user for the search parameters (search string, file types and directory) one by one, provides customizable defaults, and it automatically ignores some common files and directories you usually don't want to search, like for example .svn or .o files.

Then, there is ack, and its interface for Emacs: ack.el, whose default behavior is similar to rgrep, but can be customized to use the options that ack provides.

Upvotes: 7

Related Questions