4

I am using Octave for some Machine Learning work and I have noticed in my package library in Sublime that there is SublimeREPL: Octave as an option. However when I select it, I get the following error message:

FileNotFoundError(2, "No such file or directory: octave")

Is there a way to use sublime to code with Octave?

Many thanks

Spearfisher
  • 8,445
  • 19
  • 70
  • 124

2 Answers2

10

First, you need to find out where your octave executable lives, and note the full path to it. On Linux or OS X, open your favorite terminal emulator and type which octave, and if it's in your $PATH variable it will print the full path to it (for example, /opt/local/bin/octave or something like that). If it's not in your path, or if you're on Windows, you'll have to search around a bit until you find octave or octave.exe, if you're on Windows.

Once you have the path, open Sublime and select Preferences -> Browse Packages..., which will open your Packages folder (surprisingly). Navigate to Packages/SublimeREPL/config/Octave and open the Main.sublime-menu file in Sublime - don't worry, it's just plain JSON. Go down to line 18 (or thereabouts) - it should say "cmd": ["octave", "-i"],. Change "octave" to "/full/path/to/octave", obviously replacing /full/path/to/ with the actual full path you noted earlier.

Save the file, and you should be all set. Tools -> SublimeREPL -> Octave should now open up an interactive session, just like running octave -i on the command line would do. You can use all of the usual SublimeREPL shortcuts to send code to the running REPL, or just use if for testing functions, code snippets, etc.

Have fun!

MattDMo
  • 100,794
  • 21
  • 241
  • 231
  • this worked brilliantly thanks!! Is there a way to add color theme support when using octave and sublime? – Spearfisher May 28 '14 at 09:34
  • @Spearfisher when you open the REPL it should automatically use the Matlab syntax definition. If you look in the bottom right of the Sublime window, it should say `Matlab`. Is that not working? – MattDMo May 28 '14 at 15:04
  • yes, thanks! I just needed to configure sublime to see .m files as octave/matlab files (http://stackoverflow.com/questions/7574502/set-default-syntax-to-different-filetype-in-sublime-text-2/8014142#8014142) – Spearfisher May 28 '14 at 15:22
  • Actually I was mistaken, when I open a .m file I get the right color theme but when I use sublime REPL Octave I get the wrong ones. It says Matlab in the bottom right. How can I fix this please? – Spearfisher May 28 '14 at 16:06
  • @Spearfisher - when you open `.m` files, what language shows up in the bottom right? If it says `Octave`, which extension did you install to get the Octave language definition? It doesn't come standard with Sublime. – MattDMo May 28 '14 at 17:53
  • 1
    It's supposed to say `Matlab`, as that is the correct syntax for this type of `.m` file. ObjectiveC++ source code (not header) files also end in `.m` instead of `.cpp`, for example, but this syntax will give you incorrect highlighting. You may need to adjust your theme to highlight Matlab/Octave scopes correctly. – MattDMo May 29 '14 at 18:03
0

I am using Sublime Text 3 on OS X

Octave programs are running perfectly. So you can try the below mentioned steps

Open Sublime

Goto Tools --> Build System --> New Build System...

Paste this code

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

Save it as Octave.sublime-build

Now use Octave as your build system

Use ⌘ + B to run your code.

Enjoy!