On Sunday, November 10, 2013 1:43:55 PM UTC-6, Edward K. Ream wrote:
>
>
> Step 2 of the vim project is now complete.
>

And 20 hours later, the framework for step 3 is in place!  See rev 6265.

A recent rev added @file leoVim.py to LeoPyRef.leo, so it's now easy to see 
the code.

Only two vim-related methods work: vim_h (move cursor left) and vim_l (move 
cursor right).  But they demonstrate *all* the essential features of the 
framework.

vc.exec_ executes the command discovered by vc.scan.  Here it is::

    def exec_(self,command,n1,n2,motion):

        d = self.commands_d.get(command,{})
        command_name = d.get('command_name')
        func = self.dispatch_d.get(command_name,self.oops)

        # Set ivars describing the command.
        self.command = command
        self.func = func
        self.n1 = n1
        self.n2 = n2
        self.motion = motion

        # Call the handler.
        func()

No if statements!

The first three lines get the spelling of commands and their format from 
@data nodes, and then associate command spellings with vc methods. Elegant, 
and *very* fast.

vc.exec_ then sets ivars describing the command and calls the proper 
method. If would also be possible to pass these as arguments to the vim_xxx 
methods, but perhaps setting ivars is a little more flexible.

As I write this, I see that exec_ should probably handle n1 (the over-all 
repeat count). There will be many such jiggles, but each will be easy to 
fix because of the extreme simplicity of the framework.

Finally, vim_h and vim_l just call the corresponding c.editCommands 
methods.  Having distinct vim_xxx methods provides the perfect place for 
any "wrapping" or "tweaking" that may be required.

This is clearly the simplest scheme that could possibly work.  I'm thrilled 
with it. Take a look at the code: you will see that it is dirt simple.

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/groups/opt_out.

Reply via email to