emacs 公共/受保护/私有标签缩进 C++头文件不适用于零偏移

发布于 2024-10-09 01:36:18 字数 1385 浏览 2 评论 0原文

即使我在 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

压抑⊿情绪 2024-10-16 01:36:18

我相信你想要访问标签而不是标签。请参阅此处

I believe you want access-label instead of label. See here.

满地尘埃落定 2024-10-16 01:36:18

您需要 access-label 而不是 label,如果 CC CS 给您 ((label 1)) 这意味着您处于 C 模式而不是 C++ 模式(C 模式是 .h 文件的默认值)。如果这是您的问题,请添加

// Emacs, please set these
// Local Variables: ***
// mode: c++ ***
// End: ***

到 .h 文件的末尾或

// -*- C++ -*-

开头。

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.

心意如水 2024-10-16 01:36:18

我想你可能想使用负数。例如,在我的 c-offsets-alist 中,我有:

(inclass . +)

然后在 .emacs 中:

(c-set-offset 'access-label -1)

这让我得到了我想要的:

class A {
 public:
  A();
  ...

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();
  ...
策马西风 2024-10-16 01:36:18

如果使用

(c-set-offset 'innamespace 0)

,则命名空间的左大括号不会增加缩进级别。

If you use

(c-set-offset 'innamespace 0)

then the opening brace of a namespace does not increase the indentation level.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文