On 14. Feb 2007, at 20:19, Kevin Cox wrote:
Whoops - that was a bit messed up. Here's the ACTUAL finished source (which escapes any '$'s other than the $0 it inserts. [...]
We have the e_sn function in lib/escape.rb, this is preferable because it will do the right thing (i.e. also handle escaping of ` and ).
Here’s an alternative version using e_sn:
#!/usr/bin/env ruby require "#{ENV['TM_SUPPORT_PATH']}/lib/escape.rb"
line = STDIN.read
if line =~ /\A.*;\Z/ caret = ENV['TM_LINE_INDEX'].to_i print e_sn(line[0...caret]) + ';${0}' + e_sn(line[caret..-1]) else print e_sn(line) + ';' end
I use ${0} instead of $0 incase there is a number to the right of the caret (the manual isn’t really clear on whether or not $01 is equivalent to $1 or ${0}1 -- so let’s just avoid ever having that in a snippet ;) ).