简体   繁体   English

如何使用 uncrustify 对齐 function 声明?

[英]How to align function declaration using uncrustify?

I'm trying to replicate the GNU coding standard using uncrustify.我正在尝试使用 uncrustify 复制 GNU 编码标准。 My program has the following function declarations,我的程序有以下 function 声明,

static void connect_to_server_cb1 (GObject      *source_object,
                                   GAsyncResult *result,
                                   gpointer      user_data);

static gboolean connect_to_server_cb2 (GObject     *source_object,
                                   GAsyncResult *result,
                                   gpointer      user_data);

static void connect_to_server_cb3 (GObject      *source_object,
                                   GAsyncResult *result,
                                   gpointer      user_data);

I'm expecting output as follows,我期待 output 如下,

static void     connect_to_server_cb1 (GObject      *source_object,
                                       GAsyncResult *result,
                                       gpointer      user_data);

static gboolean connect_to_server_cb2 (GObject      *source_object,
                                       GAsyncResult *result,
                                       gpointer      user_data);

static void     connect_to_server_cb3 (GObject      *source_object,
                                       GAsyncResult *result,
                                       gpointer      user_data);

Which config option I should try to achive this?我应该尝试哪个配置选项来实现这一点?

I'm not sure that uncrustify can do exactly what you want.我不确定 uncrustify 是否可以完全满足您的要求。 You could try to post-process the output with the gcu-lineup-parameters program from GNOME C Utils , which Nautilus already uses for example.您可以尝试使用GNOME C Utils中的gcu-lineup-parameters程序对 output 进行后处理,例如,Nautilus 已经使用了该程序。 The Nautilus source tree contains a run-uncrustify.sh script which does this for each file: Nautilus 源代码树包含一个run-uncrustify.sh 脚本,它为每个文件执行此操作:

# Aligning prototypes is not working yet, so avoid headers
"$UNCRUSTIFY" -c "$DATA/uncrustify.cfg" --no-backup "$FILE"
"$DATA/lineup-parameters" "$FILE" > "$FILE.temp" && mv "$FILE.temp" "$FILE"

This should work if you only want to process the.c files, but the comment suggests that aligning prototypes in headers is more difficult.如果您只想处理 .c 文件,这应该可以工作,但评论表明在标题中对齐原型更加困难。

    # Whether to align variable definitions in prototypes and functions.
    align_func_params               = true     # true/false

    # How to consider (or treat) the '*' in the alignment of variable definitions.
    #
    # 0: Part of the type     'void *   foo;' (default)
    # 1: Part of the variable 'void     *foo;'
    # 2: Dangling             'void    *foo;'
    # Dangling: the '*' will not be taken into account when aligning.
    align_var_def_star_style        = 2        # unsigned number

    # How to consider (or treat) the '&' in the alignment of variable definitions.
    #
    # 0: Part of the type     'long &   foo;' (default)
    # 1: Part of the variable 'long     &foo;'
    # 2: Dangling             'long    &foo;'
    # Dangling: the '&' will not be taken into account when aligning.
    align_var_def_amp_style         = 2        # unsigned number

    # The span for aligning function prototypes.
    #
    # 0: Don't align (default).
    align_func_proto_span           = 4        # unsigned number

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM