First Plugin !
After a long engagement with the basic plugin that Sublime Text 3 makes for us using tool->developer->new plugin, and a bit of help from my brother and the internet, I have learned a few important things:
1. We need to open a new folder where all the plugin files will be saved.
The folder must be placed in the following path:
C:\Users\USERNAME\AppData\Roaming\Sublime Text 3\Packages
Notice not to create it in:
C:\Users\USERNAME\AppData\Roaming\Sublime Text 3\Packages\User
Because the plugin would not work (this was one of my big my issues).
2. The plugin, which looks like this:
.We need to save into the folder we created in (1) with the extension .py
This basic plugin is supposed to insert the "Hello, world!" string to the beginning of the file we are currently "standing" on while we executed the run command, which brings me to the next section…
1. So, how do we run the plugin?
(all the explanations are in here as well https://cnpagency.com/blog/creating-sublime-text-3-plugins-part-1/)
The basic way is to open the console (view->show console) and run the command: view.run_command('example').
The reason why we pass the 'example' string as an argument is so the ST3 will know what class to run.
ST3 strips the Command part from the class name and take the remaining part, in lower case, as the class name.
So, in this case, we are left with 'example' instead of 'ExampleCommand'.
Notice that if the class name has more then one word that starts with an upper case letter, ST3 will divide the words with '_', for example:
If my class is named 'EdenPluginCommand' ST3 will see it as 'eden_plugin' . so we will ren view.run_command('eden_plugin').
Another way I found is to create a menu button (there are 3 types, depending on the extension of the file we write. Check the link to learn more).
Notice:
Id- the name of the button in the ST3 system
Caption- the name of the button as we will see it in the menu
Command- the class name we want to run when the button is pressed
2. Another thing I learned is how to extract the current file name.
First, we need to import os.
Now, look at this code:
In summary: I managed to do the first thing from the previous post list and create a plugin which write a string to the beginning of the current file (the one we were on when we ran the command)
according to it's name.
according to it's name.
We came to the conclusion that we must establish our knowledge in Python before we can begin developing more difficult plugins.
So, for the coming time period we will be focusing on developing Small Python projects which will focus around OOP, Design and Events.
Comments
Post a Comment