[TxMt] Reformat comment command

Alan Schussman alan at schussman.com
Wed Aug 23 21:33:16 UTC 2006


Thanks for the feedback, Allan.

On Aug 23, 2006, at 10:41 AM, Allan Odgaard wrote:

> Probably better to grab the comment character from the start of the  
> input. Otherwise there is a more full mapping in the “Continue Line  
> Comment” snippet in the Source bundle.

Grabbing the start of the input works well, and it means setting the  
comment parameter based on what actually sits at the beginning of the  
comment scope, so that it will catch "%comment" or "% comment" or "%%  
comment". Nice.

> The line can be:
>
>     text = `ruby "#{ENV["TM_SUPPORT_PATH"]}/bin/rubywrap.rb" #{flags}`

Here's where I go "huh." That works, but 1) I don't at all get how  
the input is passed to the command; and 2) if I call on STDIN.read  
prior to this line (by using it to get the beginning of the input),  
then that line fails to get any input, and I have to manually pipe  
the text back into it. What's happening there?

>> I also added a gsub to the command because it was eating latex  
>> math and R symbols ($). There's probably a better solution to that.
>
> Likely because of the Insert as Snippet -- but the e_sn should take  
> care of that.
>
> I am however not sure inserting as snippet is ideal -- I reckon  
> this was to preserve the indent, but maybe better to Replace Text  
> and have the command indent properly.

Excellent -- thanks for pointing out what e_as was doing. When  
inserting as a snippet, e_sn does the job, and replacing the text  
instead of inserting as snippet also works, though you're right that  
it doesn't re-indent before the comment.

Here's what I have now:
---
#!/usr/bin/env ruby

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

ctext = STDIN.read
cs = ctext.split(/\s/,1)
cs[0] =~ /(^[%#\/-]+\s*)/
cstring = $1

flags =  ""
flags += " -p \"#{cstring}\" "
flags += " --retabify" if ENV["TM_SOFT_TABS"] == "NO"

text =`echo -n "#{e_sn(ctext)}" | ruby "#{ENV["TM_SUPPORT_PATH"]}/bin/ 
rubywrap.rb" #{flags}`

print text
---

-Alan




More information about the textmate mailing list