Adds support for vim-like modelines to Sublime.
SublimeModelines plugin
Updated!
- Fixed bugs in conversion from string to JSON type
- Better error reporting
Hello @guilhermoo,
How can i set a modeline for a setting the filetype (to have syntax) ?
I want to make a file named bashrc have the shell syntax.
Thanks !
This should do it:
# sublime: syntax 'Packages/ShellScript/Shell-Unix-Generic.tmLanguage'
Hello @guillermoo,
Thanks for the example ! It worked fine =)
Also, im trying to set the syntax for *.dtml files (which i need to render as css) and *.zcml (which i need to render as xml).
I trying to make *.zcml work, but the only way it works is as follow:
<!--
# sublime: syntax 'Packages/XML/XML.tmLanguage'
-->
I tried a lot of variations without the # character, but i did not had success.
I did not managed to make CSS in dtml in any way.
Can you help me ? Thanks a lot !
If you want to always use a syntax definition with certain file extensions, you’ll be better served by View > Syntax > Open all with current extension as…
Modelines are intended for single files, which I think is the case with .*rc files.
Thanks again, @guilermoo !
I did not know that option, but it still seems to be a bug to me. When i try to set the syntax of a file to css, it does not work.
I have just one dtml file and i would like to set the syntax just for it, as *.dtml may be used for other things like sql and so on.
Thanks again !
Currently SublimeModelines only looks for single-line comment characters, which does not apply to html files; I haven’t doublecheked, but I suppose the html package defines only multi-line comments, which confuse SublimeModelines. I will take a look and see if I can make modelines work in these cases too.
Thanks a lot for your effort !
The strange thing is that XML comments (multi-line) work with this workaround:
<!--
# sublime: syntax 'Packages/XML/XML.tmLanguage'
-->
But the CSS (which define multi-line comments) does not work (i tried almost everything).
I’ve checked and this works for *.dtml files:
<!-- sublime: syntax 'Packages/CSS/CSS.tmLanguage -->
If you want to declare more modelines, you need to precede them with “<!-- sublime:”, because “” too.
The *.zcml will work as you describe because Sublime Text doesn’t assign them any syntax (at least in my config), so SublimeModeliens defaults to the prefix “# sublime:”. As it can be seen in your example, it’s your modeline that’s making the file XML, so before that it was unknown.
It seems I won’t have to change the code after all…
Hmmmm,
Strange, i created a file called: “test.dtml” which have this code:
<!-- sublime: syntax 'Packages/CSS/CSS.tmLanguage' -->
body {
color:Black;
font-family:"Lucida Grande",Verdana,Lucida,Helvetica,Arial,sans-serif;
font-size:69%;
font-size-adjust:none;
font-style:normal;
font-variant:normal;
font-weight:normal;
line-height:normal;
}
And it does not work for me. Does it work for you ?
Try this (note the additional linebreak):
[code]
body {
color:Black;
font-family:“Lucida Grande”,Verdana,Lucida,Helvetica,Arial,sans-serif;
font-size:69%;
font-size-adjust:none;
font-style:normal;
font-variant:normal;
font-weight:normal;
line-height:normal;
}[/code]
I might look into excluding the TM_END_COMMENT value from the key,value extraction for modelines.