Edit: Mmm, using view.syntaxName(0) would seem to work, but it's not that obvious from the documentation at least. Not to mention needlessly wordy by passing an parameter where none should be needed for this use case IMHO.
Edit2: This function seems to return a flat Unicode string consisting of two parts. The first part being specific for the point you call syntaxName() on, the second part identifying the type of file/syntax highlighting applied, e.g.:
- Code: Select all
keyword.control.import.from.python source.python
meta.preprocessor.c source.c++
Example use:
- Code: Select all
import sublime, sublimeplugin
class MyPlugin(sublime.TextCommand):
def run(self, view, args):
syntax = view.syntaxName(0).split()[1]
>>> source.python
Edit3: jps, any chance of getting a simpler function that just returns 'python' or 'c++'?