On Sunday, August 3, 2014 7:00:58 AM UTC-5, Edward K. Ream wrote:

> ...keep revising code until it *obviously* is the simplest code possible.

Here are vim-mode's present (not pushed) state handlers.  They are neither 
tested, nor integrated with the key handlers, but pylint is happy :-)

    def do_inner_motion(vc):
        '''Handle strokes in motions.'''
        return vc.do_state(vc.motion_dispatch_dict,'motion')
            
    def do_insert_mode(vc):
        '''Handle insert mode: delegate all strokes to 
k.masterKeyHandler.'''
        vc.delegate()
    
    def do_normal_mode(vc):
        '''Handle strokes in normal mode.'''
        return vc.do_state(vc.normal_mode_dispatch_dict,'normal')
            
    def do_visual_mode(vc):
        '''Handle strokes in visual mode.'''
        return vc.do_state(vc.vis_dispatch_dict,'visual')

Three of them use the following helper::

    def do_state(vc,dispatch_dict,mode_name):
        '''General dispatcher code.'''
        trace = False and not g.unitTesting
        func = dispatch_dict.get(vc.stroke)
        if func:
            if trace: g.trace(mode_name,vc.stroke,func.__name__)
            func()
        elif vc.is_plain_key(vc.stroke):
            vc.ignore()
        else:
            # Pass non-plain keys to k.masterKeyHandler
            vc.delegate()
            vc.return_value = False

To make this scheme work, all key handlers must end in an acceptance 
method: vc.accept, vc.delegate or vc.ignore.

As a result, key handlers know nothing about state handlers and vice versa!

Nothing could be simpler or more flexible.  This is the way it is written 
in The Book.

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