[TxMt] TextMate customisation screencast, reflow comment command

Adam Sharp adsharp at me.com
Sat Mar 20 00:45:33 UTC 2010


Hi,

I'm referring to the reflow comment command in this screencast:
http://blog.macromates.com/2006/customization-screencast/

I have TextMate set to wrap at 72 characters, and currently the command
is not reflowing this text correctly:

/*
  * This constructor takes a pointer to a void function that should
  * define a set a of transformations to move this cube to its starting
  * point in the 3D coordinate system. Transformations include
  * translations, scaling and rotation. (Scaling can be performed
  * uniformly by using the Cube(float sideLength) constructor.)
  *
  * Parameters:
  *  - a function pointer that to a void function with no parameters
  *
  * Outputs: N/A
  */

When I run the command, bound to ^Q, I get this result:

/*
  * This constructor takes a pointer to a void function that should
  * define a set a of transformations to move this cube to its starting
  * point in the 3D coordinate system. Transformations include
translations,
  * scaling and rotation. (Scaling can be performed uniformly by using
  * the Cube(float sideLength) constructor.)
  *
  * Parameters: - a function pointer that to a void function with no
  * parameters
  *
  * Outputs: N/A
  */

(I have hard-wrapped the line in question to indicate that TM is
soft-wrapping here, as the line is longer than 72 characters.)

Here is the command I'm using (copied from the comments on the linked
article):

   #!/usr/bin/env ruby

   txt = STDIN.read.gsub(%r{\A/|\*/\z}, '')
   txt = txt.gsub(/^[ \t]*\*[ \t]*/, '')
   txt = %x{ fmt <<< '#{txt.gsub(/'/, "'\\\\''")}' }.chomp
   txt = txt.gsub(/[$`\\]/, '\\\\\0')
   txt = txt.sub(/(\n(?=\n))?(\n*)\z/, '\1$0\2')
   print "/* " + txt.to_a.join(' * ') + " */"

How can I modify this command to reflow correctly at 72 columns?

Thanks in advance,

-- 
Adam Sharp
www.adam-sharp.net




More information about the textmate mailing list