073263
To: vim_dev@googlegroups.com
073263
Subject: Patch 7.4.389
073263
Fcc: outbox
073263
From: Bram Moolenaar <Bram@moolenaar.net>
073263
Mime-Version: 1.0
073263
Content-Type: text/plain; charset=UTF-8
073263
Content-Transfer-Encoding: 8bit
073263
------------
073263
073263
Patch 7.4.389
073263
Problem:    Still sometimes Vim enters Replace mode when starting up.
073263
Solution:   Use a different solution in detecting the termresponse and
073263
	    location response. (Hayaki Saito)
073263
Files:	    src/globals.h, src/os_unix.c, src/term.c, src/proto/term.pro
073263
073263
073263
*** ../vim-7.4.388/src/globals.h	2014-06-12 14:01:27.575769788 +0200
073263
--- src/globals.h	2014-07-30 17:02:57.711526671 +0200
073263
***************
073263
*** 1336,1344 ****
073263
  #if defined(UNIX) || defined(VMS)
073263
  EXTERN int	term_is_xterm INIT(= FALSE);	/* xterm-like 'term' */
073263
  #endif
073263
- #if defined(UNIX)
073263
- EXTERN int	xterm_conflict_mouse INIT(= FALSE);
073263
- #endif
073263
  
073263
  #ifdef BACKSLASH_IN_FILENAME
073263
  EXTERN char	psepc INIT(= '\\');	/* normal path separator character */
073263
--- 1336,1341 ----
073263
*** ../vim-7.4.388/src/os_unix.c	2014-07-09 19:13:45.007701718 +0200
073263
--- src/os_unix.c	2014-07-30 17:06:02.375525344 +0200
073263
***************
073263
*** 3667,3674 ****
073263
      void
073263
  check_mouse_termcode()
