Xcode plugin to format code using Uncrustify or ClangFormat.
Xcode 6.0+ on OS X 10.10+.
PS: This fork works with Xcode 3.
- The easiest way to install the plugin is to download the lastest release.
- Unzip and copy
UncrustifyPlugin.xcplugin
to~/Library/Application Support/Developer/Shared/Xcode/Plug-ins
. - Relaunch Xcode after the copy.
Run on Terminal:
curl -SL https://raw.githubusercontent.com/benoitsan/BBUncrustifyPlugin-Xcode/master/install.sh | sh
-
Build the Xcode project. The plug-in will automatically be installed in
~/Library/Application Support/Developer/Shared/Xcode/Plug-ins
. -
Relaunch Xcode.
To uninstall, just remove the plugin from ~/Library/Application Support/Developer/Shared/Xcode/Plug-ins
and restart Xcode.
All the commands are in the menu Edit > Format Code
.
-
Use the menu
Format Selected Files
to format the selected items in the project navigator. -
Use the menu
Format Active File
to format the source file actually opened in the editor. -
Use the menu
Format Selected Lines
to format the selected source code (multiple selection is supported). The selection is automatically extended in full lines. If the selection is empty, it uses the line under the cursor. -
Use the menu
Edit Configuration
to edit the formatter configuration in an external editor. -
Use the menu
BBUncrustifyPlugin Preferences
to change the plugin preferences.
When the code is reformated, the modifications are recorded in the undo. So undo reverts the modifications.
The Preferences window contains detailed informations to customize the formatter settings.
You can create keyboard shortcuts for the menu items in the Keyboard Preferences of OS X System Preferences.
Use the menu Edit > Format Code > View Log
to identify issues when formatting.
The plugin includes binaries for ClangFormat and Uncrustify. To use your own version, install the binary to: /usr/local/bin/clang-format
or /usr/bin/clang-format
for ClangFormat, /usr/local/bin/uncrustify
or /usr/bin/uncrustify
for Uncrustify.
When formatting a code selection, keep in mind that formatting selected lines can fail depending of the selected scope.
-
Uncrustify assumes the first selected line is indented correctly.
-
ClangFormat takes in account the scope around the selection.
To create the initial configuration file, you can use the button "Create Configuration File" in the preferences window.
The configuration file must be located in the current directory or any parent directories of the source file. The search is started from the current directory. The plugin looks for the following file name patterns, in the order priority shown:
-
For ClangFormat:
_clang-format
.clang-format
-
For Uncrustify:
uncrustify.cfg
_uncrustify.cfg
.uncrustify.cfg
.uncrustifyconfig
- In addition: your Home Folder and
~/.uncrustify/uncrustify.cfg
So lets say you have a project with subproject1 (team1) and subproject2 (team2), you can use a structure like that:
root project folder
| subproject1
| config_file -> team1
| subproject2
| config_file -> team2
When using ClangFormat, you can use a predefined non editable style or a custom file. The plugin will use the style defined in the preferences window in the "Clang Style" section: LLVM, Google, Chromium, Mozilla, WebKit, or, Custom File.
In the plugin preferences, you can activate some post formatting operations:
When enabled, the plugin re-indents the code using Xcode. By default, this feature is not selected because it overwrites the indentation performed by the formatter.
Both ClangFormat and Uncrustify always trim whitespace-only lines. When enabled, the plugin re-indents empty lines to the code level. This option is disabled if "Including Whitespace-only lines" is enabled in Xcode preferences (Xcode Preferences > Text Editing Tab > Editing Panel > While Editing).
Using Uncrustify:
Some Style Guides:
Benoît Bourdon (@benoitsan). Thanks to the Contributors!
Additional contributors actually not listed here: Dominik Pich.
BBUncrustifyPlugin is available under the MIT license. See the LICENSE file for more info.