I have a plugin for a log viewer. My plugin maintains state about each buffer and each view (with the applicable syntax). When the contents of the file change, all of my state needs to be rebuilt. It’s a log file, so I don’t expect them to be modified often, but it does happen.
What I want to happen is when a ViewEventListener gets an on_modified() event, I want to invalidate my data structures for that view, and if the view is the primary view, invalidate my data structures for the buffer as well.
The problem is that on_modified doesn’t behave as expected. Here’s a test snippet:
class TestEventListener(sublime_plugin.ViewEventListener):
@classmethod
def is_applicable(cls, settings):
return 'Packages/Text/Plain text.tmLanguage' in settings.get('syntax')
@classmethod
def applies_to_primary_view_only(cls):
return False
def on_modified(self):
print("on_modified on view_id=%d" % self.view.id())
I open a file with the “Plain text” syntax, and then I create a second view with File->New View Into File. Then, I modify one of the views.
Because there are two views and I set applies_to_primary_view_only() to False, I have two ViewEventListeners. Therefore, when I modify the buffer, I get two calls to on_modified(), as expected. The problem is that both calls to on_modified() go the same ViewEventListener (I think it’s the primary, but I haven’t verified that). Because of that, the other view doesn’t get notified at all.
I have workaround for this, but I was wondering if I was missing something.