Permalink
Browse files

Major update to include a new "Uncrustify Document then Re-Indent" se…

…rvice.
1 parent 7654d26 commit ea1cd7e382b9ad3f6cc43527923168348bb32f22 @tonyarnold committed Nov 19, 2011
View
@@ -17,9 +17,10 @@ I will assume you have a basic understanding of installing software using a pack
2. Make sure that **uncrustify** is in your `$PATH` — you can verify this by opening a new terminal window and typing `which uncrustify` — if the full path to your copy of **uncrustify** is printed, you're set;
3. Copy or move the included workflow files into `~/Library/Services/`.
4. Open the "*Uncrustify Document*" using Automator, and update the line beginning with `set formatted_source` in the "*Run AppleScript*" block to reflect the path to your copy of uncrustify. It should look something like:
- `set formatted_source to do shell script "/usr/local/bin/uncrustify -f \"" & current_document_path & "\""`
+ `set formatted_source to do shell script "/usr/local/bin/uncrustify -c ~/.uncrustify.cfg -l OC -f " & quoted form of current_document_path`
+ 5. Do the same for the "*Uncrustify Document and Re-Indent*" automator workflow
4. Open the "*Uncrustify Selected Source Code.workflow*" documents in Automator, and update the "*Run Shell Script*" block to reflect the path to your copy of uncrustify. It should look something like:
- `/usr/local/bin/uncrustify -l OC -c ~/.uncrustify.cfg | cat`
+ `/usr/local/bin/uncrustify --frag -c ~/.uncrustify.cfg -l OC | cat`
## How do I use it? ##
@@ -29,7 +30,10 @@ Uncrustify will write over your source files with it's changes without asking yo
The "*Uncrustify Selected Source Code*" will only work with Objective-C documents due to the presence of the `-l OC` argument in the workflow script.
-The "*Uncrustify Document*" service will first save any changes you've made to the frontmost source document, and then run it through uncrustify. This service should work on any source code document (not just Objective-C documents).
+The "*Uncrustify Document*" service will first save any changes you've made to the frontmost source document, and then run it through uncrustify. It will also only work with Objective-C source code documents.
+
+The "*Uncrustify Document and Re-Indent*" service will first do the same thing as the "*Uncrustify Document*" service, but will then use Xcode's own "*Re-Indent*" function, which should mean that your final document format's indenting will match Xcode's editing style. It will also only work with Objective-C source code documents.
+
### How to ###
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>NSServices</key>
+ <array>
+ <dict>
+ <key>NSMenuItem</key>
+ <dict>
+ <key>default</key>
+ <string>Uncrustify Document then Re-Indent</string>
+ </dict>
+ <key>NSMessage</key>
+ <string>runWorkflowAsService</string>
+ <key>NSRequiredContext</key>
+ <dict>
+ <key>NSApplicationIdentifier</key>
+ <string>com.apple.dt.Xcode</string>
+ </dict>
+ </dict>
+ </array>
+</dict>
+</plist>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,208 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>AMApplicationBuild</key>
+ <string>330</string>
+ <key>AMApplicationVersion</key>
+ <string>2.2.1</string>
+ <key>AMDocumentVersion</key>
+ <string>2</string>
+ <key>actions</key>
+ <array>
+ <dict>
+ <key>action</key>
+ <dict>
+ <key>AMAccepts</key>
+ <dict>
+ <key>Container</key>
+ <string>List</string>
+ <key>Optional</key>
+ <true/>
+ <key>Types</key>
+ <array>
+ <string>com.apple.applescript.object</string>
+ </array>
+ </dict>
+ <key>AMActionVersion</key>
+ <string>1.0.1</string>
+ <key>AMApplication</key>
+ <array>
+ <string>Automator</string>
+ </array>
+ <key>AMParameterProperties</key>
+ <dict>
+ <key>source</key>
+ <dict/>
+ </dict>
+ <key>AMProvides</key>
+ <dict>
+ <key>Container</key>
+ <string>List</string>
+ <key>Types</key>
+ <array>
+ <string>com.apple.applescript.object</string>
+ </array>
+ </dict>
+ <key>ActionBundlePath</key>
+ <string>/System/Library/Automator/Run AppleScript.action</string>
+ <key>ActionName</key>
+ <string>Run AppleScript</string>
+ <key>ActionParameters</key>
+ <dict>
+ <key>source</key>
+ <string>on menu_click(mList) local appName, topMenu, r -- Validate our input if mList's length &lt; 3 then error "Menu list is not long enough" -- Set these variables for clarity and brevity later on set {appName, topMenu} to (items 1 through 2 of mList) set r to (items 3 through (mList's length) of mList) -- This overly-long line calls the menu_recurse function with -- two arguments: r, and a reference to the top-level menu tell application "System Events" to my menu_click_recurse(r, ((process appName)'s ¬ (menu bar 1)'s (menu bar item topMenu)'s (menu topMenu)))end menu_clickon menu_click_recurse(mList, parentObject) local f, r -- `f` = first item, `r` = rest of items set f to item 1 of mList if mList's length &gt; 1 then set r to (items 2 through (mList's length) of mList) -- either actually click the menu item, or recurse again tell application "System Events" if mList's length is 1 then click parentObject's menu item f else my menu_click_recurse(r, (parentObject's (menu item f)'s (menu f))) end if end tellend menu_click_recurseglobal current_documentglobal current_text_selection-- Get the currently frontmost source code document, and run uncrustify on it but rather than replacing the document, capture the formatted source and use AppleScript to update the document's contents before savingtell application "Xcode" set current_document to source document 1 whose name ends with (word -1 of (get name of window 1)) set current_text_selection to selection of current_document save current_document set current_document_path to path of current_document set raw_source to text of current_document set formatted_source to do shell script "/usr/local/bin/uncrustify -c ~/.uncrustify.cfg -l OC -f " &amp; quoted form of current_document_path set text of current_document to formatted_sourceend tell-- I wish there were a better way to do this, but Xcode's indenting is much better than uncrustify's for Objective-C source codetell application "Xcode" to activatemenu_click({"Xcode", "Edit", "Select All"})menu_click({"Xcode", "Editor", "Structure", "Re-Indent"})tell application "Xcode" to save current_document-- Deselect all texttell application "System Events" to keystroke (key code 126)</string>
+ </dict>
+ <key>BundleIdentifier</key>
+ <string>com.apple.Automator.RunScript</string>
+ <key>CFBundleVersion</key>
+ <string>1.0.1</string>
+ <key>CanShowSelectedItemsWhenRun</key>
+ <false/>
+ <key>CanShowWhenRun</key>
+ <true/>
+ <key>Category</key>
+ <array>
+ <string>AMCategoryUtilities</string>
+ </array>
+ <key>Class Name</key>
+ <string>RunScriptAction</string>
+ <key>InputUUID</key>
+ <string>154CE90C-823A-49C8-9A74-D8CE1B641BAE</string>
+ <key>Keywords</key>
+ <array>
+ <string>Run</string>
+ </array>
+ <key>OutputUUID</key>
+ <string>9EC7A124-B03D-471A-9438-BE11A4D7F90B</string>
+ <key>ShowWhenRun</key>
+ <false/>
+ <key>UUID</key>
+ <string>AA974E29-08D2-4934-9220-5E375B0D3CDC</string>
+ <key>UnlocalizedApplications</key>
+ <array>
+ <string>Automator</string>
+ </array>
+ <key>arguments</key>
+ <dict>
+ <key>0</key>
+ <dict>
+ <key>default value</key>
+ <string>on run {input, parameters}
+
+ (* Your script goes here *)
+
+ return input
+end run</string>
+ <key>name</key>
+ <string>source</string>
+ <key>required</key>
+ <string>0</string>
+ <key>type</key>
+ <string>0</string>
+ <key>uuid</key>
+ <string>0</string>
+ </dict>
+ </dict>
+ <key>isViewVisible</key>
+ <true/>
+ <key>location</key>
+ <string>572.500000:761.000000</string>
+ <key>nibPath</key>
+ <string>/System/Library/Automator/Run AppleScript.action/Contents/Resources/English.lproj/main.nib</string>
+ </dict>
+ <key>isViewVisible</key>
+ <true/>
+ </dict>
+ </array>
+ <key>connectors</key>
+ <dict/>
+ <key>state</key>
+ <dict>
+ <key>AMLogTabViewSelectedIndex</key>
+ <integer>1</integer>
+ <key>libraryState</key>
+ <dict>
+ <key>actionsMajorSplitViewState</key>
+ <dict>
+ <key>expandedPosition</key>
+ <real>269</real>
+ <key>subviewState</key>
+ <array>
+ <string>0.000000, 0.000000, 424.000000, 713.000000, NO</string>
+ <string>0.000000, 714.000000, 424.000000, 38.000000, NO</string>
+ </array>
+ </dict>
+ <key>actionsMinorSplitViewState</key>
+ <dict>
+ <key>expandedPosition</key>
+ <real>0.0</real>
+ <key>subviewState</key>
+ <array>
+ <string>0.000000, 0.000000, 163.000000, 713.000000, NO</string>
+ <string>164.000000, 0.000000, 260.000000, 713.000000, NO</string>
+ </array>
+ </dict>
+ <key>variablesMajorSplitViewState</key>
+ <dict>
+ <key>expandedPosition</key>
+ <real>0.0</real>
+ <key>subviewState</key>
+ <array>
+ <string>0.000000, 0.000000, 424.000000, 555.000000, NO</string>
+ <string>0.000000, 556.000000, 424.000000, 196.000000, NO</string>
+ </array>
+ </dict>
+ <key>variablesMinorSplitViewState</key>
+ <dict>
+ <key>expandedPosition</key>
+ <real>0.0</real>
+ <key>subviewState</key>
+ <array>
+ <string>0.000000, 0.000000, 163.000000, 555.000000, NO</string>
+ <string>164.000000, 0.000000, 260.000000, 555.000000, NO</string>
+ </array>
+ </dict>
+ </dict>
+ <key>majorSplitViewState</key>
+ <dict>
+ <key>expandedPosition</key>
+ <real>476</real>
+ <key>subviewState</key>
+ <array>
+ <string>0.000000, 0.000000, 424.000000, 797.000000, NO</string>
+ <string>425.000000, 0.000000, 1016.000000, 797.000000, NO</string>
+ </array>
+ </dict>
+ <key>minorSplitViewState</key>
+ <dict>
+ <key>expandedPosition</key>
+ <real>150</real>
+ <key>subviewState</key>
+ <array>
+ <string>0.000000, 0.000000, 1016.000000, 628.000000, NO</string>
+ <string>0.000000, 638.000000, 1016.000000, 140.000000, NO</string>
+ </array>
+ </dict>
+ <key>windowFrame</key>
+ <string>{{0, 4}, {1440, 874}}</string>
+ <key>workflowViewScrollPosition</key>
+ <string>{{0, 0}, {1016, 628}}</string>
+ </dict>
+ <key>workflowMetaData</key>
+ <dict>
+ <key>serviceApplicationBundleID</key>
+ <string>com.apple.dt.Xcode</string>
+ <key>serviceApplicationPath</key>
+ <string>/Developer/Applications/Xcode.app</string>
+ <key>serviceInputTypeIdentifier</key>
+ <string>com.apple.Automator.nothing</string>
+ <key>serviceOutputTypeIdentifier</key>
+ <string>com.apple.Automator.nothing</string>
+ <key>serviceProcessesInput</key>
+ <integer>0</integer>
+ <key>workflowTypeIdentifier</key>
+ <string>com.apple.Automator.servicesMenu</string>
+ </dict>
+</dict>
+</plist>

0 comments on commit ea1cd7e

Please sign in to comment.