Sublime Forum

User plugin not loaded at startup

#1

Version 3.2.1 Build 3207
Ubuntu (Kubuntu) 18.10, KDE

I have a user plugin which is saved in ~/.config/sulime-text-3/Packages/User/my plugin.py - it is an EventListener which handles on_new(), on_load_async(), on_pre_save() and seems to work fine after editing/saving it (the console says “reloading plugin…” in that case). But, if I quit and re-open Sublime, the plugin is not active.

Wondering if I’ve somehow wound up with the plugin in the wrong place, or if there’s something additional I need to do, so that it gets loaded at startup?

0 Likes

#2

If you are just starting ST, the file may be loaded (unless they are large) before ST loads your plugin hence on_load() and on_load_async() for the file are not fired under this situation.

NOTE: jps is the author of ST.

0 Likes

#3

Interesting - I used this same plugin on a Mac for a year or so without noticing the problem, but your explanation makes sense.

Is there an event that fires after everything has loaded (I presume the plugin ctor isn’t the right place for this, but maybe it would work?), so I could iterate over all open files?

0 Likes

#4

Maybe plugin_loaded() could be useful?

If a plugin defines a module level function plugin_loaded(), this will be called when the API is ready to use. Plugins may also define plugin_unloaded(), to get notified just before the plugin is unloaded.

Eventually, I have both plugin_loaded() and on_load_async() in my plugin.

1 Like

#5

Got it, thanks!

0 Likes

#6

Embarrassingly, the issue was actually that my plugin was working OK when reloaded, but on a fresh start of Sublime was throwing an exception in the ctor…

I only use the on_load_async() to set a little bit of state about each buffer, for use in on_pre_save(); this is a plugin to interface with our revision control system. I get around the above issue by having the on_pre_save() check to see if the state was set (if the buffer was created after the plugin loaded), and if not (scenario descirbed above) it runs similar code to what on_load_async() would’ve done.

1 Like