[SVN] Re: Point in file
Hans-Jörg Bibiko
bibiko at eva.mpg.de
Sun Oct 31 15:20:54 UTC 2010
On 31 Oct 2010, at 11:13, Mads Hartmann Jensen wrote:
> Hey guys,
>
> Is it possible to get the cursor's point in the file? So if the file is:
>
> ----
> some text
> so<cursor>me more text
> ----
>
> It would give 11
Try this written in Ruby:
#!/usr/bin/env ruby -wKU
lines = STDIN.readlines
# Find out the caret's position within the whole document as we may need to
# more back and forwards across line boundaries while building up the
# selector signature.
line_index = ENV['TM_LINE_INDEX'].to_i
line_number = ENV['TM_LINE_NUMBER'].to_i - 1 - 1 # starts from 1 and stop on line before
# caret_placement identifies the index of the character to the left of the caret's position.
caret_placement = (0..line_number).inject(0) {|sum, i| sum + lines[i].length} + line_index - 1
print caret_placement
------
with the entire document sent to the script
Cheers,
--Hans
More information about the textmate-dev
mailing list