You can put all these function definitions in a node or nodes and install them by running the node with CTRL-b. Or if there are so many that you want to put them in a module, you can import them from the module, but it doesn't have to be a plugin. You could put it into, for example, ~/.leo/functions. You can add that location to the Python system path, then import your function definition module from there.So there are many possibilities for adding your own functions and command that can be stored right in subtrees in myLeoSettings.leo, or in a module, without even needing a plugin. Or a plugin could use the same techniques to install your functions. If you want to write them as Leo minibuffer commands, you can create menu items for them, so that you can access them from Leo's menubar (you do that in myLeoSettings.leo, or in particular outlines).
class Hiliter:
def __init__(self, cc):
self.c = cc
w = cc.frame.body.wrapper
self.editor = w.widget# .....# Install the highlighter in all commandersfor cc in g.app.commanders():
cc.hiliter = Hiliter(cc)
cc.hiliter.editor.cursorPositionChanged.connect(cc.hiliter.highlightCurrentLine)
One thing you will have to decide is where the plugin should live. You don't want it to be in the Leo codebase since it's personal. Leo will load plugins from sys.path if you list them in the @enabled-plugins setting if you give the module name without the ".py" extension. So you have to get your plugin on sys.path. Here is how I do it (using Windows paths). In Lib.sitepackages I place a .pth file, custom.pth. This file walks up the the Python directory in %APPDATA%\Python:# Look in AppData\Roaming\Python for other files and packages.
..\..\
In this Python directory I created pycustomize\leo. Now I can import a module from that directory:from pycustomize.leo import my_pluginI decided to set up the location of these files (I have some others in pycustomizeI) like this so they wouldn't need to be copied to each new Python install. I only need to remember to copy custom.pth to the new install.
Here is the easy (and flexible!) way:- Define a shared @command f1 node in your myLeoSetting.leo for your function f1.- Execute the function with: c.doCommandByName("f1").
I'm going to do a bit of a balance between plugins or the way which you said.
For now, Thomas's approach to 'place a .pth file in Lib.sitepackages' and plugins way seems the most plausible if I consider writing some future tests for some of my custom functions.
Thank you, Thomas and Edward, for your suggestions.
The best thing about Leo is that if you want add some simple functions, just use @command F1 node is enough.
- Define a shared @command f1 node in your myLeoSetting.leo for your function f1.- Execute the function with: c.doCommandByName("f1").