Skip to content

Instantly share code, notes, and snippets.

@petrockblog
Created July 5, 2012 05:49
Show Gist options
  • Save petrockblog/3051595 to your computer and use it in GitHub Desktop.
Save petrockblog/3051595 to your computer and use it in GitHub Desktop.
Matlab plugin for Sublime Text 2
import sublime
import sublime_plugin
import os
class OpenmatlabfunctionCommand(sublime_plugin.TextCommand):
def run(self, edit):
for sels in self.view.sel():
didFind = False
# extract file name to find
fileToFind = self.view.substr(sels)
fileDir = os.path.dirname(self.view.file_name())
fileName, fileExtension = os.path.splitext(self.view.file_name());
# traverse the directory of the current file and look for the corresponding .m file
for fname in os.listdir(fileDir):
tempfileName, tempfileExtension = os.path.splitext(fname);
# if the .m file is found, open it and set syntax
if tempfileExtension==".m" and fileToFind==tempfileName:
didFind = True
print "Opening "+fileToFind+tempfileExtension
currentSyntax = self.view.settings().get('syntax')
newView = sublime.active_window().open_file(fileToFind+tempfileExtension)
newView.settings().set('syntax', currentSyntax)
# if we did not find the .m file, print a message
if not didFind:
print "Did not find "+fileToFind+".m in current directory."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment