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.
MacOS – MATLAB and Objective-C in Sublime Text 2
macostext-editor
Related Question
- Change highlight colour in Sublime Text 2
- Refining a Sublime Text 2 / Transmit workflow
- MacOS – How to setup Python3.3 and Sublime Text 2 correctly on OS X 10.8.2
- MacOS – Sublime Text 2 – Save Dialogue Tab Issues
- MacOS – How to add link to Sublime Text
- MacOS – Text file preview failing in Finder (perhaps due to Sublime Text?)
- Install SublimeHighlight plugin on Sublime Text 3
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 overfirstLineMatch
right now. So there's not much that can be done. WithfirstLineMatch
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.