Apple's example projects often have the variable names aligned, in addition to their type specification/general code indentation:
NSUInteger level;
double fadeSpeed;
CGPoint ballPosition;
int keyOffset;
As opposed to:
NSUInteger level;
double fadeSpeed;
CGPoint ballPosition;
int keyOffset;
Is there a shortcut to make this happen? (I don't know what it would be called or else I could search the docs for it.)
It sounds like you're looking for Uncrustify. I've not used it in anger myself, but the feature list seems to include your requirement:
Features
- Ident code, aligning on parens, assignments, etc
- Align on '=' and variable definitions
- Align structure initializers
- Align #define stuff
- Align backslash-newline stuff
- Reformat comments (a little bit)
- Fix inter-character spacing
- Add or remove parens on return statements
- Add or remove braces on single-statement if/do/while/for statements
- Supports embedded SQL 'EXEC SQL' stuff
- Highly configurable - 412 configurable options as of version 0.59
The popular pretty-printer uncrustify
has at least a dozen different variable alignment parameters that you can specify in its config file. Tony Arnold's project shows you how to use uncrustify
as an automator service (which means that you can access it from Xcode or any other editor). Robert Payne suggests using it from a shell script that you can incorporate into your build process.
My guess is that Apple runs its examples through uncrustify
or some other pretty-printer before publishing so that they're all formatted using a common style. It may take some fiddling if you want to exactly reproduce Apple's style, but at a minimum it should be pretty easy to get your variable declarations to align the way you want. It's been a while since I played with all the options, but I'd start by looking at the align_var_def_span
, align_var_def_thresh
, and align_var_def_gap
settings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With