Sublime Forum

How to check if current view is html?

#1

Am I right in thinking that I need score_selector ? If so,

sublime.active_window().active_view().score_selector(123, ‘what do I put here’) ?

0 Likes

#2

You can use this to get the current syntax: view.settings().get('syntax')

If you want to support syntaxes that mix HTML, like PHP, you can use some variation of one of these:

'html' in view.scope_name(view.sel()[0].a)
'text.html.basic' in view.scope_name(view.sel()[0].a)
view.score_selector(view.sel()[0].a, 'text.html.basic')

score_selector allows you to compare the relative specificity of a scope name. For example, inside a comment in an HTML file, the following selectors would return increasing values:

  • ‘text’

  • ‘text.html’

  • ‘comment’

  • ‘comment.block.html’

  • 'text.html.basic comment.block.html ’

0 Likes

#3

Thanks, that helps.

0 Likes

#4

Instead of using standard string operations on scopes you could also use the view.score_selector(point, selector) method which will return an integer or 0 if it didn’t match. Depending on what you want to do it will be easier to use.

For selectors, refer to manual.macromates.com/en/scope_selectors.html

0 Likes