[TxMt] Changing cursor position from command
Kevin Cox
kevintcox at gmail.com
Tue Feb 13 19:16:57 UTC 2007
Hello all,
I'm writing a command to mimic eclipse's semicolon insertion. In
Eclipse, when you press ';' it looks for a semicolon at the end of the
line; if there is one already there, you get a ';' at your cursor (as
if you had typed it normally); if not, it puts it in the proper
position at the end of the line, and your cursor is at the end of the
line.
With the following command, TextMate will put the semicolons in the
desired place, but the cursor doesn't move, which is annoying.
input: selected text or line
output: replace selected text
activation: key equivalent ';'
scope: "source"
#!/usr/bin/env ruby
$t = STDIN.read
if $t =~ /\A(.*)\;\Z/
$c = ENV['TM_LINE_INDEX'].to_i
print $t.insert($c, ';')
else
print $t+';'
end
Any idea how to move the cursor? Snippets handle cursor motion, but
I'm not sure I can get the semicolon to go to the right spot. Ideas?
Tricks?
Best,
Kevin
More information about the textmate
mailing list