2

I've looked through several similar questions, but either I didn't understand their answer or my question is different than theirs. So, I have a project contains many subdirecties and different type of files. I would like to search a function name among those .C files only.

Some information on the web suggest to use "Esc x dired-do-query-replace-regexp". However, this will search not just C files, but also other file like .elf which isn't helpfule in my case. Other people sugget to use TAG function, but it will require me to type "etags *.c" for every subdirectory which is also impossible.

How should I do this while working on those large scale software project?

Thanks Lee

Lee
  • 21
  • 2

6 Answers6

3

Use ack-grep on linux

ack-grep "keyword" -G *.c
rahul
  • 1,281
  • 2
  • 12
  • 29
  • ack (http://betterthangrep.com/) is brilliant. By default it does a recursive find+grep with all of the niggly details taken care of for you (such as ignoring version control directories, and backup files; also ignoring binary files is as simple as --nobinary). Filtering the search is trivial, and sets of extensions can be grouped under a single name (e.g. --[no]perl will exclude or include .pl .pm .pod .t). In short, it makes it trivial to do what you want with the minimum of effort. – phils Feb 02 '11 at 00:59
  • 2
    Which reminds me, I really must check out the Emacs integration http://www.emacswiki.org/emacs/Ack. I've always just used `M-x rgrep` (which also takes care of excluding the things I don't want to search). – phils Feb 02 '11 at 01:03
1

My favorite: igrep-find, found in the package igrep.el. Usage is:

M-x igrep-find some_thing RET *.C

There's the built in grep-find, docs here, but I find it awkward to use.

For a more general answer, see this similar question: Using Emacs For Big Big Projects.

Community
  • 1
  • 1
Trey Jackson
  • 73,529
  • 11
  • 197
  • 229
1

if you're on linux, you can use grep to find files with a certain text in them. you would then do this outside of emacs, in your shell/command prompt. here's a nice syntax:

grep --color=auto --include=*.c -iRnH 'string to search for' /dir/to/search/

the directory to search can be specified relative, so if you're in the directory you want to use as the root directory for your recursive search, you can just skip the whole directory address and specify a single dot.

grep --color=auto --include=*.c -iRnH 'string to search for' .

the part --color=auto makes some text highlighted. --include=*.c is the part that specifies what files to search. in this case, only files with the c-extension. the flag i makes stuff case insensitive, the flag R makes the search recursive, the flag n adds the line number to the report, and the flag H adds the file path to the report.

davogotland
  • 2,718
  • 1
  • 15
  • 19
1

To breed find and grep there is find-grep function, there you can change the invocation string to find . -name *.c etc. Make it a function, if You like. Then You use eg. C-x` et al. to navigate the results.

To search among the files in one directory i use lgrep, it prompts you in which files to search.

0

Try with dired: place the cursor on the directory name to search, type A and in the minibuffer the text to find.

Marcello
  • 1
  • 2
0

You can use cscope and xcscope.el : http://www.emacswiki.org/emacs/CScopeAndEmacs

Johnny
  • 81
  • 3