[TxMt] Re: How to set up TextMate for MATLAB?

JiHO jo.lists at gmail.com
Sun Apr 26 13:28:12 UTC 2009

On 2009-April-26  , at 04:50 , Christopher Creutzig wrote:

> Is it now possible to compile MATLAB code directly out of TextMate  
> without opening the code in the MATLAB editor?

If by that you mention execute MATLAB code from within TextMate, here  
is the solution that I use:

As opposed to the previous poster, I don't like MATLAB's GUI very  
much. I find it slow and bulky. I tend to work in terminal by starting  
MATLAB this way:
	matlab -nosplash -nodesktop
then I have a TextMate command to send the current selection or the  
current line to the frontmost Terminal window and then select the next  
line in the MATLAB (or any other language for that matter) source  
file, to which I assign a shortcut (such as ⌥↩). Now I can step  
line by line through MATLAB source by just pressing the shortcut  
repeatedly and see the result of the execution of the code in the  
Terminal, or send chunks of code at a time by selecting them and  
pressing the shortcut. The advantage of this method is that is works  
exactly the same whether your MATLAB session is running locally on  
your computer or on a server halfway around the world. This is a  
tremendous advantage for me since most of my MATLAB sessions are remote.

Here is the (very simple) command:

# input is selected text or line
# output is discarded
# scope is 'source'

# suppress tabs in the code that's sent to the Terminal (to avoid  
inappropriate shell expansion)
rawText="$(cat | sed 's/	/ /g;')"

# send the code to the Terminal
osascript -e 'on run(theCode)' \
           -e '  tell application "Terminal"' \
           -e '    do script theCode in window 1' \
           -e '  end tell' \
		  -e 'end run' -- "$rawText"
# NB: depending in the delay to display this code in the terminal  
there can be some "collisions" between the lines of code sent. if the  
Terminal does not respond fast enough and you experience errors, try  
sending smaller chunks of code.

# step to the last character of the next line in TextMate
open "txmt://open?line=$(($TM_LINE_NUMBER+1))&column=1000000" &
# NB: if your selection goes all the way to the end of the last line  
(i.e. the selection color is visible beyond the last character, all  
the way to the the right border of the TextMate window), it means that  
the last line break is actually selected and the cursor is at the  
begining of the next line already. Stepping will move it one line down  
so it will appear to have stepped two lines. I don't know how to fix  
that yet.

I hope it may help.


More information about the textmate mailing list