Here is the checkin log for rev 6284:
QQQ
Integration of vim emulation with Leo's key handling is well underway.
Created k.getVimArg and call it where appropriate. It's now possible to
execute j k h l commands from minibuffer.
To do this, do alt-x in a file with @vim_mode = True. The minibuffer prompt
will change to Normal Mode:. Type j, and the cursor moves down, leaving
focus in the body.
QQQ
You can test this out for yourself. I highly recommend putting @vim_mode =
True in a file that is dedicated only to testing vim emulation mode. That
way you have no fears about what happens (or doesn't) with the vim
emulator. This mini Aha has had a surprisingly large effect on my testing
productivity.
The new code demonstrates all the essential features:
1. Vim emulation is now fully hooked up to Leo's core.
There is a new ivar, c.vimCommands, available at all times, an instance of
the VimCommands class in leoPy.leo.
2. The new code is clean and safe:
- There are only a few tests for c.vim_mode, all in leoKeys.py.
- When @bool vim-mode is False, the net effect of the new code is exactly
nothing.
- Almost all future work will be confined to the VimCommands class.
- The only substantial addition to Leo's core is k.getVimArg, much like
k.fullCommand.
See the Post Script for details.
3. Already some surprises have appeared:
- Most of the time very few keys appear in the minibuffer. Doh! Vim
commands are *short*. About the only time more than one or two keys appear
is when the user is entering repeat counts or search patterns.
- Focus issues do not seem to be a problem. Just calling
c.bodyWantsFocus() at the end of k.getVimArg works.
4. As noted in the checkin log, at present one must do Alt-x to enter
"normal" mode. Eventually, Leo will start off in a vim-appropriate way
when in vim mode.
In short, all that remains are a few startup details and to write all the
vim commands themselves. That's the easy part! Vim command were easy to
do 30 years ago...
Edward
P.S. k.getVimArg is the key interface between Leo's key-handling code and
the vim emulator. It is a separate method to avoid any chance of
accidentally damaging Leo's existing key-handling machinery
k.getVimArg shows the value of vr.scan. Here is the (simplified) code at
its end::
# Examine each keystroke to see if we have a complete command.
if state != 0:
status,n1,command2,n2,tail = vr.scan(command)
if status == 'done':
k.resetLabel() # Clear the minibuffer.
k.setLabelBlue('%s' % (prompt),protect=True)
vr.exec_(command2,n1,n2,tail)
elif status == 'oops':
# ring bell?
c.bodyWantsFocus()
As you can see, k.getVimArg knows nothing about vim commands. It calls
vr.exec_ if vr.scan says that the minibuffer contains a complete vim
command.
This is a beautiful design, if I say so myself. I've had this design in
mind from the start. It's the reason I was willing to put so much work
into vr.scan.
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/groups/opt_out.