Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Editor with Autoit - now also running from start to cursor position


From   Gawrich Stefan <s.gawrich@hlpug.hessen.de>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   st: Editor with Autoit - now also running from start to cursor position
Date   Mon, 27 Aug 2007 11:58:46 +0200

Hi statalisters,

using Autoit integration of Notepad++ for my Stata programming (see:
http://huebler.info/2005/20050310_Stata_editor.html) I always missed a
one-click-solution for running scripts from start to cursor position.
I looked a little bit into the Autoit documentation and found that this can
be done easy by simulated keyboard commands. Resetting the cursor/caret to
the former position seems to be the more difficult issue.

Here is my solution (changes to insert into the script rundolines.au3,
Version 2.2, downloadable from the above mentioned website): 
I have called the resulting script rundostart.au3, and start it with
function key F7 in my editor
This is experimental (only tested with Notepad++ under Windows XP). 
Any comments and improvements are welcome.

*** Change Line 10 : additional vars added

; Declare variables
Global $statapath, $statawin, $commands, $tempfile, $tempfile2, $x_adjust,
$y_adjust, $c, $w, $f, $e, $t 


;Between line 31 and 32 (after ClipPut) insert: 

Opt("CaretCoordMode", 0)
$t = WinGetCaretPos()
$x_adjust =  10
$y_adjust = 70
$w = WinGetPos("")              ;window's coords
$f = ControlGetFocus("","")     ;text region "handle"
$e = ControlGetPos("", "", $f)  ;text region coords
$t[0] = $t[0] + $w[0] + $e[0] + $x_adjust
$t[1] = $t[1] + $w[1] + $e[1] + $y_adjust

; Mark Text from Cursor to beginning (STRG+Pos1)
Send("{SHIFTDOWN}")
Send("^{HOME}")
Send("{SHIFTUP}")


;After  Send("^c") insert
opt("MouseCoordMode", 0) ; relative Mouse Coordinates
; returns cursor(caret)  to former mouse position
MouseClick("main",$t[0], $t[1])


The first part of the script stores the coordinates of the cursor  into
array $t.
This is adopted from
http://www.autoit.de/dokumentation/functions/WinGetCaretPos.htm.
I had to alter the $x_adjust and $y_adjust values to fit to my editor
(otherwise, the cursor position is not exactly the same as before).
This may change with different editors, different text sizes or other
specifications.
Also the "text region handle" of the original WinGetCaretPos script gave me
an error, I specified without and it works for me

The second part of the script just marks text from cursor position to start
of file.

The third part of the script restores the cursor position by a simulated
mouseclick on the stored position and with the same click unmarks the text.


Best wishes

Stefan Gawrich
Hesse Health State Office
Dillenburg
Germany






*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index