Skip to content

Commit b702eb5

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 47fcc62 + a172b63 commit b702eb5

7 files changed

Lines changed: 192 additions & 96 deletions

File tree

src/if_cscope.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ cs_cnt_matches(int idx)
677677
{
678678
char *stok;
679679
char *buf;
680-
int nlines;
680+
int nlines = 0;
681681

682682
buf = (char *)alloc(CSREAD_BUFSIZE);
683683
if (buf == NULL)
@@ -700,7 +700,10 @@ cs_cnt_matches(int idx)
700700
* cscope will output error messages before the number-of-lines output.
701701
* Display/discard any output that doesn't match what we want.
702702
* Accept "\S*cscope: X lines", also matches "mlcscope".
703+
* Bail out for the "Unable to search" error.
703704
*/
705+
if (strstr((const char *)buf, "Unable to search database") != NULL)
706+
break;
704707
if ((stok = strtok(buf, (const char *)" ")) == NULL)
705708
continue;
706709
if (strstr((const char *)stok, "cscope:") == NULL)

src/terminal.c

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -649,16 +649,51 @@ free_terminal(buf_T *buf)
649649
in_terminal_loop = NULL;
650650
}
651651

652+
/*
653+
* Get the part that is connected to the tty. Normally this is PART_IN, but
654+
* when writing buffer lines to the job it can be another. This makes it
655+
* possible to do "1,5term vim -".
656+
*/
657+
static ch_part_T
658+
get_tty_part(term_T *term)
659+
{
660+
#ifdef UNIX
661+
ch_part_T parts[3] = {PART_IN, PART_OUT, PART_ERR};
662+
int i;
663+
664+
for (i = 0; i < 3; ++i)
665+
{
666+
int fd = term->tl_job->jv_channel->ch_part[parts[i]].ch_fd;
667+
668+
if (isatty(fd))
669+
return parts[i];
670+
}
671+
#endif
672+
return PART_IN;
673+
}
674+
652675
/*
653676
* Write job output "msg[len]" to the vterm.
654677
*/
655678
static void
656679
term_write_job_output(term_T *term, char_u *msg, size_t len)
657680
{
658681
VTerm *vterm = term->tl_vterm;
682+
size_t prevlen = vterm_output_get_buffer_current(vterm);
659683

660684
vterm_input_write(vterm, (char *)msg, len);
661685

686+
/* flush vterm buffer when vterm responded to control sequence */
687+
if (prevlen != vterm_output_get_buffer_current(vterm))
688+
{
689+
char buf[KEY_BUF_LEN];
690+
size_t curlen = vterm_output_read(vterm, buf, KEY_BUF_LEN);
691+
692+
if (curlen > 0)
693+
channel_send(term->tl_job->jv_channel, get_tty_part(term),
694+
(char_u *)buf, (int)curlen, NULL);
695+
}
696+
662697
/* this invokes the damage callbacks */
663698
vterm_screen_flush_damage(vterm_obtain_screen(vterm));
664699
}
@@ -1243,29 +1278,6 @@ term_vgetc()
12431278
return c;
12441279
}
12451280

