Sublime Forum

How to not restart sublime everytime a change is made in a file not at the root of the package


I am kinda fiddling with the idea of making a plugin but every time I make some changes to a file not at the root of the package, the changes don’t seem to propagate. For example, if I make some changes to let’s say a lib/ file, the changes don’t propagate & I have to frustratingly restart Sublime for the changes to take place. Any ideas how can I overcome this ?
Any other tips for a newbie plugin developer would also be appreciated :upside_down_face:

Technical Information:

Sublime build 3211
Windows 7, 64 bit OS



The short version of this is that only python files in the root of a package are considered plugins by Sublime; all other Python files are ignored. As you’ve seen you can still load them if you like but Sublime will otherwise ignore them. This allows you full control of what gets exposed to the plugin environment; for example something like send2trash supports multiple operating system, so it has specific code for each one that it takes care to load on its own.

Sublime automatically reloads plugins when they change, but since other Python files aren’t plugins they aren’t reloaded; thus it becomes your responsibility. By far the easiest and quickest way to do that is the AutomaticPackageReloader package.

As the package author you can also get your plugin to reload its own modules; OverrideAudit does this for example (see There has also been talk of adding this to the sublime_lib dependency, although I don’t think it’s happened yet.

Regardless of which way you go, remember to stop and restart Sublime periodically because reloading a module will leave any old symbols that it used to contain still present; for example if you delete a command from the plugin, the command will still exist until you quit. If you’re not careful you can end up relying on something you deleted and not noticing it for a while. :wink:



What’s the difference between using something like AutomaticPackageReloader to having a package reload it’s own modules ?



If you use APR, you trigger the command to reload manually whenever you’re ready; you need to be editing one of the files in the package, and that whole package will reload. This is handy for development purposes because you can make a few changes, and then make sure that everything reloads when you’re ready.

If you do it yourself in plugin code, then in order to get things to reload you need to save the root plugin file (in the example above that’s because the act of loading that file is what triggers it to reload things.

A reason to have your package do this would be that if you’re distributing your package via Package Control and you do an update, Package Control will set the package to be ignored (unloading the plugins in it), update it, and then un-ignore it. At this point the plugins will reload, but any of the modules that it contains will not, so you can end up with a mix of old and new code. Commonly in this case you would give advice somewhere that when the package updates you should restart Sublime, to make sure that everything is loaded.

This is the reason OverrideAudit does this in code, but I still use APR manually while developing it (and other packages) as well.



There is also a reload on save option in APR that you could consider. I personally use it a zillion times a day.