@@ -125,7 +125,7 @@ static int vgetorpeek(int);
125125static void map_free (mapblock_T * * );
126126static void validate_maphash (void );
127127static void showmap (mapblock_T * mp , int local );
128- static int inchar (char_u * buf , int maxlen , long wait_time , int tb_change_cnt );
128+ static int inchar (char_u * buf , int maxlen , long wait_time );
129129#ifdef FEAT_EVAL
130130static char_u * eval_map_expr (char_u * str , int c );
131131#endif
@@ -462,8 +462,7 @@ flush_buffers(int flush_typeahead)
462462 * of an escape sequence.
463463 * In an xterm we get one char at a time and we have to get them all.
464464 */
465- while (inchar (typebuf .tb_buf , typebuf .tb_buflen - 1 , 10L ,
466- typebuf .tb_change_cnt ) != 0 )
465+ while (inchar (typebuf .tb_buf , typebuf .tb_buflen - 1 , 10L ) != 0 )
467466 ;
468467 typebuf .tb_off = MAXMAPLEN ;
469468 typebuf .tb_len = 0 ;
@@ -2046,8 +2045,7 @@ vgetorpeek(int advance)
20462045 if (got_int )
20472046 {
20482047 /* flush all input */
2049- c = inchar (typebuf .tb_buf , typebuf .tb_buflen - 1 , 0L ,
2050- typebuf .tb_change_cnt );
2048+ c = inchar (typebuf .tb_buf , typebuf .tb_buflen - 1 , 0L );
20512049 /*
20522050 * If inchar() returns TRUE (script file was active) or we
20532051 * are inside a mapping, get out of insert mode.
@@ -2610,8 +2608,7 @@ vgetorpeek(int advance)
26102608 && (p_timeout
26112609 || (keylen == KEYLEN_PART_KEY && p_ttimeout ))
26122610 && (c = inchar (typebuf .tb_buf + typebuf .tb_off
2613- + typebuf .tb_len , 3 , 25L ,
2614- typebuf .tb_change_cnt )) == 0 )
2611+ + typebuf .tb_len , 3 , 25L )) == 0 )
26152612 {
26162613 colnr_T col = 0 , vcol ;
26172614 char_u * ptr ;
@@ -2848,7 +2845,7 @@ vgetorpeek(int advance)
28482845 ? -1L
28492846 : ((keylen == KEYLEN_PART_KEY && p_ttm >= 0 )
28502847 ? p_ttm
2851- : p_tm )), typebuf . tb_change_cnt );
2848+ : p_tm )));
28522849
28532850#ifdef FEAT_CMDL_INFO
28542851 if (i != 0 )
@@ -2954,12 +2951,12 @@ vgetorpeek(int advance)
29542951inchar (
29552952 char_u * buf ,
29562953 int maxlen ,
2957- long wait_time , /* milli seconds */
2958- int tb_change_cnt )
2954+ long wait_time ) /* milli seconds */
29592955{
29602956 int len = 0 ; /* init for GCC */
29612957 int retesc = FALSE; /* return ESC with gotint */
29622958 int script_char ;
2959+ int tb_change_cnt = typebuf .tb_change_cnt ;
29632960
29642961 if (wait_time == -1L || wait_time > 100L ) /* flush output before waiting */
29652962 {
@@ -3065,9 +3062,17 @@ inchar(
30653062 len = ui_inchar (buf , maxlen / 3 , wait_time , tb_change_cnt );
30663063 }
30673064
3065+ /* If the typebuf was changed further down, it is like nothing was added by
3066+ * this call. */
30683067 if (typebuf_changed (tb_change_cnt ))
30693068 return 0 ;
30703069
3070+ /* Note the change in the typeahead buffer, this matters for when
3071+ * vgetorpeek() is called recursively, e.g. using getchar(1) in a timer
3072+ * function. */
3073+ if (len > 0 && ++ typebuf .tb_change_cnt == 0 )
3074+ typebuf .tb_change_cnt = 1 ;
3075+
30713076 return fix_input_buffer (buf , len );
30723077}
30733078
0 commit comments