Sublime Forum

EventListener for a specific syntax

#1

I’m just starting to delve into Sublime’s Plugin API, as I am trying to create a new plugin for my needs.

My question is if there is a way to make an EventListener fire only when the focused view uses a specific syntax.
I know that I could use

view.settings().get("syntax")

but I’m afraid this will not scale on the long run, if someone has many views opened

Thank you!

0 Likes

#2

Just use it ! It scales because the event will likely fire for the current view, not for all the views at the same time.

0 Likes

#3

Working on

view.settings().get("syntax")

is just fine.

Another idea would be to use the associated scope that the syntax defines and match a selector on that. It’s more flexible in that you can match multiple syntaxes with a single selector and it’s easily expanded. Here are some links to work with:

docs.sublimetext.info/en/sublime … tml#scopes
github.com/SublimeText/AAAPacka … #L112-L115
docs.sublimetext.info/en/sublime … h_selector

And here is an example usage:
github.com/FichteFoll/CSScheme/ … #L224-L238

0 Likes