On Sunday, May 10, 2015 at 7:03:02 AM UTC-5, Edward K. Ream wrote:

> single dict, say *g.cmd_instance_dict*, could eliminate the need for 
per-class decorators.

This dict is Leo's Rosetta Stone! Here it is:

cmd_instance_dict = {
    # Keys are class names, values are attribute chains.

    # Created from c.initObjects...
    'AtFile': ['c','atFileCommands'],
    'AutoCompleterClass': ['c','k','autoCompleter'],
    'ChapterController': ['c','chapterController'],
    'Commands': ['c'],
    'ControlCommandsClass': ['c','controlCommands'],
    'FileCommands': ['c','fileCommands'],
    'KeyHandlerClass': ['c','k'],
    'LeoApp': ['g','app'],
    'LeoFind': ['c','findCommands'],
    'LeoImportCommands': ['c','importCommands'],
    'PrintingController': ['c','printingController'],
    'RstCommands': ['c','rstCommands'],
    'VimCommands': ['c','vimCommands'],
    'Undoer': ['c','undoer'],

    # Created from  and EditCommandsManager.__init__...
    'AbbrevCommandsClass': ['c','abbrevCommands'],
    'BufferCommandsClass': ['c','bufferCommands'],
    'EditCommandsClass': ['c','editCommands'],
    'ChapterCommandsClass': ['c','chapterCommands'],
    'ControlCommandsClass': ['c','controlCommands'],
    'DebugCommandsClass': ['c','debugCommands'],
    'EditFileCommandsClass': ['c','editFileCommands'],
    'HelpCommandsClass': ['c','helpCommands'],
    'KeyHandlerCommandsClass': ['c','keyHandlerCommands'],
    'KillBufferCommandsClass': ['c','killBufferCommands'],
    'MacroCommandsClass': ['c','macroCommands'],
    'RectangleCommandsClass': ['c','rectangleCommands'],
    'RegisterCommandsClass': ['c','registerCommands'],
    'SearchCommandsClass': ['c','searchCommands'],
    'SpellCommandsClass': ['c','spellCommands'],
}

The dict contains entries for all classes that could conceivably define Leo 
commands. Not all classes should be in the dict.

This is an important development.  A variant of this dict, containing more 
classes, could be used in type analysis.

Here is the code in leoGlobals.py that checks this dict:

def check_cmd_instance_dict(c,g):
    '''
    Check g.check_cmd_instance_dict.
    This is a permanent unit test, called from c.finishCreate.
    '''
    d = cmd_instance_dict
    for key in d.keys():
        ivars = d.get(key)
        obj = ivars2instance(c,g,ivars)
        if obj:
            name = obj.__class__.__name__
            if name != key:
                g.trace('class mismatch',key,name)

The check now passes. It is unlikely ever to fail again. The next steps 
will be:

- Use this dict in the wrapper inside g.cmd.
- Replace @cmd with @g.cmd everywhere.
- Remove/disable all the per-class cmd decorators defined yesterday.
- Unify all events passed to commands.

*Summary*

g.cmd_instance_dict is a wholly unexpected breakthrough:

- It succinctly summarizes all of Leo's classes.
- It can easily be checked for accuracy.
- It allows the all important "self" argument (whatever its spelling) to be 
passed to methods.
- Unless I am greatly mistaken, it will eliminate the need for per-class 
decorators.

There is *no way* that Python could recreate the data in this dict. A big 
step forward.

EKR

-- 
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.

Reply via email to