缩进很奇怪——修复或选择一个替代方案
indent being odd -- fix or choose an alternative
我 运行 indent
有参数 -npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1
,除了两个障碍之外一切都很好:
1) 它倾向于在 mytype_t * my;
等语句中的 *
之后添加一个额外的 space,即
void my_function(my_type *ptr)
变成
void my_function(my_type * ptr)
2) 它在 (uint16_t *) & q->drops
等表达式中的 &
符号后放置额外的 space 即
stats->drops = (uint16_t *) &q->drops
变成
stats->drops = (uint16_t *) & q->drops
运行 indent
带 -nss
或不带 -ss
都不能解决问题。
有没有办法告诉 indent
不要这样做?如果不是,indent
的替代方案是什么?
谢谢。
解决方案
% indent -T my_type -T uint16_t
经过一番搜索,我找不到删除类型和指针之间的 space 的选项。奇怪的是,只有当该类型以 _t
结尾时才会发生这种情况。因此,这可能无法回答您的问题。然而 indent
的一个很好的替代是 astyle
。对于您正在寻找的样式,您可以使用这些标志:
astyle --style=kr --indent=tab
我真的希望这对您有所帮助。
来自 man indent
:
You must use the '-T'
option to tell indent the name of all the
typenames in your program that are defined by typedef. '-T'
can be
specified more than once, and all names specified are used. For
example, if your program contains
typedef unsigned long CODE_ADDR;
typedef enum {red, blue, green} COLOR;
you would use the options -T CODE_ADDR -T COLOR
.
所以 indent
似乎不知道 stdint.h
类型,所以你必须通过传递 -T uint16_t -T mytype_t
让它知道你正在使用它们
我 运行 indent
有参数 -npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1
,除了两个障碍之外一切都很好:
1) 它倾向于在 mytype_t * my;
等语句中的 *
之后添加一个额外的 space,即
void my_function(my_type *ptr)
变成
void my_function(my_type * ptr)
2) 它在 (uint16_t *) & q->drops
等表达式中的 &
符号后放置额外的 space 即
stats->drops = (uint16_t *) &q->drops
变成
stats->drops = (uint16_t *) & q->drops
运行 indent
带 -nss
或不带 -ss
都不能解决问题。
有没有办法告诉 indent
不要这样做?如果不是,indent
的替代方案是什么?
谢谢。
解决方案
% indent -T my_type -T uint16_t
经过一番搜索,我找不到删除类型和指针之间的 space 的选项。奇怪的是,只有当该类型以 _t
结尾时才会发生这种情况。因此,这可能无法回答您的问题。然而 indent
的一个很好的替代是 astyle
。对于您正在寻找的样式,您可以使用这些标志:
astyle --style=kr --indent=tab
我真的希望这对您有所帮助。
来自 man indent
:
You must use the
'-T'
option to tell indent the name of all the typenames in your program that are defined by typedef.'-T'
can be specified more than once, and all names specified are used. For example, if your program contains
typedef unsigned long CODE_ADDR;
typedef enum {red, blue, green} COLOR;
you would use the options
-T CODE_ADDR -T COLOR
.
所以 indent
似乎不知道 stdint.h
类型,所以你必须通过传递 -T uint16_t -T mytype_t