Mar 23, 2011

Xcode + AStyle. Part 2. (for Xcode 4.x)

Anar here...

Long time ago I've described a recipe to use astyle from within Xcode 3.x.

Now as you may know, Xcode 4 doesn't provide the "user script" menu. I knew about it since Xcode 4 developer preview versions, but kept hoping the menu item would be back.
This didn't happen :( We have now a stable release of Xcode 4 and there is no sign of user's script in it.

What I think is that Apple either couldn't implement a support for "user script" or they want us to use automator services.
So, now I try to use automator to accomplish the same as I did in XCode 3's user script menu.


#1
Run Automator. Start a new service workflow.

#2
Select, that you service will receives selected "text" and check that it will "Replace selected text"

#3
Drag the "Run Shell Scrip" to your workflow and add commands as in the following screenshot:

Save your service and now when you want to re-indent your code, just select the whole source file content and select your service from the service menu. Works OK, but there are some drawbacks, see below (at the very end of the post).

Of course you must write the path to your own astyle option file, in my case I use "/Users/anar/Documents/workspace/Support/astylerc", as you can see on the screenshot, which sets the following:
#Indent a C or C++ file.
mode=c
# ANSI style formatting/indenting
style=ansi
# Do not retain a backup of the original file
suffix=none
# Indent 'class' and 'struct' blocks so that the blocks 'public:', 'protected:' and 'private:' are indented.
indent-classes
# Indent 'switch' blocks so that the 'case X:' statements are indented in the switch block.
indent-switches
# Indent 'case X:' blocks from the 'case X:' headers.
indent-cases
# Add extra indentation to namespace blocks.
indent-namespaces
# Indent multi-line preprocessor definitions ending with a backslash.
indent-preprocessor
# Converts tabs into single spaces.
convert-tabs
# Set the minimal indent that is added when a header is built of multiple-lines.
min-conditional-indent=0
# Indent a maximum of # spaces in a continuous statement
max-instatement-indent=80
# Insert space padding around operators.
pad=oper
# Insert space padding around parenthesis on the inside only. 
pad=paren-in
# Remove extra space padding around parenthesis on the inside and outside.
unpad=paren


Drawbacks

The following is the only, what I found so far:

  • Unfortunately I don't see any way to keep the potision of the cursor after the service is called.
  • One should select the whole file content and execute the service on it. Which is inconvenient in some cases. I didn't find a way to get a file name of the current file, which I could then provide to the service.

7 comments:

Gabriel Gatzsche said...

Many thanks for this great tutorial. Its so useful to me that I have created a video tutorial:

http://www.youtu.be/d8bbE6_OHGc

Best,
Gabriel

Kabir said...





Thank you for sharing this information and Very good looking blog on

Buy One Plus x Case Online

oakleyses said...

louboutin pas cher, nike free, polo ralph lauren outlet online, louis vuitton, polo outlet, nike air max, longchamp pas cher, jordan shoes, ray ban sunglasses, gucci handbags, tiffany and co, jordan pas cher, cheap oakley sunglasses, louis vuitton outlet, oakley sunglasses, christian louboutin uk, nike free run, sac longchamp pas cher, nike air max, oakley sunglasses, longchamp outlet, prada outlet, kate spade outlet, longchamp outlet, louis vuitton, oakley sunglasses wholesale, polo ralph lauren, longchamp outlet, christian louboutin outlet, chanel handbags, louis vuitton outlet, tiffany jewelry, michael kors pas cher, replica watches, replica watches, ray ban sunglasses, ugg boots, burberry pas cher, tory burch outlet, nike roshe, oakley sunglasses, louis vuitton outlet, ray ban sunglasses, prada handbags, ugg boots, nike outlet, christian louboutin shoes, uggs on sale, christian louboutin

oakleyses said...

guess pas cher, north face, lululemon canada, michael kors, michael kors outlet online, true religion outlet, oakley pas cher, nike free uk, michael kors outlet, abercrombie and fitch uk, hollister uk, true religion outlet, hollister pas cher, ray ban pas cher, polo lacoste, north face uk, michael kors outlet online, coach outlet store online, ray ban uk, mulberry uk, burberry handbags, michael kors outlet, hogan outlet, nike blazer pas cher, nike air max, nike air max uk, true religion outlet, uggs outlet, coach outlet, nike air force, nike air max uk, sac hermes, uggs outlet, michael kors outlet, michael kors, michael kors outlet online, nike roshe run uk, vans pas cher, true religion jeans, replica handbags, ralph lauren uk, sac vanessa bruno, burberry outlet, nike tn, coach purses, new balance, michael kors outlet online, kate spade, timberland pas cher

oakleyses said...

hermes belt, hollister, lancel, abercrombie and fitch, chi flat iron, instyler, north face outlet, louboutin, asics running shoes, nfl jerseys, ferragamo shoes, new balance shoes, mont blanc pens, vans outlet, celine handbags, hollister clothing, mcm handbags, mac cosmetics, beats by dre, giuseppe zanotti outlet, converse outlet, nike air max, longchamp uk, oakley, reebok outlet, bottega veneta, nike air max, timberland boots, insanity workout, nike trainers uk, gucci, lululemon, baseball bats, soccer shoes, soccer jerseys, north face outlet, valentino shoes, wedding dresses, hollister, nike roshe run, vans, ray ban, babyliss, jimmy choo outlet, nike huaraches, p90x workout, ghd hair, ralph lauren, herve leger, iphone cases

oakleyses said...

ugg,uggs,uggs canada, barbour uk, moncler outlet, coach outlet, ugg,ugg australia,ugg italia, moncler, thomas sabo, canada goose, moncler outlet, links of london, canada goose outlet, juicy couture outlet, moncler uk, pandora jewelry, montre pas cher, marc jacobs, replica watches, louis vuitton, moncler, canada goose jackets, swarovski, pandora charms, canada goose outlet, toms shoes, moncler, swarovski crystal, doudoune moncler, louis vuitton, moncler, pandora jewelry, ugg, barbour, louis vuitton, hollister, canada goose outlet, karen millen uk, ugg pas cher, supra shoes, canada goose, juicy couture outlet, louis vuitton, wedding dresses, pandora uk, canada goose, ugg uk, canada goose uk, louis vuitton

nora nor said...

Your website is extremely helpful. Thanks for sharing
http://www.prokr.net/2016/09/carpet-cleaning-companies-7.html
http://www.prokr.net/2016/09/carpet-cleaning-companies-6.html
http://www.prokr.net/2016/09/carpet-cleaning-companies-5.html