diff --git a/src/diff.c b/src/diff.c index 0e352d8938..11952c7433 100644 --- a/src/diff.c +++ b/src/diff.c @@ -1702,9 +1702,7 @@ diff_equal_char(char_u *p1, char_u *p2, int *len) diff_cmp(char_u *s1, char_u *s2) { char_u *p1, *p2; -#ifdef FEAT_MBYTE int l; -#endif if ((diff_flags & (DIFF_ICASE | DIFF_IWHITE)) == 0) return STRCMP(s1, s2); @@ -1983,10 +1981,8 @@ diff_find_change( int idx; int off; int added = TRUE; -#ifdef FEAT_MBYTE char_u *p1, *p2; int l; -#endif /* Make a copy of the line, the next ml_get() will invalidate it. */ line_org = vim_strsave(ml_get_buf(wp->w_buffer, lnum, FALSE)); diff --git a/src/evalfunc.c b/src/evalfunc.c index 54f75e4d02..5503094598 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -9912,7 +9912,10 @@ set_buffer_lines(buf_T *buf, linenr_T lnum, typval_T *lines, typval_T *rettv) buf_T *curbuf_save; int is_curbuf = buf == curbuf; - if (buf == NULL || buf->b_ml.ml_mfp == NULL || lnum < 1) + /* When using the current buffer ml_mfp will be set if needed. Useful when + * setline() is used on startup. For other buffers the buffer must be + * loaded. */ + if (buf == NULL || (!is_curbuf && buf->b_ml.ml_mfp == NULL) || lnum < 1) { rettv->vval.v_number = 1; /* FAIL */ return; diff --git a/src/getchar.c b/src/getchar.c index d7d0d8e088..f2c382fa78 100644 --- a/src/getchar.c +++ b/src/getchar.c @@ -1598,8 +1598,13 @@ vgetc(void) { int did_inc = FALSE; - if (mod_mask) /* no mapping after modifier has been read */ + if (mod_mask +#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) + || im_is_preediting() +#endif + ) { + /* no mapping after modifier has been read */ ++no_mapping; ++allow_keys; did_inc = TRUE; /* mod_mask may change value */ diff --git a/src/libvterm/src/screen.c b/src/libvterm/src/screen.c index a174e8657c..8d6218f67d 100644 --- a/src/libvterm/src/screen.c +++ b/src/libvterm/src/screen.c @@ -214,7 +214,7 @@ static int moverect_internal(VTermRect dest, VTermRect src, void *user) VTermPos pos; for(pos.row = 0; pos.row < src.start_row; pos.row++) { for(pos.col = 0; pos.col < screen->cols; pos.col++) - vterm_screen_get_cell(screen, pos, screen->sb_buffer + pos.col); + (void)vterm_screen_get_cell(screen, pos, screen->sb_buffer + pos.col); (screen->callbacks->sb_pushline)(screen->cols, screen->sb_buffer, screen->cbdata); } diff --git a/src/libvterm/src/state.c b/src/libvterm/src/state.c index 88c259c34e..5a6feacb1b 100644 --- a/src/libvterm/src/state.c +++ b/src/libvterm/src/state.c @@ -878,6 +878,7 @@ static void request_dec_mode(VTermState *state, int num) case 2004: reply = state->mode.bracketpaste; + break; default: vterm_push_output_sprintf_ctrl(state->vt, C1_CSI, "?%d;%d$y", num, 0); diff --git a/src/mbyte.c b/src/mbyte.c index 1e294e3dcc..efd02c028d 100644 --- a/src/mbyte.c +++ b/src/mbyte.c @@ -4983,7 +4983,11 @@ im_delete_preedit(void) } # endif - if (State & NORMAL) + if (State & NORMAL +#ifdef FEAT_TERMINAL + && !term_use_loop() +#endif + ) { im_preedit_cursor = 0; return; diff --git a/src/os_unix.c b/src/os_unix.c index 8e3e82ca68..8d6ca4a2e9 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -5714,7 +5714,10 @@ mch_create_pty_channel(job_T *job, jobopt_T *options) channel = add_channel(); if (channel == NULL) + { + close(pty_master_fd); return FAIL; + } job->jv_channel = channel; /* ch_refcount was set by add_channel() */ channel->ch_keep_open = TRUE; diff --git a/src/term.c b/src/term.c index 30a0aec93f..3fc4775190 100644 --- a/src/term.c +++ b/src/term.c @@ -4578,12 +4578,12 @@ check_termcode( && STRNCMP(tp + extra - 2, "1;95;0c", 7) == 0) is_not_xterm = TRUE; # endif - /* Gnome terminal sends 1;3801;0 or 1;4402;0. + /* Gnome terminal sends 1;3801;0, 1;4402;0 or 1;2501;0. * xfce4-terminal sends 1;2802;0. * screen sends 83;40500;0 - * Assuming any version number over 2800 is not an + * Assuming any version number over 2500 is not an * xterm (without the limit for rxvt and screen). */ - if (col >= 2800) + if (col >= 2500) is_not_xterm = TRUE; /* PuTTY sends 0;136;0 */ diff --git a/src/terminal.c b/src/terminal.c index 4166883b82..db8a65cbc8 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -38,7 +38,9 @@ * in tl_scrollback are no longer used. * * TODO: - * - ":term NONE" does not work in MS-Windows. + * - ":term NONE" does not work on MS-Windows. + * https://github.com/vim/vim/pull/2056 + * - Redirecting output does not work on MS-Windows. * - implement term_setsize() * - add test for giving error for invalid 'termsize' value. * - support minimal size when 'termsize' is "rows*cols". @@ -56,6 +58,8 @@ * - In the GUI use a terminal emulator for :!cmd. * - Copy text in the vterm to the Vim buffer once in a while, so that * completion works. + * - add an optional limit for the scrollback size. When reaching it remove + * 10% at the start. */ #include "vim.h" @@ -366,10 +370,10 @@ term_start(typval_T *argvar, jobopt_T *opt, int forceit) } else if (argvar->v_type != VAR_LIST || argvar->vval.v_list == NULL - || argvar->vval.v_list->lv_len < 1) + || argvar->vval.v_list->lv_len < 1 + || (cmd = get_tv_string_chk( + &argvar->vval.v_list->lv_first->li_tv)) == NULL) cmd = (char_u*)""; - else - cmd = get_tv_string_chk(&argvar->vval.v_list->lv_first->li_tv); len = STRLEN(cmd) + 10; p = alloc((int)len); @@ -458,7 +462,7 @@ term_start(typval_T *argvar, jobopt_T *opt, int forceit) void ex_terminal(exarg_T *eap) { - typval_T argvar; + typval_T argvar[2]; jobopt_T opt; char_u *cmd; char_u *tofree = NULL; @@ -521,8 +525,8 @@ ex_terminal(exarg_T *eap) } cmd = skipwhite(p); } - if (cmd == NULL || *cmd == NUL) - /* Make a copy, an autocommand may set 'shell'. */ + if (*cmd == NUL) + /* Make a copy of 'shell', an autocommand may change the option. */ tofree = cmd = vim_strsave(p_sh); if (eap->addr_count > 0) @@ -535,9 +539,10 @@ ex_terminal(exarg_T *eap) opt.jo_in_bot = eap->line2; } - argvar.v_type = VAR_STRING; - argvar.vval.v_string = cmd; - term_start(&argvar, &opt, eap->forceit); + argvar[0].v_type = VAR_STRING; + argvar[0].vval.v_string = cmd; + argvar[1].v_type = VAR_UNKNOWN; + term_start(argvar, &opt, eap->forceit); vim_free(tofree); } @@ -2887,7 +2892,8 @@ f_term_wait(typval_T *argvars, typval_T *rettv UNUSED) && STRCMP(job_status(buf->b_term->tl_job), "dead") == 0) { /* The job is dead, keep reading channel I/O until the channel is - * closed. */ + * closed. buf->b_term may become NULL if the terminal was closed while + * waiting. */ ch_log(NULL, "term_wait(): waiting for channel to close"); while (buf->b_term != NULL && !buf->b_term->tl_channel_closed) { diff --git a/src/testdir/shared.vim b/src/testdir/shared.vim index 646d9608ee..eddcb9dc1f 100644 --- a/src/testdir/shared.vim +++ b/src/testdir/shared.vim @@ -166,15 +166,21 @@ func s:feedkeys(timer) endfunc " Get the command to run Vim, with -u NONE and --not-a-term arguments. +" If there is an argument use it instead of "NONE". " Returns an empty string on error. -func GetVimCommand() +func GetVimCommand(...) if !filereadable('vimcmd') return '' endif + if a:0 == 0 + let name = 'NONE' + else + let name = a:1 + endif let cmd = readfile('vimcmd')[0] - let cmd = substitute(cmd, '-u \f\+', '-u NONE', '') - if cmd !~ '-u NONE' - let cmd = cmd . ' -u NONE' + let cmd = substitute(cmd, '-u \f\+', '-u ' . name, '') + if cmd !~ '-u '. name + let cmd = cmd . ' -u ' . name endif let cmd .= ' --not-a-term' let cmd = substitute(cmd, 'VIMRUNTIME=.*VIMRUNTIME;', '', '') diff --git a/src/testdir/test_alot.vim b/src/testdir/test_alot.vim index 189cd82d12..61c3472b2a 100644 --- a/src/testdir/test_alot.vim +++ b/src/testdir/test_alot.vim @@ -1,6 +1,8 @@ " A series of tests that can run in one Vim invocation. " This makes testing go faster, since Vim doesn't need to restart. +source shared.vim + set belloff=all source test_assign.vim source test_bufline.vim diff --git a/src/testdir/test_bufline.vim b/src/testdir/test_bufline.vim index 7df36aa6a2..f57dd73ef3 100644 --- a/src/testdir/test_bufline.vim +++ b/src/testdir/test_bufline.vim @@ -1,5 +1,9 @@ " Tests for setbufline() and getbufline() +if !exists('*GetVimCommand') + source shared.vim +endif + func Test_setbufline_getbufline() new let b = bufnr('%') @@ -24,3 +28,16 @@ func Test_setbufline_getbufline() call assert_equal([], getbufline(b, 6)) exe "bwipe! " . b endfunc + +func Test_setline_startup() + let cmd = GetVimCommand('Xscript') + if cmd == '' + return + endif + call writefile(['call setline(1, "Hello")', 'silent w Xtest', 'q!'], 'Xscript') + call system(cmd) + call assert_equal(['Hello'], readfile('Xtest')) + + call delete('Xscript') + call delete('Xtest') +endfunc diff --git a/src/testdir/test_terminal.vim b/src/testdir/test_terminal.vim index dce5f05cd1..800567920d 100644 --- a/src/testdir/test_terminal.vim +++ b/src/testdir/test_terminal.vim @@ -165,7 +165,9 @@ func Test_terminal_scrape_123() call term_wait(buf) let g:buf = buf - call WaitFor('len(term_scrape(g:buf, 1)) > 0') + " On MS-Windows we first get a startup message of two lines, wait for the + " "cls" to happen, after that we have one line with three characters. + call WaitFor('len(term_scrape(g:buf, 1)) == 3') call Check_123(buf) " Must still work after the job ended. @@ -590,12 +592,15 @@ func Test_terminal_wrong_options() endfunc func Test_terminal_redir_file() - let cmd = Get_cat_123_cmd() - let buf = term_start(cmd, {'out_io': 'file', 'out_name': 'Xfile'}) - call term_wait(buf) - call WaitFor('len(readfile("Xfile")) > 0') - call assert_match('123', readfile('Xfile')[0]) - call delete('Xfile') + " TODO: this should work on MS-Window + if has('unix') + let cmd = Get_cat_123_cmd() + let buf = term_start(cmd, {'out_io': 'file', 'out_name': 'Xfile'}) + call term_wait(buf) + call WaitFor('len(readfile("Xfile")) > 0') + call assert_match('123', readfile('Xfile')[0]) + call delete('Xfile') + endif if has('unix') let buf = term_start('xyzabc', {'err_io': 'file', 'err_name': 'Xfile'}) @@ -609,6 +614,8 @@ func Test_terminal_redir_file() call term_wait(buf) call WaitFor('term_getline(' . buf . ', 1) == "one line"') call assert_equal('one line', term_getline(buf, 1)) + let g:job = term_getjob(buf) + call WaitFor('job_status(g:job) == "dead"') bwipe call delete('Xfile') endif diff --git a/src/testdir/test_timers.vim b/src/testdir/test_timers.vim index c9b1071f82..0c08a45abf 100644 --- a/src/testdir/test_timers.vim +++ b/src/testdir/test_timers.vim @@ -1,11 +1,13 @@ " Test for timers -source shared.vim - if !has('timers') finish endif +if !exists('*WaitFor') + source shared.vim +endif + func MyHandler(timer) let g:val += 1 endfunc diff --git a/src/version.c b/src/version.c index 0b57b004ab..d2941f08ac 100644 --- a/src/version.c +++ b/src/version.c @@ -784,6 +784,30 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1064, +/**/ + 1063, +/**/ + 1062, +/**/ + 1061, +/**/ + 1060, +/**/ + 1059, +/**/ + 1058, +/**/ + 1057, +/**/ + 1056, +/**/ + 1055, +/**/ + 1054, +/**/ + 1053, /**/ 1052, /**/