Sublime Forum

Get current source

#1

Hey all,

How do I get the current source type? I can get the whole line, punctuation, numbers etc, but how about just “source.json” or “source.php” say?

[code]import sublime, sublime_plugin

class GetSyntaxCommand(sublime_plugin.TextCommand):
def run(self, edit):
for region in self.view.sel():
syntax = self.view.syntax_name(region.begin())
sublime.status_message(syntax)[/code]
I guess I could regex it out, but I’m intrigued to know if there is a better way?

James

0 Likes

#2

The base syntax name as such isn’t exposed, but if you want want to switch on the top level language, then you can query the view for it’s ‘syntax’ setting, getting back the name of the .tmLanguage file

0 Likes

#3

That’ll do me :smile:

0 Likes