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

Re: "." fails to repeat the last executed operator with ":normal v"

Expand Messages
  • Yukihiro Nakadaira
    ... Oops, this doesn t work. Sorry for noise. -- -- You received this message from the vim_dev maillist. Do not top-post! Type your reply below the text you
    Message 1 of 19 , Mar 20, 2013
      On Wednesday, March 20, 2013 10:49:19 PM UTC+9, Yukihiro Nakadaira wrote:
      > Perhaps this works?
      >
      > onoremap foo :<C-u>call Select()<CR>
      > function! Select()
      >   execute "normal! viw\<Esc>"
      > endfunction

      Oops, this doesn't work. Sorry for noise.

      --
      --
      You received this message from the "vim_dev" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php

      ---
      You received this message because you are subscribed to the Google Groups "vim_dev" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • glts
      Hi ... I spent some time looking into this. Attached is a first *proposal* for a patch for the current Vim version 7.3.875, which -- I believe -- fixes this.
      Message 2 of 19 , Mar 23, 2013
        Hi

        On Wednesday, March 20, 2013 1:07:53 AM UTC+1, Sung Pae wrote:
        > On Tue, Mar 19, 2013 at 04:39:11PM -0700, Kana Natsuno wrote:
        >
        >
        >
        > > On Wed, Mar 20, 2013 at 7:21 AM, Sung Pae wrote:
        >
        > >
        >
        > > > The motion mappings created by the above function work with both
        >
        > > > native operators and with the custom operators provided by two other
        >
        > > > plugins by Tim Pope: vim-surround and vim-commentary.
        >
        > >
        >
        > > Really? Suppose that we invoke a new Vim process with the following
        >
        > > environment:
        >
        > >
        >
        > > ------------------------------------------------------------
        >
        >
        >
        > Yes, this combination does fail due to the implementation of the `ys`
        >
        > operator. This can be ameliorated, but it would not be pretty.
        >
        >
        >
        > Other combinations do not fail (like the `gc` vim-commentary operator
        >
        > with the `af` text object), and the native operators with custom text
        >
        > objects work well.
        >
        >
        >
        > Again, this is a hack against the constraints of the bug you have
        >
        > pointed out, which I am very much in favor of seeing fixed. Do you have
        >
        > a patch to supply to the list, or should I look into it?
        >
        >
        >
        > Sung Pae

        I spent some time looking into this. Attached is a first *proposal* for
        a patch for the current Vim version 7.3.875, which -- I believe -- fixes
        this.

        However, the code surrounding Visual mode and operators is rather ...
        tricky to say the least, so I urge you to look it over carefully, and
        comment on whether you think it is correct or how it could be improved.

        There has not been any response on the status of this issue. Operators
        and text objects are two of the major advantages Vim has over other
        editors. So I believe it is essential to let users leverage the full
        power of their own custom operators and text objects by making them
        repeatable with the dot command.

        David Bürgin

        --
        --
        You received this message from the "vim_dev" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php

        ---
        You received this message because you are subscribed to the Google Groups "vim_dev" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • Sung Pae
        ... I can confirm it works for simple repeats of custom motions with `d` and `c` operators, as well the custom `ys` operator that Kana showed was problematic.
        Message 3 of 19 , Mar 23, 2013
          On Sat, Mar 23, 2013 at 09:56:58AM -0700, glts wrote:

          > I spent some time looking into this. Attached is a first *proposal*
          > for a patch for the current Vim version 7.3.875, which -- I believe --
          > fixes this.

          I can confirm it works for simple repeats of custom motions with `d` and
          `c` operators, as well the custom `ys` operator that Kana showed was
          problematic.

          > However, the code surrounding Visual mode and operators is rather ...
          > tricky to say the least, so I urge you to look it over carefully,
          > and comment on whether you think it is correct or how it could be
          > improved.

          I see two issues on first glance:

          * Counts are not repeated; d2x (x being a custom motion) repeats as
          dx only
          * Making a visual selection with a custom operator clobbers the redo

          It's promising that your small patch enables so much of the desired
          functionality. Please continue!

          > There has not been any response on the status of this issue. Operators
          > and text objects are two of the major advantages Vim has over other
          > editors. So I believe it is essential to let users leverage the full
          > power of their own custom operators and text objects by making them
          > repeatable with the dot command.

          Perhaps we will be able to convince Bram if the solution is clean and
          unobtrusive.

          Sung Pae

          --
          --
          You received this message from the "vim_dev" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php

          ---
          You received this message because you are subscribed to the Google Groups "vim_dev" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • glts
          Sung Pae, thank you for your feedback. ... Yes, but this is due to another bug. My patch does not affect this. ... If you try the normal mode mapping, e.g.
          Message 4 of 19 , Mar 24, 2013
            Sung Pae, thank you for your feedback.

            On Sun, Mar 24, 2013 at 12:40 AM, Sung Pae <self@...> wrote:
            > I see two issues on first glance:
            >
            > * Counts are not repeated; d2x (x being a custom motion) repeats as
            > dx only

            Yes, but this is due to another bug. My patch does not affect this.

            The v:count variables are treated differently in omaps. Compare:

            :nnoremap <silent> x :<C-U>exe "norm! d".v:count1."e"<CR>
            :onoremap <silent> x :<C-U>exe "norm! ".v:count1."e"<CR>

            If you try the normal mode mapping, e.g. "2x", then the dot command will
            have the same effect as "2x". You can also override the count by giving
            a count to the dot command, e.g. "3.". This is the expected behaviour.

            The omap on the other hand doesn't work like that. Try "d2x" and then
            repeat with the dot command: The original count is not used. You have to
            use "2." to get the same as with "d2x".

            This is a different issue, and I'd rather put it off for the moment.

            > * Making a visual selection with a custom operator clobbers the redo

            Can you give an example? I don't see the problem.

            --
            --
            You received this message from the "vim_dev" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php

            ---
            You received this message because you are subscribed to the Google Groups "vim_dev" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
            For more options, visit https://groups.google.com/groups/opt_out.
          • Sung Pae
            ... Ah yes, you re totally correct. I remember now that I had to work around that myself by saving v:count to a buffer-local variable on omap invocation, then
            Message 5 of 19 , Mar 24, 2013
              On Sun, Mar 24, 2013 at 06:43:47PM +0100, glts wrote:

              > On Sun, Mar 24, 2013 at 12:40 AM, Sung Pae <self@...> wrote:
              > > I see two issues on first glance:
              > >
              > > * Counts are not repeated; d2x (x being a custom motion) repeats as
              > > dx only
              >
              > Yes, but this is due to another bug. My patch does not affect this.
              >
              > The v:count variables are treated differently in omaps. Compare:

              Ah yes, you're totally correct. I remember now that I had to work
              around that myself by saving v:count to a buffer-local variable on omap
              invocation, then string-replace the v:count variable in the omap rhs
              with the buffer-local "b:_count", so that the cached value would be used
              on repeat. It was very nasty, but it worked.

              > This is a different issue, and I'd rather put it off for the moment.

              Yes, I imagine a new count variable needs to be created to handle omaps.

              > > * Making a visual selection with a custom operator clobbers the redo
              >
              > Can you give an example? I don't see the problem.

              I apologize, that was a bit vague.

              Let's create a simple (and incomplete) custom motion:

              function! SelectInCaps()
              let [bl, bc] = searchpos('\u', 'cbW')
              let [el, ec] = searchpos('.\u\ze', 'W')
              call setpos("'<", [0, bl, bc, 0])
              call setpos("'>", [0, el, ec, 0])
              normal! gv
              endfunction

              Then map it to both visual and operator-pending modes:

              vmap ic :<C-U>call SelectInCaps()<CR>
              omap ic :<C-U>call SelectInCaps()<CR>

              Repeating the command dic with the . command works now with your patch:

              Foo|BarBazQuux
              Foo|BazQuux " dic
              Foo|Quuz " .

              However, if we invoke vic after running dic, the . command no longer has
              any affect:

              Foo|BarBazQuux
              Foo|BazQuux " dic
              Foo|BazQuux " vic<Esc>
              Foo|BazQuux " .

              This is not true of the builtin motions like `aw`; visual commands do
              not clobber the repeat buffer (or however it may work).

              Thank you for your work on this!

              Sung Pae

              --
              --
              You received this message from the "vim_dev" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php

              ---
              You received this message because you are subscribed to the Google Groups "vim_dev" group.
              To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
              For more options, visit https://groups.google.com/groups/opt_out.
            • glts
              ... Yes, sorry, and thanks for reporting. Operator and Visual mode handling isn t easy and I m learning it the hard way ... Anyway, after another session in
              Message 6 of 19 , Mar 25, 2013
                On Mon, Mar 25, 2013 at 2:08 AM, Sung Pae <self@...> wrote:
                > Let's create a simple (and incomplete) custom motion:
                >
                > function! SelectInCaps()
                > let [bl, bc] = searchpos('\u', 'cbW')
                > let [el, ec] = searchpos('.\u\ze', 'W')
                > call setpos("'<", [0, bl, bc, 0])
                > call setpos("'>", [0, el, ec, 0])
                > normal! gv
                > endfunction
                >
                > Then map it to both visual and operator-pending modes:
                >
                > vmap ic :<C-U>call SelectInCaps()<CR>
                > omap ic :<C-U>call SelectInCaps()<CR>
                >
                > Repeating the command dic with the . command works now with your patch:
                >
                > Foo|BarBazQuux
                > Foo|BazQuux " dic
                > Foo|Quuz " .
                >
                > However, if we invoke vic after running dic, the . command no longer has
                > any affect:
                >
                > Foo|BarBazQuux
                > Foo|BazQuux " dic
                > Foo|BazQuux " vic<Esc>
                > Foo|BazQuux " .

                Yes, sorry, and thanks for reporting. Operator and Visual mode handling
                isn't easy and I'm learning it the hard way ...

                Anyway, after another session in the debugger I came up with the slight
                amendment in the attachment. If you would like to try it, be my guest. I
                hope I can find the time to write a few tests.

                David

                --
                --
                You received this message from the "vim_dev" maillist.
                Do not top-post! Type your reply below the text you are replying to.
                For more information, visit http://www.vim.org/maillist.php

                ---
                You received this message because you are subscribed to the Google Groups "vim_dev" group.
                To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
                For more options, visit https://groups.google.com/groups/opt_out.
              • Sung Pae
                ... Yes, this definitely solves the problem with visual selections clearing the repeat. I tried poking around a bit more, and I couldn t find any obvious
                Message 7 of 19 , Mar 25, 2013
                  On Mon, Mar 25, 2013 at 10:14:48PM +0100, glts wrote:

                  > On Mon, Mar 25, 2013 at 2:08 AM, Sung Pae <self@...> wrote:
                  >
                  > > Let's create a simple (and incomplete) custom motion: …
                  >
                  > Anyway, after another session in the debugger I came up with the
                  > slight amendment in the attachment. If you would like to try it, be my
                  > guest. I hope I can find the time to write a few tests.

                  Yes, this definitely solves the problem with visual selections clearing
                  the repeat. I tried poking around a bit more, and I couldn't find any
                  obvious problems, which is exciting.

                  All that appears to be left to achieve parity with builtin cursor
                  motions is the issue with v:count. I will report any problems should I
                  find them.

                  Thank you for looking into this.

                  Sung Pae

                  --
                  --
                  You received this message from the "vim_dev" maillist.
                  Do not top-post! Type your reply below the text you are replying to.
                  For more information, visit http://www.vim.org/maillist.php

                  ---
                  You received this message because you are subscribed to the Google Groups "vim_dev" group.
                  To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
                  For more options, visit https://groups.google.com/groups/opt_out.
                Your message has been successfully submitted and would be delivered to recipients shortly.