[ACCEPTED]-.m files as MATLAB/Octave for Sublime Text-sublimetext

Accepted answer
Score: 65

Sublime 2 can be configured to associate 3 certain file extensions to certain syntax 2 highlighting schemes. See this answer 1 for exactly how to do it https://stackoverflow.com/a/8014142/694184

Score: 3

Here is how to run Matlab/Octave code directly 8 from Sublime Text with CTRL+B and associate .m files 7 to this Matlab syntax. Here it is specific 6 for Windows, see the reason below in the 5 note.

First a Matlab.sublime-build:

    "cmd": ["cmd", "/k", "D:\\Documents\\software\\octave-4.0.0\\bin\\octave-cli.exe", "$file"],
    "selector": "source.matlab"

Then a Matlab.sublime-settings:


Note: I used the cmd /k trick 4 to have the plot displayed in a new window 3 that doesn't "disappear" after 2 10 milliseconds (see How to run Octave code without the Octave IDE (similarly to Python)? and Octave: How to prevent plot window from closing itself?). For this reason, don't 1 forget to add this to your plots:

h = plot(...)
Score: 2

Are those files scripts or functions? If 15 they are Octave scripts and not functions 14 then you can have any extension you like 13 and use source() to run them, independently of the 12 extension. If they are functions, unlike 11 Matlab you can define functions in a script 10 file, load it, and they will stay in memory.

But 9 if you don't need syntax highlight at all, you 8 should be able to change Sublime, just find 7 the file Objective-C.Sublime-package. Without 6 running it, just by looking at the files 5 in the installer, I see two ways to do it:

  1. try to remove it (or just change its name for something .bak so you can restore it in case something goes wrong)
  2. that file is a tarball with two XML files. Open those files and edit the entry that sets what's the extension for those files for something different of .m

And 4 of course, there's also the option of change 3 to a free as in freedom text editor that 2 allows you to look in their source and do 1 whatever you want.

Score: 0

This worked fine for me. I had just put 2 the path for the octave and the code is 1 perfectly running

"cmd": ["/usr/local/octave/3.8.0/bin/octave-3.8.0", "$file"],
"selector": "source.m"

Save it as Octave.sublime-build

More Related questions