My problem is that imenu or speedbar/semantic fails because of indentation. For this simple file, it is ok:
#include <iostream>
void bar() {
std::cout << "bar" << std::endl;
}
But if I want to put function bar in a namespace and indent its code:
with speedbar (having (require 'semantic/sb)
in init.el), I don't have the file tags in the speedbar frame, and I got "File mode specification error: (void-function c-subword-mode)" in minibuffer
with M-X imenu, I got "No items suitable for an index found in this buffer" in minibuffer
Exemple code that fails:
#include <iostream>
namespace foo {
void bar() {
std::cout << "bar" << std::endl;
}
}
It is not the namespace that makes it fail, but the identation. The following fails too:
#include <iostream>
void bar() {
std::cout << "bar" << std::endl;
}
Any idea why and how to have it to work?
Thanks!!
EDIT: Ok the solution is indeed speedbar+sementics. It actually works (I had something wrong in my init.el...)
Maybe, the example regexp from imenu.el
is used together with 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
))
The caret ^
at the beginning means beginning of line. If you insert [[:blank:]]*
behind it also function definitions with leading spaces are indexed.
I do not know whether stuff like
else if(...) {
...
}
gives false positives in this case. (You have to try.)
Actually, if I had sufficient time I would try to use semantic
or ctags
for the indexing. That would be much more robust.
Note, I did not try this. I just had a look at imenu.el
. (Currently, I do not have much spare time. Sorry.)