1246-
/*
1247-
* Get the part that is connected to the tty. Normally this is PART_IN, but
1248-
* when writing buffer lines to the job it can be another. This makes it
1249-
* possible to do "1,5term vim -".
1250-
*/
1251-
static ch_part_T
1252-
get_tty_part(term_T *term)
1253-
{
1254-
#ifdef UNIX
1255-
ch_part_T parts[3] = {PART_IN, PART_OUT, PART_ERR};
1256-
int i;
1257-
1258-
for (i = 0; i < 3; ++i)
1259-
{
1260-
int fd = term->tl_job->jv_channel->ch_part[parts[i]].ch_fd;
1261-
1262-
if (isatty(fd))
1263-
return parts[i];
1264-
}
1265-
#endif
1266-
return PART_IN;
1267-
}
1268-
12691281
/*
12701282
* Send keys to terminal.
12711283
* Return FAIL when the key needs to be handled in Normal mode.

src/testdir/test_search.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,8 @@ func Test_search_cmdline_incsearch_highlight_attr()
619619
let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile', 'Xsearch.txt'], {'term_rows': 3})
620620

621621
call WaitFor({-> lines == [term_getline(buf, 1), term_getline(buf, 2)] })
622+
" wait for vim to complete initialization
623+
call term_wait(buf)
622624

623625
" Get attr of normal(a0), incsearch(a1), hlsearch(a2) highlight
624626
call term_sendkeys(buf, ":set incsearch hlsearch\<cr>")

src/testdir/test_terminal.vim

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,3 +811,26 @@ func Test_terminal_term_start_empty_command()
811811
let cmd = "call term_start(0, {'curwin' : 1, 'term_finish' : 'close'})"
812812
call assert_fails(cmd, 'E474')
813813
endfunc
814+
815+
func Test_terminal_response_to_control_sequence()
816+
if !has('unix')
817+
return
818+
endif
819+
820+
let buf = Run_shell_in_terminal({})
821+
call term_wait(buf)
822+
823+
call term_sendkeys(buf, s:python . " -c 'import sys;sys.stdout.write(\"\\x1b[6n\")'\<cr>")
824+
" wait for the response of control sequence from libvterm (and send it to tty)
825+
call term_wait(buf, 100)
826+
" wait for output from tty to display
827+
call term_wait(buf)
828+
call assert_match(';\d\+R', term_getline(buf, 2))
829+
830+
call term_sendkeys(buf, "\<c-c>")
831+
call term_wait(buf)
832+
call Stop_shell_in_terminal(buf)
833+
834+
exe buf . 'bwipe'
835+
unlet g:job
836+
endfunc

src/testdir/test_undo.vim

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,3 +359,47 @@ func Test_undo_append()
359359
norm o
360360
quit
361361
endfunc
362+
363+
func Test_undo_0()
364+
new
365+
set ul=100
366+
normal i1
367+
undo
368+
normal i2
369+
undo
370+
normal i3
371+
372+
undo 0
373+
let d = undotree()
374+
call assert_equal('', getline(1))
375+
call assert_equal(0, d.seq_cur)
376+
377+
redo
378+
let d = undotree()
379+
call assert_equal('3', getline(1))
380+
call assert_equal(3, d.seq_cur)
381+
382+
undo 2
383+
undo 0
384+
let d = undotree()
385+
call assert_equal('', getline(1))
386+
call assert_equal(0, d.seq_cur)
387+
388+
redo
389+
let d = undotree()
390+
call assert_equal('2', getline(1))
391+
call assert_equal(2, d.seq_cur)
392+
393+
undo 1
394+
undo 0
395+
let d = undotree()
396+
call assert_equal('', getline(1))
397+
call assert_equal(0, d.seq_cur)
398+
399+
redo
400+
let d = undotree()
401+
call assert_equal('1', getline(1))
402+
call assert_equal(1, d.seq_cur)
403+
404+
bwipe!
405+
endfunc

src/undo.c

Lines changed: 76 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,7 +2272,7 @@ undo_time(
22722272
long closest_start;
22732273
long closest_seq = 0;
22742274
long val;
2275-
u_header_T *uhp;
2275+
u_header_T *uhp = NULL;
22762276
u_header_T *last;
22772277
int mark;
22782278
int nomark;
@@ -2295,14 +2295,7 @@ undo_time(
22952295
* Init "closest" to a value we can't reach. */
22962296
if (absolute)
22972297
{
2298-
if (step == 0)
2299-
{
2300-
/* target 0 does not exist, got to 1 and above it. */
2301-
target = 1;
2302-
above = TRUE;
2303-
}
2304-
else
2305-
target = step;
2298+
target = step;
23062299
closest = -1;
23072300
}
23082301
else
@@ -2369,6 +2362,10 @@ undo_time(
23692362
closest_start = closest;
23702363
closest_seq = curbuf->b_u_seq_cur;
23712364

2365+
/* When "target" is 0; Back to origin. */
2366+
if (target == 0)
2367+
goto found;
2368+
23722369
/*
23732370
* May do this twice:
23742371
* 1. Search for "target", update "closest" to the best match found.
@@ -2494,8 +2491,9 @@ undo_time(
24942491
above = TRUE; /* stop above the header */
24952492
}
24962493

