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

:redir make confusion of cursor position in command line.

Expand Messages
  • mattn
    Hi. Try following on windows. ... function! DoSpace() return endfunction cnoremap DoSpace() ... function! DoSpace() redir = foo silent!
    Message 1 of 9 , Sep 15, 2011
    • 0 Attachment
      Hi.

      Try following on windows.

      ---- script1 ----
      function! DoSpace()
        return ' '
      endfunction
      cnoremap <expr> <space> DoSpace()
      ----

      ---- script2 ----
      function! DoSpace()
        redir => foo
        silent! command
        redir END
        return ' '
      endfunction
      cnoremap <expr> <space> DoSpace()
      ----

      When run script1 and type ":XXX " in normal mode, you'll see ":XXX ".
      But if run script2 and type it, it show " XXX ". You can see ":" is erased in command line.

      The cause is:
      Doing redir and something that updating cursor position in scripts are change msg_col even if command use silent!. This is not a problem. But if enter "redir END" for <expr> function, msg_col should be restored to original position that is started with ":redir foo".

      Below is a patch. Please check this.

      https://gist.github.com/1219080

      diff -r 15b934a16641 src/ex_docmd.c
      --- a/src/ex_docmd.c Wed Sep 14 19:04:40 2011 +0200
      +++ b/src/ex_docmd.c Thu Sep 15 20:43:11 2011 +0900
      @@ -8628,9 +8628,13 @@
           char *mode;
           char_u *fname;
           char_u *arg = eap->arg;
      +    static int save_msg_col = 0;
       
           if (STRICMP(eap->arg, "END") == 0)
      +    {
        close_redir();
      + msg_col = save_msg_col;
      +    }
           else
           {
        if (*arg == '>')
      @@ -8736,8 +8740,10 @@
       #ifdef FEAT_EVAL
         || redir_reg || redir_vname
       #endif
      - )
      + ) {
        redir_off = FALSE;
      + save_msg_col = msg_col;
      +    }
       }
       
       /*


      --
      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
    • mattn
      Ah sorry. it should be more strictly. https://gist.github.com/1219080 diff -r 15b934a16641 src/ex_docmd.c ... +++ b/src/ex_docmd.c Thu Sep 15 21:19:47 2011
      Message 2 of 9 , Sep 15, 2011
      • 0 Attachment
        Ah sorry. it should be more  strictly.

        https://gist.github.com/1219080

        diff -r 15b934a16641 src/ex_docmd.c
        --- a/src/ex_docmd.c Wed Sep 14 19:04:40 2011 +0200
        +++ b/src/ex_docmd.c Thu Sep 15 21:19:47 2011 +0900
        @@ -8628,9 +8628,16 @@
             char *mode;
             char_u *fname;
             char_u *arg = eap->arg;
        +    static int save_msg_col = -1;
         
             if (STRICMP(eap->arg, "END") == 0)
        +    {
          close_redir();
        + if (save_msg_col != -1) {
        +    msg_col = save_msg_col;
        +    save_msg_col = -1;
        + }
        +    }
             else
             {
          if (*arg == '>')
        @@ -8736,8 +8743,10 @@
         #ifdef FEAT_EVAL
           || redir_reg || redir_vname
         #endif
        - )
        + ) {
          redir_off = FALSE;
        + save_msg_col = msg_col;
        +    }
         }
         
         /*

        --
        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
      • mattn
        Shoud be applied to row. diff -r 15b934a16641 src/ex_docmd.c ... +++ b/src/ex_docmd.c Fri Sep 16 10:23:53 2011 +0900 @@ -8628,9 +8628,19 @@ char *mode; char_u
        Message 3 of 9 , Sep 15, 2011
        • 0 Attachment
          Shoud be applied to row.

          diff -r 15b934a16641 src/ex_docmd.c
          --- a/src/ex_docmd.c Wed Sep 14 19:04:40 2011 +0200
          +++ b/src/ex_docmd.c Fri Sep 16 10:23:53 2011 +0900
          @@ -8628,9 +8628,19 @@
               char *mode;
               char_u *fname;
               char_u *arg = eap->arg;
          +    static int save_msg_col = -1;
          +    static int save_msg_row = -1;
           
               if (STRICMP(eap->arg, "END") == 0)
          +    {
            close_redir();
          + if (save_msg_col != -1 && save_msg_row != -1) {
          +    msg_col = save_msg_col;
          +    msg_row = save_msg_row;
          +    save_msg_col = -1;
          +    save_msg_row = -1;
          + }
          +    }
               else
               {
            if (*arg == '>')
          @@ -8736,8 +8746,11 @@
           #ifdef FEAT_EVAL
             || redir_reg || redir_vname
           #endif
          - )
          + ) {
            redir_off = FALSE;
          + save_msg_col = msg_col;
          + save_msg_row = msg_row;
          +    }
           }
           
           /*

          --
          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
        • Bram Moolenaar
          ... I am unable to reproduce the problem. What settings would be needed? Is this in a terminal or in gvim? -- hundred-and-one symptoms of being an internet
          Message 4 of 9 , Sep 30, 2011
          • 0 Attachment
            Yasuhiro Matsumoto wrote:

            > Try following on windows.
            >
            > ---- script1 ----
            > function! DoSpace()
            > return ' '
            > endfunction
            > cnoremap <expr> <space> DoSpace()
            > ----
            >
            > ---- script2 ----
            > function! DoSpace()
            > redir => foo
            > silent! command
            > redir END
            > return ' '
            > endfunction
            > cnoremap <expr> <space> DoSpace()
            > ----
            >
            > When run script1 and type ":XXX " in normal mode, you'll see ":XXX ".
            > But if run script2 and type it, it show " XXX ". You can see ":" is erased
            > in command line.
            >
            > The cause is:
            > Doing redir and something that updating cursor position in scripts are
            > change msg_col even if command use silent!. This is not a problem. But if
            > enter "redir END" for <expr> function, msg_col should be restored to
            > original position that is started with ":redir foo".
            >
            > Below is a patch. Please check this.

            I am unable to reproduce the problem. What settings would be needed?
            Is this in a terminal or in gvim?

            --
            hundred-and-one symptoms of being an internet addict:
            29. Your phone bill comes to your doorstep in a box.

            /// 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
          • Yasuhiro MATSUMOTO
            ... I can reproduce it on vim.exe. -- - Yasuhiro Matsumoto -- You received this message from the vim_dev maillist. Do not top-post! Type your reply below the
            Message 5 of 9 , Sep 30, 2011
            • 0 Attachment
              > I am unable to reproduce the problem.  What settings would be needed?
              > Is this in a terminal or in gvim?

              I can reproduce it on vim.exe.

              --
              - Yasuhiro Matsumoto

              --
              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
            • Bram Moolenaar
              ... So that is on a Windows console window. Did you build Vim yourself? With what compiler? -- On the other hand, you have different fingers. -- Steven Wright
              Message 6 of 9 , Oct 2, 2011
              • 0 Attachment
                Yasuhiro Matsumoto wrote:

                > > I am unable to reproduce the problem.  What settings would be needed?
                > > Is this in a terminal or in gvim?
                >
                > I can reproduce it on vim.exe.

                So that is on a Windows console window. Did you build Vim yourself?
                With what compiler?

                --
                On the other hand, you have different fingers.
                -- Steven Wright

                /// 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
              • mattn
                Yes, mingw32, -u NONE -N. -- You received this message from the vim_dev maillist. Do not top-post! Type your reply below the text you are replying to. For
                Message 7 of 9 , Oct 3, 2011
                • 0 Attachment
                  Yes, mingw32, -u NONE -N.

                  --
                  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
                • Bram Moolenaar
                  ... I still cannot reproduce the problem. It does not look like it is specific for Windows. I think saving and restoring msg_row and msg_col in :redir will
                  Message 8 of 9 , Dec 14, 2011
                  • 0 Attachment
                    Yasuhiro Matsumoto wrote:

                    > Try following on windows.
                    >
                    > ---- script1 ----
                    > function! DoSpace()
                    > return ' '
                    > endfunction
                    > cnoremap <expr> <space> DoSpace()
                    > ----
                    >
                    > ---- script2 ----
                    > function! DoSpace()
                    > redir => foo
                    > silent! command
                    > redir END
                    > return ' '
                    > endfunction
                    > cnoremap <expr> <space> DoSpace()
                    > ----
                    >
                    > When run script1 and type ":XXX " in normal mode, you'll see ":XXX ".
                    > But if run script2 and type it, it show " XXX ". You can see ":" is erased
                    > in command line.
                    >
                    > The cause is:
                    > Doing redir and something that updating cursor position in scripts are
                    > change msg_col even if command use silent!. This is not a problem. But if
                    > enter "redir END" for <expr> function, msg_col should be restored to
                    > original position that is started with ":redir foo".
                    >
                    > Below is a patch. Please check this.

                    I still cannot reproduce the problem. It does not look like it is
                    specific for Windows.

                    I think saving and restoring msg_row and msg_col in ":redir" will not
                    work well. It's probably better to do this while evaluating the
                    expression. Please try out this patch instead of yours:


                    *** ../vim-7.3.377/src/getchar.c 2011-10-12 22:02:07.000000000 +0200
                    --- src/getchar.c 2011-12-14 18:37:52.000000000 +0100
                    ***************
                    *** 4510,4515 ****
                    --- 4510,4517 ----
                    char_u *expr;
                    char_u *save_cmd;
                    pos_T save_cursor;
                    + int save_msg_col;
                    + int save_msg_row;

                    /* Remove escaping of CSI, because "str" is in a format to be used as
                    * typeahead. */
                    ***************
                    *** 4533,4544 ****
                    --- 4535,4550 ----
                    #endif
                    set_vim_var_char(c); /* set v:char to the typed character */
                    save_cursor = curwin->w_cursor;
                    + save_msg_col = msg_col;
                    + save_msg_row = msg_row;
                    p = eval_to_string(expr, NULL, FALSE);
                    --textlock;
                    #ifdef FEAT_EX_EXTRA
                    --ex_normal_lock;
                    #endif
                    curwin->w_cursor = save_cursor;
                    + msg_col = save_msg_col;
                    + msg_row = save_msg_row;

                    restore_cmdline_alloc(save_cmd);
                    vim_free(expr);


                    --
                    DINGO: And after the spanking ... the oral sex.
                    GALAHAD: Oh, dear! Well, I...
                    GIRLS: The oral sex ... The oral sex.
                    GALAHAD: Well, I suppose I could stay a BIT longer.
                    "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
                  • mattn
                    It seems good to me. :) -- 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
                    Message 9 of 9 , Dec 14, 2011
                    • 0 Attachment
                      It seems good to me. :)

                      --
                      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
                    Your message has been successfully submitted and would be delivered to recipients shortly.