Fre*_*ots 19 c++ code-formatting eclipse-cdt
CDT代码格式化程序有一个相当不错的选项选项,但似乎没有一个功能允许人们告诉它忽略代码块.Java代码格式化程序中存在此功能:
// @formatter:off
... // code that should not be formatted
// @formatter:on
Run Code Online (Sandbox Code Playgroud)
这个功能是否存在,我只是不知道它,或者有没有人知道任何体面的解决方案?
在我的特定情况下,我正在尝试定义我想要具有特定布局的数据结构(枚举类型和字符串数组).
使用Astyle(艺术风格)格式化程序,它远远优于Eclipse CDT内置格式化程序,并具有您需要的功能:
http://astyle.sourceforge.net/astyle.html#_Disable_Formatting
例:
#include <iostream>
int main(int argc, char** argv)
{
// *INDENT-OFF*
std::cout<<"hello world"<<'\n';
// *INDENT-ON*
}
Run Code Online (Sandbox Code Playgroud)
使用astyle格式化它不会在// INDENT-OFF和// INDENT-ON之间缩进代码,但它也会禁用astyle所做的任何其他格式化功能,例如本例中指令的间距.
我自己配置为外部工具.唯一的问题是,外部工具没有热键,但有一个热键"运行最后启动的外部工具",如果你只使用一个外部工具,它的工作原理相同.
有关配置(linux)的更多详细信息:
的astyle:
您可以从您的分发存储库或官方网站轻松获取它.
要使用格式设置设置配置文件:
http://astyle.sourceforge.net/astyle.html#_Options_File
我使用主文件夹变体,只需在$ HOME中创建一个.astylerc,我的包含:
--suffix=none
--style=allman
--indent=tab=4
--max-code-length=70
--close-templates
--keep-one-line-blocks
--break-elseifs
--break-closing-brackets
--align-reference=type
--align-pointer=type
--indent-classes
--indent-modifiers
--indent-switches
--indent-cases
--indent-labels
--indent-col1-comments
--min-conditional-indent=0
--pad-oper
--pad-header
--unpad-paren
Run Code Online (Sandbox Code Playgroud)
日食:
"运行"菜单 - >外部工具 - >外部工具配置...添加新的"程序"并在配置窗口中:
位置:/ usr/bin/astyle(使用whereis或locate来检查这个)
工作目录:$ {project_loc}
参数:$ {selected_resource_loc}
在同一窗口中,刷新选项卡:
完成后勾选刷新资源.
勾选"所选资源"
同一窗口,常用标签:
| 归档时间: |
|
| 查看次数: |
2943 次 |
| 最近记录: |