views:

507

answers:

7

Hello,

Maybe is a often repeated question here, but i can't find anything similar with the search. The point is that i like to use Emacs for my personal projects, usually very small applications using C or python, but i was wondering how to use it also for my work, in which we have project with about 10k files of source code, so is veeeery big (actually i am using source insight, that is very nice tool, but only for windows), questions are:

  • Searching: Which is the most convenient way to search a string within the whole project?
  • Navigating throught the function: I mean something like putting the cursor over a function, define, var, and going to the definition
  • Refactoring

Also if you have any experience with this and want to share your thoughts i will consider it highly interesting.

Br

+7  A: 

The "traditional" way of navigating C source files is to use "etags" to make a file called TAGS, then use ALT-. to go to functions across files.

For searching for strings in files, I usually use "grep". You could make a shell script with all the directories you want to search or something if you get tired of typing them in each time.

Kinopiko
Actually, etags stands for emacs tags, which is just one of the formats that exuberant ctags can produce. When exuberant ctags is invoked using the name etags, it produces emacs format tag files. When it is invoked using the name ctags, it produces ctags format files. Of course, you can also pass it command-line options to control which format is used regardless of the name used to invoke the tool.
jamessan
very interesting, any special hint for using grep in more convenient way, i mean i found very slow to enter every time the grep options and search path
ignatius
OK I removed the bit about exuberant.
Kinopiko
+1  A: 

look to EDE from CEDET - it provide base support for projects...

Alex Ott
+4  A: 

There is also the Emacs Code Browser. It makes exploring projects a lot simpler. See here and here for more information.

pmr
+1  A: 

Regarding searches in the whole project, I find extremely useful the rgrep command.

Also, imenu is quite handy to jump to a function definition in the same file.

These are my 2p.

Roberto Aloi
thanks i will take a look at this imenu function
ignatius
+1  A: 

In addition to using TAGS as others have mentioned, I find igrep and igrep-find very useful. There is also Emacs' built in grep and grep-find, but I find their interface more clumsy.

My standard search is:

M-x igrep-find some_regexp RET ~/work_area/*.cxx

Which will look for all *.cxx files under ~/work/area, and show results matching some_regexp. Like all the search utilities, it populates a compilation-like buffer you can navigate using C-x ` (aka M-x next-error).

Trey Jackson
+6  A: 

My projects typically live in git, so I put this together to quickly search them:

;; There's something similar (but fancier) in vc-git.el: vc-git-grep
;; -I means don't search through binary files
(defcustom git-grep-switches "--extended-regexp -I -n --ignore-case"
  "Switches to pass to `git grep'."
  :type 'string)

(defun git-grep (command-args)
  (interactive
   (list (read-shell-command "Run git-grep (like this): "
                             (format "git grep %s -e "
                                     git-grep-switches)
                             'git-grep-history)))
  (let ((grep-use-null-device nil))
    (grep command-args)))
offby1
wow, i also use git, that's so useful and fast!!! thanks
ignatius
+1 for git grep, though it's handy to keep tags around too.
Matt Curtis
If anyone's reading this and doesn't have their project in git, I find ack is nicer than grep for searching code. It doesn't search as fast (though it's not much slower on a pretty big codebase) but it is much faster to type "ack blah" than "find . -name "*.cc" -o -name "*.h" -exec grep blah {} \;" :-)
Matt Curtis
How about M-x tags-search instead of grep?
Eddy Pronk
The problem with M-x tags-search is that you must first create a TAGS file, and occasionally that's difficult. For example, I don't think etags will do anything sensible with a Visual Studio build file, but I want to search through those, too.
offby1
+1  A: 

ECB is too heavyweight for my taste. I have had good results with xcscope. Needless to say it doesn't help too much with Python.

http://www.emacswiki.org/emacs/CScopeAndEmacs

daladd