Align comments in Textmate
Unless I’m using Objective-C, which is fantastically self-documenting, I often like to add comments to parameters to remind me of what they do. For example:
imagecopy($image, $frame, ($x=max($width-$this->topRightCap[kCapWidth], $this->topLeftCap[kCapWidth])), // Destination x 0, // Destination y $x, // Source x 0, // Source y min($this->topRightCap[kCapWidth], $width-$this->topLeftCap[kCapWidth]), // Source width $this->topRightCap[kCapHeight]); // Source height |
The only thing is, it looks terrible and is very hard to read. I usually carefully insert spaces before the comments so they line up, but that’s really hard to maintain.
I use [Textmate](http://macromates.com/), and found an ‘Align Assignments’ script by Chris Poirier which applies very nice formatting to a block of assignments.
Some trivial modifications resulted in a similar script to align comments. Hit Ctrl-Option-Command-/, and:
imagecopy($image, $frame, ($x=max($width-$this->topRightCap[kCapWidth], $this->topLeftCap[kCapWidth])), // Destination x 0, // Destination y $x, // Source x 0, // Source y min($this->topRightCap[kCapWidth], $width-$this->topLeftCap[kCapWidth]), // Source width $this->topRightCap[kCapHeight]); // Source height |
Here it is:
Read More