Blob Blame History Raw
To: vim_dev@googlegroups.com
Subject: Patch 7.3.091
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 7.3.091
Problem:    "vim -w foo" writes special key codes for removed escape
	    sequences. (Josh Triplett)
Solution:   Don't write K_IGNORE codes.
Files:	    src/getchar.c, src/misc1.c, src/term.c, src/vim.h


*** ../vim-7.3.090/src/getchar.c	2010-10-27 17:39:00.000000000 +0200
--- src/getchar.c	2010-12-30 12:16:36.000000000 +0100
***************
*** 1506,1514 ****
      }
  }
  
- #define KL_PART_KEY -1		/* keylen value for incomplete key-code */
- #define KL_PART_MAP -2		/* keylen value for incomplete mapping */
- 
  /*
   * Get the next input character.
   * Can return a special key or a multi-byte character.
--- 1506,1511 ----
***************
*** 2171,2177 ****
  					if (!timedout)
  					{
  					    /* break at a partly match */
! 					    keylen = KL_PART_MAP;
  					    break;
  					}
  				    }
--- 2168,2174 ----
  					if (!timedout)
  					{
  					    /* break at a partly match */
! 					    keylen = KEYLEN_PART_MAP;
  					    break;
  					}
  				    }
***************
*** 2192,2198 ****
  
  			/* If no partly match found, use the longest full
  			 * match. */
! 			if (keylen != KL_PART_MAP)
  			{
  			    mp = mp_match;
  			    keylen = mp_match_len;
--- 2189,2195 ----
  
  			/* If no partly match found, use the longest full
  			 * match. */
! 			if (keylen != KEYLEN_PART_MAP)
  			{
  			    mp = mp_match;
  			    keylen = mp_match_len;
***************
*** 2230,2236 ****
  			}
  			/* Need more chars for partly match. */
  			if (mlen == typebuf.tb_len)
! 			    keylen = KL_PART_KEY;
  			else if (max_mlen < mlen)
  			    /* no match, may have to check for termcode at
  			     * next character */
--- 2227,2233 ----
  			}
  			/* Need more chars for partly match. */
  			if (mlen == typebuf.tb_len)
! 			    keylen = KEYLEN_PART_KEY;
  			else if (max_mlen < mlen)
  			    /* no match, may have to check for termcode at
  			     * next character */
***************
*** 2238,2244 ****
  		    }
  
  		    if ((mp == NULL || max_mlen >= mp_match_len)
! 						     && keylen != KL_PART_MAP)
  		    {
  			int	save_keylen = keylen;
  
--- 2235,2241 ----
  		    }
  
  		    if ((mp == NULL || max_mlen >= mp_match_len)
! 						 && keylen != KEYLEN_PART_MAP)
  		    {
  			int	save_keylen = keylen;
  
***************
*** 2264,2271 ****
  			    /* If no termcode matched but 'pastetoggle'
  			     * matched partially it's like an incomplete key
  			     * sequence. */
! 			    if (keylen == 0 && save_keylen == KL_PART_KEY)
! 				keylen = KL_PART_KEY;
  
  			    /*
  			     * When getting a partial match, but the last
--- 2261,2268 ----
  			    /* If no termcode matched but 'pastetoggle'
  			     * matched partially it's like an incomplete key
  			     * sequence. */
! 			    if (keylen == 0 && save_keylen == KEYLEN_PART_KEY)
! 				keylen = KEYLEN_PART_KEY;
  
  			    /*
  			     * When getting a partial match, but the last
***************
*** 2302,2308 ****
  				    continue;
  				}
  				if (*s == NUL)	    /* need more characters */
! 				    keylen = KL_PART_KEY;
  			    }
  			    if (keylen >= 0)
  #endif
--- 2299,2305 ----
  				    continue;
  				}
  				if (*s == NUL)	    /* need more characters */
! 				    keylen = KEYLEN_PART_KEY;
  			    }
  			    if (keylen >= 0)
  #endif
***************
*** 2339,2345 ****
  			if (keylen > 0)	    /* full matching terminal code */
  			{
  #if defined(FEAT_GUI) && defined(FEAT_MENU)
! 			    if (typebuf.tb_buf[typebuf.tb_off] == K_SPECIAL
  					 && typebuf.tb_buf[typebuf.tb_off + 1]
  								   == KS_MENU)
  			    {
--- 2336,2343 ----
  			if (keylen > 0)	    /* full matching terminal code */
  			{
  #if defined(FEAT_GUI) && defined(FEAT_MENU)
! 			    if (typebuf.tb_len >= 2
! 				&& typebuf.tb_buf[typebuf.tb_off] == K_SPECIAL
  					 && typebuf.tb_buf[typebuf.tb_off + 1]
  								   == KS_MENU)
  			    {
***************
*** 2381,2387 ****
  			/* Partial match: get some more characters.  When a
  			 * matching mapping was found use that one. */
  			if (mp == NULL || keylen < 0)
! 			    keylen = KL_PART_KEY;
  			else
  			    keylen = mp_match_len;
  		    }
--- 2379,2385 ----
  			/* Partial match: get some more characters.  When a
  			 * matching mapping was found use that one. */
  			if (mp == NULL || keylen < 0)
! 			    keylen = KEYLEN_PART_KEY;
  			else
  			    keylen = mp_match_len;
  		    }
***************
*** 2553,2559 ****
  #endif
  			&& typebuf.tb_maplen == 0
  			&& (State & INSERT)
! 			&& (p_timeout || (keylen == KL_PART_KEY && p_ttimeout))
  			&& (c = inchar(typebuf.tb_buf + typebuf.tb_off
  						     + typebuf.tb_len, 3, 25L,
  						 typebuf.tb_change_cnt)) == 0)
--- 2551,2558 ----
  #endif
  			&& typebuf.tb_maplen == 0
  			&& (State & INSERT)
! 			&& (p_timeout
! 			    || (keylen == KEYLEN_PART_KEY && p_ttimeout))
  			&& (c = inchar(typebuf.tb_buf + typebuf.tb_off
  						     + typebuf.tb_len, 3, 25L,
  						 typebuf.tb_change_cnt)) == 0)
