Home

Awesome

BBUncrustifyPlugin-Xcode

Xcode plugin to format code using Uncrustify or ClangFormat.

menu

preferences

Requirements

Xcode 6.0+ on OS X 10.10+.

PS: This fork works with Xcode 3.

Installation

Compiled Version

Script Version

Run on Terminal:


curl -SL https://raw.githubusercontent.com/benoitsan/BBUncrustifyPlugin-Xcode/master/install.sh | sh

Build from Source

To uninstall, just remove the plugin from ~/Library/Application Support/Developer/Shared/Xcode/Plug-ins and restart Xcode.

How does it work?

All the commands are in the menu Edit > Format Code.

Tips

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.

Style configuration

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:

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

ClangFormat: Predefined style or Custom style file

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.

Post Formatting options

In the plugin preferences, you can activate some post formatting operations:

Perform Xcode syntax-aware indenting

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.

Indent whitespace-only lines to code level

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).

Some Objective-C Style Guides

Using Uncrustify:

Some Style Guides:

Creator

Benoît Bourdon (@benoitsan). Thanks to the Contributors!

Additional contributors actually not listed here: Dominik Pich.

License

BBUncrustifyPlugin is available under the MIT license. See the LICENSE file for more info.