On Thursday, July 31, 2014 6:21:25 AM UTC-5, Edward K. Ream wrote:
My appologies for the double post. The first got posted by mistake and it
would be too confusing if allowed to remain.
> So this is good. Getting these points exactly right right at the start
is a good strategy for the following reasons:
> 1. They are crucial to a good user experience.
> 2. They will make working on the vim commands much less confusing.
> 3. They will demonstrate that the vim code can be integrated seamlessly
into Leo's core, especially into the very complex code in > leoKeys.py
(k.masterKeyHandler, k.masterCommandHandler and their allies).
> 4. They will strongly affect the design of helper methods within
leoKeys.py and corresponding methods within leoVim.py.
This strategy has been a spectacular success. As of rev d9cca94...
- Vim mode code is now simply and correctly connected to code in leoKeys.py.
- Vim modes shows the correct state at all times.
- Crucially, ':' in normal mode and Alt-X do exactly the same thing.
- More generally, Leo handles *all* non-plain keys exactly as in non-vim
mode(!)
However, Ctrl-R is hard-bound to redo. Exceptions may also have to be
made for arrow keys.
- Undo and redo "just work", using Leo's existing undo handler,
*regardless* of how vim mode changes text(!!)
- The parsing code now handles constructs such as: dd, 2dd, d2j, 3d2j and
many others.
Much work remains:
- Parsing is likely to be revised further. This is a very tricky subject.
- d2j and 3d2j don't work exactly as in vim. Soon it will, as described
below.
- The i,o,O,a and A commands do not support a leading repeat count.
- No support for dot yet. It should be straightforward.
- The h and l motions can move past newlines, unlike in vim. This will be
corrected.
- Vim mode must show (probably in the status line) the command keys as the
user types them.
For example, it should show 2d2 while the user types the 3d2j command.
I believe I have grokked an important principle underlying the real vim,
one that I will emulate in Leo's vim mode code. The idea is that parsers
for movements like 2j or 0 or $ or gg, etc, **actually move the cursor**.
This simplifies command handling.
For example, in a command like 3d2j, the code for d will remember the
leading repeat count and the insertion point, say I1, before parsing the
last part of the command, in this case 2j. The parser for 2j moves the
cursor down two lines and calls a "callback" for the d command. The
callback (for the d command) compares the saved insertion point I1 with the
present insertion point, I2 and then does the following:
- If I2 is on the same line as I1, leave I2 unchanged, othewise:
A. If I1 < I2, we move I2 to the end of the line (if it isn't already
there).
B. If I1 > I2, we move I2 to the beginning of the line (if it isn't
already there).
Imo, this will make dj work *exactly* as in vim: it deletes *two* lines,
not one. Similarly for all other movements, like d2h or d0 or d$ or dgg
etc.
Exactly the same general strategy will support repeats counts for the
i,a,A,o and O commands. The command remembers the starting insert point,
I1, and the callback for the i,a,A,o and O commands will compute the text
actually inserted by comparing the new insertion point I2 with I2. The
inserted text is everything between I1 and I2 (with perhaps a few
tweaks...).
So yesterday was a very good day. I expect to have a usable (and truly
compatible!) vim mode in just a few days.
Edward
P.S. I stated above that the h and l commands will soon be "anchored" to
present line. We want this for strict compatibility with vim. This
compatibility is important. For example, dj deletes by lines, but one can
imagine situations in which d5h can be combined with the dot to delete
columns. In that case, it's important not to move past line boundaries!
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.