[TxMt] Re: How to execute all lines before the cursor position?
Steve King
sking at arbor.net
Wed Apr 20 16:47:20 UTC 2011
On 2011-04-20 02:18, Marius Hofert wrote:
> Dear textmate-experts,
>
> I use textmate to program in the statistical software R. To execute an R script, I typically first select the lines and then use "Apple-key + R" which launches "Send Selection/Document to ... R.app". In order to execute all lines before the current cursor position, I also first select all lines (with "Apple-key + shirt + up"). But that shifts the view to the top of the document, which is a bit tedious. Is there a simple way to tell textmate to execute all lines before the current cursor position?
I can think of a couple ways to do it.
The easiest way is with a macro. Start recording, jump to beginning of
line, select to top, "Send selection to R.app", right arrow, stop
recording. Save the macro as you wish. The key is the right-arrow
action at the end, which will deselect everything and leave the cursor
at the end of the selected area. Two disadvantages: It does move your
cursor to the beginning of the current line, and it moves the current
line to the bottom of the window.
Better, and almost as easy, would be to modify the bundle command "Send
Selection/Document to R.app", which is in the "R Console (R.app)"
bundle. It's just a shell script which captures its stdin and uses
AppleScript to send it to R.app. This can be modified really easily to
do what you want. The line that captures the input is near the top:
'rawText="`cat`"' Change that to:
rawText = "`head -$(($TM_LINE_NUMBER-1))`"
The $TM_LINE_NUMBER environment variable contains the number of the
current line. The $((... -1)) expression simply says to subtract one to
get all lines *before* the cursor. And the head command simply gets
that many lines from stdin and discards the rest.
--
Steve King
Sr. Software Engineer
Arbor Networks
+1 734 821 1461
www.arbornetworks.com <http://www.arbornetworks.com/>
More information about the textmate
mailing list