Created
July 5, 2012 05:49
-
-
Save petrockblog/3051595 to your computer and use it in GitHub Desktop.
Matlab plugin for Sublime Text 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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