How can I align function parameter names in clang-format?

后端 未结 3 1958
渐次进展
渐次进展 2021-01-13 20:36

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

For example:

struct
{
   int                


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-13 20:50

    Well, you can get close.

    For function declarations:

    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.

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

    Also, see the option AllowAllParametersOfDeclarationOnNextLine

    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.

    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.

提交回复
热议问题