Here is the code in question

require "#{ENV['TM_SUPPORT_PATH']}/lib/escape"
don't forget to escape the relevant parts as I have done below with e_sn

class String
  def index_of_nth_occurrence_of(n, ch)
    self.unpack("U*").each_with_index do |e, i|
      return i if e == ch && (n -= 1) == 0
    end
    return -1
  end
end

def caret_position(line)
  tmp = ENV['TM_LINE_NUMBER'].to_i - ENV['TM_INPUT_START_LINE'].to_i
  if tmp > 0
    caret_placement = line.index_of_nth_occurrence_of(tmp,?\n) +
ENV['TM_LINE_INDEX'].to_i
  else
    caret_placement
=ENV['TM_LINE_INDEX'].to_i-ENV['TM_INPUT_START_LINE_INDEX'].to_i - 1
  end
end

line = STDIN.read
caret_placement = caret_position(line)

print e_sn(line[0..caret_placement]) + res + e_sn(line[caret_placement + 1
..-1])



_______________________________________________
textmate-dev mailing list
[email protected]
http://lists.macromates.com/mailman/listinfo/textmate-dev

Reply via email to