Skip to content

Commit 6a2633b

Browse files
committed
patch 8.1.0466: autocmd test fails
Problem: Autocmd test fails. Solution: Do call inchar() when flushing typeahead.
1 parent 95ba5c3 commit 6a2633b

File tree

7 files changed

+34
-22
lines changed

7 files changed

+34
-22
lines changed

src/getchar.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -438,23 +438,29 @@ typeahead_noflush(int c)
438438
* flush all typeahead characters (used when interrupted by a CTRL-C).
439439
*/
440440
void
441-
flush_buffers(int flush_typeahead)
441+
flush_buffers(flush_buffers_T flush_typeahead)
442442
{
443443
init_typebuf();
444444

445445
start_stuff();
446446
while (read_readbuffers(TRUE) != NUL)
447447
;
448448

449-
if (flush_typeahead) /* remove all typeahead */
449+
if (flush_typeahead == FLUSH_MINIMAL)
450450
{
451-
/*
452-
* We have to get all characters, because we may delete the first part
453-
* of an escape sequence.
454-
* In an xterm we get one char at a time and we have to get them all.
455-
*/
456-
while (inchar(typebuf.tb_buf, typebuf.tb_buflen - 1, 10L) != 0)
457-
;
451+
// remove mapped characters at the start only
452+
typebuf.tb_off += typebuf.tb_maplen;
453+
typebuf.tb_len -= typebuf.tb_maplen;
454+
}
455+
else
456+
{
457+
// remove typeahead
458+
if (flush_typeahead == FLUSH_INPUT)
459+
// We have to get all characters, because we may delete the first
460+
// part of an escape sequence. In an xterm we get one char at a
461+
// time and we have to get them all.
462+
while (inchar(typebuf.tb_buf, typebuf.tb_buflen - 1, 10L) != 0)
463+
;
458464
typebuf.tb_off = MAXMAPLEN;
459465
typebuf.tb_len = 0;
460466
#if defined(FEAT_CLIENTSERVER) || defined(FEAT_EVAL)
@@ -463,11 +469,6 @@ flush_buffers(int flush_typeahead)
463469
typebuf_was_filled = FALSE;
464470
#endif
465471
}
466-
else /* remove mapped characters at the start only */
467-
{
468-
typebuf.tb_off += typebuf.tb_maplen;
469-
typebuf.tb_len -= typebuf.tb_maplen;
470-
}
471472
typebuf.tb_maplen = 0;
472473
typebuf.tb_silent = 0;
473474
cmd_silent = FALSE;
@@ -1858,6 +1859,7 @@ plain_vgetc(void)
18581859
* Check if a character is available, such that vgetc() will not block.
18591860
* If the next character is a special character or multi-byte, the returned
18601861
* character is not valid!.
1862+
* Returns NUL if no character is available.
18611863
*/
18621864
int
18631865
vpeekc(void)
@@ -1956,7 +1958,8 @@ vungetc(int c)
19561958
* KeyTyped is set to TRUE in the case the user typed the key.
19571959
* KeyStuffed is TRUE if the character comes from the stuff buffer.
19581960
* if "advance" is FALSE (vpeekc()):
1959-
* just look whether there is a character available.
1961+
* Just look whether there is a character available.
1962+
* Return NUL if not.
19601963
*
19611964
* When "no_mapping" is zero, checks for mappings in the current mode.
19621965
* Only returns one byte (of a multi-byte character).
@@ -2084,7 +2087,7 @@ vgetorpeek(int advance)
20842087
c = ESC;
20852088
else
20862089
c = Ctrl_C;
2087-
flush_buffers(TRUE); /* flush all typeahead */
2090+
flush_buffers(FLUSH_INPUT); // flush all typeahead
20882091

20892092
if (advance)
20902093
{
@@ -2510,7 +2513,7 @@ vgetorpeek(int advance)
25102513
redrawcmdline();
25112514
else
25122515
setcursor();
2513-
flush_buffers(FALSE);
2516+
flush_buffers(FLUSH_MINIMAL);
25142517
mapdepth = 0; /* for next one */
25152518
c = -1;
25162519
break;

src/memline.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4522,7 +4522,7 @@ findswapname(
45224522

45234523
// If vimrc has "simalt ~x" we don't want it to
45244524
// interfere with the prompt here.
4525-
flush_buffers(TRUE);
4525+
flush_buffers(FLUSH_TYPEAHEAD);
45264526
}
45274527

45284528
#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)

src/message.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,8 @@ emsg(char_u *s)
688688
if (p_eb)
689689
beep_flush(); /* also includes flush_buffers() */
690690
else
691-
flush_buffers(FALSE); /* flush internal buffers */
692-
did_emsg = TRUE; /* flag for DoOneCmd() */
691+
flush_buffers(FLUSH_MINIMAL); // flush internal buffers
692+
did_emsg = TRUE; // flag for DoOneCmd()
693693
#ifdef FEAT_EVAL
694694
did_uncaught_emsg = TRUE;
695695
#endif

src/misc1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3825,7 +3825,7 @@ beep_flush(void)
38253825
{
38263826
if (emsg_silent == 0)
38273827
{
3828-
flush_buffers(FALSE);
3828+
flush_buffers(FLUSH_MINIMAL);
38293829
vim_beep(BO_ERROR);
38303830
}
38313831
}

src/proto/getchar.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ char_u *get_inserted(void);
55
int stuff_empty(void);
66
int readbuf1_empty(void);
77
void typeahead_noflush(int c);
8-
void flush_buffers(int flush_typeahead);
8+
void flush_buffers(flush_buffers_T flush_typeahead);
99
void ResetRedobuff(void);
1010
void CancelRedo(void);
1111
void saveRedobuff(save_redo_T *save_redo);

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,8 @@ static char *(features[]) =
792792

793793
static int included_patches[] =
794794
{ /* Add new patch number below this line */
795+
/**/
796+
466,
795797
/**/
796798
465,
797799
/**/

src/vim.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,6 +2108,13 @@ typedef enum {
21082108
PASTE_ONE_CHAR /* return first character */
21092109
} paste_mode_T;
21102110

2111+
// Argument for flush_buffers().
2112+
typedef enum {
2113+
FLUSH_MINIMAL,
2114+
FLUSH_TYPEAHEAD, // flush current typebuf contents
2115+
FLUSH_INPUT // flush typebuf and inchar() input
2116+
} flush_buffers_T;
2117+
21112118
#include "ex_cmds.h" /* Ex command defines */
21122119
#include "spell.h" /* spell checking stuff */
21132120

0 commit comments

Comments
 (0)