c++ - 由于 C++ 模式下的缩进,Emacs imenu 和 speedbar+semantic 失败

标签 c++ emacs emacs-semantic emacs-speedbar

我的问题是 imenu 或 speedbar/semantic 由于缩进而失败。对于这个简单的文件,没问题:

#include <iostream>
void bar() {
   std::cout << "bar" << std::endl;
}

但是如果我想将函数 bar 放在命名空间中并缩进其代码:

  • 使用 speedbar(在 init.el 中有 (require 'semantic/sb)),我在 speedbar 框架中没有文件标签,我得到了“文件模式规范”错误:(void-function c-subword-mode)”在迷你缓冲区中

  • 使用 M-X imenu,我在迷你缓冲区中得到“没有适合在此缓冲区中找到的索引的项目”

失败的示例代码:

#include <iostream>

namespace foo {
    void bar() {
    std::cout << "bar" << std::endl;
    }
}

使它失败的不是 namespace ,而是标识。以下也失败了:

#include <iostream>
    void bar() {
       std::cout << "bar" << std::endl;
    }

知道为什么以及如何让它工作吗?

谢谢!!

编辑:好的,解决方案确实是 speedbar+sementics。它确实有效(我的 init.el 中有问题...)

最佳答案

也许,imenu.el 中的示例正则表达式与 imenu-example--create-c-index 一起使用:

(defvar imenu-example--function-name-regexp-c
  (concat
   "^[a-zA-Z0-9]+[ \t]?"        ; type specs; there can be no
   "\\([a-zA-Z0-9_*]+[ \t]+\\)?"    ; more than 3 tokens, right?
   "\\([a-zA-Z0-9_*]+[ \t]+\\)?"
   "\\([*&]+[ \t]*\\)?"         ; pointer
   "\\([a-zA-Z0-9_*]+\\)[ \t]*("    ; name
   ))

开头的插入符号 ^ 表示行首。如果你在它后面插入 [[:blank:]]* 也会索引带有前导空格的函数定义。

不知道是不是这样

else if(...) {
...
}

在这种情况下给出误报。 (你必须尝试。)

实际上,如果我有足够的时间,我会尝试使用 semanticctags 进行索引。那会更健壮。

请注意,我没有尝试过这个。我刚刚查看了 imenu.el。 (目前,我没有多少空闲时间。抱歉。)

关于c++ - 由于 C++ 模式下的缩进,Emacs imenu 和 speedbar+semantic 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24408948/

相关文章:

c++ - 强制机器使用专用显卡?

emacs - 如何关闭不再需要的缓冲区

emacs - 如何在windows下mintty下以CLI模式运行emacs?

Emacs/CEDET。多个项目和代码完成

c++ - 在 Netbeans 中使用 Eigen 库

c++ - 如何等待有效输入

c++ - 如何在二维数组 (C++) 中检查我周围单元格的邻居?

使用 Emacs 进行 Python 开发?

emacs - 使用语义定位符号时出现"void-variable last-command-char"错误

c++ - 奇怪的语义错误