我的问题是 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(...) {
...
}
在这种情况下给出误报。 (你必须尝试。)
实际上,如果我有足够的时间,我会尝试使用 semantic
或 ctags
进行索引。那会更健壮。
请注意,我没有尝试过这个。我刚刚查看了 imenu.el
。 (目前,我没有多少空闲时间。抱歉。)
关于c++ - 由于 C++ 模式下的缩进,Emacs imenu 和 speedbar+semantic 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24408948/