***************
*** 2783,2791 ****
  			    ? 0
  			    : ((typebuf.tb_len == 0
  				    || !(p_timeout || (p_ttimeout
! 						   && keylen == KL_PART_KEY)))
  				    ? -1L
! 				    : ((keylen == KL_PART_KEY && p_ttm >= 0)
  					    ? p_ttm
  					    : p_tm)), typebuf.tb_change_cnt);
  
--- 2782,2790 ----
  			    ? 0
  			    : ((typebuf.tb_len == 0
  				    || !(p_timeout || (p_ttimeout
! 					       && keylen == KEYLEN_PART_KEY)))
  				    ? -1L
! 				    : ((keylen == KEYLEN_PART_KEY && p_ttm >= 0)
  					    ? p_ttm
  					    : p_tm)), typebuf.tb_change_cnt);
  
*** ../vim-7.3.090/src/misc1.c	2010-12-02 16:01:23.000000000 +0100
--- src/misc1.c	2010-12-30 12:28:59.000000000 +0100
***************
*** 3114,3123 ****
  	       && (!p_ttimeout || waited * 100L < (p_ttm < 0 ? p_tm : p_ttm)))
  	    continue;
  
! 	/* found a termcode: adjust length */
! 	if (n > 0)
  	    len = n;
! 	if (len == 0)	    /* nothing typed yet */
  	    continue;
  
  	/* Handle modifier and/or special key code. */
--- 3114,3124 ----
  	       && (!p_ttimeout || waited * 100L < (p_ttm < 0 ? p_tm : p_ttm)))
  	    continue;
  
! 	if (n == KEYLEN_REMOVED)  /* key code removed */
! 	    continue;
! 	if (n > 0)		/* found a termcode: adjust length */
  	    len = n;
! 	if (len == 0)		/* nothing typed yet */
  	    continue;
  
  	/* Handle modifier and/or special key code. */
*** ../vim-7.3.090/src/term.c	2010-08-15 21:57:32.000000000 +0200
--- src/term.c	2010-12-30 12:14:48.000000000 +0100
***************
*** 3828,3833 ****
--- 3831,3837 ----
   * Check from typebuf.tb_buf[typebuf.tb_off] to typebuf.tb_buf[typebuf.tb_off
   * + max_offset].
   * Return 0 for no match, -1 for partial match, > 0 for full match.
+  * Return KEYLEN_REMOVED when a key code was deleted.
   * With a match, the match is removed, the replacement code is inserted in
   * typebuf.tb_buf[] and the number of characters in typebuf.tb_buf[] is
   * returned.
***************
*** 3845,3850 ****
--- 3849,3855 ----
      int		slen = 0;	/* init for GCC */
      int		modslen;
      int		len;
+     int		retval = 0;
      int		offset;
      char_u	key_name[2];
      int		modifiers;
***************
*** 4940,4945 ****
--- 4945,4957 ----
  #endif
  		string[new_slen++] = key_name[1];
  	}
+ 	else if (new_slen == 0 && key_name[0] == KS_EXTRA
+ 						  && key_name[1] == KE_IGNORE)
+ 	{
+ 	    /* Do not put K_IGNORE into the buffer, do return KEYLEN_REMOVED
+ 	     * to indicate what happened. */
+ 	    retval = KEYLEN_REMOVED;
+ 	}
  	else
  	{
  	    string[new_slen++] = K_SPECIAL;
***************
*** 4976,4982 ****
  						   (size_t)(buflen - offset));
  	    mch_memmove(buf + offset, string, (size_t)new_slen);
  	}
! 	return (len + extra + offset);
      }
  
      return 0;			    /* no match found */
--- 4988,4994 ----
  						   (size_t)(buflen - offset));
  	    mch_memmove(buf + offset, string, (size_t)new_slen);
  	}
! 	return retval == 0 ? (len + extra + offset) : retval;
      }
  
      return 0;			    /* no match found */
*** ../vim-7.3.090/src/vim.h	2010-12-17 20:23:56.000000000 +0100
--- src/vim.h	2010-12-30 12:06:45.000000000 +0100
***************
*** 2211,2214 ****
--- 2211,2218 ----
  #define MSCR_LEFT	-1
  #define MSCR_RIGHT	-2
  
+ #define KEYLEN_PART_KEY -1	/* keylen value for incomplete key-code */
+ #define KEYLEN_PART_MAP -2	/* keylen value for incomplete mapping */
+ #define KEYLEN_REMOVED  9999	/* keylen value for removed sequence */
+ 
  #endif /* VIM__H */
*** ../vim-7.3.090/src/version.c	2010-12-30 11:41:05.000000000 +0100
--- src/version.c	2010-12-30 12:24:56.000000000 +0100
***************
*** 716,717 ****
--- 716,719 ----
  {   /* Add new patch number below this line */
+ /**/
+     91,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
56. You leave the modem speaker on after connecting because you think it
    sounds like the ocean wind...the perfect soundtrack for "surfing the net".

 /// Bram Moolenaar -- Bram@Moolenaar.net -- 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    ///