ClangFormat-Xcode

Xcode 插件,用于在 Xcode 中使用 clang-format,并始终如一地使用 Clang 格式化你的代码。「Xcode plug-in to to use clang-format from in Xcode and consistently format your code with Clang」

Github星跟踪图

ClangFormat-Xcode

An Xcode plug-in to format your code using Clang's format tools, by @travisjeffery.

With clang-format you can use Clang to format your code to styles such as LLVM, Google, Chromium, Mozilla, WebKit, or your own configuration.

usage

demo

Installation:

:warning: From XCode 8+, unsigning is required in order to use community-made plugins.
Check https://github.com/inket/update_xcode_plugins for more information.

Install via Alcatraz.

OR

Clone this repo, build and run ClangFormat, restart Xcode.

Removing ClangFormat

To remove ClangFormat, run the following in your terminal:

rm -r "~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/ClangFormat.xcplugin"

Or just find the same file and move it to the trash. You'll need to restart Xcode after deleting the plugin.

Usage:

Format on save

I.e., you press command-s and the file is formatted and wrote to disk.

In the menu, open Edit > Clang Format > Click Format on save (a checkmark appears in this menu item indicicating that the feature is active.)

Assign keyboard shortcuts

You can assign your own keyboard shortcuts like so:

  • Open the System Preferences > Keyboard > Shortcuts > App Shortcuts > Click +
  • Set the application to be Xcode
  • Set the menu title to an action title, e.g. "Format File in Focus"
  • Set your shortcut

In this example, we'll format the active file when control-i is pressed.

assign keyboard shortcut

Using your own style configuration

By using Clang Format > File in the plug-in menu, Clang will look for the nearest .clang-format file from the input file. Most likely, you'll have a .clang-format file at the root of your project.

Here are the options for .clang-format and how they're configured. Here's a cool interactive website to help you make your .clang-format file.

If one of the built-in styles is close to what you want, you can bootstrap your own configuration with:

./bin/clang-format -style=llvm -dump-config > .clang-format

For example, this .clang-format is similar to the Linux Kernel style:

BasedOnStyle: LLVM
IndentWidth: 8
UseTab: Always
BreakBeforeBraces: Linux
AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: false

And this is similar to Visual Studio's style:

UseTab: Never
IndentWidth: 4
BreakBeforeBraces: Allman
AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: false
ColumnLimit: 0

主要指标

概览
名称与所有者travisjeffery/ClangFormat-Xcode
主编程语言Objective-C
编程语言Objective-C (语言数: 1)
平台Mac
许可证MIT License
所有者活动
创建于2014-01-07 12:24:05
推送于2020-11-04 02:36:32
最后一次提交2020-11-04 03:36:30
发布数0
用户参与
星数2.9k
关注者数101
派生数286
提交数149
已启用问题?
问题数87
打开的问题数32
拉请求数32
打开的拉请求数2
关闭的拉请求数17
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?