Skip to content

Commit

Permalink
Merge pull request #2 from yieldmo/installation-n-usage
Browse files Browse the repository at this point in the history
Installation and usage
  • Loading branch information
yieldmo-rao authored Sep 13, 2016
2 parents 45c76f4 + 0fb4de0 commit 2025088
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
# uncrustifier
A simple Xcode 8 extension that wraps https://github.com/uncrustify/uncrustify/

## build + installation
1. Build using Xcode 8+.
1. If you are using macOS 10.11, run ```sudo /usr/libexec/xpccachectl``` and restart your machine.
1. Replace /Uncrustify/uncrustify.cfg with your desired configuration file.
1. Open Uncrustifier.xcodeproj and run the Uncrustify target. Choose Xcode as the host application.

## usage

Editor > Uncrustify > Format Current Document

![](readme-images/demo.gif)

The extension will format the active file.

## contributing

Feel free to send bugs or feature requests [here](https://github.com/yieldmo/uncrustifier/issues).

[Pull requests](https://github.com/yieldmo/uncrustifier/pulls) are also welcome!
4 changes: 4 additions & 0 deletions Uncrustify/SourceEditorCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ class SourceEditorCommand: NSObject, XCSourceEditorCommand {
task.standardInput = invocation.buffer.completeBuffer
task.standardOutput = outputPipe
task.launchPath = commandPath

// configure uncrustify to format with bundled uncrustify.cfg, format for Objective-C, and strip messages
task.arguments = [ "-c=\(commandConfigPath)","-l=OC","-q"]

let inputPipe = Pipe()
task.standardInput = inputPipe
let stdinHandle = inputPipe.fileHandleForWriting

// write text to stdin (where uncrustify reads from)
if let data = invocation.buffer.completeBuffer.data(using: .utf8) {
stdinHandle.write(data)
stdinHandle.closeFile()
Expand All @@ -51,6 +54,7 @@ class SourceEditorCommand: NSObject, XCSourceEditorCommand {

}

// fixes crash if there is no selection when completion handler is called
invocation.buffer.selections.add(XCSourceTextRange(start: XCSourceTextPosition(line: 0, column: 0), end: XCSourceTextPosition(line: 0, column: 0)))

completionHandler(nil)
Expand Down
Binary file added readme-images/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2025088

Please sign in to comment.