Loading ...
Sorry, an error occurred while loading the content.

Re: Operator pending mode

Expand Messages
  • Ben Schmidt
    ... Try the attached patch which is against recent-ish svn. I think it will apply cleanly enough to any similar vintage code. I used v:operator. There s only
    Message 1 of 12 , Oct 29, 2007
    • 0 Attachment
      > 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
      > a v:swapcommand).

      Try the attached patch which is against recent-ish svn. I think it will apply
      cleanly enough to any similar vintage code. I used v:operator. There's only one
      place it needs to be changed if a different name is preferred.

      Ben.




      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_dev" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Bram Moolenaar
      ... 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
      Message 2 of 12 , Oct 30, 2007
      • 0 Attachment
        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
        > > a v:swapcommand).
        >
        > Try the attached patch which is against recent-ish svn. I think it
        > will apply cleanly enough to any similar vintage code. I used
        > v:operator. There's only one place it needs to be changed if a
        > different name is preferred.

        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"?

        --
        hundred-and-one symptoms of being an internet addict:
        60. As your car crashes through the guardrail on a mountain road, your first
        instinct is to search for the "back" button.

        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
        /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
        \\\ download, build and distribute -- http://www.A-A-P.org ///
        \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_dev" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • dfishburn.vim@gmail.com
        ... 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
        Message 3 of 12 , Oct 30, 2007
        • 0 Attachment
          On Oct 30, 1:38 pm, Bram Moolenaar <B...@...> 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.

          Dave


          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_dev" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Bram Moolenaar
          ... 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
          Message 4 of 12 , Oct 30, 2007
          • 0 Attachment
            David Fishburn wrote:

            > On Oct 30, 1:38 pm, Bram Moolenaar <B...@...> 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.

            --
            hundred-and-one symptoms of being an internet addict:
            64. The remote to the T.V. is missing...and you don't even care.

            /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
            /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
            \\\ download, build and distribute -- http://www.A-A-P.org ///
            \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_dev" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • David Fishburn
            ... 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
            Message 5 of 12 , Oct 30, 2007
            • 0 Attachment
              On 10/30/07, Bram Moolenaar <Bram@...> wrote:
              >
              > David Fishburn wrote:
              >
              > > On Oct 30, 1:38 pm, Bram Moolenaar <B...@...> 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
              -~----------~----~----~----~------~----~------~--~---
            • Ben Schmidt
              ... Here s a somewhat naively implemented example where a custom text-object is defined that allows you to operate on a function name whether the cursor is on
              Message 6 of 12 , Oct 30, 2007
              • 0 Attachment
                > 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.

                Here's a somewhat naively implemented example where a custom text-object is
                defined that allows you to operate on a function name whether the cursor is on the
                name itself or on its arguments. You can yank with yF, change with cF, uppercase
                with gUF, etc. I can't think of any other way to do this, or more complicated
                language-based custom text-object definition--e.g. yank/change a whole conjunction
                or disjunction in a logic language, yank or change the condition of an 'if' or
                'while' loop from anywhere within its body. Some of these would be more useful
                than others, of course, but there are a lot of real world possibilities, I think.

                Ben.



                :onoremap F <Esc>:call OperateFunctionName()<CR>
                function! OperateFunctionName()
                let last_count = v:count
                let last_op = v:operator
                let last_reg = v:register
                exe "normal \<Esc>"
                while search('\(\%#\i\|\i\s*\%#\)\i*\s*(','ce',line('.')+1) == 0
                normal [(
                endwhile
                exe "normal \<BS>\"_yiw"
                echo 'normal '.(last_count>0?(last_count):'').'"'.last_reg.last_op.'e'
                endfun





                Send instant messages to your online friends http://au.messenger.yahoo.com


                --~--~---------~--~----~------------~-------~--~----~
                You received this message from the "vim_dev" maillist.
                For more information, visit http://www.vim.org/maillist.php
                -~----------~----~----~----~------~----~------~--~---
              • Ben Schmidt
                ... Send instant messages to your online friends http://au.messenger.yahoo.com --~--~---------~--~----~------------~-------~--~----~ You received this message
                Message 7 of 12 , Oct 30, 2007
                • 0 Attachment
                  >> 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.
                  >
                  > Here's a somewhat naively implemented example where a custom text-object is
                  > defined that allows you to operate on a function name whether the cursor is on the
                  > name itself or on its arguments. You can yank with yF, change with cF, uppercase
                  > with gUF, etc. I can't think of any other way to do this, or more complicated
                  > language-based custom text-object definition--e.g. yank/change a whole conjunction
                  > or disjunction in a logic language, yank or change the condition of an 'if' or
                  > 'while' loop from anywhere within its body. Some of these would be more useful
                  > than others, of course, but there are a lot of real world possibilities, I think.

                  A better one:

                  :onoremap F <Esc>:call OperateFunctionName()<CR>
                  :function! OperateFunctionName()
                  : let save_count = v:count
                  : let save_op = v:operator
                  : let save_reg = v:register
                  : while search('\(\%#\i\|\i\s*\%#\)\i*\s*(','ce',line('.')+1) == 0
                  : if searchpair('(','',')','bW') == 0
                  : normal "\<Esc>"
                  : return
                  : endif
                  : endwhile
                  : exe "normal \<BS>\"_yiw"
                  : exe 'normal "'.save_reg.(save_count>0?(save_count):'').save_op.'e'
                  :endfun





                  Send instant messages to your online friends http://au.messenger.yahoo.com


                  --~--~---------~--~----~------------~-------~--~----~
                  You received this message from the "vim_dev" maillist.
                  For more information, visit http://www.vim.org/maillist.php
                  -~----------~----~----~----~------~----~------~--~---
                • Ben Schmidt
                  [CCing this to the mailing lists; only went to Bram before, but some parts may be useful for others.] ... Very happy to modify the patch to document this. It
                  Message 8 of 12 , Oct 30, 2007
                  • 0 Attachment
                    [CCing this to the mailing lists; only went to Bram before, but some parts may be
                    useful for others.]

                    > 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"?

                    Very happy to modify the patch to document this. It does not include the count;
                    that is what v:count is for. And it will be two characters for commands that begin
                    with 'g' or 'z', and one character otherwise.

                    Happy to include an example or two as well. I emailed a candidate a few moments
                    ago. Interested to hear what people think, and will do so before revising the
                    patch. My gut feeling regarding this, though, would be that if people want to use
                    this, they will know how they want to use it, so an example isn't really necessary
                    and would probably add more clutter to the docs than insight. Still, as I said,
                    I'm very happy to put one in the patch!

                    Ben.





                    Send instant messages to your online friends http://au.messenger.yahoo.com


                    --~--~---------~--~----~------------~-------~--~----~
                    You received this message from the "vim_dev" maillist.
                    For more information, visit http://www.vim.org/maillist.php
                    -~----------~----~----~----~------~----~------~--~---
                  • Bram Moolenaar
                    ... Well, if you show us the omap for one command that would be the example I was asking for. Leaving out some of the YankRing stuff perhaps to keep it small.
                    Message 9 of 12 , Oct 31, 2007
                    • 0 Attachment
                      David Fishburn wrote:

                      > > > 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.

                      Well, if you show us the omap for one command that would be the
                      example I was asking for. Leaving out some of the YankRing stuff
                      perhaps to keep it small.

                      --
                      hundred-and-one symptoms of being an internet addict:
                      69. Yahoo welcomes you with your own start page

                      /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
                      /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
                      \\\ download, build and distribute -- http://www.A-A-P.org ///
                      \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

                      --~--~---------~--~----~------------~-------~--~----~
                      You received this message from the "vim_dev" maillist.
                      For more information, visit http://www.vim.org/maillist.php
                      -~----------~----~----~----~------~----~------~--~---
                    • Bram Moolenaar
                      ... I see. In general the reason we need v:operator would then be that you need it for situations where you need to get out of operator pending mode, move
                      Message 10 of 12 , Oct 31, 2007
                      • 0 Attachment
                        Ben Schmidt wrote:

                        > > 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.
                        >
                        > Here's a somewhat naively implemented example where a custom
                        > text-object is defined that allows you to operate on a function name
                        > whether the cursor is on the name itself or on its arguments. You can
                        > yank with yF, change with cF, uppercase with gUF, etc. I can't think
                        > of any other way to do this, or more complicated language-based custom
                        > text-object definition--e.g. yank/change a whole conjunction or
                        > disjunction in a logic language, yank or change the condition of an
                        > 'if' or 'while' loop from anywhere within its body. Some of these
                        > would be more useful than others, of course, but there are a lot of
                        > real world possibilities, I think.
                        >
                        > Ben.
                        >
                        >
                        > :onoremap F <Esc>:call OperateFunctionName()<CR>
                        > function! OperateFunctionName()
                        > let last_count = v:count
                        > let last_op = v:operator
                        > let last_reg = v:register
                        > exe "normal \<Esc>"
                        > while search('\(\%#\i\|\i\s*\%#\)\i*\s*(','ce',line('.')+1) == 0
                        > normal [(
                        > endwhile
                        > exe "normal \<BS>\"_yiw"
                        > echo 'normal '.(last_count>0?(last_count):'').'"'.last_reg.last_op.'e'
                        > endfun

                        I see. In general the reason we need v:operator would then be that you
                        need it for situations where you need to get out of operator pending
                        mode, move around and restart the operator.

                        Did you copy the v:variable values because they change when executing
                        the other commands? A remark about that will be useful in the docs.

                        OK, I'll include the patch after sufficient testing.

                        --
                        hundred-and-one symptoms of being an internet addict:
                        70. ISDN lines are added to your house on a hourly basis

                        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
                        /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
                        \\\ download, build and distribute -- http://www.A-A-P.org ///
                        \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

                        --~--~---------~--~----~------------~-------~--~----~
                        You received this message from the "vim_dev" maillist.
                        For more information, visit http://www.vim.org/maillist.php
                        -~----------~----~----~----~------~----~------~--~---
                      • Erik Falor
                        ... Please do include an example. I didn t understand how useful this new variable could be until I read through the example posted previously. Some of us
                        Message 11 of 12 , Oct 31, 2007
                        • 0 Attachment
                          On 30/10/2007, Ben Schmidt <mail_ben_schmidt@...> wrote:

                          Very happy to modify the patch to document this. It does not include the count;
                          that is what v:count is for. And it will be two characters for commands that begin
                          with 'g' or 'z', and one character otherwise.

                          Happy to include an example or two as well. I emailed a candidate a few moments
                          ago. Interested to hear what people think, and will do so before revising the
                          patch. My gut feeling regarding this, though, would be that if people want to use
                          this, they will know how they want to use it, so an example isn't really necessary
                          and would probably add more clutter to the docs than insight. Still, as I said,
                          I'm very happy to put one in the patch!

                          Please do include an example.  I didn't understand how useful this new variable could be until I read through the example posted previously.  Some of us folks don't "get it" without an example.


                          --
                          Registered Linux User #445632
                          http://counter.li.org
                          --~--~---------~--~----~------------~-------~--~----~
                          You received this message from the "vim_dev" maillist.
                          For more information, visit http://www.vim.org/maillist.php
                          -~----------~----~----~----~------~----~------~--~---

                        • Ben Schmidt
                          [CCing vim_dev; apologies for my continued disorganised postings!] OK, folks, After reading feedback, etc., here is a revised patch. It s just the
                          Message 12 of 12 , Nov 4, 2007
                          • 0 Attachment
                            [CCing vim_dev; apologies for my continued disorganised postings!]

                            OK, folks,

                            After reading feedback, etc., here is a revised patch. It's just the documentation
                            that is different from the previous patch.

                            In the end, given that a number of things can be done without v:operator, as Andy
                            demonstrated, and that Yankring is a pretty specific example, I thought perhaps
                            the best thing would be to put a brief example analogous to the v:prevcount
                            example which is right nextdoor in the docs.

                            If you still think a lengthier example is better, though, Bram, I'm happy to
                            revise the patch again. I thought this, or a scaled-down count-ignorant version
                            might be a more useful lengthy example (compared to the function name thing I
                            suggested before):

                            :" Defines a motion/text-object <C> which allows you to operate on
                            :" the {count}th column of a tab-delimited table, or the column
                            :" the cursor is currently in if no count is given.
                            :onoremap C <Esc>:call OperateColumn()<CR>
                            :function! OperateColumn()
                            : let c = v:prevcount
                            : if c == 0
                            : call search('^\|\t\zs','bc',line("."))
                            : else
                            : call cursor(line("."),1)
                            : while search('\v(\zs[^\t]*(\t|$)){'.c.'}','c',line(".")) == 0
                            : call setline(line("."),getline(line("."))."\t")
                            : endwhile
                            : endif
                            : call feedkeys('"'.v:register.v:operator)
                            : if strpart(getline(line('.')),col('.')-1,1) == "\t"
                            : call feedkeys(":\<CR>")
                            : else
                            : call feedkeys(search('\t','n',line(".")) == 0 ? "$" : "t\t")
                            : endif
                            :endfun

                            Ben.







                            --~--~---------~--~----~------------~-------~--~----~
                            You received this message from the "vim_dev" maillist.
                            For more information, visit http://www.vim.org/maillist.php
                            -~----------~----~----~----~------~----~------~--~---
                          Your message has been successfully submitted and would be delivered to recipients shortly.