tags:

views:

107

answers:

4

Hello Im not sure if this question should be placed here or in another forum. But here goes. Im currently in the beginning of a switching process forwards Emacs. However im having to basic problems, I cant seem to find an answer for on the internet (google).

A. How do I search for multiple files recursively from a specific path. I assume I have to use find/grep/dired but im not sure. For instance I would like to find all "*.scala" files at path "C:/src/xxx" When these files are found I would also like to open them all in the buffer at once. The only way Im currently familiar with is C-x C-f.

B. When all these files are in the buffer how do I then search across all the buffers, and get some kind of list of the result and/or perhaps able to navigate from result to result. Saying I would like to find all places with the text "case Int =>".

Im really looking forward to a solution to these problems:)

Thx in advance. Regards Stefan

+3  A: 

For Part A, you might look here.

For Part B you might have a look at multi-occur-in-matching-buffers, which let's you specify which buffers you want to take (e.g. all buffers .*.scala to look in all scala files) and what to look for (e.g. case Int =>). This gives you a list of all occurences.

phimuemue
+3  A: 

I concur with phimuemue's answer, but I'll point out M-x rgrep as well, which will run the necessary find/grep in order to present all of the matches without actually opening the files. Selecting a match then opens the relevant file at that line number. In some situations, this may be preferable to opening all of those files.

Also see these:

phils
A: 

I think you're artificially constraining the answer. You don't need to load all the files into Emacs in order to find those occurrences. And, once you've found the occurrences of the regexp, you can easily jump to the line in the file with a keystroke.

My favorite way to do this is to use M-x igrep-find because I like the igrep interface better than Emacs's grep-find.

You can find the igrep library on emacswiki: igrep.el

And the usage would be

M-x igrep-find case Int => RET

which would populate a buffer with all the matches, and then (like in occur, grep-find, compilation, etc.) you can use C-x ` or M-x next-error to cycle through the matches.

Trey Jackson
+1  A: 

You're trying to find all occurrences of "case Int =>" in *.scala files in C:/src

The easiest way (assuming a default Emacs setup) is to use M-x rgrep. It'll ask you for a search-string, file type and directory (in that order, and the prompts are labeled so there's no confusion). Just type in case Int =>, *.scala and C:/src/xxx.

What you should see is a new buffer with a list of occurrences of "case Int =>" in all .scala files in that directory. If you click on an occurrence, Emacs will open that file and navigate to the line that contains it.

As a note, if you're trying to do search and replace across multiple files, you can do that using dired options. You can find information on that option here.

Inaimathi