073263
  {
073263
-     xterm_conflict_mouse = FALSE;
073263
- 
073263
  # ifdef FEAT_MOUSE_XTERM
073263
      if (use_xterm_mouse()
073263
  # ifdef FEAT_MOUSE_URXVT
073263
--- 3667,3672 ----
073263
***************
073263
*** 3713,3719 ****
073263
  # endif
073263
  
073263
  # ifdef FEAT_MOUSE_JSB
073263
!     /* There is no conflict, but it was disabled for xterm before. */
073263
      if (!use_xterm_mouse()
073263
  #  ifdef FEAT_GUI
073263
  	    && !gui.in_use
073263
--- 3711,3717 ----
073263
  # endif
073263
  
073263
  # ifdef FEAT_MOUSE_JSB
073263
!     /* Conflicts with xterm mouse: "\033[" and "\033[M" ??? */
073263
      if (!use_xterm_mouse()
073263
  #  ifdef FEAT_GUI
073263
  	    && !gui.in_use
073263
***************
073263
*** 3740,3784 ****
073263
  # endif
073263
  
073263
  # ifdef FEAT_MOUSE_DEC
073263
!     /* Conflicts with xterm mouse: "\033[" and "\033[M".
073263
!      * Also conflicts with the xterm termresponse, skip this if it was
073263
!      * requested already. */
073263
      if (!use_xterm_mouse()
073263
- #  ifdef FEAT_TERMRESPONSE
073263
- 	    && !did_request_esc_sequence()
073263
- #  endif
073263
  #  ifdef FEAT_GUI
073263
  	    && !gui.in_use
073263
  #  endif
073263
  	    )
073263
-     {
073263
  	set_mouse_termcode(KS_DEC_MOUSE, (char_u *)(term_is_8bit(T_NAME)
073263
  		     ? IF_EB("\233", CSI_STR) : IF_EB("\033[", ESC_STR "[")));
073263
- 	xterm_conflict_mouse = TRUE;
073263
-     }
073263
      else
073263
  	del_mouse_termcode(KS_DEC_MOUSE);
073263
  # endif
073263
  # ifdef FEAT_MOUSE_PTERM
073263
!     /* same as the dec mouse */
073263
      if (!use_xterm_mouse()
073263
- #  ifdef FEAT_TERMRESPONSE
073263
- 	    && !did_request_esc_sequence()
073263
- #  endif
073263
  #  ifdef FEAT_GUI
073263
  	    && !gui.in_use
073263
  #  endif
073263
  	    )
073263
-     {
073263
  	set_mouse_termcode(KS_PTERM_MOUSE,
073263
  				      (char_u *) IF_EB("\033[", ESC_STR "["));
073263
- 	xterm_conflict_mouse = TRUE;
073263
-     }
073263
      else
073263
  	del_mouse_termcode(KS_PTERM_MOUSE);
073263
  # endif
073263
  # ifdef FEAT_MOUSE_URXVT
073263
!     /* same as the dec mouse */
073263
      if (use_xterm_mouse() == 3
073263
  #  ifdef FEAT_GUI
073263
  	    && !gui.in_use
073263
--- 3738,3768 ----
073263
  # endif
073263
  
073263
  # ifdef FEAT_MOUSE_DEC
073263
!     /* Conflicts with xterm mouse: "\033[" and "\033[M" */
073263
      if (!use_xterm_mouse()
073263
  #  ifdef FEAT_GUI
073263
  	    && !gui.in_use
073263
  #  endif
073263
  	    )
073263
  	set_mouse_termcode(KS_DEC_MOUSE, (char_u *)(term_is_8bit(T_NAME)
073263
  		     ? IF_EB("\233", CSI_STR) : IF_EB("\033[", ESC_STR "[")));
073263
      else
073263
  	del_mouse_termcode(KS_DEC_MOUSE);
073263
  # endif
073263
  # ifdef FEAT_MOUSE_PTERM
073263
!     /* same conflict as the dec mouse */
073263
      if (!use_xterm_mouse()
073263
  #  ifdef FEAT_GUI
073263
  	    && !gui.in_use
073263
  #  endif
073263
  	    )
073263
  	set_mouse_termcode(KS_PTERM_MOUSE,
073263
  				      (char_u *) IF_EB("\033[", ESC_STR "["));
073263
      else
073263
  	del_mouse_termcode(KS_PTERM_MOUSE);
073263
  # endif
073263
  # ifdef FEAT_MOUSE_URXVT
073263
!     /* same conflict as the dec mouse */
073263
      if (use_xterm_mouse() == 3
073263
  #  ifdef FEAT_GUI
073263
  	    && !gui.in_use
073263
***************
073263
*** 3794,3801 ****
073263
  	    mch_setmouse(FALSE);
073263
  	    setmouse();
073263
  	}
073263
- 	/* It's OK to request the xterm version for uxterm. */
073263
- 	resume_get_esc_sequence();
073263
      }
073263
      else
073263
  	del_mouse_termcode(KS_URXVT_MOUSE);
073263
--- 3778,3783 ----
073263
*** ../vim-7.4.388/src/term.c	2014-07-09 20:51:04.519583033 +0200
073263
--- src/term.c	2014-07-30 17:20:54.915518929 +0200
073263
***************
073263
*** 153,163 ****
073263
  static char_u *vim_tgetstr __ARGS((char *s, char_u **pp));
073263
  #endif /* HAVE_TGETENT */
073263
  
073263
- #if defined(FEAT_TERMRESPONSE)
073263
- static int xt_index_in = 0;
073263
- static int xt_index_out = 0;
073263
- #endif
073263
- 
073263
  static int  detected_8bit = FALSE;	/* detected 8-bit terminal */
073263
  
073263
  static struct builtin_term builtin_termcaps[] =
073263
--- 153,158 ----
073263
***************
073263
*** 3312,3351 ****
073263
  }
073263
  
073263
  #if defined(FEAT_TERMRESPONSE) || defined(PROTO)
073263
- # if defined(UNIX) || defined(PROTO)
073263
- /*
073263
-  * Return TRUE when the xterm version was requested or anything else that
073263
-  * would send an ESC sequence back to Vim.
073263
-  * If not sent yet, prevent it from being sent soon.
073263
-  * Used to check whether it is OK to enable checking for DEC mouse codes,
073263
-  * which conflict with may xterm ESC sequences.
073263
-  */
073263
-     int
073263
- did_request_esc_sequence()
073263
- {
073263
-     if (crv_status == CRV_GET)
073263
- 	crv_status = 0;
073263
-     if (u7_status == U7_GET)
073263
- 	u7_status = 0;
073263
-     return crv_status == CRV_SENT || u7_status == U7_SENT
073263
- 						|| xt_index_out > xt_index_in;
073263
- }
073263
- 
073263
- /*
073263
-  * If requesting the version was disabled in did_request_esc_sequence(),
073263
-  * enable it again.
073263
-  */
073263
-     void
073263
- resume_get_esc_sequence()
073263
- {
073263
-     if (crv_status == 0)
073263
- 	crv_status = CRV_GET;
073263
-     if (u7_status == 0)
073263
- 	u7_status = U7_GET;
073263
- }
073263
- # endif
073263
- 
073263
- 
073263
  /*
073263
   * Request version string (for xterm) when needed.
073263
   * Only do this after switching to raw mode, otherwise the result will be
073263
--- 3307,3312 ----
073263
***************
073263
*** 3358,3365 ****
073263
   * Insert mode.
073263
   * On Unix only do it when both output and input are a tty (avoid writing
073263
   * request to terminal while reading from a file).
073263
-  * Do not do this when a mouse is being detected that starts with the same ESC
073263
-  * sequence as the termresponse.
073263
   * The result is caught in check_termcode().
073263
   */
073263
      void
073263
--- 3319,3324 ----
073263
***************
073263
*** 3373,3379 ****
073263
  # ifdef UNIX
073263
  	    && isatty(1)
073263
  	    && isatty(read_cmd_fd)
073263
- 	    && !xterm_conflict_mouse
073263
  # endif
073263
  	    && *T_CRV != NUL)
073263
      {
073263
--- 3332,3337 ----
073263
***************
073263
*** 3742,3749 ****
073263
  #if defined(WIN3264) && !defined(FEAT_GUI)
073263
      if (s[0] == K_NUL)
073263
      {
073263
!         STRMOVE(s + 1, s);
073263
!         s[1] = 3;
073263
      }
073263
  #endif
073263
  
073263
--- 3700,3707 ----
073263
  #if defined(WIN3264) && !defined(FEAT_GUI)
073263
      if (s[0] == K_NUL)
073263
      {
073263
! 	STRMOVE(s + 1, s);
073263
! 	s[1] = 3;
073263
      }
073263
  #endif
073263
  
073263
***************
073263
*** 4212,4235 ****
073263
  
073263
  #ifdef FEAT_TERMRESPONSE
073263
  	if (key_name[0] == NUL
073263
! 	    /* URXVT mouse uses <ESC>[#;#;#M, but we are matching <ESC>[ */
073263
  	    || key_name[0] == KS_URXVT_MOUSE
073263
- # ifdef FEAT_MBYTE
073263
- 	    || u7_status == U7_SENT
073263
  # endif
073263
!             )
073263
  	{
073263
! 	    /* Check for some responses from terminal start with "<Esc>[" or
073263
! 	     * CSI.
073263
  	     *
073263
! 	     * - xterm version string: <Esc>[>{x};{vers};{y}c
073263
  	     *   Also eat other possible responses to t_RV, rxvt returns
073263
  	     *   "<Esc>[?1;2c". Also accept CSI instead of <Esc>[.
073263
  	     *   mrxvt has been reported to have "+" in the version. Assume
073263
  	     *   the escape sequence ends with a letter or one of "{|}~".
073263
  	     *
073263
! 	     * - cursor position report: <Esc>[{row};{col}R
073263
! 	     *   The final byte is 'R'. now it is only used for checking for
073263
  	     *   ambiguous-width character state.
073263
  	     */
073263
  	    p = tp[0] == CSI ? tp + 1 : tp + 2;
073263
--- 4170,4200 ----
073263
  
073263
  #ifdef FEAT_TERMRESPONSE
073263
  	if (key_name[0] == NUL
073263
! 	    /* Mouse codes of DEC, pterm, and URXVT start with <ESC>[.  When
073263
! 	     * detecting the start of these mouse codes they might as well be
073263
! 	     * another key code or terminal response. */
073263
! # ifdef FEAT_MOUSE_DEC
073263
! 	    || key_name[0] == KS_DEC_MOUSE
073263
! # endif
073263
! # ifdef FEAT_MOUSE_PTERM
073263
! 	    || key_name[0] == KS_PTERM_MOUSE
073263
! # endif
073263
! # ifdef FEAT_MOUSE_URXVT
073263
  	    || key_name[0] == KS_URXVT_MOUSE
073263
  # endif
073263
! 	   )
073263
  	{
073263
! 	    /* Check for some responses from the terminal starting with
073263
! 	     * "<Esc>[" or CSI:
073263
  	     *
073263
! 	     * - Xterm version string: <Esc>[>{x};{vers};{y}c
073263
  	     *   Also eat other possible responses to t_RV, rxvt returns
073263
  	     *   "<Esc>[?1;2c". Also accept CSI instead of <Esc>[.
073263
  	     *   mrxvt has been reported to have "+" in the version. Assume
073263
  	     *   the escape sequence ends with a letter or one of "{|}~".
073263
  	     *
073263
! 	     * - Cursor position report: <Esc>[{row};{col}R
073263
! 	     *   The final byte must be 'R'. It is used for checking the
073263
  	     *   ambiguous-width character state.
073263
  	     */
073263
  	    p = tp[0] == CSI ? tp + 1 : tp + 2;
073263
***************
073263
*** 4269,4304 ****
073263
  		 * u7_status is not "sent", it may be from a previous Vim that
073263
  		 * just exited.  But not for <S-F3>, it sends something
073263
  		 * similar, check for row and column to make sense. */
073263
! 		if (j == 1 && tp[i] == 'R' && row_char == '2' && col >= 2)
073263
  		{
073263
! 		    char *aw = NULL;
073263
  
073263
! 		    LOG_TR("Received U7 status");
073263
! 		    u7_status = U7_GOT;
073263
  # ifdef FEAT_AUTOCMD
073263
! 		    did_cursorhold = TRUE;
073263
  # endif
073263
! 		    if (col == 2)
073263
! 			aw = "single";
073263
! 		    else if (col == 3)
073263
! 			aw = "double";
073263
! 		    if (aw != NULL && STRCMP(aw, p_ambw) != 0)
073263
! 		    {
073263
! 			/* Setting the option causes a screen redraw. Do that
073263
! 			 * right away if possible, keeping any messages. */
073263
! 			set_option_value((char_u *)"ambw", 0L, (char_u *)aw, 0);
073263
! # ifdef DEBUG_TERMRESPONSE
073263
  			{
073263
! 			    char buf[100];
073263
! 			    int  r = redraw_asap(CLEAR);
073263
  
073263
! 			    sprintf(buf, "set 'ambiwidth', redraw_asap(): %d",
073263
! 									   r);
073263
! 			    log_tr(buf);
073263
! 			}
073263
  # else
073263
! 			redraw_asap(CLEAR);
073263
  # endif
073263
  		    }
073263
  		    key_name[0] = (int)KS_EXTRA;
073263
  		    key_name[1] = (int)KE_IGNORE;
073263
--- 4234,4275 ----
073263
  		 * u7_status is not "sent", it may be from a previous Vim that
073263
  		 * just exited.  But not for <S-F3>, it sends something
073263
  		 * similar, check for row and column to make sense. */
073263
! 		if (j == 1 && tp[i] == 'R')
073263
  		{
073263
! 		    if (row_char == '2' && col >= 2)
073263
! 		    {
073263
! 			char *aw = NULL;
073263
  
073263
! 			LOG_TR("Received U7 status");
073263
! 			u7_status = U7_GOT;
073263
  # ifdef FEAT_AUTOCMD
073263
! 			did_cursorhold = TRUE;
073263
  # endif
073263
! 			if (col == 2)
073263
! 			    aw = "single";
073263
! 			else if (col == 3)
073263
! 			    aw = "double";
073263
! 			if (aw != NULL && STRCMP(aw, p_ambw) != 0)
073263
  			{
073263
! 			    /* Setting the option causes a screen redraw. Do
073263
! 			     * that right away if possible, keeping any
073263
! 			     * messages. */
073263
! 			    set_option_value((char_u *)"ambw", 0L,
073263
! 					     (char_u *)aw, 0);
073263
! # ifdef DEBUG_TERMRESPONSE
073263
! 			    {
073263
! 				char buf[100];
073263
! 				int  r = redraw_asap(CLEAR);
073263
  
073263
! 				sprintf(buf,
073263
! 					"set 'ambiwidth', redraw_asap(): %d",
073263
! 					r);
073263
! 				log_tr(buf);
073263
! 			    }
073263
  # else
073263
! 			    redraw_asap(CLEAR);
073263
  # endif
073263
+ 			}
073263
  		    }
073263
  		    key_name[0] = (int)KS_EXTRA;
073263
  		    key_name[1] = (int)KE_IGNORE;
073263
***************
073263
*** 4563,4581 ****
073263
  			return -1;
073263
  
073263
  		    /* when mouse reporting is SGR, add 32 to mouse code */
073263
!                     if (key_name[0] == KS_SGR_MOUSE)
073263
!                         mouse_code += 32;
073263
  
073263
  		    mouse_col = getdigits(&p) - 1;
073263
  		    if (*p++ != ';')
073263
  			return -1;
073263
  
073263
  		    mouse_row = getdigits(&p) - 1;
073263
!                     if (key_name[0] == KS_SGR_MOUSE && *p == 'm')
073263
  			mouse_code |= MOUSE_RELEASE;
073263
!                     else if (*p != 'M')
073263
  			return -1;
073263
!                     p++;
073263
  
073263
  		    slen += (int)(p - (tp + slen));
073263
  
073263
--- 4534,4552 ----
073263
  			return -1;
073263
  
073263
  		    /* when mouse reporting is SGR, add 32 to mouse code */
073263
! 		    if (key_name[0] == KS_SGR_MOUSE)
073263
! 			mouse_code += 32;
073263
  
073263
  		    mouse_col = getdigits(&p) - 1;
073263
  		    if (*p++ != ';')
073263
  			return -1;
073263
  
073263
  		    mouse_row = getdigits(&p) - 1;
073263
! 		    if (key_name[0] == KS_SGR_MOUSE && *p == 'm')
073263
  			mouse_code |= MOUSE_RELEASE;
073263
! 		    else if (*p != 'M')
073263
  			return -1;
073263
! 		    p++;
073263
  
073263
  		    slen += (int)(p - (tp + slen));
073263
  
073263
***************
073263
*** 4592,4598 ****
073263
  			for (slen2 = slen; slen2 < len; slen2++)
073263
  			{
073263
  			    if (tp[slen2] == 'M'
073263
!                                 || (key_name[0] == KS_SGR_MOUSE
073263
  							 && tp[slen2] == 'm'))
073263
  			    {
073263
  				cmd_complete = 1;
073263
--- 4563,4569 ----
073263
  			for (slen2 = slen; slen2 < len; slen2++)
073263
  			{
073263
  			    if (tp[slen2] == 'M'
073263
! 				    || (key_name[0] == KS_SGR_MOUSE
073263
  							 && tp[slen2] == 'm'))
073263
  			    {
073263
  				cmd_complete = 1;
073263
***************
073263
*** 5769,5774 ****
073263
--- 5740,5748 ----
073263
   * termcap codes from the terminal itself.
073263
   * We get them one by one to avoid a very long response string.
073263
   */
073263
+ static int xt_index_in = 0;
073263
+ static int xt_index_out = 0;
073263
+ 
073263
      static void
073263
  req_codes_from_term()
073263
  {
073263
*** ../vim-7.4.388/src/proto/term.pro	2014-07-09 19:13:45.007701718 +0200
073263
--- src/proto/term.pro	2014-07-30 17:04:40.791525930 +0200
073263
***************
073263
*** 34,41 ****
073263
  void settmode __ARGS((int tmode));
073263
  void starttermcap __ARGS((void));
073263
  void stoptermcap __ARGS((void));
073263
- int did_request_esc_sequence __ARGS((void));
073263
- void resume_get_esc_sequence __ARGS((void));
073263
  void may_req_termresponse __ARGS((void));
073263
  void may_req_ambiguous_char_width __ARGS((void));
073263
  int swapping_screen __ARGS((void));
073263
--- 34,39 ----
073263
*** ../vim-7.4.388/src/version.c	2014-07-30 16:44:17.503534723 +0200
073263
--- src/version.c	2014-07-30 17:03:13.715526556 +0200
073263
***************
073263
*** 736,737 ****
073263
--- 736,739 ----
073263
  {   /* Add new patch number below this line */
073263
+ /**/
073263
+     389,
073263
  /**/
073263
073263
-- 
073263
The only way the average employee can speak to an executive is by taking a
073263
second job as a golf caddie.
073263
				(Scott Adams - The Dilbert principle)
073263
073263
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
073263
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
073263
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
073263
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///