Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tags in emacs with a large codebase

Tags:

emacs

tags

I was wondering how people use tags in emacs when working on a large codebase (approx. 50000 cpp|.h|.cs files). Some of my colleagues use indexing tools (names escape me) which return all the results over the codebase in seconds. I can't seem to get anywhere near that sort of performance on emacs and tags, but it's essentially the same thing!

Some approaches I've tried:

  1. Create one TAGS file for the whole repository. This is usually quite large and generally awkward to use (sometimes too many tags match).
  2. Create seperate TAGS files for cpp|h|cs. A bit more focused if I know (roughly (at least the programming language that will have been used)) what I happen to be looking for.
  3. Smaller tags files on a section of the repository. These are great when I'm pretty sure of the area but the management overhead is a pain. I'll usually generate these as and when needed.

Any suggestions \ examples of your workflow is appreciated.

like image 470
cristobalito Avatar asked Jun 26 '10 16:06

cristobalito


2 Answers

Here is a script I use:

#!/usr/bin/bash
echo "Creating list of files to build tags..."
find `pwd` -name '*.c' -o -name '*.h' > cscope_files

echo "Building cscope and ctags databases..."
cscope -bqki cscope_files
ctags -eL cscope_files

> cat cscope_files | wc -l
10700

For 10700 files which is comparable to your project, jumps between tags are instantaneous. As you'd notice this builds both cscope and etags databases. I start this script at the top of the tree. Also if this is of any help, these are the keybindings in my .emacs.el file.

(defun hide-cscope-buffer ()
  "Turn off the display of cscope buffer"
   (interactive)
   (if (not cscope-display-cscope-buffer)
       (progn
         (set-variable 'cscope-display-cscope-buffer t)
         (message "Turning ON display of cscope results buffer."))
     (set-variable 'cscope-display-cscope-buffer nil)
     (message "Toggling OFF display of cscope results buffer.")))


(global-set-key [f9] 'cscope-find-this-symbol)
(global-set-key [f10] 'cscope-find-global-definition-no-prompting)
(global-set-key [f11] 'cscope-find-functions-calling-this-function)
(global-set-key [f12] 'cscope-find-this-file)
(global-set-key (kbd "C-t") 'cscope-pop-mark)
(global-set-key (kbd "C-n") 'cscope-next-symbol)
(global-set-key (kbd "C-p") 'cscope-prev-symbol)
(global-set-key (kbd "C-b") 'hide-cscope-buffer)
(global-set-key [S-f7] 'cscope-next-file)
(global-set-key [S-f8] 'cscope-prev-file)
(global-set-key [S-f9] 'cscope-find-this-text-string)
(global-set-key [S-f10] 'cscope-find-global-definition)
(global-set-key [S-f11] 'cscope-find-egrep-pattern)                                                                                                                           
(global-set-key [S-f12] 'cscope-find-files-including-file)

I am not a regular emacs user though. These were used by me when I was trying to switch to emacs, but then reverted to vim, where I found ways to do all the things that I was happy doing in emacs.

Update: For multiple tags files in a directory hierarchy, take a look at the Multiple tags files section of this article.

like image 168
Sudhanshu Avatar answered Nov 11 '22 04:11

Sudhanshu


I wrote some packages to help with managing multiple tag hits and many TAGS files:

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

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

like image 34
scottfrazer Avatar answered Nov 11 '22 05:11

scottfrazer