PRAGTICAL
Discover and extend the Pragtical editor
Ever-practical David Bolton demonstrates how to write a plugin for the open source editor Pragtical in the Lua language.
OUR EXPERT
David Bolton
likes writing extensions and plugins. Here he has created a simple plugin to show file size information for a file that you pick. It’s just 50 lines long!
QUICK TIP
Plugins should register immediately if you save them in the data/ plugins folder. A way to test is to look for your commands in the palette. If they aren’t there, close and reopen Pragtical. It will tell you what’s wrong.
A section of the core log highlighting an error loading a module.
If you’ve not had enough of development environments in this month’s Roundup (see page 26), I perhaps you should try Pragtical. This practical code editor feels a lot like Visual Studio Code but with less Microsoft. And what better way of learning to use a new editor than writing your own plugin for it?
Pragtical
can be extended through plugins written in Lua. It also has themes, so once you’ve learned how to create plugins, you can apply your artistic ability to try to create your own themes. There are also widgets, which are visual controls.
Pragtical
comes with a collection of those in the widget folder for buttons, checkboxes and so on, all written in Lua source code.
The data directory is a central place for all widgets, fonts, plugins and so on that each have their own directory. By default, it’s called data and is usually found under where the Pragtical app is installed. Other locations are possible if the app is installed according to the Unix Filesystem Hierarchy. However, on Ubuntu, we extracted the downloaded tar.gz file in Downloads and then moved the Pragtical folder to our home directory. So, the path to the data folder is ~/pragtical/data
On the home screen in Pragtical with no files open, there’s a link to the Plugin Manager. You can also run it in a terminal by using this command: $ ./pragtical pm
There are a lot of available commands. Run the following to see them: $ ./pragtical pm list
The Plugin Manager is itself a plugin. You can see the C/Lua source code in data/plugins/plugin_ manager along with the init.lua. The bulk of it is written in C and found in the plugin-manager GitHub project.