Sublime Forum

SublimeModelines plugin

#1

Adds support for vim-like modelines to Sublime.

github.com/SublimeText/Modelines

0 Likes

#2

Thanks, I’ve wanted modelines support for a while!

0 Likes

#3

Updated!

  • Fixed bugs in conversion from string to JSON type
  • Better error reporting

github.com/SublimeText/Modelines

0 Likes

#4

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 !

0 Likes

#5

This should do it:

# sublime: syntax 'Packages/ShellScript/Shell-Unix-Generic.tmLanguage'
0 Likes

#6

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 !

0 Likes

#7

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.

0 Likes

#8

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 !

0 Likes

#9

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.

0 Likes

#10

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).

0 Likes

#11

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… :slight_smile:

0 Likes

#12

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 ?

0 Likes

#13

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.

0 Likes