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

Problem with CursorMoved events: x position isn't maintained

Expand Messages
  • Tom Link
    Hi, A user complained that a plugin of mine broke cursor movement. He ... It seems the problem is caused by CursorMoved(I) autocommands. The problem becomes
    Message 1 of 5 , Jul 28 11:32 AM
      Hi,

      A user complained that a plugin of mine broke cursor movement. He
      writes:

      > have a text file:
      >
      > xxxxxxxxxxFxxxxxxxxxxxxxxxExx
      > yyyyyyyyyyD
      > zzzzzzzzzzzzzzzzzzzzzzzzzzCzzzzz
      >
      > Position cursor at C, move up a line: you're on D, move up, you're on
      > E. However, when I've quickfixsigns in plugin, I land at F instead of
      > E.

      It seems the problem is caused by CursorMoved(I) autocommands.

      The problem becomes apparent when evaluating the following code:

      function! QuickfixsignsSet(event)
      let lz = &lazyredraw
      set lz
      let &lz = lz
      endf

      autocmd CursorMoved * call QuickfixsignsSet("CursorMoved")

      If this is intended, this interaction should probably be added the
      the
      help section of CursorMoved(I).

      Regards,
      Thomas.

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_dev" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Bram Moolenaar
      ... The problem is caused by setting the lazyredraw option, it causes the cursor column to be computed. Even though that is not needed. It s actually done
      Message 2 of 5 , Jul 29 1:19 AM
        Tom Link wrote:

        > A user complained that a plugin of mine broke cursor movement. He
        > writes:
        >
        > > have a text file:
        > >
        > > xxxxxxxxxxFxxxxxxxxxxxxxxxExx
        > > yyyyyyyyyyD
        > > zzzzzzzzzzzzzzzzzzzzzzzzzzCzzzzz
        > >
        > > Position cursor at C, move up a line: you're on D, move up, you're on
        > > E. However, when I've quickfixsigns in plugin, I land at F instead of
        > > E.
        >
        > It seems the problem is caused by CursorMoved(I) autocommands.
        >
        > The problem becomes apparent when evaluating the following code:
        >
        > function! QuickfixsignsSet(event)
        > let lz = &lazyredraw
        > set lz
        > let &lz = lz
        > endf
        >
        > autocmd CursorMoved * call QuickfixsignsSet("CursorMoved")
        >
        > If this is intended, this interaction should probably be added the
        > the help section of CursorMoved(I).

        The problem is caused by setting the 'lazyredraw' option, it causes the
        cursor column to be computed. Even though that is not needed. It's
        actually done for all boolean options. The comment says it's for when
        the 'list' option is changed, which makes sense. Any other boolean
        option that changes the cursor column on the screen?

        --
        Corduroy pillows: They're making headlines!

        /// 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
        -~----------~----~----~----~------~----~------~--~---
      • Tom
        ... This leads to a related question. Given the cursor is at position D, is there a way to determine that the target column is 27 and not 11? I.e. is there a
        Message 3 of 5 , Aug 2, 2009
          > > > xxxxxxxxxxFxxxxxxxxxxxxxxxExx
          > > > yyyyyyyyyyD
          > > > zzzzzzzzzzzzzzzzzzzzzzzzzzCzzzzz

          > The problem is caused by setting the 'lazyredraw' option, it causes the
          > cursor column to be computed.

          This leads to a related question. Given the cursor is at position D,
          is there a way to determine that the "target column" is 27 and not 11?
          I.e. is there a way to temporarily move the cursor someplace else and
          to return to position D without breaking cursor movement?

          I often use something like this

          let p = getpos('.')
          ...
          call setpos('.', p)

          If the cursor is at position D, this will set the column to 11 and the
          cursor will move to position F when pressing k. Is there a way to make
          it move to position E?

          Regards,
          Thomas.

          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_dev" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Bram Moolenaar
          ... You can use winsaveview() and winrestview(). -- hundred-and-one symptoms of being an internet addict: 140. You d rather catch a score on the web than watch
          Message 4 of 5 , Aug 3, 2009
            Tom wrote:

            > > > > xxxxxxxxxxFxxxxxxxxxxxxxxxExx
            > > > > yyyyyyyyyyD
            > > > > zzzzzzzzzzzzzzzzzzzzzzzzzzCzzzzz
            >
            > > The problem is caused by setting the 'lazyredraw' option, it causes the
            > > cursor column to be computed.
            >
            > This leads to a related question. Given the cursor is at position D,
            > is there a way to determine that the "target column" is 27 and not 11?
            > I.e. is there a way to temporarily move the cursor someplace else and
            > to return to position D without breaking cursor movement?
            >
            > I often use something like this
            >
            > let p = getpos('.')
            > ...
            > call setpos('.', p)
            >
            > If the cursor is at position D, this will set the column to 11 and the
            > cursor will move to position F when pressing k. Is there a way to make
            > it move to position E?

            You can use winsaveview() and winrestview().

            --
            hundred-and-one symptoms of being an internet addict:
            140. You'd rather catch a score on the web than watch the game as
            it is being played on tv.

            /// 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
            -~----------~----~----~----~------~----~------~--~---
          • Tony Mechelynck
            On 29/07/09 10:19, Bram Moolenaar wrote: [...] ... ambiwidth maybe? Ah no, that s a string option. Ah yes: rightleft , and also arabic which sets it as a
            Message 5 of 5 , Aug 12, 2009
              On 29/07/09 10:19, Bram Moolenaar wrote:
              [...]
              > The problem is caused by setting the 'lazyredraw' option, it causes the
              > cursor column to be computed. Even though that is not needed. It's
              > actually done for all boolean options. The comment says it's for when
              > the 'list' option is changed, which makes sense. Any other boolean
              > option that changes the cursor column on the screen?
              >

              'ambiwidth' maybe? Ah no, that's a string option.

              Ah yes: 'rightleft', and also 'arabic' which sets it as a side-effect
              'arabicshape' when after composing characters or laam-alif pairs

              not sure about 'compatible', it has so many side effects

              'foldenable' maybe, and 'diff' if folding happens as a result (because
              when on a closed fold, the cursor is always shown in column 1)

              'wrap' and 'linebreak'

              you already mentioned 'list'

              'number'

              'scrollbind' maybe? No, I think it may move the text about relative to
              the window but not change on which character the cursor sits?

              not sure about 'termbidi'


              I may have missed a few.
              Best regards,
              Tony.
              --
              Q: How many DEC repairmen does it take to fix a flat ?
              A: Five; four to hold the car up and one to swap tires.

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