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

Re: InsertEnter cursor position related

Expand Messages
  • troydm
    ... Well for example one of my plugins includes bash shell emulation inside a vim buffer, it s called shellasync.vim and it s source code is at
    Message 1 of 10 , May 18, 2013
    • 0 Attachment
      On Saturday, May 18, 2013 3:21:15 PM UTC+4, Bram Moolenaar wrote:
      > Troydm (?) wrote:
      >
      >
      >
      > > v7-3-768 commit introduced following check for InsertEnter autocommand
      >
      > > event execution e.g. calling check_cursor_col()
      >
      > >
      >
      > > http://pastebin.com/tShmNDDz
      >
      > >
      >
      > > However after this commit some of my plugins that heavily rely on InsertEnter
      >
      > > stopped working namely because some of those plugins change cursor
      >
      > > position on autocommand event thus making those changes obsolete and
      >
      > > cursor position not changing
      >
      > >
      >
      > > As i see this is a bug however i'm not sure if it's a bug or expected
      >
      > > behavior
      >
      > >
      >
      > > The way to fix this is to save cursor position only after autocommand
      >
      > > event is executed e.g. moving following line
      >
      > >
      >
      > > pos_T save_cursor = curwin->w_cursor;
      >
      > >
      >
      > > after this call
      >
      > >
      >
      > > apply_autocmds(EVENT_INSERTENTER, NULL, NULL, FALSE, curbuf);
      >
      > >
      >
      > > So is this a bug or not?
      >
      >
      >
      > The documentation says that the InsertEnter autocommand must not move
      >
      > the cursor:
      >
      >
      >
      > InsertEnter Just before starting Insert mode. Also for
      >
      > Replace mode and Virtual Replace mode. The
      >
      > |v:insertmode| variable indicates the mode.
      >
      > Be careful not to move the cursor or do
      >
      > anything else that the user does not expect.
      >
      >
      >
      > Why do you want to move the cursor, what is it for?
      >
      >
      >
      > --
      >
      > User: I'm having problems with my text editor.
      >
      > Help desk: Which editor are you using?
      >
      > User: I don't know, but it's version VI (pronounced: 6).
      >
      > Help desk: Oh, then you should upgrade to version VIM (pronounced: 994).
      >
      >
      >
      > /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
      >
      > /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
      >
      > \\\ an exciting new programming language -- http://www.Zimbu.org ///
      >
      > \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

      Well for example one of my plugins includes bash shell emulation inside a vim buffer, it's called shellasync.vim and it's source code is at https://github.com/troydm/shellasync.vim, it uses InsertEnter to check if user went into insert mode while his cursor was on prefix of shell e.g. '$' symbol and if it does it just automaticly moves cursor on 3rd col instead. For a user of my plugin (atleast for me) this is an expected behaviour

      --
      --
      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.
    • troydm
      Also as it is now i can move a cursor from InsertEnter as long as it s moved on a different line (not the same line) for example open some multi line file do
      Message 2 of 10 , May 18, 2013
      • 0 Attachment
        Also as it is now i can move a cursor from InsertEnter as long as it's moved on a different line (not the same line)

        for example open some multi line file

        do

        :au InsertEnter <buffer> normal! 3jl

        try entering insert mode on the first line (it works)

        now reopen some other multiline file and do

        :au InsertEnter <buffer> normal! 3l

        And it doesn't works

        --
        --
        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.
      • Bram Moolenaar
        ... That s a bug. The check for the line is to avoid going outside of the available lines when the text has changed. -- Permission is granted to read this
        Message 3 of 10 , May 18, 2013
        • 0 Attachment
          Troydm (?) wrote:

          > Also as it is now i can move a cursor from InsertEnter as long as it's moved on a different line (not the same line)
          >
          > for example open some multi line file
          >
          > do
          >
          > :au InsertEnter <buffer> normal! 3jl
          >
          > try entering insert mode on the first line (it works)
          >
          > now reopen some other multiline file and do
          >
          > :au InsertEnter <buffer> normal! 3l
          >
          > And it doesn't works

          That's a bug. The check for the line is to avoid going outside of the
          available lines when the text has changed.

          --
          Permission is granted to read this message out aloud on Kings Cross Road,
          London, under the condition that the orator is properly dressed.

          /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
          /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
          \\\ an exciting new programming language -- http://www.Zimbu.org ///
          \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

          --
          --
          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.
        • Bram Moolenaar
          ... You can use the CursorMovedI event instead. If it s slow you can set a flag in InsertEnter and only do something in CursorMovedI when it set. Hmm, I
          Message 4 of 10 , May 18, 2013
          • 0 Attachment
            Troydm (?) wrote:

            > Well for example one of my plugins includes bash shell emulation
            > inside a vim buffer, it's called shellasync.vim and it's source code
            > is at https://github.com/troydm/shellasync.vim, it uses InsertEnter to
            > check if user went into insert mode while his cursor was on prefix of
            > shell e.g. '$' symbol and if it does it just automaticly moves cursor
            > on 3rd col instead. For a user of my plugin (atleast for me) this is
            > an expected behaviour

            You can use the CursorMovedI event instead. If it's slow you can set a
            flag in InsertEnter and only do something in CursorMovedI when it' set.
            Hmm, I suppose it doesn't work for the "i" command, the cursor doesn't
            move then. You would have to map it.

            --
            ARTHUR: No, hang on! Just answer the five questions ...
            GALAHAD: Three questions ...
            ARTHUR: Three questions ... And we shall watch ... and pray.
            "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

            /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
            /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
            \\\ an exciting new programming language -- http://www.Zimbu.org ///
            \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

            --
            --
            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.
          • troydm
            ... You mean check_cursor_col() call is to check for the line to avoid going outside of the available lines when text has changed i presume? So what is the
            Message 5 of 10 , May 18, 2013
            • 0 Attachment
              On Sunday, May 19, 2013 1:23:23 AM UTC+4, Bram Moolenaar wrote:
              >
              >
              > That's a bug. The check for the line is to avoid going outside of the
              >
              > available lines when the text has changed.
              >

              You mean check_cursor_col() call is to check for the line to avoid going outside of the available lines when text has changed i presume?
              So what is the proposed fix?

              commenting/removing this line?
              curwin->w_cursor = save_cursor;

              --
              --
              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.
            • troydm
              ... Wait, isn t check_cursor_col() called only when line number hasn t changed, and that is when cursor s position is resetted to value before event call -- --
              Message 6 of 10 , May 18, 2013
              • 0 Attachment
                On Sunday, May 19, 2013 1:53:16 AM UTC+4, troydm wrote:
                > On Sunday, May 19, 2013 1:23:23 AM UTC+4, Bram Moolenaar wrote:
                > >
                > >
                > > That's a bug. The check for the line is to avoid going outside of the
                > >
                > > available lines when the text has changed.
                > >
                >
                > You mean check_cursor_col() call is to check for the line to avoid going outside of the available lines when text has changed i presume?
                > So what is the proposed fix?
                >
                > commenting/removing this line?
                > curwin->w_cursor = save_cursor;

                Wait, isn't check_cursor_col() called only when line number hasn't changed, and that is when cursor's position is resetted to value before event call

                --
                --
                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.
              • Bram Moolenaar
                ... Well, if text got deleted the saved cursor position may no longer be valid. Hmm, that would be a problem though. If the autocommand removed text and
                Message 7 of 10 , May 19, 2013
                • 0 Attachment
                  Troydm wrote:

                  > On Sunday, May 19, 2013 1:23:23 AM UTC+4, Bram Moolenaar wrote:
                  > >
                  > >
                  > > That's a bug. The check for the line is to avoid going outside of the
                  > >
                  > > available lines when the text has changed.
                  > >
                  >
                  > You mean check_cursor_col() call is to check for the line to avoid
                  > going outside of the available lines when text has changed i presume?
                  > So what is the proposed fix?
                  >
                  > commenting/removing this line?
                  > curwin->w_cursor = save_cursor;

                  Well, if text got deleted the saved cursor position may no longer be
                  valid.

                  Hmm, that would be a problem though. If the autocommand removed text
                  and positioned the cursor where it should be it will be restored in the
                  wrong position.

                  Most InsertEnter autocommands will not change text, restoring the cursor
                  is useful then. But we need some way to avoid restoring the cursor.
                  We could use the v:char variable perhaps.

                  --
                  There is no right or wrong, there is only your personal opinion.
                  (Bram Moolenaar)

                  /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
                  /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
                  \\\ an exciting new programming language -- http://www.Zimbu.org ///
                  \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

                  --
                  --
                  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.
                • troydm
                  ... Thanks, works perfectly -- -- You received this message from the vim_dev maillist. Do not top-post! Type your reply below the text you are replying to.
                  Message 8 of 10 , May 19, 2013
                  • 0 Attachment
                    On Sunday, May 19, 2013 11:04:12 PM UTC+4, Bram Moolenaar wrote:
                    > Troydm wrote:
                    >
                    >
                    >
                    > > On Sunday, May 19, 2013 1:23:23 AM UTC+4, Bram Moolenaar wrote:
                    >
                    > > >
                    >
                    > > >
                    >
                    > > > That's a bug. The check for the line is to avoid going outside of the
                    >
                    > > >
                    >
                    > > > available lines when the text has changed.
                    >
                    > > >
                    >
                    > >
                    >
                    > > You mean check_cursor_col() call is to check for the line to avoid
                    >
                    > > going outside of the available lines when text has changed i presume?
                    >
                    > > So what is the proposed fix?
                    >
                    > >
                    >
                    > > commenting/removing this line?
                    >
                    > > curwin->w_cursor = save_cursor;
                    >
                    >
                    >
                    > Well, if text got deleted the saved cursor position may no longer be
                    >
                    > valid.
                    >
                    >
                    >
                    > Hmm, that would be a problem though. If the autocommand removed text
                    >
                    > and positioned the cursor where it should be it will be restored in the
                    >
                    > wrong position.
                    >
                    >
                    >
                    > Most InsertEnter autocommands will not change text, restoring the cursor
                    >
                    > is useful then. But we need some way to avoid restoring the cursor.
                    >
                    > We could use the v:char variable perhaps.
                    >
                    >
                    >
                    > --
                    >
                    > There is no right or wrong, there is only your personal opinion.
                    >
                    > (Bram Moolenaar)
                    >
                    >
                    >
                    > /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
                    >
                    > /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
                    >
                    > \\\ an exciting new programming language -- http://www.Zimbu.org ///
                    >
                    > \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

                    Thanks, works perfectly

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