Sublime Forum

On_load is not triggered in a new view with Ctrl+N


I need to set the view settings when a new view is created:

class ToggleSettingsCommandListener(sublime_plugin.EventListener):

    def on_load(self, view):
        global capture_new_window_from
        window = sublime.active_window()

But, it does not work when I create a new view with Ctrl+N, i.e., the on_load event is not fired.

Then, I added the on_new event to trigger on_load:

class ToggleSettingsCommandListener(sublime_plugin.EventListener):

    def on_new(self, view):

    def on_load(self, view):
        global capture_new_window_from

Now, it seems to be working when I create new views with Ctrl+N.

  1. Why do I need both on_load and on_new?
  2. Every time I open some file, I am not creating a “new” buffer?
  3. Can I only use on_new instead of on_load? All I do is set the view settings.

Related threads:



The help for on_load says that it fires when the file has finished loading. If you create a new empty view, it is by definition not loading a file, and so there is no need to invoke on_load because nothing was actually loaded.

On the other hand, on_new is triggered whenever a new view is created.

So on the whole, I’m not surprised that on_load is not triggered and it sounds like it’s behaving exactly the way that it should be.