I have been developing a plugin for a while now and I think I am missing some basic concepts, despite relative success. So here are a few questions that I hope somebody can answer, and if the answer is just a pointer to the right document, that would be perfect.
- In python, a file is called a module and a folder full of modules is a package?
- Is a sublime text plugin a module or a package? I suspect that the answer is ‘module’ because when I am editing files in my live plugin, sublime loads each file as it changes and refers to the file itself as a plugin.
reloading plugin sublemacspro.jove reloading plugin sublemacspro.sbp_goto_file
-
If each module is in fact its own plugin, is there any way to load those plugins individually?
-
If I split my code into smaller files, but want to share infrastructure between them, is that possible? In my sublemacspro plugin, I keep state on every active view, such as last touched time, but often more substantial data as well. It’s implemented as an EventListener. If I put that code into its own module and import it into other modules with actual TextCommand classes, is that event listener and view state duplicated in each module? I’d hate to be invoking difference instances of the same event listener N times just so my code can be better organized.
I am very confused. I tried to answer some of these questions just now, and here’s where I am at:
- There is only one instance of that event listener. That’s good.
- Importing a class from another module seems to work.
- However, I seem to end up with multiple versions of that class, possibly just 2 versions: one for modules that did “from sublemacspro.misc import *” before sublemacspro.misc was loaded, and one version after sublemacspro.misc was loaded by sublime.
reloading plugin sublemacspro.complete_all_buffers MISC 140391396522240 reloading plugin sublemacspro.jove JOVE 140391396522240 reloading plugin sublemacspro.mark_ring reloading plugin sublemacspro.misc MISC 140391395024112
This different ID means that I cannot do issubclass(SomeCommand, BaseClass) because they are two different classes. It also means class variables and the like will not be shared.
So is this sublime weirdness or just python weirdness I am not understanding? Is there a way for me to control the order that files are loaded in a sublime plugin? If I could specify the correct order, it might solve my problems.