[SVN] Re: Source bundle, comment line command: Changes for Ruby 1.9

Charles Turner vze26m98 at optonline.net
Thu Aug 28 20:38:41 UTC 2008


On Thu, 28 Aug 2008 14:52:55 -0500, James Gray wrote:
> My copy of the command already has text.map().  We cannot do the  
> reverse either, switch to text.lines.map() as 1.8 doesn't have lines().

OK, my embarrassment level is up pretty high. :-)

This is what works for me in 1.9:

  when "line"  # line by line comment
    if text !~ /\A[\t ]+\z/ &&
       text.lines.map { |l| !!(l =~ /\A\s*(#{com[:esc_start]}|$)/) 
}.uniq == [true]
      if $selected
        out text.gsub( 
/^(\s*)#{com[:esc_start]}(.*?)#{com[:esc_end]}(\s*)$/,
                       '\1\2\3' )
        exit
      else
        r = text.sub( 
/^(\s*)#{com[:esc_start]}(.*?)#{com[:esc_end]}(\s*)$/,
                      '\1\2\3' )
        i = ENV["TM_LINE_INDEX"].to_i
        i = i > text.index(/#{com[:esc_start]}/)            ?
            [[0, i - com[:start].length].max, r.length].min :
            [i, r.length].min
        r[i, 0] = "\0"
        out r
        exit
      end
    end

-Charles




More information about the textmate-dev mailing list