Patch 8.0.1573
Problem:    getwinpos(1) may cause response to be handled as command.
Solution:   Handle any cursor position report once one was request. (partly by
            Hirohito Higashi)
Files:      src/term.c


*** ../vim-8.0.1572/src/term.c  2018-03-04 20:14:08.252064314 +0100
--- src/term.c  2018-03-05 22:41:17.476679622 +0100
***************
*** 143,148 ****
--- 143,151 ----
  
  /* Request cursor style report: */
  static int rcs_status = STATUS_GET;
+ 
+ /* Request windos position report: */
+ static int winpos_status = STATUS_GET;
  # endif
  
  /*
***************
*** 2778,2786 ****
            && p_ek;
  }
  
! static int winpos_x;
! static int winpos_y;
! static int waiting_for_winpos = FALSE;
  
  /*
   * Try getting the Vim window position from the terminal.
--- 2781,2789 ----
            && p_ek;
  }
  
! static int winpos_x = -1;
! static int winpos_y = -1;
! static int did_request_winpos = 0;
  
  /*
   * Try getting the Vim window position from the terminal.
***************
*** 2790,2818 ****
  term_get_winpos(int *x, int *y, varnumber_T timeout)
  {
      int count = 0;
  
      if (*T_CGP == NUL || !can_get_termresponse())
        return FAIL;
      winpos_x = -1;
      winpos_y = -1;
!     waiting_for_winpos = TRUE;
      OUT_STR(T_CGP);
      out_flush();
  
      /* Try reading the result for "timeout" msec. */
!     while (count++ < timeout / 10)
      {
        (void)vpeekc_nomap();
        if (winpos_x >= 0 && winpos_y >= 0)
        {
            *x = winpos_x;
            *y = winpos_y;
-           waiting_for_winpos = FALSE;
            return OK;
        }
        ui_delay(10, FALSE);
      }
!     waiting_for_winpos = FALSE;
      return FALSE;
  }
  # endif
--- 2793,2835 ----
  term_get_winpos(int *x, int *y, varnumber_T timeout)
  {
      int count = 0;
+     int prev_winpos_x = winpos_x;
+     int prev_winpos_y = winpos_y;
  
      if (*T_CGP == NUL || !can_get_termresponse())
        return FAIL;
      winpos_x = -1;
      winpos_y = -1;
!     ++did_request_winpos;
!     winpos_status = STATUS_SENT;
      OUT_STR(T_CGP);
      out_flush();
  
      /* Try reading the result for "timeout" msec. */
!     while (count++ <= timeout / 10 && !got_int)
      {
        (void)vpeekc_nomap();
        if (winpos_x >= 0 && winpos_y >= 0)
        {
            *x = winpos_x;
            *y = winpos_y;
            return OK;
        }
        ui_delay(10, FALSE);
      }
!     /* Do not reset "did_request_winpos", if we timed out the response might
!      * still come later and we must consume it. */
! 
!     winpos_x = prev_winpos_x;
!     winpos_y = prev_winpos_y;
!     if (timeout < 10 && prev_winpos_y >= 0 && prev_winpos_y >= 0)
!     {
!       /* Polling: return previous values if we have them. */
!       *x = winpos_x;
!       *y = winpos_y;
!       return OK;
!     }
! 
      return FALSE;
  }
  # endif
***************
*** 3365,3371 ****
  #endif
                                         || rbg_status == STATUS_SENT
                                         || rbm_status == STATUS_SENT
!                                        || rcs_status == STATUS_SENT))
                    (void)vpeekc_nomap();
                check_for_codes_from_term();
            }
--- 3382,3389 ----
  #endif
                                         || rbg_status == STATUS_SENT
                                         || rbm_status == STATUS_SENT
!                                        || rcs_status == STATUS_SENT
!                                        || winpos_status == STATUS_SENT))
                    (void)vpeekc_nomap();
                check_for_codes_from_term();
            }
***************
*** 3439,3445 ****
  # endif
                    || rbg_status == STATUS_SENT
                    || rbm_status == STATUS_SENT
!                   || rcs_status == STATUS_SENT)
            {
  # ifdef UNIX
                /* Give the terminal a chance to respond. */
--- 3457,3464 ----
  # endif
                    || rbg_status == STATUS_SENT
                    || rbm_status == STATUS_SENT
!                   || rcs_status == STATUS_SENT
!                   || winpos_status == STATUS_SENT)
            {
  # ifdef UNIX
                /* Give the terminal a chance to respond. */
***************
*** 4468,4474 ****
             */
            char_u *argp = tp[0] == ESC ? tp + 2 : tp + 1;
  
!           if ((*T_CRV != NUL || *T_U7 != NUL || waiting_for_winpos)
                        && ((tp[0] == ESC && len >= 3 && tp[1] == '[')
                            || (tp[0] == CSI && len >= 2))
                        && (VIM_ISDIGIT(*argp) || *argp == '>' || *argp == '?'))
--- 4487,4493 ----
             */
            char_u *argp = tp[0] == ESC ? tp + 2 : tp + 1;
  
!           if ((*T_CRV != NUL || *T_U7 != NUL || did_request_winpos)
                        && ((tp[0] == ESC && len >= 3 && tp[1] == '[')
                            || (tp[0] == CSI && len >= 2))
                        && (VIM_ISDIGIT(*argp) || *argp == '>' || *argp == '?'))
***************
*** 4730,4736 ****
                 * Check for a window position response from the terminal:
                 *       {lead}3;{x}:{y}t
                 */
!               else if (waiting_for_winpos
                            && ((len >= 4 && tp[0] == ESC && tp[1] == '[')
                                || (len >= 3 && tp[0] == CSI))
                            && tp[(j = 1 + (tp[0] == ESC))] == '3'
--- 4749,4755 ----
                 * Check for a window position response from the terminal:
                 *       {lead}3;{x}:{y}t
                 */
!               else if (did_request_winpos
                            && ((len >= 4 && tp[0] == ESC && tp[1] == '[')
                                || (len >= 3 && tp[0] == CSI))
                            && tp[(j = 1 + (tp[0] == ESC))] == '3'
***************
*** 4752,4757 ****
--- 4771,4779 ----
                            key_name[0] = (int)KS_EXTRA;
                            key_name[1] = (int)KE_IGNORE;
                            slen = i + 1;
+ 
+                           if (--did_request_winpos <= 0)
+                               winpos_status = STATUS_GOT;
                        }
                    }
                    if (i == len)
*** ../vim-8.0.1572/src/version.c       2018-03-05 21:59:33.214889934 +0100
--- src/version.c       2018-03-05 22:42:17.424294620 +0100
***************
*** 768,769 ****
--- 768,771 ----
  {   /* Add new patch number below this line */
+ /**/
+     1573,
  /**/

-- 
OLD WOMAN: King of the WHO?
ARTHUR:    The Britons.
OLD WOMAN: Who are the Britons?
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [email protected] -- 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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui