ClangFormat代码格式化

下载地址:https://github.com/travisjeffery/ClangFormat-Xcodegit

 

配合Xcode自带的格式化操做,就很不错了github

选中内容组合操做:xcode

第一步:ClangFormat(control+U)ui

第二步:XcodeFormat(control+I)spa

 

选中文件组合操做:插件

第一步:ClangFormat(control+shift+U)code

第二步:XcodeFormat(control+A,control+I)orm

 

修改ClangFormat.xcodeproj工程里的TRVSClangFormat.m文件的内容,实现快捷键功能(control+U和control+shift+U):blog

 1 - (void)addActioningMenuItemsToFormatMenu {
 2   NSMenuItem *formatActiveFileItem = [[NSMenuItem alloc]
 3       initWithTitle:NSLocalizedString(@"Format File in Focus", nil)
 4              action:@selector(formatActiveFile)
 5       keyEquivalent:@""];
 6   [formatActiveFileItem setTarget:self.formatter];
 7   [self.formatMenu addItem:formatActiveFileItem];
 8   NSMenuItem *formatSelectedCharacters = [[NSMenuItem alloc]
 9       initWithTitle:NSLocalizedString(@"Format Selected Text", nil)
10              action:@selector(formatSelectedCharacters)
11       keyEquivalent:@"u"]; //modified by Kenmu
12   [formatSelectedCharacters setKeyEquivalentModifierMask:NSControlKeyMask]; //created by Kenmu, in order to use shortcut key to access it.
13   [formatSelectedCharacters setTarget:self.formatter];
14   [self.formatMenu addItem:formatSelectedCharacters];
15   NSMenuItem *formatSelectedFilesItem = [[NSMenuItem alloc]
16       initWithTitle:NSLocalizedString(@"Format Selected Files", nil)
17              action:@selector(formatSelectedFiles)
18       keyEquivalent:@"u"]; //modified by Kenmu
19   [formatSelectedFilesItem setKeyEquivalentModifierMask:NSControlKeyMask | NSShiftKeyMask]; //created by, in order to use shortcut key to access it. Kenmu
20   [formatSelectedFilesItem setTarget:self.formatter];
21   [self.formatMenu addItem:formatSelectedFilesItem];
22 }

 

跟VVDocumenter规范注释生成器的安装方式同样:get

下载开源工程在Xcode从新编译运行会自动安装此插件,重启Xcode就可使用了

 

PS:可使用系统偏好设置中设置键盘里针对某应用程序的快捷键,以下操做:

 

插件设置:

 

使用方式:

 

 

相关文章
相关标签/搜索