Rev 3fef357 demonstrates the amazing power of simplicity. I had not 
foreseen how important my recent work would be.

Eliminating the invisible cmd_ convention in leoPlugins.leo has instantly 
made *all *commands created by *any *plugin available in the Plugins menu.

Furthermore, there is much less code than before!  Here is 
Plugin.create_menu:

def create_menu(self):
    '''
    Add items in the main menu for each
    decorated command in this plugin.
    The g.command decorator sets
    func.is_command & func.command_name.
    '''
    self.othercmds = {}
    for item in self.mod.__dict__.keys():
        func = self.mod.__dict__[item]
        if getattr(func,'is_command',None):
            self.othercmds[func.command_name] = func

To make this work the g.command decorator injects two attributes into the 
decorated function:

def command(name):
    '''A global decorator for functions
    outside of any class.'''
    def _decorator(func):
        global_commands_dict[name]=func
        func.is_command = True
        func.command_name = name
        return func
    return _decorator

Advantages:

- The Plugins menu contains all commands added in any plugin.
- Plugin authors can name commands as they like.
- The Plugins menu shows actual minibuffer command names.
- Plugin.niceMenuName is no longer used.  

In short, eliminating the cmd_ convention has simplified the code and made 
it applicable to *all *plugins.

The last phase of the new_dispatch project will be to eliminate code 
disabled when g.new_dispatch is True.  This will likely create secondary 
simplifications in Leo's startup logic.

Finally, eliminating dispatch tables will make it easier to split code into 
separate modules.  Indeed, each *module *will likely define a cmd decorator 
at the top level.  This is better style: there will be no need for the 
following in each decorator.

# pylint: disable=no-self-argument

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.

Reply via email to