如何以clang格式对齐函数参数名称? [英] How can I align function parameter names in clang-format?

查看:110
本文介绍了如何以clang格式对齐函数参数名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用 clang-format 将结构成员和函数参数名称格式化为列?

Is it possible to use clang-format to format struct members and function parameter names into columns?

例如:

struct
{
   int           alpha; //aligned to 'b' of "beta"
   unsigned int  beta;
   MyObject     *gamma; //aligned with 'g' not '*'
};

void foobar (int           alpha, //aligned to 'b' of "beta"
             unsigned int  beta
             MyObject     *gamma) //aligned with 'g' not '*'
{
}

如果不可能,我可以通过某种方式扩展clang格式来实现这一目标吗?

If it's not possible, could I extend clang-format somehow to achieve this?

推荐答案

好吧,你可以接近.

对于函数声明:

您可以设置 BinPackParameters = false ,这将强制函数声明的所有参数都在一行上,或者每个参数在不同的行上,并且它们将按照您显示的方式对齐.

You can set BinPackParameters=false, which will force that all the parameters of a function declaration are either on one line or each on a different line, and they will be aligned as you show.

(但不能在类型和标识符之间使用制表符停靠点.现在无法使用clang格式afaik.)

(But not with tab stops in between types and identifiers. That is not possible in clang format right now afaik.)

此外,请参见选项 AllowAllParametersOfDeclarationOnNextLine

即使BinPackParameters为false,也允许将函数声明的所有参数放在下一行.

Allow putting all parameters of a function declaration onto the next line even if BinPackParameters is false.

对于结构,我认为您无法实现.

For structs, I don't think you can achieve this.

过去我曾经为clang格式编写过补丁,我认为要像您建议的那样进行对齐将需要大量工作.您必须自己编写一些C ++到clang lib格式才能支持此操作.

Having written patches for clang-format myself in the past, I think it would be a lot of work to get the alignment like you are suggesting. You would have to write a fair bit of C++ yourself into clang lib format to support this.

这篇关于如何以clang格式对齐函数参数名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