Emacs源代码导航功能

发布于 2024-09-15 05:19:17 字数 3424 浏览 4 评论 0原文

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

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

  • 我有同一项目的多个版本(发行版),每个版本都在自己的文件夹中。我如何告诉 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

这是我在 .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" . "")
                                )
)

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

染火枫林 2024-09-22 05:19:17

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

如果给定的源文件显示:

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

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

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

那么你的 :include-path 应该包含

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

在其中。

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

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

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

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

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.

梦在深巷 2024-09-22 05:19:17

我过去在处理 C++ 项目时使用过 Emacs 代码浏览器,我发现它非常令人满意 - 在除了出色的文件和代码结构导航之外,您还可以获得出色的 VCS 集成(根据项目中文件的当前状态使用不同的图标)。结合 ECB,我在 Emacs 中使用了 cscope,因为您在 vim 中提到过,您可能也想在 Emacs 中使用它。

或者,如果您想要更简单的解决方案,您可以查看 Emacs Nav。它也支持一些奇特的东西,并且不依赖于语义和速度栏 - 您只需要使用 etags/ctags 来索引您的项目。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文