Home Download Buy Blog Forum Support

Get current source

Get current source

Postby jbrooksuk on Thu Apr 14, 2011 8:01 am

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: Select all
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)

I guess I could regex it out, but I'm intrigued to know if there is a better way?

James
jbrooksuk
 
Posts: 765
Joined: Sun Apr 11, 2010 10:37 am
Location: England

Re: Get current source

Postby jps on Thu Apr 21, 2011 7:55 am

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
jps
Site Admin
 
Posts: 3067
Joined: Wed Mar 19, 2008 12:33 pm

Re: Get current source

Postby jbrooksuk on Thu Apr 21, 2011 8:02 am

jps wrote: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

That'll do me :)
jbrooksuk
 
Posts: 765
Joined: Sun Apr 11, 2010 10:37 am
Location: England


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 3 guests