PDA

View Full Version : How to align colon with code?




Darkroom
Jun 14, 2008, 11:57 AM
i always see neat code being displayed with aligned colons, but i can't figure out how to do the same. i use tabs, but even spaces don't seem to work. there must be an automated way right?

this is what i get:



yeroen
Jun 14, 2008, 12:06 PM
Which editor are you using? Xcode, TextMate, vim, emacs, nedit, something else?

Most text editors meant for editing source have a code beautifier for prettyprinting and auto indentation. Then there are always command line utilities like indent(1) that will do this for you after the fact.

Darkroom
Jun 14, 2008, 12:07 PM
Which editor are you using? Xcode, TextMate, vim, emacs, nedit, something else?

Most text editors meant for editing source have a code beautifier for prettyprinting and auto indentation. Then there are always command line utilities like indent(1) that will do this for you after the fact.

im using xCode3... i can't seem to find anyway to do this properly.

lee1210
Jun 14, 2008, 12:50 PM
So you're wanting your parameter list to have the colons line up? I don't know what beautifier, autoindenter, etc. that could do that, unless you're using a fixed-width font. The default Xcode font is Monaco at 10pt. It's variable width, so even if you had exactly the same number of characters in a line, the last characters would be in different positions.

In the preferences you can change the font to something fixed like courier if you would like, then you could line things up with spaces. It looks like Xcode displays a tab as the width of 4 spaces, so you could mix and match, i suppose.

I'm not sure where you've seen others/examples where things line up. if you put things in a code block on this site:

Then text ends up
being fixed width


-Lee

Sbrocket
Jun 14, 2008, 01:24 PM
Take a look at this panel in Xcode's preferences. Your problem is most likely related to the fact that you're not using a monospaced font, which I would recommend for organized code. Monaco isn't that bad, is it? :p

HiRez
Jun 14, 2008, 08:29 PM
Sbrocket is right, Xcode will do that for you, although I personally don't like the aligned-on-colons style, and it gets messy when you have multiple nested message calls.

As fonts go, Monaco is not bad, but I really like Panic Sans for a code font. It's a bit thicker than Monaco, making it a little easier to read, and I like some of the characters better, for example dashes line up better with < and > for making arrows, and the parenthesis are less severe. If you download Coda, you can steal it from the application bundle. :)

120023

Darkroom
Jun 17, 2008, 02:40 PM
it's just that i have code suggestions turned on, and when i press tab to accept a long string of code where i simply have to fill parts, it doesn't align it for me, even if i have syntax aware indenting turned on... this is what i get:

HiRez
Jun 17, 2008, 04:11 PM
it's just that i have code suggestions turned on, and when i press tab to accept a long string of code where i simply have to fill parts, it doesn't align it for me, even if i have syntax aware indenting turned on... this is what i get:I believe you have to manually put returns between each argument. Then they should line up. Be sure to eliminate the space between arguments as well.