Emacs source code navigation features

2.7k views Asked by At

I am working on a large c++ project. I am working with emacs for the last six months. I have try to configure CEDET so as to be able to navigate easily but i have found some problems.

1.- Sometimes semantic does not find some symbols and sometimes he don't ... i do not know clearly which files is semantic indexing. I have tried to use EDE (following the instructions in this paper http://alexott.net/en/writings/emacs-devenv/EmacsCedet.html), but i have found some problems also...

  • I have multiple version ( Releases) of the same project, each one in its own folder. How can i tell emacs which project i am working with?
  • How can i tell ede where to look for my header files? Can I specify just a root directory and semantic will search for header files in all the subdirectories?

2.- I was working with vim+cscope some time ago and i remember there was a way to navigate back in the stack of symbols (Ctrl-t). Is there anything like this in emacs?

P.D.> Some data to make the question more clear.

I have multiple releases of the same project. Each one has its own root directory. Each project has multiple modules each one inside a subdirectory. There are headers file in each module.

/home/user/
          |
           \Release-001
          |           |
          |            \makefile
          |            \ Module-001
          |           |           |
          |           |            \makefile
          |           |            \subdir-001
          |           |           |          \header-001.h
          |           |           |          \header-002.h
          |           |            \subdir-002
          |           |           |          \header-003.h
          |            \ Module-002
          |           |           |
          |           |            \makefile
          |           |            \subdir-003
          |           |           |          \header-004.h
          |           |           |          \header-005.h
          |           |            \subdir-004
          |           |           |          \header-006.h
          |
           \Release-002
          |           |
          |            \makefile
          |            \ Module-001
          |           |           |
          |           |            \makefile
          |           |            \subdir-001
          |           |           |          \header-001.h
          |           |           |          \header-002.h
          |           |            \subdir-002
          |           |           |          \header-003.h
          |            \ Module-002
          |           |           |
          |           |            \makefile
          |           |            \subdir-003
          |           |           |          \header-004.h
          |           |           |          \header-005.h
          |           |            \subdir-004
          |           |           |          \header-006.h

This is the configuration about EDE i have in my .emacs

;; Cedet load commands
(add-to-list 'load-path "~/emacs-dir/cedet/cedet")
(load-file "~/emacs-dir/cedet/cedet/common/cedet.el") 

;; EDE: activating mode.
(global-ede-mode t)

;; Projects definition
(ede-cpp-root-project "Release-001"
                     :name "Release-001"
                     :file "~/Release-001/makefile"
                     :include-path '("/"
                                     )
                     :system-include-path '("~/exp/include")
                     :spp-table '(("SUSE9" . "")
                                )
)
(ede-cpp-root-project "Release-002"
                     :name "Release-002"
                     :file "~/Release-002/makefile"
                     :include-path '("/"
                                     )
                     :system-include-path '("~/exp/include")
                     :spp-table '(("SUSE9" . "")
                                )
)

Just to let you know ... I am working with the console version ( -nw) of emacs.

2

There are 2 answers

2
Eric On BEST ANSWER

Your configuration is basically correct, except for the :include-path for your projects.

If a given source file says:

   #include "Module-001/subdir-002/header-003.h"

then it is ok. If the include says:

   #include "subdir-002/header-003.h"

then your :include-path should have

   :include-path '("/Module-001" )

in it.

As for which things does semantic index, it will index your current file, and all includes it can find. Use the semantic-decoration mode to see which headers EDE has found for you to determine if your configuration is accurate.

It will also index all files in the same directory as the one you are editing, but only in idle time, so if you don't let Emacs be idle, it won't get around to it.

You can speed the indexing operations up if you use CScope as Bozhidar suggests. You can then enable the CScope support in both EDE and the Semantic database. The inclusion of CScope support in Semantic DB is recent, however, so you would need the CVS version of CEDET. That would make sure the whole thing was indexed.

To navigate backward, investigate the help for semantic-mru-bookmark-mode. This tracks your progress through your files on a named location basis that is quite handy and always works.

0
Bozhidar Batsov On

I had used in the past the Emacs Code Browser when working on C++ projects and I found it very satisfactory - in a addition to great files and code structure navigation you get excellent VCS integration(different icons according to current state of a file in the project). In conjunction with ECB I used cscope for Emacs, since you mentioned in for vim, you'll probably want to use it in Emacs as well.

Alternatively if you want a simpler solution you might have a look at Emacs Nav. It supports some fancy stuff as well and has no dependency to semantic and speedbar - you'll only have to use etags/ctags to index your project.