2494+
found:
24972495
/* If we found it: Follow the path to go to where we want to be. */
2498-
if (uhp != NULL)
2496+
if (uhp != NULL || target == 0)
24992497
{
25002498
/*
25012499
* First go up the tree as much as needed.
@@ -2510,87 +2508,93 @@ undo_time(
25102508
uhp = curbuf->b_u_newhead;
25112509
else
25122510
uhp = uhp->uh_next.ptr;
2513-
if (uhp == NULL || uhp->uh_walk != mark
2511+
if (uhp == NULL || (target > 0 && uhp->uh_walk != mark)
25142512
|| (uhp->uh_seq == target && !above))
25152513
break;
25162514
curbuf->b_u_curhead = uhp;
25172515
u_undoredo(TRUE);
2518-
uhp->uh_walk = nomark; /* don't go back down here */
2516+
if (target > 0)
2517+
uhp->uh_walk = nomark; /* don't go back down here */
25192518
}
25202519

2521-
/*
2522-
* And now go down the tree (redo), branching off where needed.
2523-
*/
2524-
while (!got_int)
2520+
/* When back to origin, redo is not needed. */
2521+
if (target > 0)
25252522
{
2526-
/* Do the change warning now, for the same reason as above. */
2527-
change_warning(0);
2523+
/*
2524+
* And now go down the tree (redo), branching off where needed.
2525+
*/
2526+
while (!got_int)
2527+
{
2528+
/* Do the change warning now, for the same reason as above. */
2529+
change_warning(0);
25282530

2529-
uhp = curbuf->b_u_curhead;
2530-
if (uhp == NULL)
2531-
break;
2531+
uhp = curbuf->b_u_curhead;
2532+
if (uhp == NULL)
2533+
break;
25322534

2533-
/* Go back to the first branch with a mark. */
2534-
while (uhp->uh_alt_prev.ptr != NULL
2535+
/* Go back to the first branch with a mark. */
2536+
while (uhp->uh_alt_prev.ptr != NULL
25352537
&& uhp->uh_alt_prev.ptr->uh_walk == mark)
2536-
uhp = uhp->uh_alt_prev.ptr;
2538+
uhp = uhp->uh_alt_prev.ptr;
25372539

2538-
/* Find the last branch with a mark, that's the one. */
2539-
last = uhp;
2540-
while (last->uh_alt_next.ptr != NULL
2540+
/* Find the last branch with a mark, that's the one. */
2541+
last = uhp;
2542+
while (last->uh_alt_next.ptr != NULL
25412543
&& last->uh_alt_next.ptr->uh_walk == mark)
2542-
last = last->uh_alt_next.ptr;
2543-
if (last != uhp)
2544-
{
2545-
/* Make the used branch the first entry in the list of
2546-
* alternatives to make "u" and CTRL-R take this branch. */
2547-
while (uhp->uh_alt_prev.ptr != NULL)
2548-
uhp = uhp->uh_alt_prev.ptr;
2549-
if (last->uh_alt_next.ptr != NULL)
2550-
last->uh_alt_next.ptr->uh_alt_prev.ptr =
2544+
last = last->uh_alt_next.ptr;
2545+
if (last != uhp)
2546+
{
2547+
/* Make the used branch the first entry in the list of
2548+
* alternatives to make "u" and CTRL-R take this branch. */
2549+
while (uhp->uh_alt_prev.ptr != NULL)
2550+
uhp = uhp->uh_alt_prev.ptr;
2551+
if (last->uh_alt_next.ptr != NULL)
2552+
last->uh_alt_next.ptr->uh_alt_prev.ptr =
25512553
last->uh_alt_prev.ptr;
2552-
last->uh_alt_prev.ptr->uh_alt_next.ptr = last->uh_alt_next.ptr;
2553-
last->uh_alt_prev.ptr = NULL;
2554-
last->uh_alt_next.ptr = uhp;
2555-
uhp->uh_alt_prev.ptr = last;
2556-
2557-
if (curbuf->b_u_oldhead == uhp)
2558-
curbuf->b_u_oldhead = last;
2559-
uhp = last;
2560-
if (uhp->uh_next.ptr != NULL)
2561-
uhp->uh_next.ptr->uh_prev.ptr = uhp;
2562-
}
2563-
curbuf->b_u_curhead = uhp;
2554+
last->uh_alt_prev.ptr->uh_alt_next.ptr =
2555+
last->uh_alt_next.ptr;
2556+
last->uh_alt_prev.ptr = NULL;
2557+
last->uh_alt_next.ptr = uhp;
2558+
uhp->uh_alt_prev.ptr = last;
2559+
2560+
if (curbuf->b_u_oldhead == uhp)
2561+
curbuf->b_u_oldhead = last;
2562+
uhp = last;
2563+
if (uhp->uh_next.ptr != NULL)
2564+
uhp->uh_next.ptr->uh_prev.ptr = uhp;
2565+
}
2566+
curbuf->b_u_curhead = uhp;
25642567

2565-
if (uhp->uh_walk != mark)
2566-
break; /* must have reached the target */
2568+
if (uhp->uh_walk != mark)
2569+
break; /* must have reached the target */
25672570

2568-
/* Stop when going backwards in time and didn't find the exact
2569-
* header we were looking for. */
2570-
if (uhp->uh_seq == target && above)
2571-
{
2572-
curbuf->b_u_seq_cur = target - 1;
2573-
break;
2574-
}
2571+
/* Stop when going backwards in time and didn't find the exact
2572+
* header we were looking for. */
2573+
if (uhp->uh_seq == target && above)
2574+
{
2575+
curbuf->b_u_seq_cur = target - 1;
2576+
break;
2577+
}
25752578

2576-
u_undoredo(FALSE);
2579+
u_undoredo(FALSE);
25772580

2578-
/* Advance "curhead" to below the header we last used. If it
2579-
* becomes NULL then we need to set "newhead" to this leaf. */
2580-
if (uhp->uh_prev.ptr == NULL)
2581-
curbuf->b_u_newhead = uhp;
2582-
curbuf->b_u_curhead = uhp->uh_prev.ptr;
2583-
did_undo = FALSE;
2581+
/* Advance "curhead" to below the header we last used. If it
2582+
* becomes NULL then we need to set "newhead" to this leaf. */
2583+
if (uhp->uh_prev.ptr == NULL)
2584+
curbuf->b_u_newhead = uhp;
2585+
curbuf->b_u_curhead = uhp->uh_prev.ptr;
2586+
did_undo = FALSE;
25842587

2585-
if (uhp->uh_seq == target) /* found it! */
2586-
break;
2588+
if (uhp->uh_seq == target) /* found it! */
2589+
break;
25872590

2588-
uhp = uhp->uh_prev.ptr;
2589-
if (uhp == NULL || uhp->uh_walk != mark)
2590-
{
2591-
/* Need to redo more but can't find it... */
2592-
internal_error("undo_time()");
2593-
break;
2591+
uhp = uhp->uh_prev.ptr;
2592+
if (uhp == NULL || uhp->uh_walk != mark)
2593+
{
2594+
/* Need to redo more but can't find it... */
2595+
internal_error("undo_time()");
2596+
break;
2597+
}
25942598
}
25952599
}
25962600
}

0 commit comments

Comments
 (0)