On 10/30/07, Bram Moolenaar <[EMAIL PROTECTED]> wrote:
>
> David Fishburn wrote:
>
> > On Oct 30, 1:38 pm, Bram Moolenaar <[EMAIL PROTECTED]> wrote:
> > > Ben Schmidt wrote:
> > > > > 3.  Don't know about v:operator (works for me), the showcmd option
> > > > > means it could also be v:command or v:operatorcommand (since there is
> > ...
> > > I'm not quite convinced adding v:operator is useful.  What would help is
> > > giving a couple of examples how it's used.  Also, in the docs for
> > > v:operator it would be good to have a few examples of the values.  I
> > > suppose it can be one char, like "d", but also something longer.  How
> > > about the count, e.g., when I do "4d"?
> >
> > Here is a simple example:
> >
> > function! MyOp(op)
> >    let cmd = a:op
> >    echo 'v:count:' v:count 'v:register:' v:register 'v:operator'
> > v:operator 'you pressed:' cmd
> >    exec "normal! ".
> >                \ ((v:count > 0)?(v:count):'').
> >                \ (v:register=='"'?'':'"'.v:register).
> >                \ v:operator.
> >                \ cmd
> > endfunction
> >
> > omap w :call MyOp('w')<CR>
> > omap e :call MyOp('e')<CR>
> > omap $ :call MyOp('$')<CR>
> >
> > If you type the following commands:
> > c$
> > 2yw
> > "a3de
> >
> > You will get the following output:
> > v:count: 0 v:register: " v:operator c you pressed: $
> > v:count: 2 v:register: " v:operator y you pressed: w
> > v:count: 3 v:register: a v:operator d you pressed: e
> >
> > What this provides is all the information to capture what the user
> > pressed which Vim does not currently support.
> >
> > In the YankRing case, I will be able to replay what the user typed and
> > still manage to capture the registers.
> >
> > This is very useful for me, but I suspect other plugin developers will
> > also benefit since they can make smarter functions by looking at what
> > the user has keyed in.
>
> Well, I can see that you get the information, but this is not really a
> useful real-world example.  Think of a user that wants to get something
> done for which v:operator is needed.  And for which there is no other
> solution.


This is as real as it gets, using omaps there is no other solution
that I or this list could find.

The echo was just an FYI to the user, but my function is replaying the
command the user typed so that I can later act on the effects of the
command:
exec "normal! ".
               \ ((v:count > 0)?(v:count):'').
               \ (v:register=='"'?'':'"'.v:register).
               \ v:operator.
               \ cmd

Without v:operator, anyone who is writing an omap is hamstrung.  omap
lets me define (or redefine) a motion.  But without the context of the
command (in this case I don't know whether the user is yanking,
deleting or changing).  Vim provides all the other information except
this one piece of critical data (basically the same thing showcmd
displays in the statusline).  omaps can be much more useful than they
currently are.

In my "real" world plugin I will be creating an omap for every motion
Vim supports.  That way I have the opporunity to record changes made
by Vim and the user.  The YankRing is missing a lot of functionality
at the moment since I cannot support change commands (and quite a few
others) but omaps can provide the missing link, but they are
essentially useless without providing the "intent" of the user.
"c,d,y" provides that context.

Dave

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui