Hello all,
after searching the list archive for a while, I have hacked together a short command to run Matlab straight from within textmate. The current problem is (as has been discussed on the list previously) that Matlab has to be launched from scratch every time (takes about 5s for simple hello-world scripts to execute).
Is there a maintainer for the Matlab bundle? Is there anyone around who knows how to access the current Matlab session?
Best, Jonas
Thx, nice work! On Dec 17, 2007 5:45 PM, Jonas Müller muellerj@gmx.de wrote:
Hello all,
after searching the list archive for a while, I have hacked together a short command to run Matlab straight from within textmate. The current problem is (as has been discussed on the list previously) that Matlab has to be launched from scratch every time (takes about 5s for simple hello-world scripts to execute).
Is there a maintainer for the Matlab bundle? Is there anyone around who knows how to access the current Matlab session?
As far as I know (and this was something we really looked for for a while) there is no real way to access matlab's current session. You might want to take a look at this project, though: http://jmatlink.sourceforge.net/
Btw, a colleague of mine did his "link" with something called HotKeys (I think) in windows. He defined a macro for pasting the selected text in his editor directly in the matlab window. No idea, though, how to make this in os x.
Best, Miguel
Best, Jonas
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
On Dec 17, 2007, at 2:27 PM, Miguel Vaz wrote:
Btw, a colleague of mine did his "link" with something called HotKeys (I think) in windows. He defined a macro for pasting the selected text in his editor directly in the matlab window. No idea, though, how to make this in os x.
Sounds like a job for… Applescript UI Scripting.
I have a handy command that takes the current selection and pastes it into the terminal. (not directly attached since it is so incredibly dangerous)
Input: Selection or Document Output: Tooltip
pbcopy osascript -e 'tell application "Terminal" to activate' \ -e 'tell application "System Events"' \ -e 'tell application process "terminal"' \ -e 'delay 0.1' -e 'keystroke "k" using command down' \ -e 'keystroke "v" using command down' \ -e 'end tell' \ -e 'end tell' \ -e 'tell application "TextMate" to activate' echo "Selection Sent to Terminal"
That might be convertible for whatever. I made one similar for doing Second Life code. (I have a whole Second life bundle, if anyone is interested.)
—Thomas Aylott – subtleGradient—
I looked into this early on in textmate's life, but never found a solution that I would call graceful. However, the work recently done by Hans connecting to R in textmate may provide some inspiration. Also, there was a terminal plugin based on iterm built as a proof of concept some time ago that could also perhaps be used, but I never had much success getting that running, and I don't know that it's still actively maintained.
-d
On 17.12.2007, at 22:41, Don Kalar wrote:
I looked into this early on in textmate's life, but never found a solution that I would call graceful. However, the work recently done by Hans connecting to R in textmate may provide some inspiration.
I'm just fine-tuning the R daemon which runs in a pseudo terminal. The basic idea works pretty well, and if Matlab – to be honest, my last contact with Matlab was about 15 years ago – runs in the Terminal then it should be possible (theoretically) to use the same approach. However, my crucial point with R is the synchronisation, meaning after sending a task to R how does one know whether R did the job. My current approach is very naïve but it works for 98% of all cases; I simply look at R's CPU coverage, but this could not be the end, because if R by itself starts some shell commands etc...
Thus one can try to adopt that idea using the pty library (in Ruby) and run Matlab. BTW is Matlab downloadable for free? Or a test version? Then I could run a dry-run.
--Hans
Matlab is now Java-based, but provides terminal access as well. Personally I almost exclusively use the terminal and textmate, both out of habit (the early Java versions were both slow and buggy, though it appears the devs at Mathworks have fixed a lot of that with recent releases) and because a lot of my work requires timing precision that excludes a JVM.
I'm still fairly naive to the details of your approach, but matlab provides an 'eval' function that executes a string passed as code. Could one simply pipe the code to run from textmate into an eval call, followed by a `touch /tmp/file_indicating_script_is_finished`? You'd need to wrap it in a try-catch most likely to ensure that the touch command occurs even if the executed string fails.
I don't think Mathworks provides demos, but Octave may be compatible enough to be a drop in replacement for these purposes. Ideally I guess the Matlab bundle should support Octave as well.
cheers, -d
On 12/17/07, Hans-Jörg Bibiko bibiko@eva.mpg.de wrote:
I'm just fine-tuning the R daemon which runs in a pseudo terminal. The basic idea works pretty well, and if Matlab – to be honest, my last contact with Matlab was about 15 years ago – runs in the Terminal then it should be possible (theoretically) to use the same approach. However, my crucial point with R is the synchronisation, meaning after sending a task to R how does one know whether R did the job. My current approach is very naïve but it works for 98% of all cases; I simply look at R's CPU coverage, but this could not be the end, because if R by itself starts some shell commands etc...
Thus one can try to adopt that idea using the pty library (in Ruby) and run Matlab. BTW is Matlab downloadable for free? Or a test version? Then I could run a dry-run.
--Hans
On Dec 18, 2007, at 12:37 AM, Don Kalar wrote:
I don't think Mathworks provides demos, but Octave may be compatible enough to be a drop in replacement for these purposes. Ideally I guess the Matlab bundle should support Octave as well.
Yes, I agree. Given the more terminal-based nature of Octave, calling a new instance here seems feasible though (see attached) and only takes a second or so for me.
Best, Jonas
On 18 Dec 2007, at 00:37, Don Kalar wrote:
I'm still fairly naive to the details of your approach, but matlab provides an 'eval' function that executes a string passed as code. Could one simply pipe the code to run from textmate into an eval call, followed by a `touch /tmp/file_indicating_script_is_finished`? You'd need to wrap it in a try-catch most likely to ensure that the touch command occurs even if the executed string fails.
Yes, I already tried that approach. It works perfectly, even for errors/messages BUT one looses the possibility to interact with R, e.g. readline("Give me the value for x:"). I didn't find a way to distinguish whether R is waiting for the user's input. And unfortunately it's not allowed to overwrite the function 'readline'.
--Hans
Ahh, a good point. That brings us back to coming up with a clever way of piping IO to a shell process, which is where I eventually gave up because my methods were both fragile and unwieldy. Perhaps there's a graceful hack out there? I still think something like the TerminalMate plugin based on the iTerm codebase could be a means of embedding an interactive shell (useful for R, matlab, irb, etc.), but that's a big undertaking. I'll have to take a look at Thomas' Second Life bundle to see how he's doing it.
cheers, -d
On Dec 18, 2007 2:36 AM, Hans-Joerg Bibiko bibiko@eva.mpg.de wrote:
Yes, I already tried that approach. It works perfectly, even for errors/messages BUT one looses the possibility to interact with R, e.g. readline("Give me the value for x:"). I didn't find a way to distinguish whether R is waiting for the user's input. And unfortunately it's not allowed to overwrite the function 'readline'.
--Hans
On 17 dec 2007, at 21.09, Thomas Aylott - subtleGradient wrote:
On Dec 17, 2007, at 2:27 PM, Miguel Vaz wrote:
Btw, a colleague of mine did his "link" with something called HotKeys (I think) in windows. He defined a macro for pasting the selected text in his editor directly in the matlab window. No idea, though, how to make this in os x.
Sounds like a job for… Applescript UI Scripting.
I have a handy command that takes the current selection and pastes it into the terminal. (not directly attached since it is so incredibly dangerous)
Input: Selection or Document Output: Tooltip
pbcopy osascript -e 'tell application "Terminal" to activate' \ -e 'tell application "System Events"' \ -e 'tell application process "terminal"' \ -e 'delay 0.1' -e 'keystroke "k"
using command down' \ -e 'keystroke "v" using command down' \ -e 'end tell' \ -e 'end tell' \ -e 'tell application "TextMate" to activate' echo "Selection Sent to Terminal"
That might be convertible for whatever. I made one similar for doing Second Life code. (I have a whole Second life bundle, if anyone is interested.)
I would love to see that bundle, i have a project in school comming up soon that involves coding a game in second life.