[TxMt] Changing cursor position from command

Charilaos Skiadas skiadas at hanover.edu
Tue Feb 13 20:28:05 UTC 2007


On Feb 13, 2007, at 2:16 PM, Kevin Cox wrote:
> Hello all,
>
> 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?

Set your output to Insert as snippet. This will actually replace  
whatever the input is, but will interpret the output as a snippet.  
Then you do the processing of the line, and you snippet-escape the  
result, and add $0 at the location where you want the caret to end  
up. The library escape.rb will be of help to you, it contains an  
"e_sn" command that escapes the text for use in a snippet.

> Best,
> Kevin

Haris



More information about the textmate mailing list