MacOS – MATLAB and Objective-C in Sublime Text 2

macostext-editor

Is there a way to set Sublime Text 2 (running under OSX) so that it can identify MATLAB (.m) files and Objective-C (.m) files automatically? Meaning that ST2 would be able to differentiate between each one and apply it's special syntax highlighting rules. I have already seen this behavior in the all mighty VIM and Emacs.

Best Answer

You may want to have a look at /Users//Library/Application Support/Sublime Text 2/Packages/Matlab.sublime-package. It's a simple ZIP file containing a bunch of XML (Plist) files.

In the Sublime Doc for syntax definitions you'd be able to find a documentation of how to create (and edit) syntax definitions.

For an example have a look at the perl syntax definition, it contains a key named "firstLineMatch" which is not used in the Matlab syntax definition. But you could add one and create a file magic for/in your Matlab files.

Update : I just gave it a go and it doesn't seem to work. Do be fair TextMate can't do it either.

Update 2 : After some more investigation: The question about firstLineMatch came up in the Sublime Forum. The file extension is taking precedence over firstLineMatch right now. So there's not much that can be done. With firstLineMatch working you could do nice things. And this would mean that no file magic would be necessary since the syntax of Obj-C and Matlab files is different.