使用Uncrustify不仅在逗号处完全拆分长函数定义 我使用 unCRusivtV0.60来格式化我的C++源代码。为了配置Uncrustify,我使用的是UniversalIndentGUI v1.2.0 rev.1070
在UniversalIndentGUI的使用Uncrustify不仅在逗号处完全拆分长函数定义 我使用 unCRusivtV0.60来格式化我的C++源代码。为了配置Uncrustify,我使用的是UniversalIndentGUI v1.2.0 rev.1070,c++,code-formatting,uncrustify,C++,Code Formatting,Uncrustify,在UniversalIndentGUI的行分割选项部分,我已将代码宽度设置为120 假设我有以下示例代码: namespace MyNameSpace { class MyClass { public: std::map< std::string, MyOtherClass* >* ConstructMyOtherClassMap( std::vector< std::string >* allNames, int arg0, do
行分割选项
部分,我已将代码宽度
设置为120
假设我有以下示例代码:
namespace MyNameSpace
{
class MyClass
{
public:
std::map< std::string, MyOtherClass* >* ConstructMyOtherClassMap( std::vector< std::string >* allNames, int arg0, double arg1, char arg2 );
}
}
不幸的是,在当前的未锈蚀状态下,这是不可能的。因此,您最好用以下方式配置您提到的选项:
nl_func_decl_start = ignore
nl_func_def_start = ignore
nl_func_decl_start_single = ignore
nl_func_def_start_single = ignore
ls_func_split_full = true
并在适当的情况下手动包装第一个参数。然而,就我个人而言,我认为这不是一个好主意。让它自动执行惰性/按需包装。例如,我喜欢上面列出的设置,并且在任何可能的情况下仍然有非常简洁的代码。下面是一些例子
无换行-构造函数参数和构造函数初始值设定项列表都适合最大行长度:
PluginDialog::
PluginDialog(QString const& path, QStringList const& fileNames, QWidget* parent): QDialog(parent), label(new QLabel), treeWidget(new QTreeWidget), okButton(new QPushButton(tr("OK"))) {
// ...
}
现在它们不适合,按照惯例,我们决定首先包装初始值设定项列表:
PluginDialog::
PluginDialog(QString const& path, QStringList const& fileNames, QWidget* parent): QDialog(parent),
label(new QLabel),
treeWidget(new QTreeWidget),
okButton(new QPushButton(tr("OK"))) {
// ...
}
也可以采用相反的惯例:
PluginDialog::
PluginDialog(QString const& path,
QStringList const& fileNames,
QWidget* parent): QDialog(parent), label(new QLabel), treeWidget(new QTreeWidget), okButton(new QPushButton(tr("OK"))) {
// ...
}
PluginDialog::
PluginDialog(
QString const& path,
QStringList const& fileNames,
QWidget* parent): QDialog(parent),
label(new QLabel),
treeWidget(new QTreeWidget),
okButton(new QPushButton(tr("OK"))) {
// ...
}
现在,前两种情况中的任何一种都不适合,因此它们中的任何一种都会合并到下一种也是唯一可能的配置中:
PluginDialog::
PluginDialog(QString const& path,
QStringList const& fileNames,
QWidget* parent): QDialog(parent),
label(new QLabel),
treeWidget(new QTreeWidget),
okButton(new QPushButton(tr("OK"))) {
// ...
}
PluginDialog::
PluginDialog(
QString const& path,
QStringList const& fileNames,
QWidget* parent):
QDialog(parent),
label(new QLabel),
treeWidget(new QTreeWidget),
okButton(new QPushButton(tr("OK"))) {
// ...
}
现在我们不再适应,按照惯例,我们决定将构造函数初始值设定项列表列移到构造函数参数列表列下:
PluginDialog::
PluginDialog(QString const& path,
QStringList const& fileNames,
QWidget* parent):
QDialog(parent),
label(new QLabel),
treeWidget(new QTreeWidget),
okButton(new QPushButton(tr("OK"))) {
// ...
}
顺便说一下,我们又有了分支情况,也就是说,这也是可能的:
PluginDialog::
PluginDialog(QString const& path,
QStringList const& fileNames,
QWidget* parent): QDialog(parent), label(new QLabel), treeWidget(new QTreeWidget), okButton(new QPushButton(tr("OK"))) {
// ...
}
PluginDialog::
PluginDialog(
QString const& path,
QStringList const& fileNames,
QWidget* parent): QDialog(parent),
label(new QLabel),
treeWidget(new QTreeWidget),
okButton(new QPushButton(tr("OK"))) {
// ...
}
最后,前两种情况中的任何一种都不适合,因此它们中的任何一种都会合并到最终和唯一可能的配置中:
PluginDialog::
PluginDialog(QString const& path,
QStringList const& fileNames,
QWidget* parent): QDialog(parent),
label(new QLabel),
treeWidget(new QTreeWidget),
okButton(new QPushButton(tr("OK"))) {
// ...
}
PluginDialog::
PluginDialog(
QString const& path,
QStringList const& fileNames,
QWidget* parent):
QDialog(parent),
label(new QLabel),
treeWidget(new QTreeWidget),
okButton(new QPushButton(tr("OK"))) {
// ...
}
如果Uncrustify像Jindent一样提供“避免混淆压痕”选项,那就太好了。在本例中,最后一个代码段的示例如下所示:
PluginDialog::
PluginDialog(
QString const& path,
QStringList const& fileNames,
QWidget* parent):
QDialog(parent),
label(new QLabel),
treeWidget(new QTreeWidget),
okButton(new QPushButton(tr("OK"))) {
// ...
}
这显然更具可读性和愉悦性。我提出这个特性是为了不生锈。然而,我怀疑我们能否很快看到它的实施,因为这个项目的作者似乎忙于其他事情,或者对积极开发这个项目不再感兴趣。对于我来说(使用Uncrustify 0.63),为了实现你想要的,它采用以下组合:
在函数声明中的“(”之后添加或删除换行符
nl_func_decl_start = add
在函数定义中的“(”之后添加或删除换行符
nl_func_def_start = add
nl_func_def_args = add
nl_func_def_end = add
当只有一个参数时,重写nl_func_decl_start
nl_func_decl_start_single = remove
当只有一个参数时,重写nl_func_def_start
nl_func_def_start_single = remove
nl_func_decl_end_single = remove
nl_func_def_end_single = remove
在函数声明中的每个“,”之后添加或删除换行符
nl_func_decl_args = add
nl_func_decl_end = add
在函数定义中的每个“,”之后添加或删除换行符
nl_func_def_start = add
nl_func_def_args = add
nl_func_def_end = add
在函数声明中,在“')之前添加或删除换行符
nl_func_decl_args = add
nl_func_decl_end = add
在函数定义中“')之前添加或删除换行符
nl_func_def_start = add
nl_func_def_args = add
nl_func_def_end = add
当只有一个参数时,重写nl_func_decl_end
nl_func_def_start_single = remove
nl_func_decl_end_single = remove
nl_func_def_end_single = remove
当只有一个参数时,重写nl_func_def_end
nl_func_def_start_single = remove
nl_func_decl_end_single = remove
nl_func_def_end_single = remove
紧凑型(无需解释):
有没有更新过Uncrustify 0.63?你实现了你想要的吗?@mtb:我不再使用Uncrustify了,所以我没有测试过这个。不过,从你的回答来看,你似乎已经自己弄明白了。