Emacs缩进为C ++中的每个语句

时间:2022-10-10 22:31:39

I'm trying to get emacs to correctly format the "for each" construct in c++.

我正在尝试让emacs正确格式化c ++中的“for each”构造。

I want the braces to be lined up with the f in for in both of the following examples:

我希望在以下两个示例中将大括号与f in排成一行:

for each(Type a in b)
        { //^c^s shows substatement-open
            //... do stuff
        }

for( ; ; )
{ //^c^s shows substatement-open
    //... do stuff
}

In both cases, using [Ctrl-c Ctrl-s] (or [Ctrl-c Ctrl-o]) shows that both opening { characters are of type substatement-open and when viewing the c-offsets-alist I see that substatement-open is equal to 0.

在这两种情况下,使用[Ctrl-c Ctrl-s](或[Ctrl-c Ctrl-o])显示打开{字符的类型为substatement-open,当查看c-offsets-alist时,我看到该子语句 - open等于0。

How can I make emacs indent the for each() command similar to how it indents the for(;;) command?

我怎样才能使emac缩进for each()命令,类似于缩进for(;;)命令的方式?

2 个解决方案

#1


Presumably emacs is not recognising "for each" as c++ syntax (I don't either. Is this a microsoft extension? A preprocessor hack? New for the upcoming standard?). So there is no wonder that it is not formatting it "right".

据推测,emacs并没有将“for each”识别为c ++语法(我也没有。这是一个微软扩展吗?一个预处理器黑客?新标准的新版本?)。所以毫无疑问,它没有“正确”地格式化它。

You could hack the mode, or ask the maintainer of the same (I wouldn't expect a possitive response, though, unless this is going to be proper c++ Very Soon Now).

你可以破解模式,或者向维护人员询问相同的模式(我不会期望得到可能的反应,除非这将是正确的c ++很快就会出现)。


From the comments The answers to my parenthetical questions are:

从评论我的括号问题的答案是:

  • The precise form the OP asks about is a Microsoft managed-c++ extension.
  • OP提出的确切形式是Microsoft managed-c ++扩展。

  • There is BOOST_FOREACH available now
  • 现在有BOOST_FOREACH可用

  • The C++0x stand will include a container-ranged loop with a syntax like for( <type> <loopcounter> : <container> )
  • C ++ 0x stand将包含一个容器范围循环,其语法类似于( : )

and from slink's answer it appears that the mode maintainer is supporting the Microsoft syntax in the latest versions...

从slink的回答看来,模式维护者在最新版本中支持Microsoft语法......

#2


For me--under Emacs 23.0.91--the c++-mode indents the for each block as it was a normal for loop.

对我来说 - 在Emacs 23.0.91下 - c ++ - 模式缩进每个块,因为它是循环的正常。

#1


Presumably emacs is not recognising "for each" as c++ syntax (I don't either. Is this a microsoft extension? A preprocessor hack? New for the upcoming standard?). So there is no wonder that it is not formatting it "right".

据推测,emacs并没有将“for each”识别为c ++语法(我也没有。这是一个微软扩展吗?一个预处理器黑客?新标准的新版本?)。所以毫无疑问,它没有“正确”地格式化它。

You could hack the mode, or ask the maintainer of the same (I wouldn't expect a possitive response, though, unless this is going to be proper c++ Very Soon Now).

你可以破解模式,或者向维护人员询问相同的模式(我不会期望得到可能的反应,除非这将是正确的c ++很快就会出现)。


From the comments The answers to my parenthetical questions are:

从评论我的括号问题的答案是:

  • The precise form the OP asks about is a Microsoft managed-c++ extension.
  • OP提出的确切形式是Microsoft managed-c ++扩展。

  • There is BOOST_FOREACH available now
  • 现在有BOOST_FOREACH可用

  • The C++0x stand will include a container-ranged loop with a syntax like for( <type> <loopcounter> : <container> )
  • C ++ 0x stand将包含一个容器范围循环,其语法类似于( : )

and from slink's answer it appears that the mode maintainer is supporting the Microsoft syntax in the latest versions...

从slink的回答看来,模式维护者在最新版本中支持Microsoft语法......

#2


For me--under Emacs 23.0.91--the c++-mode indents the for each block as it was a normal for loop.

对我来说 - 在Emacs 23.0.91下 - c ++ - 模式缩进每个块,因为它是循环的正常。

相关文章