Eclipse如何缩进c++预处理器宏。

时间:2022-11-25 11:02:39

I can't find a setting in eclipse so that I can have it automatically indent my preprocessor macros the same way it indents code. For example eclipse tries to format code like this.

我在eclipse中找不到设置,因此我可以让它自动缩进我的预处理器宏,就像它缩进代码一样。例如,eclipse尝试这样格式化代码。

int main()
{
#ifdef SOMETHING
     cout << "Something Defined" << endl;
#endif
    return 0;
}

Whereas I want it to look like...

而我想让它看起来……

int main()
{
    #ifdef SOMETHING
     cout << "Something Defined" << endl;
    #endif
    return 0;
}

Any ideas to make eclipse do it how I want?

有什么办法可以让eclipse按照我的意愿来做吗?

5 个解决方案

#1


2  

Pre-ANSI C preprocessor did not allow for space between the start of a line and the "#" character; the leading "#" had to always be placed in the first column.

前ansi C预处理器不允许在行开始和“#”字符之间留出空间;开头的“#”必须始终放在第一列。

Pre-ANSI C compilers are non-existent these days. Use which ever style (space before "#" or space between "#" and the identifier) you prefer.

ansi之前的C编译器现在已经不存在了。使用您喜欢的样式(“#”之前的空格或“#”和标识符之间的空格)。

But I suggest you do this: Eclipse如何缩进c++预处理器宏。

但我建议你这样做:

Just use Find/Replace dialog and the push "Replace all"

只需使用查找/替换对话框并按下“替换全部”

#2


1  

The Eclipse indentation is correct. Preprocessor directives should be on the leftmost column, regardless of the indentation of the surrounding code.

Eclipse缩进是正确的。预处理器指令应该位于最左边的列,而不考虑周围代码的缩进。

#3


1  

I think there is no option for macro indentation. But I see clangformat seems to have option for macro indentation so you can customize your own clang format (http://clang.llvm.org/docs/ClangFormatStyleOptions.html) and configure eclipse to use clangformat instead of the default.

我认为宏缩进没有选择。但是我看到clangformat似乎有宏缩进选项,所以您可以定制自己的clang格式(http://clang.llvm.org/docs/ClangFormatStyleOptions.html),并配置eclipse使用clangformat而不是默认的clangformat。

#4


1  

To indent the preprocessor you might need to use Neatbens instead. It's formatter disregard the preANSIc.

要缩进预处理器,您可能需要使用tidy bens。这是不顾前提的形式。

#5


0  

Like others already pointed out compiler directives # have to start in the first column to be standard conform. Nevertheless it is allowed to put spaces behind them. So my preferred solution looks as follows and then it should no longer be an eclipse issue.

像其他人已经指出的那样,编译器指令#必须从第一列开始,才能符合标准。然而,它被允许在它们后面放置空间。因此,我首选的解决方案如下所示,那么它应该不再是eclipse问题。

int main()
{
#  ifdef SOMETHING
     cout << "Something Defined" << endl;
#  endif
}

#1


2  

Pre-ANSI C preprocessor did not allow for space between the start of a line and the "#" character; the leading "#" had to always be placed in the first column.

前ansi C预处理器不允许在行开始和“#”字符之间留出空间;开头的“#”必须始终放在第一列。

Pre-ANSI C compilers are non-existent these days. Use which ever style (space before "#" or space between "#" and the identifier) you prefer.

ansi之前的C编译器现在已经不存在了。使用您喜欢的样式(“#”之前的空格或“#”和标识符之间的空格)。

But I suggest you do this: Eclipse如何缩进c++预处理器宏。

但我建议你这样做:

Just use Find/Replace dialog and the push "Replace all"

只需使用查找/替换对话框并按下“替换全部”

#2


1  

The Eclipse indentation is correct. Preprocessor directives should be on the leftmost column, regardless of the indentation of the surrounding code.

Eclipse缩进是正确的。预处理器指令应该位于最左边的列,而不考虑周围代码的缩进。

#3


1  

I think there is no option for macro indentation. But I see clangformat seems to have option for macro indentation so you can customize your own clang format (http://clang.llvm.org/docs/ClangFormatStyleOptions.html) and configure eclipse to use clangformat instead of the default.

我认为宏缩进没有选择。但是我看到clangformat似乎有宏缩进选项,所以您可以定制自己的clang格式(http://clang.llvm.org/docs/ClangFormatStyleOptions.html),并配置eclipse使用clangformat而不是默认的clangformat。

#4


1  

To indent the preprocessor you might need to use Neatbens instead. It's formatter disregard the preANSIc.

要缩进预处理器,您可能需要使用tidy bens。这是不顾前提的形式。

#5


0  

Like others already pointed out compiler directives # have to start in the first column to be standard conform. Nevertheless it is allowed to put spaces behind them. So my preferred solution looks as follows and then it should no longer be an eclipse issue.

像其他人已经指出的那样,编译器指令#必须从第一列开始,才能符合标准。然而,它被允许在它们后面放置空间。因此,我首选的解决方案如下所示,那么它应该不再是eclipse问题。

int main()
{
#  ifdef SOMETHING
     cout << "Something Defined" << endl;
#  endif
}