- Notifications
You must be signed in to change notification settings - Fork287
Xcode plug-in to to use clang-format from in Xcode and consistently format your code with Clang
License
travisjeffery/ClangFormat-Xcode
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
An Xcode plug-in to format your code using Clang's format tools, by@travisjeffery.
Withclang-format you can use Clang to format your code to styles such as LLVM, Google, Chromium, Mozilla, WebKit, or your own configuration.
Install viaAlcatraz.
OR
Clone this repo, build and run ClangFormat, restart Xcode.
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.
I.e., you presscommand-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.)
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 whencontrol-i
is pressed.
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 acool 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 theLinux Kernel style:
BasedOnStyle: LLVMIndentWidth: 8UseTab: AlwaysBreakBeforeBraces: LinuxAllowShortIfStatementsOnASingleLine: falseIndentCaseLabels: false
And this is similar to Visual Studio's style:
UseTab: NeverIndentWidth: 4BreakBeforeBraces: AllmanAllowShortIfStatementsOnASingleLine: falseIndentCaseLabels: falseColumnLimit: 0
About
Xcode plug-in to to use clang-format from in Xcode and consistently format your code with Clang
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.