Align on colons in Objective-C headers
Asked Answered
G

1

3

I want to use uncrustify to align my parameters on colon, and have some limited success.

Using the information in Can Uncrustify align colons in Objective-C method calls? I have the following in my config file:

align_oc_decl_colon = true
align_oc_msg_colon_span = 20

My .m-files look great, like this:

- (id)initWithStreetName:(NSString *)streetName
                areaCode:(NSString *)areaCode
                    city:(NSString *)city
                 country:(NSString *)country
        positionLatitude:(NSString *)positionLatitude
       positionLongitude:(NSString *)positionLongitude
      serverAssignmentId:(NSString *)serverAssignmentId
                 comment:(NSString *)comment
               timestamp:(NSDate *)timestamp
                  status:(AssignmentStatus)status

but the very same method looks like this in the header:

- (id)initWithStreetName:(NSString *)streetName
             areaCode             :(NSString *)areaCode
                 city                 :(NSString *)city
              country              :(NSString *)country
     positionLatitude     :(NSString *)positionLatitude
    positionLongitude    :(NSString *)positionLongitude
   serverAssignmentId   :(NSString *)serverAssignmentId
              comment              :(NSString *)comment
            timestamp            :(NSDate *)timestamp
               status               :(AssignmentStatus)status;

Any ideas on how I can get the header code to look like the implementation code?

Gegenschein answered 5/6, 2012 at 16:32 Comment(3)
If you go to Xcode's preferences -> Text Editing -> Indentation -> Tab Key: Indent Always and then select all of your text and hit the tab key, it will properly indent all of your code and align colons without any work on your part.Bantling
Alternatively, Edit->Select All then Editor->Structure->Reindent (or press control-I).Wagram
Yes, that's a valid way of doing it in xcode, thanks. I would like to script this on check-in though, so I need a way to do it in shell.Breastplate
C
1

That is a known bug on the latest release of uncrustify. At the time of this answer the latest one was 9 months ago. However a patch for this error was already committed and hopefully it will appear in the next release.

Look here: https://github.com/bengardner/uncrustify/issues/18

As a temporal fix you can compile yourself the current master. Compiling with XCode will generate just one single binary that you can use until the next official release.

The bug is on 0.59, should be solved on 0.60

Crimson answered 25/6, 2012 at 10:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.