Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

emacs - "go to beginning of the function" doesn't work if function is enclosed in a namespace (C++)

In emacs, I use C-M-a and C-M-e to go the beginning/end of functions in C++ code. However, this functionality no longer works if the function is enclosed in a namespace (it just jumps to the beginning or end of the namespace enclosure). Does anyone have a good solution for this?

like image 296
daj Avatar asked Jun 13 '12 14:06

daj


2 Answers

This is a known bug. It has been fixed in Emacs 24.1 which has been released three days ago. Get it. Unfortunately that fix has never been back-ported and it is unlikely that this will happen anytime soon.

like image 115
pmr Avatar answered Sep 28 '22 10:09

pmr


Getting Emacs 24.1 which fixes the issue is the best course. If you are stuck on an older version of Emacs, a common work around was to use a preprocessor macro.

#define NAMESPACE_BEGIN(X) namespace X {
#define NAMESPACE_END      }

NAMESPACE_BEGIN(tools)

class Foo {
    //...
};

NAMESPACE_END

Some practitioners of this had other reasons. I personally liked how it prevented the default Emacs settings from indenting namespace'd code.

like image 37
jxh Avatar answered Sep 28 '22 10:09

jxh