The goal is simple: improve the g.command decorator so that all commands
can be defined like this:
@g.command('command-name')
def do_command(self,event=None):
'''Implement the command'''
This decorator would eliminate the need for command-definition tables that
occur in various places in leoEditCommands.py and leoCommands.py. These
tables shouldn't be necessary. They are quite a kludge. (To be fair, these
tables were necessary in Leo's early days because decorators did not exist
then.)
At present, the pattern for defining commands is:
@g.command('command-name')
def do_command(event):
c = event.get('c')
if c:
aClass = c.aClass
aClass.do_command
This is clumsy, and prevents the decorator from being used inside classes.
To define a command outside of a class we could define an
@g.command_function decorator with the signature as in the legacy
@g.command decorator. However, it's always possible to wrap a function in
a class, so @g.command_function is not really required.
Only small changes will likely be necessary to create the new g.command
decorator. However, actually replacing the command tables by @g.command
decorators will involve a significant amount of work. I am certainly
willing to update @g.command in all existing official plugins.
*Summary*
The new scheme promises several benefits:
1. It will simplify Leo's too-complex startup logic by eliminating the
need to call code that handles command-definition tables. This would fix a
small but irritating hangnail and might lead to further simplifications of
Leo's startup logic.
2. It will make finding the code for a particular command easier. Just
search for 'command-name' (single quotes). That will almost certainly take
you directly to the correct code, not the command definition table.
3. It will provide a single pattern for defining commands, like Emacs
macros, but simpler and better.
Your comments, please.
Edward
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.