Emacs源代码导航功能

tha*_*ath 6 emacs cedet emacs-semantic

我正在开发一个大型的c ++项目.我在过去的六个月里一直在使用emacs.我尝试配置CEDET以便能够轻松导航但我发现了一些问题.

1.-有时语义不会找到一些符号,有时候他不会...我不清楚哪些文件是语义索引.我曾尝试使用EDE(按照本文中的说明http://alexott.net/en/writings/emacs-devenv/EmacsCedet.html),但我也发现了一些问题......

  • 我有同一个项目的多个版本(Releases),每个版本都在自己的文件夹中.我如何告诉emacs我正在使用哪个项目?
  • 我如何告诉ede在哪里查找我的头文件?我可以只指定一个根目录,语义将在所有子目录中搜索头文件吗?

2.-前段时间我正在使用vim + cscope,我记得有一种方法可以在符号堆栈中导航回来(Ctrl-t).在emacs中有这样的东西吗?

PD>一些数据使问题更加清晰.

我有同一个项目的多个版本.每个人都有自己的根目录.每个项目都有多个模块,每个模块都在一个子目录中.每个模块都有头文件.

/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
Run Code Online (Sandbox Code Playgroud)

这是我在.emacs中的EDE配置

;; 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" . "")
                                )
)
Run Code Online (Sandbox Code Playgroud)

只是为了让你知道......我正在使用emacs的控制台版本(-nw).

Eri*_*ric 2

除了项目的 :include-path 之外,您的配置基本上是正确的。

如果给定的源文件显示:

   #include "Module-001/subdir-002/header-003.h"
Run Code Online (Sandbox Code Playgroud)

那么就可以了。如果包含说:

   #include "subdir-002/header-003.h"
Run Code Online (Sandbox Code Playgroud)

那么你的 :include-path 应该有

   :include-path '("/Module-001" )
Run Code Online (Sandbox Code Playgroud)

在里面。

至于哪些东西做语义索引,它会索引你当前的文件,所有包含它能找到的东西。使用语义修饰模式查看 EDE 为您找到了哪些标头,以确定您的配置是否准确。

它还会索引与您正在编辑的目录相同的所有文件,但仅限于空闲时间,因此如果您不让 Emacs 空闲,它就不会抽出时间来处理它。

如果按照 Bozhidar 的建议使用 CScope,则可以加快索引操作速度。然后,您可以在 EDE 和语义数据库中启用 CScope 支持。然而,语义 DB 中最近才包含 CScope 支持,因此您需要 CEDET 的 CVS 版本。这将确保整个内容都被索引。

要向后导航,请研究语义 mru 书签模式的帮助。这会在指定位置的基础上跟踪您的文件进度,非常方便且始终有效。