自动格式化 - Eclipse C++

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16062600/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 20:23:07  来源:igfitidea点击:

Auto formatting - Eclipse C++

c++eclipseeclipse-cdt

提问by Nark

Hi all I'm trying to stop the auto formatting in eclipse from indenting my opening and close brace after a function that has a throw() statement on the end.

大家好,我试图阻止 eclipse 中的自动格式化在末尾有 throw() 语句的函数之后缩进我的左括号和右括号。

e.g

例如

void function(std::string param) throw()
{

}

after auto format will look like this:

自动格式化后将如下所示:

void function(std::string param) throw()
  {

  }

But it will carry on adding another tab to the front of the brackets every time I autoformat my code. Anyone know how I can turn this feature off, or is it a bug

但是每次我自动格式化我的代码时,它都会继续在括号的前面添加另一个选项卡。任何人都知道我如何关闭此功能,或者这是一个错误

Eclipse info: Version: Juno Release Build id: 20120614-1722 using CDT

Eclipse 信息:版本:Juno 发布版本 ID:20120614-1722 使用 CDT

Note:I am using my own code style profile.

注意:我使用的是我自己的代码样式配置文件。

回答by masoud

The name of that style is Whitesmiths- Try to change it to Allman.

该样式的名称是Whitesmiths- 尝试将其更改为Allman

In C/C++ perspective mode, Goto Window > Preferences > C/C++ > Code Style

在 C/C++ 透视模式下,转到 Window > Preferences > C/C++ > Code Style

enter image description here

在此处输入图片说明

Choose BSD/Allman or whatever you want.

选择 BSD/Allman 或任何你想要的。

回答by stdcall

You might want to consider Astyle, this is a eclipse plguin, an interface to a wondeful code beautyfication command line tool. you can set the indentation, formatting, etc. Very handy tool.

您可能要考虑Astyle,这是一个 Eclipse 插件,一个美妙的代码美化命令行工具的接口。您可以设置缩进、格式等。非常方便的工具。