Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
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:
 

Attachments

  • Picture 1.png
    Picture 1.png
    26.8 KB · Views: 327

yeroen

macrumors 6502a
Mar 8, 2007
944
2
Cambridge, MA
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

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
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

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
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:
Code:
Then text ends up
being fixed width

-Lee
 

Sbrocket

macrumors 65816
Jun 3, 2007
1,250
0
/dev/null
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
 

Attachments

  • Indenting.png
    Indenting.png
    90.4 KB · Views: 146

HiRez

macrumors 603
Jan 6, 2004
6,265
2,630
Western US
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. :)

Panic Sans Xcode.png
 

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
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:
 

Attachments

  • Picture 1.png
    Picture 1.png
    17.8 KB · Views: 141

HiRez

macrumors 603
Jan 6, 2004
6,265
2,630
Western US
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.