如何对这种函数定义进行格式化

时间:2018-02-14 19:25:50

标签: c clang clang-format

我想将我的C代码格式化为特定样式的函数定义,如下所示:

foo.c(其中“Arg”是一个类型/结构)

例1:

void *
foo(
    const Arg *arg1 /**< my arg */
)
{
...
}

例2

void *
foo(
    const Arg *arg1, /**< my arg */
    const Arg *arg2  /**< my arg2 */
)
{
...
}
  1. 返回类型后断开(AlwaysBreakAfterDefinitionReturnType) - 这可以正常工作
  2. 在功能名称后打破+打开parens
  3. 新行上的每个参数,缩进
  4. 关闭新线上的parens,取消缩进
  5. 我尝试了很多参数组合而没有成功......任何提示?

1 个答案:

答案 0 :(得分:1)

我不知道如何使用indent,但indent -i4 -cd24 -blf -bfda file.c 可以非常接近:

#import "RNNotification.h"
@implementation RNNotification

RCT_EXPORT_MODULE();

+ (id)allocWithZone:(NSZone *)zone {
    static RNNotification *sharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedInstance = [super allocWithZone:zone];
    });
    return sharedInstance;
}

- (NSArray<NSString *> *)supportedEvents
{
    return @[@"EventReminder"];
}

- (void)sendNotificationToReactNative
{
    [self sendEventWithName:@"EventReminder" body:@{@"name": @"name"}];
}

(除了那个关闭的人 - 不知道怎么做)。

相关问题