[TxMt] Changing cursor position from command

Kevin Cox kevintcox at gmail.com
Thu Feb 15 17:26:49 UTC 2007


Wow, thanks, Allan!

One minor modifcation to the regular expression:

#!/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

This prevents it from putting a semicolon at the end of a line after
an open {. Helps with for loops, for instance.

It's pretty clear I'm not a ruby programmer, eh?


On 2/14/07, Allan Odgaard <throw-away-1 at macromates.com> wrote:
> 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 ;) ).
>
>
> ______________________________________________________________________
> For new threads USE THIS: textmate at lists.macromates.com
> (threading gets destroyed and the universe will collapse if you don't)
> http://lists.macromates.com/mailman/listinfo/textmate
>



More information about the textmate mailing list