emacs 公共/受保护/私有标签缩进 C++头文件不适用于零偏移
即使我在 .emacs 文件中定义了 C++ 头文件的某些内容,我也无法获得零偏移量。
下面的头文件显示了两个命名空间内的类定义,最重要的是我希望具有零偏移量的 public 关键字,如下所示。
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
在我的 .emacs 文件中,我添加了如下标签:
(c-set-offset 'label 0)
我使用 Ctrl-C Ctrl-S 来查找要修改的内容。我在 .emacs 文件中定义的其他偏移量工作正常,并且 0 以外的值也适用于标签。
当我为标签设置偏移量 0 时,点击该行的 Tab 时结果为 1。这很奇怪,看起来像是其他东西覆盖或添加了至少 1。
任何人都可以解释我如何实现我想要的,也许还可以解释当前正在发生的事情?
唷,这是我的第一个问题。谢谢:)
更新:
感谢这些答案,我已经能够走得更远,但总体上仍然没有解决方案,因为更改访问器的总偏移量 0 所需的内容会导致其他我不想要的事情。这就是我目前所处的位置:
(c-set-offset 'access-label 0)
我还需要将 .h 文件理解为 C++,所以我添加了:
(add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))
仅此一项并没有删除我看到的 1 个偏移量,但似乎还有访问器的 inclass。将其设置为 0 实际上会导致总偏移量为 0。
(c-set-offset 'inclass 0)
问题是,现在其他东西(例如成员)的总数为 0,如下所示:
class Foo
{
public:
Foo();
~Foo();
为了解决这个问题,我将 topmost-intro 更改为偏移 4,
(c-set-offset 'topmost-intro 4)
这反过来又导致了同一文件中的内联函数声明等其他更改。总而言之,我不确定如何按照我想要的方式调整它。
UPDATE2:
添加了 SomeClass ctor 的内联声明,没有偏移量。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我相信你想要访问标签而不是标签。请参阅此处。
I believe you want access-label instead of label. See here.
您需要
access-label
而不是 label,如果 CC CS 给您((label 1))
这意味着您处于 C 模式而不是 C++ 模式(C 模式是.h
文件的默认值)。如果这是您的问题,请添加到 .h 文件的末尾或
开头。
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, addto the end of your .h file or
at the start.
我想你可能想使用负数。例如,在我的
c-offsets-alist
中,我有:然后在
.emacs
中:这让我得到了我想要的:
I think you may want to use a negative number. For example, in my
c-offsets-alist
, I have:Then in
.emacs
:Which gets me my desired:
如果使用
,则命名空间的左大括号不会增加缩进级别。
If you use
then the opening brace of a namespace does not increase the indentation level.