[TxMt] Using the layout engine to wrap comments nicely

Timothy Bates timothy.c.bates at gmail.com
Tue Jul 24 12:31:49 UTC 2012


Hi All

There's a great new blog entry from James Gray on the TM2 Layout engine  http://blog.macromates.com/2012/the-layout-engine/

In TM2, comments in source code are set to wrap, even on no-wrap lines. But the defaul wrapping is to stay to the right of the comment start.


This leads to lines like the one I append below :-)

You can fix this to your pleasure, and learn about Style settings.

Goal: Set comments to wrap, not under their start column, but, say, with a 20-char indent from the left margin of the code in the line

[12:43pm] timbates:Infininight: you are the master of assumed knowledge: Which match, where?

[12:43pm] Infininight:that one 

consists of two parts: a match and a format string

The match string counts out the characters you want to wrap to. In the default case, all the way out to the comment char and any spaces immediately afer:
	match = '.*(##?)\s+';
Then the format just blanks all the non-white-space characters
   format= '${0/\S/ /g}';

The wrapping for source lines is in the Source bundle, under settings. There are settings for all the difference comment characters... Pity this isn't munged into one, but anyhow...

All I had to do was set match
    match='^ *.{5}';

This now wraps the long comments to a left margin equal to the indent of the line plus 5 more characters
Here's an example
http://pastie.textmate.org/private/uyfbafdeaepyxn5o2otpw

Here's an example of what I wanted to fix

long source linelong source linelong source linelong source line # thin
                                                                   comm
																   ent
																   that
																   is
																   very
																   hard
																   to 
																   read
																   :-)
																   
Happy TM-2 ing!


More information about the textmate mailing list