Can Uncrustify align colons in Objective-C method calls?
Asked Answered
F

2

15

I am using uncrustify 0.52. When I run it against Objective-C files, it wants to convert method invocations like this:

[NSApp beginSheet:startTimerDialog
   modalForWindow:nil
    modalDelegate:nil
   didEndSelector:nil
      contextInfo:nil];

to this:

[NSApp beginSheet:startTimerDialog
 modalForWindow:nil
 modalDelegate:nil
 didEndSelector:nil
 contextInfo:nil];

I prefer the first version, with the colons aligned. Is there an option in the uncrustify config file that can support what I want, or does uncrustify just not support aligned colons?

If uncrustify can't align the colons, is there a way to prevent it from de-aligning the colons that I've aligned myself?

Update:

mmc notes that this feature was available in the Uncrustify svn repository as of build 1581. It is in uncrustify 0.54. Set align_oc_msg_colon = true in your config file to enable it.

Further Update

For people who find this answer in the future: The name of the preference in the .cfg file has been changed. It is now align_oc_msg_colon_span= 1 to get the behavior described above. There is also now a align_oc_decl_colon = true that will do the name thing for multi-line declarations.

Fumatorium answered 2/6, 2009 at 10:4 Comment(1)
There is a bug on the current release (0.59) where these options do not work as expected. See my answer https://mcmap.net/q/825795/-align-on-colons-in-objective-c-headersGrecism
H
10

I played around with this for some time last night, and (although I don't think that this deserves the bounty) the answer to both your questions is "no, current versions (.53) of Uncrustify do not do this."

I even investigated writing a patch to do exactly this (because I really want it, too) and after looking at the Uncrustify source, and concluded it would take far more time than I had available to figure out where to insert the patch to accomplish "multi-line message parameter colon alignment" rather than "multi-line message left alignment" It does seem that there has been some improvements to Objective-C parsing in recent patches.

I was so hoping someone would answer this question. I really wanted to know, too.

NOTE: For people who find this answer in the future: The name of the preference in the .cfg file has been changed. It is now align_oc_msg_colon_span = 1 to get the behavior described above. There is also now a align_oc_decl_colon that will do the name thing for multi-line declarations.

Hydrolyze answered 23/6, 2009 at 15:30 Comment(3)
I hope to do a patch myself in my copious free time. I don't know when I'll have any of that.Fumatorium
You might not want to bother... looks like it's coming. Uncrustify .53 was version 1571 in svn. Current in his SourceForge svn is 1581. Build 1581 seems to be in the process of (may not be complete, I have not downloaded and compiled) adding a new option for Objective C called "align_oc_msg_colon." Dunno about you, but I think that sounds extremely promising. Now I am off to try and build 1581 to see if it actually works.Hydrolyze
Well, it seems to work... mostly. It does not seem to want to allow any message portion extend to the left of the opening bracket on the previous line. 90% of the time, this is fine. The other 10% it puts spaces between the object name and the first (segment? Parameter name?) of the message. I don't like this. I have a feeling it can be turned off, but I have not found the right option yet.Hydrolyze
T
0

Did you try:

align_var_def_colon=true
Transliterate answered 18/6, 2009 at 3:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.