开发者

How to search a text among c files under a directory

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 al开发者_运维知识库so impossible.

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

Thanks Lee


Use ack-grep on linux

ack-grep "keyword" -G *.c


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.


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.


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