So, before I get to your problems:
- Don’t use so many globals! It will hunt you down eventually and is a very bad habit. Use parameters or class properties where possible, such as for your
populate_file
function.
- You are leaking file handles. Thrice. Use the
with
operator in Python to reliably close resources like file handles once you are done with them (even when exceptions occur). with
is awesome.
Anyway, back to your problem.
In find_templates
you use os.walk(sublime.packages_path())
.You need to use sublime.find_resource
on ST3 instead as it will find files in .sublime-packages (such as this very package when installed) and then use the load_resource API. These are only for ST3 however, so you either need to provide a different mechanism for ST2 or stop supporting it.
I’m not exactly sure if that’s everything, but that is the first and pretty much only offense I found.
And a tip: You may provide the open_file command with text that it will open if the file does not exist. window.run_command("open_file", {"file": filepath, "contents": content})
That will get rid of the very weird on_load construct and the event listener in general.