Setting file size for one project in Sublime Text 2
For those interested in a solution for ST3, I wrote this blog post that I will endure here.
First of all, you need to save the python code below to a file in a directory Packages/User
. Where this directory is located depends on your system. On macOS, it's in ~/Library/Application Support/Sublime Text 3/Packages/User
. Give the file a name, for example project_specific_file_syntax.py
.
import os.path
import re
import sublime_plugin
class ProjectSpecificFileSyntax(sublime_plugin.EventListener):
def on_load(self, view):
filename = view.file_name()
if not filename:
return
syntax = self._get_project_specific_syntax(view, filename)
if syntax:
self._set_syntax(view, syntax)
def _get_project_specific_syntax(self, view, filename):
project_data = view.window().project_data()
if not project_data:
return None
syntax_settings = project_data.get('syntax_override', {})
for regex, syntax in syntax_settings.items():
if re.search(regex, filename):
return syntax
return None
def _set_syntax(self, view, syntax):
syntax_path = os.path.join('Packages', *syntax)
view.set_syntax_file('{0}.tmLanguage'.format(syntax_path))
Now you just need to add a section syntax_override
to your .sublime-project
file eg.
{
...
"syntax_override": {
"\\.html$": [ "HTML Underscore Syntax", "HTML (Underscore)" ]
}
}
A section syntax_override
can contain as many key / value pairs as you need. The key must be a regular expression to match against the filename. The value must be an array containing two strings. The first line is the name of the package containing the syntax file and the second is the name of the syntax. Create a root structure in the Sublime Text structure to find files that end in .tmLanguage
. The names of these files (minus the extension .tmLanguage
) are what you would use for the second line.
I've only tested this with Sublime Text 3, but I'm pretty sure it can be easily adapted to work with Sublime Text 2.
source to share
Sublime Text 2 doesn't have built-in syntax options for every project.
I am currently using the Modelines plugin as a workaround, but to do this I need to add this model at the top (or bottom) of each file .html
in your project:
<!-- sublime: x_syntax Packages/Mason/Syntaxes/Mason.tmLanguage
-->
Note that a carriage return , -->
should not be in the same row or be interpreted as a parameter.
Another track, I read many comments about the DetectSyntax plugin . I quickly tried to try, but without success, but maybe you will be more patient than me! Anyway, I'm interested in feedback if you can get it to work.
source to share