I cannot get zero offset for some things for my C++ header files in emacs even if I have it defined in my .emacs file.
The header file below shows a class definition inside two namespaces and most importantly the public keyword I would like to have with zero offset like below.
namespace n1
{
namespace n2 // no offset
{
class SomeClass // no offset from namespace open curly
{
public: // this line with zero offset
SomeClass(); // offset 4
...
};
inline SomeClass::SomeClass() // no offset
{
}
} // n2
} // n2
In my .emacs file I have added label like this:
(c-set-offset 'label 0)
I used Ctrl-C Ctrl-S to find开发者_开发知识库 out what to modify. Other offsets I have defined in the .emacs file are working fine and also values other than 0 work for label.
When I set offset 0 for label it turns out to be 1 when hitting tab for that line. This is strange and looks like something else is overriding or adding a minimum of 1.
Can anyone explain how I can achieve what I want and maybe also an explanation what is happening currently?
Phew, this was my first question here. Thanks :)
UPDATE:
Thanks to the answers I have been able to get a bit farther, but still no solution overall, because changing the things necessary to get total offset 0 for the accessors result in other things I don't want. Thsi is where I'm currently:
(c-set-offset 'access-label 0)
I also needed to get the .h file to be understoor as C++, so I added:
(add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))
This alone is not removing the 1 offset I was seeing, but it seems there is also inclass for the accessor. Setting this to 0 actually results in total 0 offset.
(c-set-offset 'inclass 0)
Problem is that now other things such as members are with total of 0 like below:
class Foo
{
public:
Foo();
~Foo();
To remedy this I changed topmost-intro to offset 4
(c-set-offset 'topmost-intro 4)
Which in turn resulted in other changes for e.g. inline function declarations in the same file. All in all, I'm not sure how to tweak this the way I want it.
UPDATE2:
Added inline declaration of SomeClass ctor with no offset.
I believe you want access-label instead of label. See here.
You want access-label
instead of label, and if C-C C-S gave you ((label 1))
that's mean you are in C mode and not in C++ mode (C mode is the default for .h
files). If this is your problem, add
// Emacs, please set these
// Local Variables: ***
// mode: c++ ***
// End: ***
to the end of your .h file or
// -*- C++ -*-
at the start.
If you use
(c-set-offset 'innamespace 0)
then the opening brace of a namespace does not increase the indentation level.
I think you may want to use a negative number. For example, in my c-offsets-alist
, I have:
(inclass . +)
Then in .emacs
:
(c-set-offset 'access-label -1)
Which gets me my desired:
class A {
public:
A();
...
精彩评论