MATLAB and Objective-C in Sublime Text 2

Solution 1:

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.

Solution 2:

In the file Matlab.tmLanguage change it to

<key>fileTypes</key>
<array>
    <!-- Actually, it's generally .m, but that's taken by Objective-C. It needs an entry to show up in the syntax list. -->
    <string>m</string>
    <string>matlab</string>
</array>

and remove it from ObjC.tmLanguage