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,
On 20/03/2010, at 9:45 AM, Adam Sharp wrote:
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:
By default fmt wrap at 72 characters, and if you followed the screencast, then you should know that you first use fmt to wrap lines, and then you add the comment a bullet characters, so it is 72 + 3. Thus you have to instruct fmt to wrap at 69 characters.
#!/usr/bin/env ruby
txt = STDIN.read.gsub(%r{\A/|*/\z}, '') txt = txt.gsub(/^[ \t]**[ \t]*/, '') txt = %x{ fmt <<< '#{txt.gsub(/'/, "'\\''")}' }.chomp
change the above line to
txt = %x{ fmt -69 <<< '#{txt.gsub(/'/, "'\\''")}' }.chomp
All the best
Guido -- Guido Governatori http://www.governatori.net/Textmate