Sublime Forum

Dynamically start/stop EventListener?

#1

Hi all,

Sorry if this is a dumb question, I’m just getting started with the SublimeText 3 API. I’m working on a plugin for Sublime which will require an EventListener to listen to on_modified() and do an action that’s relatively resource-intensive. However, based on the way the plugin is structured, it’ll only be necessary to perform this action when within a plugin session. Is it possible to dynamically start or stop a listener from within a command’s run() method? Or, if that’s not possible, is there a way to create a listener which will only listen to certain windows and stop listening when the targeted windows close?

Sorry again if this is a stupid question.

0 Likes

#2

You can get the functionality you want. What you could do is create a global flag. When the flag is enabled, the listener will actually do its “work”. If the flag is disabled, the listener will just exit out. Then you can have a run command that can turn off/on said global switch.

0 Likes

#3

Okay, thanks. That was what I was planning on doing if there was no other method.

0 Likes