我希望将源代码格式化程序Uncrustify与Vim 集成.以下两个选项中的任何一个都足够了.
gq按下时).选项1是优选的.我试过了
set formatprg=uncrustify\ -c ~/misc/uncrustify.cfg --no-backup
Run Code Online (Sandbox Code Playgroud)
即我用命令行选项调用Uncrustify.这不起作用.Vi给出了E518: Unknown option: ~/misc/uncrustify.cfg错误.
对于选项2,我在vimrc文件中尝试了以下内容
autocmd bufwritepost *.cpp ! ~/bin/uncrustify -c ~/misc/uncrustify.cfg --no-backup <afile>
Run Code Online (Sandbox Code Playgroud)
保存后文件格式化,但我必须手动将文件重新加载到Vim中.
我想知道是否有任何方法可以使用Uncrustify在嵌套的If-else中添加大括号.例如:
if( stat_error == -1 ){
if ( debug > 0 )
printf( "...ERROR ); //I would like to add braces around here.
exit( -1 );
} else {
Run Code Online (Sandbox Code Playgroud)
我看到了这个:
# Add or remove braces on single-line 'if' statement. Will not remove the braces if they contain an 'else'.
mod_full_brace_if = add # ignore/add/remove/force
Run Code Online (Sandbox Code Playgroud)
但它似乎不适用于嵌套条件.
有什么办法吗?
我的公司我设置了持续集成测试,当有人在服务器上推送代码时我会运行测试.
现在我想检查代码是否与我们的基本编码规则匹配,第一条规则是"在代码上运行mogrify!"
有什么可以检查"现成的"?这个分析的输出可以存储在文件或其他东西上.
谢谢
我正在尝试使用Allman Style获得可与Swift配合使用的UncrustifyX配置.我在Xcode中使用BBUncrustifyPlugin.这是我到目前为止所拥有的:
# indent using tabs
input_tab_size = 8
output_tab_size = 4
indent_columns = output_tab_size
indent_with_tabs = 1
# indent case
indent_switch_case = indent_columns
indent_case_brace = 0
# indent class body
indent_class = True
# newlines
nl_after_semicolon = true
# spaces
# add in general
sp_before_sparen = add
# but remove for
sp_version_paren = remove
sp_catch_paren = remove
sp_scope_paren = remove
sp_func_call_user_paren = remove
# Allman style for curly braces
nl_assign_brace = add
nl_enum_brace = add
nl_union_brace = add
nl_struct_brace …Run Code Online (Sandbox Code Playgroud) 我有一块看起来像这样的客观c代码
[paths enumerateObjectsUsingBlock:^(NSString * path, NSUInteger idx, BOOL * stop) {
BOOL isDir;
if ([fm fileExistsAtPath:path isDirectory:&isDir]) {
......
}
}];
Run Code Online (Sandbox Code Playgroud)
然而,在通过Uncrustify后,它变成了
[paths enumerateObjectsUsingBlock:^(NSString * path, NSUInteger idx, BOOL * stop) {
BOOL isDir;
if ([fm fileExistsAtPath:path isDirectory:&isDir]) {
......
}
}];
Run Code Online (Sandbox Code Playgroud)
反正有没有让Uncrustify将两个缩进合并为一个并保留代码的格式?
我试图找到在空行上留下空白的选项.目前unrustify将删除所有尾随空格(好!),但是我想保留空白,如果它在空白行,因为它通常是缩进级别.
这是一个空行nl_*选项还是缩进indent_*选项?我找不到一个做我想做的事情,甚至无法控制尾随空格选项!它只是默认情况下.
我对unrustify(v0.60)有一个非常特殊的问题,似乎没有选择影响.只有在括号内括号括起时才会出现此问题:
// from a C header file:
#define BEGIN_STACK_MODIFY(L) int __index = lua_gettop( (L) );
^ ^
// from an ObjC (.m) implementation file:
if ( (self = [super init]) )
^ ^
Run Code Online (Sandbox Code Playgroud)
我想重新格式化这些看起来像这样,但unrustify总是在括号之间添加这些空格(当我手动重新格式化到下面的代码时,uncrustify会将其重新格式化为上面的版本,所以它不仅仅被uncrustify忽略):
// from an ObjC header file:
#define BEGIN_STACK_MODIFY(L) int __index = lua_gettop((L));
// from an ObjC (.m) implementation file:
if ((self = [super init]))
Run Code Online (Sandbox Code Playgroud)
我使用UncrustifyX检查空间和括号可能相关设置的所有(好的,很多)变化而没有运气.
您可以在gist上查看我的uncrustify配置文件.
如果你知道我应该尝试什么设置,或者可能相互冲突的设置,我很乐意测试它.
我只想格式化源文件的一部分,例如函数而不是整个文件。
这是需要的,因为我无法完整格式化旧源。只有新添加的函数或函数的更改才应该通过 uncrustify 自动格式化。
uncrustify 是否可以进行基于选择的格式化?
也许可以对每个函数进行自动格式化,这些函数通过 git diff--function-context和 uncrustify 调用的组合进行更改。
git diff --function-context | uncrustify -xyc
如何在使用uncrustify调用super之后添加换行符
当前:
- (void)someFunction
{
[super someFunction];
more stuff;
and more stuff;
}
Run Code Online (Sandbox Code Playgroud)
期望:
- (void)someFunction
{
[super someFunction];
more stuff;
and more stuff;
}
Run Code Online (Sandbox Code Playgroud)
如何在界面声明和实现声明之前和之后添加换行符
当前:
@interface SCLoginScreenViewController ()
@property (weak, nonatomic) IBOutlet UIView *someView;
@property (weak, nonatomic) IBOutlet UIView *anotherView;
@end
@implementation SCLoginScreenViewController
- (void)someFunction
{
}
Run Code Online (Sandbox Code Playgroud)
期望:
@interface SCLoginScreenViewController ()
@property (weak, nonatomic) IBOutlet UIView *someView;
@property (weak, nonatomic) IBOutlet UIView *anotherView;
@end
@implementation SCLoginScreenViewController
- (void)someFunction
{
}
Run Code Online (Sandbox Code Playgroud)
我一直在查看atom-beautify站点和示例.jsbeauifyrc、.editorconfig 和uncrustify.cgf 文件。
我还回顾了原子美化的选项。我知道我应该指定配置文件在atom-beautify 设置中的位置。我尝试将 .jsbeautifyrc 文件、uncrustify.cfg 文件以及这两个文件放在我在atom-beautify 设置中指定的同一目录中。它没有任何效果。使用默认设置。我想让一些旧的 C++ 代码对于我当前的项目和我的团队正在开发的未来项目看起来更加统一。
总而言之,我想在 Atom 编辑器中使用 uncrustify(使用atom-beautify 包)让我的 C++ 代码看起来更漂亮。
uncrustify ×10
objective-c ×3
atom-editor ×1
coding-style ×1
git ×1
if-statement ×1
ios ×1
javascript ×1
node.js ×1
swift ×1
vim ×1
xcode ×1