[TxMt] Command to reflow JavaDoc comment

Trevor Harmon trevor at vocaro.com
Fri Apr 13 00:09:08 UTC 2007


Inspired by the customization screencast [1], I decided to write a  
reflow command for us Java users. It's designed for reflowing JavaDoc  
comments. Based heavily on Allan's original code, it works well  
except for one problem: The reflowed text is never indented, even  
though I've set the output to "Insert as Snippet." Anyone know how to  
fix this?

Here's the command:

#!/usr/bin/env ruby
# Grab comment text
txt = STDIN.read
# Remove beginning and ending slashes
txt = txt.gsub(%r{\A[ \t]*/|\s*\*/\s*\z}, '')
# Remove leading bullets
txt = txt.gsub(/^[ \t]*\*+[ \t]*/, '')
# Escape single quotes
txt = txt.gsub(/'/, "'\\\\''")
# Use fmt command to reflow text
txt = %x{ fmt <<< '#{txt}' }.chomp
# Put leading bullets back in
txt = txt.to_a.join(' * ')
# Escape special snippet characters
txt = txt.gsub(/[$`\\]/, '\\\\\0')
# Put cursor marker on last line
txt = txt.sub(/\n?\z/, '$0\0')
# Put beginning and ending slashes back in
txt = "/**" + txt + "\n */\n"
print txt

I've set the input to "Selected Text or Scope" and the scope to  
"comment.block.documentation.java".

Thanks,

Trevor

[1] http://macromates.com/blog/archives/2006/04/12/customization- 
screencast/




More information about the textmate mailing list