Skip to content
Browse files

Add macro to execute the current cell in MATLAB

Needs more work, currently it will actually select the entire cell instead of leaving the cursor at its current location; if you run the macro twice in a row it will move to the next cell instead of executing the current cell twice. Probably needs to be written as an actual command.

The execute command's script has been moved into a stand alone script so it can be used in this command as well.
  • Loading branch information...
1 parent 42296c6 commit cdb510dbb957042a83acdd1f64ae11adb4f70678 Daniel Grady committed with infininight Dec 24, 2010
Showing with 176 additions and 25 deletions.
  1. +1 −25 Commands/Execute in MATLAB.tmCommand
  2. +148 −0 Macros/Execute cell.tmMacro
  3. +25 −0 Support/to_matlab.scpt
  4. +2 −0 info.plist
View
26 Commands/Execute in MATLAB.tmCommand
@@ -5,31 +5,7 @@
<key>beforeRunningCommand</key>
<string>nop</string>
<key>command</key>
- <string>#!/usr/bin/env osascript
-
-set das_inputzen to do shell script "cat"
-set mt to missing value
-
-tell application "Terminal"
- repeat with w in every window
- repeat with t from 1 to (count tabs of w)
- if processes of item t of tabs of w contains "MATLAB" then
- set mw to id of w
- set mt to t
- end if
- end repeat
- end repeat
-
- if mt is not equal to missing value then
- do script das_inputzen in tab mt of window id mw
- end if
-end tell
-
-if mt is equal to missing value then
- return "No running instances of MATLAB found."
-else
- return
-end if
+ <string>cat | "$TM_BUNDLE_SUPPORT/to_matlab.scpt"
</string>
<key>fallbackInput</key>
<string>line</string>
View
148 Macros/Execute cell.tmMacro
@@ -0,0 +1,148 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>commands</key>
+ <array>
+ <dict>
+ <key>argument</key>
+ <dict>
+ <key>commands</key>
+ <array>
+ <dict>
+ <key>command</key>
+ <string>moveRight:</string>
+ </dict>
+ <dict>
+ <key>argument</key>
+ <dict>
+ <key>action</key>
+ <string>findNext</string>
+ <key>findInProjectIgnoreCase</key>
+ <false/>
+ <key>findInProjectRegularExpression</key>
+ <false/>
+ <key>findString</key>
+ <string>^[ \t]*%%</string>
+ <key>ignoreCase</key>
+ <false/>
+ <key>regularExpression</key>
+ <true/>
+ <key>replaceAllScope</key>
+ <string>document</string>
+ <key>wrapAround</key>
+ <true/>
+ </dict>
+ <key>command</key>
+ <string>findWithOptions:</string>
+ </dict>
+ <dict>
+ <key>command</key>
+ <string>moveLeft:</string>
+ </dict>
+ </array>
+ </dict>
+ <key>command</key>
+ <string>playMacroWithOptions:</string>
+ </dict>
+ <dict>
+ <key>argument</key>
+ <dict>
+ <key>commands</key>
+ <array>
+ <dict>
+ <key>argument</key>
+ <dict>
+ <key>action</key>
+ <string>findPrevious</string>
+ <key>findInProjectIgnoreCase</key>
+ <false/>
+ <key>findInProjectRegularExpression</key>
+ <false/>
+ <key>findString</key>
+ <string>^[ \t]*%%</string>
+ <key>ignoreCase</key>
+ <false/>
+ <key>regularExpression</key>
+ <true/>
+ <key>replaceAllScope</key>
+ <string>document</string>
+ <key>wrapAround</key>
+ <true/>
+ </dict>
+ <key>command</key>
+ <string>findWithOptions:</string>
+ </dict>
+ <dict>
+ <key>command</key>
+ <string>moveLeft:</string>
+ </dict>
+ </array>
+ </dict>
+ <key>command</key>
+ <string>playMacroWithOptions:</string>
+ </dict>
+ <dict>
+ <key>argument</key>
+ <dict>
+ <key>action</key>
+ <string>findNext</string>
+ <key>findInProjectIgnoreCase</key>
+ <false/>
+ <key>findInProjectRegularExpression</key>
+ <false/>
+ <key>findString</key>
+ <string>%%(?m:.*?)(?=^[ \t]*%% |\z)</string>
+ <key>ignoreCase</key>
+ <false/>
+ <key>regularExpression</key>
+ <true/>
+ <key>replaceAllScope</key>
+ <string>document</string>
+ <key>wrapAround</key>
+ <false/>
+ </dict>
+ <key>command</key>
+ <string>findWithOptions:</string>
+ </dict>
+ <dict>
+ <key>argument</key>
+ <dict>
+ <key>beforeRunningCommand</key>
+ <string>nop</string>
+ <key>command</key>
+ <string>cat | "$TM_BUNDLE_SUPPORT/to_matlab.scpt"
+</string>
+ <key>fallbackInput</key>
+ <string>line</string>
+ <key>input</key>
+ <string>selection</string>
+ <key>keyEquivalent</key>
+ <string>@r</string>
+ <key>name</key>
+ <string>Execute in MATLAB</string>
+ <key>output</key>
+ <string>showAsTooltip</string>
+ <key>scope</key>
+ <string>source.matlab</string>
+ <key>uuid</key>
+ <string>064E306B-FF23-432B-952F-55AC3BEF029E</string>
+ </dict>
+ <key>command</key>
+ <string>executeCommandWithOptions:</string>
+ </dict>
+ <dict>
+ <key>command</key>
+ <string>moveLeft:</string>
+ </dict>
+ </array>
+ <key>keyEquivalent</key>
+ <string>@R</string>
+ <key>name</key>
+ <string>Execute Cell</string>
+ <key>scope</key>
+ <string>source.matlab</string>
+ <key>uuid</key>
+ <string>E888D2B7-977A-4A68-A966-6BE2762EB9C3</string>
+</dict>
+</plist>
View
25 Support/to_matlab.scpt
@@ -0,0 +1,25 @@
+#!/usr/bin/env osascript
+
+set das_inputzen to do shell script "cat"
+set mt to missing value
+
+tell application "Terminal"
+ repeat with w in every window
+ repeat with t from 1 to (count tabs of w)
+ if processes of item t of tabs of w contains "MATLAB" then
+ set mw to id of w
+ set mt to t
+ end if
+ end repeat
+ end repeat
+
+ if mt is not equal to missing value then
+ do script das_inputzen in tab mt of window id mw
+ end if
+end tell
+
+if mt is equal to missing value then
+ return "No running instances of MATLAB found."
+else
+ return
+end if
View
2 info.plist
@@ -22,6 +22,7 @@
<array>
<string>07FBCD52-B897-4931-AE99-86C5B25C2132</string>
<string>064E306B-FF23-432B-952F-55AC3BEF029E</string>
+ <string>E888D2B7-977A-4A68-A966-6BE2762EB9C3</string>
<string>------------------------------------</string>
<string>78BBA099-C976-415C-AA88-FE596173D38D</string>
<string>8EDB89D6-79E4-4A26-8E14-ED60254782FB</string>
@@ -174,6 +175,7 @@
<string>Matlab</string>
<key>ordering</key>
<array>
+ <string>652F22CD-6A4C-4308-B5F7-DBE6E0FE5538</string>
<string>548092DA-0275-4312-9F4F-5FA6375B1B01</string>
<string>3D39FA94-9A43-4CB1-8C72-F262E5DBF96E</string>
<string>2CD1353B-AEC7-4BBF-8061-6038D1E93FA8</string>

0 comments on commit cdb510d

Please sign in to comment.
Something went wrong with that request. Please try again.