setting default syntax for sublime doesn't work

matlab, sublimetext, sublimetext2, syntax

Solution

I'm not sure why Sublime is doing this, but there's a way around it. Since you're using ST2, it's quite easy. Select `Preferences -> Browse Packages...` to open your `Packages` folder, and open the `Objective-C` subfolder. Open `Objective-C.tmLanguage` in Sublime as an XML file, and comment out (or remove entirely) Line 7:

<string>m</string>

Save the file and close it. Next, open `Objective-C++.tmLanguage` and do the same thing to Line 8:

<string>M</string>

Save and close that file as well. Finally, just to make sure your `Open all with current extension as...` command worked, go to `Packages/User` and check for the existence of a file called `MATLAB.sublime-settings`. Open it as a JSON file, and double-check that its contents are as follows:

{
    "extensions":
    [
        "m"
    ]
}

If for some reason the file doesn't exist, create it with the above contents and save it. You should now be able to open any `.m` file and have the syntax automatically set to `MATLAB`.

Note for Sublime Text 3 users:

ST3 does not store its default packages in `Packages` anymore, instead they're in the `Installed Packages` folder (its location varies by OS and type of install) as zipped `.sublime-package` files. To access the contents, install @skuroda's `PackageResourceViewer` plugin to seamlessly access the contents of these files. Once installed, open the Command Palette (CtrlShiftP on Windows/Linux, ⌘ShiftP on OS X) and type `prv` to bring up the `PackageResourceViewer` options. Select `Extract Package`, scroll down to `Objective-C`, and hit Enter. You can now follow the directions above for opening the `Packages/Objective-C` folder and editing the `.tmLanguage` files. The `Packages/User` directory is a regular directory, so you don't need to extract it to verify the contents of `MATLAB.sublime-settings`.

Problem

Whenever I open a .m file the default syntax is objective-c but I want to change that to matlab. So when I open a .m file I go to view -> syntax -> open all with current extension as.. and choose matlab. After that if I open another .m file the default syntax is matlab. But if I close sublime and open it again the default syntax is back to objective-c. I added objective-c to ignore syntax list but now it opens .m files as plain text. Is there another way to set default syntax for a file extension?

Original source