Sublime Forum

Set Syntax for View?

#1

I’m trying to create a keyboard shortcut to set an unsaved file’s syntax.
view.syntax_name(view.buffer_id()) in the console returns the correct type for files already saved, but I can’t figure out how to set it.

Thanks,
Kirk

0 Likes

#2

I think when the quick panel API becomes available that will make a syntax selection tool much better.

0 Likes

#3

Try something like this:
view.settings().set(‘syntax’, ‘Packages/’+ syntax + ‘/’ + syntax + ‘.tmLanguage’)

0 Likes

#4

Isn’t view.settings().set() implemented in the ST2 alpha? The syntax doesn’t appear to change when I execute

view.settings().set('syntax', 'Packages/'+ syntax + '/' + syntax + '.tmLanguage') where syntax is “XML”, for example.

I’m trying to implement the DetectFileType plugin in ST2, to be able to detect .html.erb etc. in a reliable way.

0 Likes

#5

view.settings().set() should work, but isn’t the best way to change the syntax in any case, as it won’t cause the right .sublime-settings files to be associated with the view.

There will be a new API function, view.set_syntax_name(), in the next version.

0 Likes

#6

Is this an issue in 1.x as well?

0 Likes

#7

Yep

0 Likes