[TxMt] Re: Reformat comment command

Daniel Grady d.c.grady at gmail.com
Sun May 18 00:57:06 UTC 2008


Hi, I'm not sure if anyone's brought this up before, but I think there are
three problems with the Reformat Comment command in the Source bundle:

1. It doesn't respect the wrap column (the TM_COLUMNS variable)
2. It adds an extra newline at the end of the comment
3. It doesn't correctly handle comments that are indented

Are these actually problems, or am I thinking about the purpose the command
incorrectly? If they are actually problems, I think the way to fix them is by
changing two of the lines in the command, and switching the Input to Selected
Text or Line (rather than Selected Text or Scope) since this will pass leading
whitespace to the rubywrap script. The updated command is included below.

Is this right? I came across this problem while fiddling with a Python script;
I'm not a very experienced programmer and I really have no idea if these
changes cause problems with other languages. Thanks for any feedback!

-Daniel


#!/usr/bin/env ruby

$LOAD_PATH << "#{ENV["TM_SUPPORT_PATH"]}/lib"
require "escape"
require "exit_codes"

ctext = STDIN.read
if ctext =~ /^\s*(.[^\s\w\\]*\s*)/
  cstring = $1
else
  TextMate.exit_show_tool_tip("Unable to determine comment character.")
end

flags = %Q{-p "#{cstring}"}
flags += " --retabify" unless ENV["TM_SOFT_TABS"] == "YES"
flags += " -c #{ENV["TM_COLUMNS"]}"

command = "ruby #{e_sh(ENV["TM_BUNDLE_SUPPORT"])}/bin/rubywrap.rb #{flags}"
text    = open("| #{command}", "r+") do |wrapper|
  wrapper << ctext
  wrapper.close_write
  wrapper.read
end

print e_sn(text.chomp)




More information about the textmate mailing list