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

Bug in @{reg} together with g@?

Expand Messages
  • Nikolai Weibull
    I have the following mapping: map g: :set operatorfunc= get_command_mode_range g@ and have recorded g:}j^M into register a . Running @a now does
    Message 1 of 7 , Jan 8, 2008
      I have the following mapping:

      map g: <Esc>:set operatorfunc=<SID>get_command_mode_range<CR>g@

      and have recorded

      g:}j^M

      into register 'a'.

      Running @a now does nothing.

      Why?

      (It should run :join from the current line to the end of the current paragraph.)

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_dev" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Charles E Campbell Jr
      ... It might help folks help you if you included the get_command_mode_range() function. Regards, Chip Campbell
      Message 2 of 7 , Jan 8, 2008
        Nikolai Weibull wrote:

        >I have the following mapping:
        >
        >map g: <Esc>:set operatorfunc=<SID>get_command_mode_range<CR>g@
        >
        >and have recorded
        >
        >g:}j^M
        >
        >into register 'a'.
        >
        >Running @a now does nothing.
        >
        >Why?
        >
        >(It should run :join from the current line to the end of the current paragraph.)
        >
        >
        It might help folks help you if you included the
        get_command_mode_range() function.

        Regards,
        Chip Campbell


        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_dev" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Nikolai Weibull
        ... Ugh, yeah, I m beginning to have a suspicion as to what the problem is: function! s:get_command_mode_range(type) let b = line( [ ) let e = line( ] ) if b
        Message 3 of 7 , Jan 8, 2008
          On Jan 8, 2008 6:45 PM, Charles E Campbell Jr <drchip@...> wrote:

          > It might help folks help you if you included the
          > get_command_mode_range() function.

          Ugh, yeah, I'm beginning to have a suspicion as to what the problem is:

          function! s:get_command_mode_range(type)
          let b = line("'[")
          let e = line("']")

          if b < e
          let range = '.,+' . (e - b)
          elseif b == e
          let range = '.'
          else
          let range = '.,+' . (b - e)
          endif

          call feedkeys(':' . range, 'n')
          endfunction

          I'm guessing that feedkeys() is the culprit here.

          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_dev" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Ben Schmidt
          ... You re missing a :, the in the mapping clears the command line but doesn t put the : back to receive the }j^M which instead become normal commands
          Message 4 of 7 , Jan 8, 2008
            Nikolai Weibull wrote:
            > I have the following mapping:
            >
            > map g: <Esc>:set operatorfunc=<SID>get_command_mode_range<CR>g@
            >
            > and have recorded
            >
            > g:}j^M
            >
            > into register 'a'.
            >
            > Running @a now does nothing.
            >
            > Why?
            >
            > (It should run :join from the current line to the end of the current paragraph.)

            You're missing a :, the <Esc> in the mapping clears the command line but doesn't
            put the : back to receive the }j^M which instead become normal commands (end of
            paragraph, cursor down, cursor to next line). Either record

            g::}j^M

            or use

            map g: <Esc>:set operatorfunc=<SID>get_command_mode_range<CR>g@:

            Cheers,

            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
            -~----------~----~----~----~------~----~------~--~---
          • Ben Schmidt
            ... Mmm. And excuse my dumb reply from earlier that was agnostic about your function. Ben. Send instant messages to your online friends
            Message 5 of 7 , Jan 8, 2008
              >> It might help folks help you if you included the
              >> get_command_mode_range() function.
              >
              > Ugh, yeah, I'm beginning to have a suspicion as to what the problem is:
              >
              > function! s:get_command_mode_range(type)
              > let b = line("'[")
              > let e = line("']")
              >
              > if b < e
              > let range = '.,+' . (e - b)
              > elseif b == e
              > let range = '.'
              > else
              > let range = '.,+' . (b - e)
              > endif
              >
              > call feedkeys(':' . range, 'n')
              > endfunction

              Mmm. And excuse my dumb reply from earlier that was agnostic about your function.

              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
              -~----------~----~----~----~------~----~------~--~---
            • Andy Wokula
              ... Yes, feedkeys() puts its argument at the end of the input buffer, which already contains the contents of register a. I think you have found a limit of g@
              Message 6 of 7 , Jan 8, 2008
                Nikolai Weibull schrieb:
                > On Jan 8, 2008 6:45 PM, Charles E Campbell Jr <drchip@...> wrote:
                >
                >> It might help folks help you if you included the
                >> get_command_mode_range() function.
                >
                > Ugh, yeah, I'm beginning to have a suspicion as to what the problem is:
                >
                > function! s:get_command_mode_range(type)
                > let b = line("'[")
                > let e = line("']")
                >
                > if b < e
                > let range = '.,+' . (e - b)
                > elseif b == e
                > let range = '.'
                > else
                > let range = '.,+' . (b - e)
                > endif
                >
                > call feedkeys(':' . range, 'n')
                > endfunction
                >
                > I'm guessing that feedkeys() is the culprit here.

                Yes, feedkeys() puts its argument at the end of the input buffer, which
                already contains the contents of register a.

                I think you have found a limit of g@ -- I wasn't able to find a solution
                that keeps the elegance, now an additional _r in the recording is needed
                to insert the range.

                Try this one (g: for Normal mode only):

                nmap g: :set operatorfunc=<sid>get_command_mode_range<CR>g@

                let @a = "g:}_rj\r"
                " note: the final ^M causes an additional ^@ to be added to the
                " register

                func! s:get_command_mode_range(type)
                let b = line("'[")
                let e = line("']")

                if b < e
                let range = '.,+' . (e - b)
                elseif b == e
                let range = '.'
                else
                let range = '.,+' . (b - e)
                endif

                exe "nmap _r :". range
                endfunc


                Problem:
                If we use g@ in the {rhs} of a mapping for g: , we cannot add further
                keys there, because Vim has no concept of place holders for the motion
                the user has to type. Currently, the first few of the "further keys"
                will be taken as the motion for g@ before continuing.

                Fiction (can be safely ignored):
                A solution (another todo item?) could be a mode in which g@ (i.e. its
                new brother, gX@) evaluates the operatorfunction as if defined with
                <expr>. This would change the above code into this:

                nmap g: :set operatorfunc=<sid>get_command_mode_range<CR>gX@

                let @a = "g:}j\r"
                " ah, without _r

                func! s:get_command_mode_range(type)
                let b = line("'[")
                let e = line("']")

                if b < e
                let range = '.,+' . (e - b)
                elseif b == e
                let range = '.'
                else
                let range = '.,+' . (b - e)
                endif

                return ":". range
                endfunc

                --
                Andy


                --~--~---------~--~----~------------~-------~--~----~
                You received this message from the "vim_dev" maillist.
                For more information, visit http://www.vim.org/maillist.php
                -~----------~----~----~----~------~----~------~--~---
              • Andy Wokula
                ... Ok, I was wrong. Vim *has* inputsave() and inputrestore(). nmap g: :set operatorfunc= ExRangeOp g@ let @a = g:}join final to be
                Message 7 of 7 , Jan 14, 2008
                  Andy Wokula schrieb:
                  > Nikolai Weibull schrieb:
                  >> On Jan 8, 2008 6:45 PM, Charles E Campbell Jr <drchip@...> wrote:
                  >>
                  >>> It might help folks help you if you included the
                  >>> get_command_mode_range() function.
                  >> Ugh, yeah, I'm beginning to have a suspicion as to what the problem is:
                  >>
                  >> function! s:get_command_mode_range(type)
                  >> let b = line("'[")
                  >> let e = line("']")
                  >>
                  >> if b < e
                  >> let range = '.,+' . (e - b)
                  >> elseif b == e
                  >> let range = '.'
                  >> else
                  >> let range = '.,+' . (b - e)
                  >> endif
                  >>
                  >> call feedkeys(':' . range, 'n')
                  >> endfunction
                  >>
                  >> I'm guessing that feedkeys() is the culprit here.
                  >
                  > Yes, feedkeys() puts its argument at the end of the input buffer, which
                  > already contains the contents of register a.
                  >
                  > I think you have found a limit of g@ -- I wasn't able to find a solution
                  > that keeps the elegance, now an additional _r in the recording is needed
                  > to insert the range.
                  >
                  > Try this one (g: for Normal mode only):
                  >
                  > nmap g: :set operatorfunc=<sid>get_command_mode_range<CR>g@
                  >
                  > let @a = "g:}_rj\r"
                  > " note: the final ^M causes an additional ^@ to be added to the
                  > " register
                  >
                  > func! s:get_command_mode_range(type)
                  > let b = line("'[")
                  > let e = line("']")
                  >
                  > if b < e
                  > let range = '.,+' . (e - b)
                  > elseif b == e
                  > let range = '.'
                  > else
                  > let range = '.,+' . (b - e)
                  > endif
                  >
                  > exe "nmap _r :". range
                  > endfunc
                  >
                  >
                  > Problem:
                  > If we use g@ in the {rhs} of a mapping for g: , we cannot add further
                  > keys there, because Vim has no concept of place holders for the motion
                  > the user has to type. Currently, the first few of the "further keys"
                  > will be taken as the motion for g@ before continuing.

                  Ok, I was wrong. Vim *has* inputsave() and inputrestore().

                  nmap <silent> g: :set operatorfunc=<sid>ExRangeOp<CR>g@

                  let @a = "g:}join"
                  " final <CR> to be added

                  func! s:ExRangeOp(type)
                  let b = line("'[")
                  let e = line("']")

                  if b < e
                  let range = '.,+' . (e - b)
                  elseif b == e
                  let range = '.'
                  else
                  let range = '.,+' . (b - e)
                  endif

                  call inputsave()
                  call feedkeys(':'. range. "\<c-r>=''[inputrestore()]\r", 'n')
                  endfunc

                  --
                  Andy

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