Hello.
Sublime Text 2.0.2, Build 2221.
-
Create example plugin:
import sublime, sublime_pluginclass EventListener(sublime_plugin.EventListener):
def on_pre_save(self, view):
print(’[listener] pre save event’, view.id(), view.file_name())def on_post_save(self, view): print('[listener] post save event', view.id(), view.file_name())
-
Save it to User/event_listener.py.
-
Open a duplicate view for this file – File / New view into file.
-
Switсh to the first view tab, open console, check view ID:
>>> view.id() 927
-
Switсh to the second view tab, check view ID:
>>> view.id() 929
-
Switch to the first (origin) view tab. Save it. See in console:
('[listener] pre save event', 927, u'…User\\even_listener.py') … ('[listener] post save event', 927, u'…User\\even_listener.py')
-
Swithch to the second (cloned) view tab. Save it. See in console ID of the origin view:
('[listener] pre save event', 927, u'…User\\even_listener.py') … ('[listener] post save event', 927, u'…User\\even_listener.py')
-
Expect this:
('[listener] pre save event', 929, u'…User\\even_listener.py') … ('[listener] post save event', 929, u'…User\\even_listener.py')
In Sublime Text 3, Build 3114 is the same behavior.
So, event fired only for origin view?
How can I catch save event for every view, not only for origin?
Now I am using workaround:
view = sublime.active_window().active_view()
instead of view parameter of the event method.