This Aha is a direct result of our discussions in #581: Define all commands 
using a LeoCommand class? 
<https://github.com/leo-editor/leo-editor/issues/581>

*The problem*

The present Commands class (in leoCommands.py) is *way* too large. Besides 
providing essential services, the Commands class *also* defines *commander 
commands*. These are commander *methods*, like c.save, c.convertAllBlanks, 
etc., that define Leo's minibuffer commands. This was a design mistake, as 
I'll now explain.

Potentially *any* of these commands can be accessed in user scripts. For 
example, many of my own scripts call c.save(). As a result, *all *the 
command-related methods that *now* exist in the Commands class must 
*continue* to exist *forever*.  Removing any of these would break scripts 
of which we Leo devs have no knowledge.

Previously, there was no *safe *way of defining commander commands outside 
of the Commands class. This was the design mistake.


*The Aha*
The @c.command decorator, defined in leoCommands.py, will define a command, 
just like g.command. And (Aha!) the decorator will *also *inject the 
function (as a method) into the Commands class.  Voila!  This creates a *safe 
and convenient* way of defining commander commands outside the Commands 
class and outside of leoCommands.py.

For example, the c.save *member* will continue to exist even though the 
save *function *will reside in another file.

At present, commander commands reside in: class Commands-->c.Top-level 
commands. They are organized by menu. These commander commands will be 
moved out of the Commands class into corresponding files in the 
leo/commands folder: commanderFileCommands.py, commanderEditCommands.py, 
etc.

*Summary*

Once the @c.command decorator is proven to work we can:

- Migrate commander commands out of leoCommands.py safely and conveniently.

- Close #581. There will be no need to define commands using classes.

@c.command might also be able to handle complications such as 
c.universalCallback.  Or not.

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 https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to