Sublime Forum

Monitor syntax changes made by other plugins?

#1

Is it possible to monitor syntax changes due to view.set_syntax_file(syntaxFile) in another plugin?
Just tried all event listener and it looked like none of them captured it.

0 Likes

Change language = lost focus = annoying behavior
#2

I believe not, you have to hope the plugin developer chose to use the set_file_type command or beg/bribe them to change it unfortunately…

btw, set_syntax_file is depreciated by assign_syntax these days

0 Likes

#3

Actually, maybe it is worth trying view.settings().add_on_change('syntax', your_on_change_callback_here)

0 Likes

#4

confirmed, the add_on_change method of the view's settings object works :smiley: :thumbsup:

3 Likes

#5

add_on_change() should work, yes, but the string you pass in the first argument is not supposed to be the identifier of the setting but instead a (potentially) unique identifier that you can use later to un-register the listener.

0 Likes

#6
from uuid import uuid4 as guid

unique_key = str(guid())
view.settings().add_on_change(unique_key, your_on_change_callback_here)

probably it would make sense to manually track the syntax value then to determine when it changes, as opposed to when a value for a different key is changed in the view’s settings.

0 Likes

#7

Indeed.

0 Likes