From 5bab555c2f1b3b86d57e4adeb86d908eff477fc9 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Fri, 13 Apr 2018 20:41:29 +0200 Subject: [PATCH 01/10] patch 8.0.1705: when making a vertical split the mode message isn't updated Problem: When making a vertical split the mode message isn't always updated, "VISUAL" remains. (Alexei Averchenko) Solution: Only reset clear_cmdline when filling all columns of the last screen line. (Tom M. closes #2611) --- src/screen.c | 3 ++- src/testdir/test_window_cmd.vim | 24 ++++++++++++++++++++++++ src/version.c | 2 ++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/screen.c b/src/screen.c index bcfaabed19..d1f17b51ba 100644 --- a/src/screen.c +++ b/src/screen.c @@ -8699,7 +8699,8 @@ screen_fill( if (row == Rows - 1) /* overwritten the command line */ { redraw_cmdline = TRUE; - if (c1 == ' ' && c2 == ' ') + if (start_col == 0 && end_col == Columns + && c1 == ' ' && c2 == ' ' && attr == 0) clear_cmdline = FALSE; /* command line has been cleared */ if (start_col == 0) mode_displayed = FALSE; /* mode cleared or overwritten */ diff --git a/src/testdir/test_window_cmd.vim b/src/testdir/test_window_cmd.vim index 69b139fe3b..296cba2fd8 100644 --- a/src/testdir/test_window_cmd.vim +++ b/src/testdir/test_window_cmd.vim @@ -483,4 +483,28 @@ func Test_access_freed_mem() bwipe xxx endfunc +func Test_visual_cleared_after_window_split() + new | only! + let smd_save = &showmode + set showmode + let ls_save = &laststatus + set laststatus=1 + call setline(1, ['a', 'b', 'c', 'd', '']) + norm! G + exe "norm! kkvk" + redraw + exe "norm! \v" + redraw + " check if '-- VISUAL --' disappeared from command line + let columns = range(1, &columns) + let cmdlinechars = map(columns, 'nr2char(screenchar(&lines, v:val))') + let cmdline = join(cmdlinechars, '') + let cmdline_ltrim = substitute(cmdline, '^\s*', "", "") + let mode_shown = substitute(cmdline_ltrim, '\s*$', "", "") + call assert_equal('', mode_shown) + let &showmode = smd_save + let &laststatus = ls_save + bwipe! +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/version.c b/src/version.c index 8d7049d5fd..6c3b38ddb9 100644 --- a/src/version.c +++ b/src/version.c @@ -762,6 +762,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1705, /**/ 1704, /**/ From b59118d5012a6a07e2d54504fbb04837b5a1208c Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Fri, 13 Apr 2018 22:11:56 +0200 Subject: [PATCH 02/10] patch 8.0.1706: cannot sent CTRL-\ to a terminal window Problem: Cannot sent CTRL-\ to a terminal window. Solution: Make CTRL-W CTRL-\ send CTRL-\ to a terminal window. --- runtime/doc/terminal.txt | 1 + src/terminal.c | 7 ++++++- src/version.c | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/runtime/doc/terminal.txt b/runtime/doc/terminal.txt index 551a3740c2..63217c2fa0 100644 --- a/runtime/doc/terminal.txt +++ b/runtime/doc/terminal.txt @@ -72,6 +72,7 @@ See |CTRL-W| for more commands. Special in the terminal window: *CTRL-W_.* *CTRL-W_N* CTRL-W . send a CTRL-W to the job in the terminal + CTRL-W CTRL-\ send a CTRL-\ to the job in the terminal CTRL-W N go to Terminal-Normal mode, see |Terminal-mode| CTRL-\ CTRL-N go to Terminal-Normal mode, see |Terminal-mode| CTRL-W " {reg} paste register {reg} *CTRL-W_quote* diff --git a/src/terminal.c b/src/terminal.c index 9a62edd67b..f980a09929 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -2056,6 +2056,11 @@ terminal_loop(int blocking) /* "CTRL-W .": send CTRL-W to the job */ c = Ctrl_W; } + else if (termkey == 0 && c == Ctrl_BSL) + { + /* "CTRL-W CTRL-\": send CTRL-\ to the job */ + c = Ctrl_BSL; + } else if (c == 'N') { /* CTRL-W N : go to Terminal-Normal mode. */ @@ -2173,7 +2178,7 @@ color2index(VTermColor *color, int fg, int *boldp) case 2: return lookup_color( 4, fg, boldp) + 1; /* dark red */ case 3: return lookup_color( 2, fg, boldp) + 1; /* dark green */ case 4: return lookup_color( 6, fg, boldp) + 1; /* brown */ - case 5: return lookup_color( 1, fg, boldp) + 1; /* dark blue*/ + case 5: return lookup_color( 1, fg, boldp) + 1; /* dark blue */ case 6: return lookup_color( 5, fg, boldp) + 1; /* dark magenta */ case 7: return lookup_color( 3, fg, boldp) + 1; /* dark cyan */ case 8: return lookup_color( 8, fg, boldp) + 1; /* light grey */ diff --git a/src/version.c b/src/version.c index 6c3b38ddb9..4cba818494 100644 --- a/src/version.c +++ b/src/version.c @@ -762,6 +762,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1706, /**/ 1705, /**/ From 98da6ecab905df48a67da36ce60233f45726c979 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Fri, 13 Apr 2018 22:15:46 +0200 Subject: [PATCH 03/10] patch 8.0.1707: when 'wfh' is set ":bel 10new" scrolls window Problem: When 'wfh' is set ":bel 10new" scrolls window. (Andrew Pyatkov) Solution: Set the fraction before changing the window height. (closes #2798) --- src/version.c | 2 ++ src/window.c | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/version.c b/src/version.c index 4cba818494..5facbc5811 100644 --- a/src/version.c +++ b/src/version.c @@ -762,6 +762,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1707, /**/ 1706, /**/ diff --git a/src/window.c b/src/window.c index a1b2a45cc0..333663ba36 100644 --- a/src/window.c +++ b/src/window.c @@ -778,6 +778,7 @@ win_split_ins( int before; int minheight; int wmh1; + int did_set_fraction = FALSE; if (flags & WSP_TOP) oldwin = firstwin; @@ -959,6 +960,11 @@ win_split_ins( * instead, if possible. */ if (oldwin->w_p_wfh) { + /* Set w_fraction now so that the cursor keeps the same relative + * vertical position using the old height. */ + set_fraction(oldwin); + did_set_fraction = TRUE; + win_setheight_win(oldwin->w_height + new_size + STATUS_HEIGHT, oldwin); oldwin_height = oldwin->w_height; @@ -1088,7 +1094,8 @@ win_split_ins( /* Set w_fraction now so that the cursor keeps the same relative * vertical position. */ - set_fraction(oldwin); + if (!did_set_fraction) + set_fraction(oldwin); wp->w_fraction = oldwin->w_fraction; if (flags & WSP_VERT) From 78a16b0f2a142aae1fdc96c50ab0f25194d0e755 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sat, 14 Apr 2018 13:51:55 +0200 Subject: [PATCH 04/10] patch 8.0.1708: mkdir with 'p' flag fails on existing directory Problem: Mkdir with 'p' flag fails on existing directory, which is different from the mkdir shell command. Solution: Don't fail if the directory already exists. (James McCoy, closes #2775) --- runtime/doc/eval.txt | 2 ++ src/evalfunc.c | 34 +++++++++++++++++++++------------ src/testdir/test_eval_stuff.vim | 17 +++++++++++++++++ src/version.c | 2 ++ 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index b0170b847b..1868f4ee73 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -6138,6 +6138,8 @@ mkdir({name} [, {path} [, {prot}]]) Example: > :call mkdir($HOME . "/tmp/foo/bar", "p", 0700) < This function is not available in the |sandbox|. + There is no error if the directory already exists and the "p" + flag is passed (since patch 8.0.1708). Not available on all systems. To check use: > :if exists("*mkdir") < diff --git a/src/evalfunc.c b/src/evalfunc.c index 65279a52f8..4b09951852 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -8057,22 +8057,32 @@ f_mkdir(typval_T *argvars, typval_T *rettv) dir = get_tv_string_buf(&argvars[0], buf); if (*dir == NUL) - rettv->vval.v_number = FAIL; - else - { - if (*gettail(dir) == NUL) - /* remove trailing slashes */ - *gettail_sep(dir) = NUL; + return; - if (argvars[1].v_type != VAR_UNKNOWN) + if (*gettail(dir) == NUL) + /* remove trailing slashes */ + *gettail_sep(dir) = NUL; + + if (argvars[1].v_type != VAR_UNKNOWN) + { + if (argvars[2].v_type != VAR_UNKNOWN) { - if (argvars[2].v_type != VAR_UNKNOWN) - prot = (int)get_tv_number_chk(&argvars[2], NULL); - if (prot != -1 && STRCMP(get_tv_string(&argvars[1]), "p") == 0) - mkdir_recurse(dir, prot); + prot = (int)get_tv_number_chk(&argvars[2], NULL); + if (prot == -1) + return; + } + if (STRCMP(get_tv_string(&argvars[1]), "p") == 0) + { + if (mch_isdir(dir)) + { + /* With the "p" flag it's OK if the dir already exists. */ + rettv->vval.v_number = OK; + return; + } + mkdir_recurse(dir, prot); } - rettv->vval.v_number = prot == -1 ? FAIL : vim_mkdir_emsg(dir, prot); } + rettv->vval.v_number = vim_mkdir_emsg(dir, prot); } #endif diff --git a/src/testdir/test_eval_stuff.vim b/src/testdir/test_eval_stuff.vim index 12222303d3..41ba1374d8 100644 --- a/src/testdir/test_eval_stuff.vim +++ b/src/testdir/test_eval_stuff.vim @@ -25,3 +25,20 @@ func Test_nocatch_restore_silent_emsg() let c5 = nr2char(screenchar(&lines, 5)) call assert_equal('wrong', c1 . c2 . c3 . c4 . c5) endfunc + +func Test_mkdir_p() + call mkdir('Xmkdir/nested', 'p') + call assert_true(isdirectory('Xmkdir/nested')) + try + " Trying to make existing directories doesn't error + call mkdir('Xmkdir', 'p') + call mkdir('Xmkdir/nested', 'p') + catch /E739:/ + call assert_report('mkdir(..., "p") failed for an existing directory') + endtry + " 'p' doesn't suppress real errors + call writefile([], 'Xfile') + call assert_fails('call mkdir("Xfile", "p")', 'E739') + call delete('Xfile') + call delete('Xmkdir', 'rf') +endfunc diff --git a/src/version.c b/src/version.c index 5facbc5811..6bebac2913 100644 --- a/src/version.c +++ b/src/version.c @@ -762,6 +762,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1708, /**/ 1707, /**/ From 2e324950b83fcdf60843b54a6a339183370f338a Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sat, 14 Apr 2018 14:37:07 +0200 Subject: [PATCH 05/10] patch 8.0.1709: some non-C89 code may slip through Problem: Some non-C89 code may slip through. Solution: Enforce C89 in configure. Fix detected problems. (James McCoy, closes #2735) --- src/auto/configure | 99 +++++++++++++++++++++++++++++++++++++++++++++- src/channel.c | 6 +-- src/configure.ac | 13 +++++- src/gui_gtk_x11.c | 12 +++--- src/if_python3.c | 2 +- src/version.c | 2 + 6 files changed, 122 insertions(+), 12 deletions(-) diff --git a/src/auto/configure b/src/auto/configure index 7fe5975751..e9ee0171f7 100755 --- a/src/auto/configure +++ b/src/auto/configure @@ -3449,6 +3449,97 @@ ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 +$as_echo_n "checking for $CC option to accept ISO C89... " >&6; } +if ${ac_cv_prog_cc_c89+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_cv_prog_cc_c89=no +ac_save_CC=$CC +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +struct stat; +/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ +struct buf { int x; }; +FILE * (*rcsopen) (struct buf *, struct stat *, int); +static char *e (p, i) + char **p; + int i; +{ + return p[i]; +} +static char *f (char * (*g) (char **, int), char **p, ...) +{ + char *s; + va_list v; + va_start (v,p); + s = g (p, va_arg (v,int)); + va_end (v); + return s; +} + +/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has + function prototypes and stuff, but not '\xHH' hex character constants. + These don't provoke an error unfortunately, instead are silently treated + as 'x'. The following induces an error, until -std is added to get + proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an + array size at least. It's necessary to write '\x00'==0 to get something + that's true only with -std. */ +int osf4_cc_array ['\x00' == 0 ? 1 : -1]; + +/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters + inside strings and character constants. */ +#define FOO(x) 'x' +int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; + +int test (int i, double x); +struct s1 {int (*f) (int a);}; +struct s2 {int (*f) (double a);}; +int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); +int argc; +char **argv; +int +main () +{ +return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; + ; + return 0; +} +_ACEOF +for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ + -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" +do + CC="$ac_save_CC $ac_arg" + if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_c89=$ac_arg +fi +rm -f core conftest.err conftest.$ac_objext + test "x$ac_cv_prog_cc_c89" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC + +fi +# AC_CACHE_VAL +case "x$ac_cv_prog_cc_c89" in + x) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +$as_echo "none needed" >&6; } ;; + xno) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +$as_echo "unsupported" >&6; } ;; + *) + CC="$CC $ac_cv_prog_cc_c89" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 +$as_echo "$ac_cv_prog_cc_c89" >&6; } ;; +esac +if test "x$ac_cv_prog_cc_c89" != xno; then : + +fi + ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' @@ -4115,6 +4206,8 @@ if test "$GCC" = yes; then CFLAGS="$CFLAGS -fno-strength-reduce" fi fi + + CPPFLAGS="$CPPFLAGS -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for clang version" >&5 @@ -4187,7 +4280,7 @@ if test "`(uname) 2>/dev/null`" = Darwin; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } MACOS_X=yes - CPPFLAGS="$CPPFLAGS -DMACOS_X" + CPPFLAGS="$CPPFLAGS -D_DARWIN_C_SOURCE -DMACOS_X" { $as_echo "$as_me:${as_lineno-$LINENO}: checking --disable-darwin argument" >&5 $as_echo_n "checking --disable-darwin argument... " >&6; } @@ -14341,6 +14434,10 @@ if test "$zOSUnix" = "yes"; then CFLAGS="-D_ALL_SOURCE -Wc,float\(ieee\),dll" fi +if test "$GCC" = yes -a "$GUITYPE" != "GTK"; then + CFLAGS="$CFLAGS -ansi" +fi + ac_config_files="$ac_config_files auto/config.mk:config.mk.in" cat >confcache <<\_ACEOF diff --git a/src/channel.c b/src/channel.c index a25e9fe9c8..f5d86ed057 100644 --- a/src/channel.c +++ b/src/channel.c @@ -672,9 +672,9 @@ channel_open( { char *p; - /* When using host->h_addr directly ubsan warns for it to not be - * aligned. First copy the pointer to aviod that. */ - memcpy(&p, &host->h_addr, sizeof(p)); + /* When using host->h_addr_list[0] directly ubsan warns for it to not + * be aligned. First copy the pointer to avoid that. */ + memcpy(&p, &host->h_addr_list[0], sizeof(p)); memcpy((char *)&server.sin_addr, p, host->h_length); } diff --git a/src/configure.ac b/src/configure.ac index f2655a575d..27309b205d 100644 --- a/src/configure.ac +++ b/src/configure.ac @@ -11,7 +11,7 @@ AC_DEFINE(UNIX) AC_PROG_MAKE_SET dnl Checks for programs. -AC_PROG_CC dnl required by almost everything +AC_PROG_CC_C89 dnl required by almost everything AC_PROG_CPP dnl required by header file checks AC_PROGRAM_EGREP dnl required by AC_EGREP_CPP AC_PROG_FGREP dnl finds working grep -F @@ -61,6 +61,9 @@ if test "$GCC" = yes; then CFLAGS="$CFLAGS -fno-strength-reduce" fi fi + + dnl Declare what standards the code should comply with + CPPFLAGS="$CPPFLAGS -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700" fi dnl clang-500.2.75 or around has abandoned -f[no-]strength-reduce and issues a @@ -135,7 +138,7 @@ AC_MSG_CHECKING([for Darwin (Mac OS X)]) if test "`(uname) 2>/dev/null`" = Darwin; then AC_MSG_RESULT(yes) MACOS_X=yes - CPPFLAGS="$CPPFLAGS -DMACOS_X" + CPPFLAGS="$CPPFLAGS -D_DARWIN_C_SOURCE -DMACOS_X" AC_MSG_CHECKING(--disable-darwin argument) AC_ARG_ENABLE(darwin, @@ -4400,6 +4403,12 @@ if test "$zOSUnix" = "yes"; then CFLAGS="-D_ALL_SOURCE -Wc,float\(ieee\),dll" fi +dnl Declare what standards the code should comply with. But not when using +dnl GTK, the header files cause all kinds of warnings. +if test "$GCC" = yes -a "$GUITYPE" != "GTK"; then + CFLAGS="$CFLAGS -ansi" +fi + dnl write output files AC_OUTPUT(auto/config.mk:config.mk.in) diff --git a/src/gui_gtk_x11.c b/src/gui_gtk_x11.c index bb679bd975..9c7e8d5648 100644 --- a/src/gui_gtk_x11.c +++ b/src/gui_gtk_x11.c @@ -5607,15 +5607,17 @@ gui_mch_free_font(GuiFont font) guicolor_T gui_mch_get_color(char_u *name) { + guicolor_T color = INVALCOLOR; + if (!gui.in_use) /* can't do this when GUI not running */ - return INVALCOLOR; + return color; + + if (name != NULL) + color = gui_get_color_cmn(name); #if GTK_CHECK_VERSION(3,0,0) - return name != NULL ? gui_get_color_cmn(name) : INVALCOLOR; + return color; #else - guicolor_T color; - - color = (name != NULL) ? gui_get_color_cmn(name) : INVALCOLOR; if (color == INVALCOLOR) return INVALCOLOR; diff --git a/src/if_python3.c b/src/if_python3.c index b885deb049..4360fe45c5 100644 --- a/src/if_python3.c +++ b/src/if_python3.c @@ -815,7 +815,7 @@ python3_end(void) #endif if (Py_IsInitialized()) { - // acquire lock before finalizing + /* acquire lock before finalizing */ PyGILState_Ensure(); Py_Finalize(); diff --git a/src/version.c b/src/version.c index 6bebac2913..b24935f14d 100644 --- a/src/version.c +++ b/src/version.c @@ -762,6 +762,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1709, /**/ 1708, /**/ From 2a43230ce39eea340aab15fb50a083bc527fb8d0 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sat, 14 Apr 2018 16:12:30 +0200 Subject: [PATCH 06/10] patch 8.0.1710: building with Ruby fails Problem: Building with Ruby fails. Solution: Don't add -ansi when building with Ruby. --- src/auto/configure | 2 +- src/configure.ac | 7 ++++--- src/version.c | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/auto/configure b/src/auto/configure index e9ee0171f7..29dadf2747 100755 --- a/src/auto/configure +++ b/src/auto/configure @@ -14434,7 +14434,7 @@ if test "$zOSUnix" = "yes"; then CFLAGS="-D_ALL_SOURCE -Wc,float\(ieee\),dll" fi -if test "$GCC" = yes -a "$GUITYPE" != "GTK"; then +if test "$GCC" = yes -a "$GUITYPE" != "GTK" -a "X$RUBY_CFLAGS" = "X"; then CFLAGS="$CFLAGS -ansi" fi diff --git a/src/configure.ac b/src/configure.ac index 27309b205d..eef443b741 100644 --- a/src/configure.ac +++ b/src/configure.ac @@ -4403,9 +4403,10 @@ if test "$zOSUnix" = "yes"; then CFLAGS="-D_ALL_SOURCE -Wc,float\(ieee\),dll" fi -dnl Declare what standards the code should comply with. But not when using -dnl GTK, the header files cause all kinds of warnings. -if test "$GCC" = yes -a "$GUITYPE" != "GTK"; then +dnl Declare what standards the code should comply with. +dnl But not when using GTK, the header files cause all kinds of warnings. +dnl But not when using Ruby, it needs "inline". +if test "$GCC" = yes -a "$GUITYPE" != "GTK" -a "X$RUBY_CFLAGS" = "X"; then CFLAGS="$CFLAGS -ansi" fi diff --git a/src/version.c b/src/version.c index b24935f14d..b340f11701 100644 --- a/src/version.c +++ b/src/version.c @@ -762,6 +762,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1710, /**/ 1709, /**/ From a42d363bac8a581afe769c370db70cf833767c41 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sat, 14 Apr 2018 17:05:38 +0200 Subject: [PATCH 07/10] patch 8.0.1711: term_setsize() is not implemented yet Problem: Term_setsize() is not implemented yet. Solution: Implement it. --- runtime/doc/eval.txt | 29 +++++++++++++++++++++++++++-- src/evalfunc.c | 1 + src/proto/terminal.pro | 3 ++- src/terminal.c | 30 +++++++++++++++++++++++++++--- src/testdir/test_terminal.vim | 13 +++++++++++-- src/version.c | 2 ++ 6 files changed, 70 insertions(+), 8 deletions(-) diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 1868f4ee73..35e7063680 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -8402,6 +8402,24 @@ term_setansicolors({buf}, {colors}) *term_setansicolors()* color codes, like those accepted by |highlight-guifg|. Also see |term_getansicolors()| and |g:terminal_ansi_colors|. + The colors normally are: + 0 black + 1 dark red + 2 dark green + 3 brown + 4 dark blue + 5 dark magenta + 6 dark cyan + 7 light grey + 8 dark grey + 9 red + 10 green + 11 yellow + 12 blue + 13 magenta + 14 cyan + 15 white + These colors are used in the GUI and in the terminal when 'termguicolors' is set. When not using GUI colors (GUI mode or |termguicolors|), the terminal window always uses the 16 @@ -8431,8 +8449,15 @@ term_setrestore({buf}, {command}) *term_setrestore()* Use "NONE" to not restore this window. {only available when compiled with the |+terminal| feature} -term_setsize({buf}, {expr}) *term_setsize()* - Not implemented yet. +term_setsize({buf}, {rows}, {cols}) *term_setsize()* + Set the size of terminal {buf}. The size of the window + containing the terminal will also be adjusted, if possible. + If {rows} or {cols} is zero or negative, that dimension is not + changed. + + {buf} must be the buffer number of a terminal window. Use an + empty string for the current buffer. If the buffer does not + exist or is not a terminal window, an error is given. {only available when compiled with the |+terminal| feature} term_start({cmd}, {options}) *term_start()* diff --git a/src/evalfunc.c b/src/evalfunc.c index 4b09951852..599d61ab81 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -876,6 +876,7 @@ static struct fst # endif {"term_setkill", 2, 2, f_term_setkill}, {"term_setrestore", 2, 2, f_term_setrestore}, + {"term_setsize", 3, 3, f_term_setsize}, {"term_start", 1, 2, f_term_start}, {"term_wait", 1, 2, f_term_wait}, #endif diff --git a/src/proto/terminal.pro b/src/proto/terminal.pro index f7cea5a161..78b640f7a5 100644 --- a/src/proto/terminal.pro +++ b/src/proto/terminal.pro @@ -32,19 +32,20 @@ int term_swap_diff(void); void f_term_dumpdiff(typval_T *argvars, typval_T *rettv); void f_term_dumpload(typval_T *argvars, typval_T *rettv); void f_term_getaltscreen(typval_T *argvars, typval_T *rettv); -void f_term_getansicolors(typval_T *argvars, typval_T *rettv); void f_term_getattr(typval_T *argvars, typval_T *rettv); void f_term_getcursor(typval_T *argvars, typval_T *rettv); void f_term_getjob(typval_T *argvars, typval_T *rettv); void f_term_getline(typval_T *argvars, typval_T *rettv); void f_term_getscrolled(typval_T *argvars, typval_T *rettv); void f_term_getsize(typval_T *argvars, typval_T *rettv); +void f_term_setsize(typval_T *argvars, typval_T *rettv); void f_term_getstatus(typval_T *argvars, typval_T *rettv); void f_term_gettitle(typval_T *argvars, typval_T *rettv); void f_term_gettty(typval_T *argvars, typval_T *rettv); void f_term_list(typval_T *argvars, typval_T *rettv); void f_term_scrape(typval_T *argvars, typval_T *rettv); void f_term_sendkeys(typval_T *argvars, typval_T *rettv); +void f_term_getansicolors(typval_T *argvars, typval_T *rettv); void f_term_setansicolors(typval_T *argvars, typval_T *rettv); void f_term_setrestore(typval_T *argvars, typval_T *rettv); void f_term_setkill(typval_T *argvars, typval_T *rettv); diff --git a/src/terminal.c b/src/terminal.c index f980a09929..09d48872da 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -40,7 +40,6 @@ * TODO: * - Win32: Make terminal used for :!cmd in the GUI work better. Allow for * redirection. Probably in call to channel_set_pipes(). - * - implement term_setsize() * - add an optional limit for the scrollback size. When reaching it remove * 10% at the start. * - Copy text in the vterm to the Vim buffer once in a while, so that @@ -4602,6 +4601,31 @@ f_term_getsize(typval_T *argvars, typval_T *rettv) list_append_number(l, buf->b_term->tl_cols); } +/* + * "term_setsize(buf, rows, cols)" function + */ + void +f_term_setsize(typval_T *argvars UNUSED, typval_T *rettv UNUSED) +{ + buf_T *buf = term_get_buf(argvars, "term_setsize()"); + term_T *term; + varnumber_T rows, cols; + + if (buf == NULL || buf->b_term->tl_vterm == NULL) + return; + term = buf->b_term; + rows = get_tv_number(&argvars[1]); + rows = rows <= 0 ? term->tl_rows : rows; + cols = get_tv_number(&argvars[2]); + cols = cols <= 0 ? term->tl_cols : cols; + vterm_set_size(term->tl_vterm, rows, cols); + /* handle_resize() will resize the windows */ + + /* Get and remember the size we ended up with. Update the pty. */ + vterm_get_size(term->tl_vterm, &term->tl_rows, &term->tl_cols); + term_report_winsize(term, term->tl_rows, term->tl_cols); +} + /* * "term_getstatus(buf)" function */ @@ -5432,7 +5456,7 @@ term_free_vterm(term_T *term) } /* - * Request size to terminal. + * Report the size to the terminal. */ static void term_report_winsize(term_T *term, int rows, int cols) @@ -5514,7 +5538,7 @@ term_free_vterm(term_T *term) } /* - * Request size to terminal. + * Report the size to the terminal. */ static void term_report_winsize(term_T *term, int rows, int cols) diff --git a/src/testdir/test_terminal.vim b/src/testdir/test_terminal.vim index e97ee06910..137de7ddd6 100644 --- a/src/testdir/test_terminal.vim +++ b/src/testdir/test_terminal.vim @@ -286,9 +286,18 @@ func Test_terminal_size() vsplit exe 'terminal ++rows=5 ++cols=33 ' . cmd - let size = term_getsize('') + call assert_equal([5, 33], term_getsize('')) + + call term_setsize('', 6, 0) + call assert_equal([6, 33], term_getsize('')) + + call term_setsize('', 0, 35) + call assert_equal([6, 35], term_getsize('')) + + call term_setsize('', 7, 30) + call assert_equal([7, 30], term_getsize('')) + bwipe! - call assert_equal([5, 33], size) call term_start(cmd, {'term_rows': 6, 'term_cols': 36}) let size = term_getsize('') diff --git a/src/version.c b/src/version.c index b340f11701..255e24bd98 100644 --- a/src/version.c +++ b/src/version.c @@ -762,6 +762,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1711, /**/ 1710, /**/ From 8c041b6b95f49f7383cf00e2036cf009b326fa8d Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sat, 14 Apr 2018 18:14:06 +0200 Subject: [PATCH 08/10] patch 8.0.1712: terminal scrollback is not limited Problem: Terminal scrollback is not limited. Solution: Add the 'terminalscroll' option. --- runtime/doc/options.txt | 12 +++++++++++- runtime/doc/terminal.txt | 11 ++++++++--- src/option.c | 9 +++++++++ src/option.h | 3 +++ src/terminal.c | 24 +++++++++++++++++++++--- src/version.c | 2 ++ 6 files changed, 54 insertions(+), 7 deletions(-) diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index cc19e253de..0820699c67 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -1,4 +1,4 @@ -*options.txt* For Vim version 8.0. Last change: 2018 Mar 13 +*options.txt* For Vim version 8.0. Last change: 2018 Apr 14 VIM REFERENCE MANUAL by Bram Moolenaar @@ -7933,6 +7933,16 @@ A jump table for the options with a short description can be found at |Q_op|. Note that the "cterm" attributes are still used, not the "gui" ones. NOTE: This option is reset when 'compatible' is set. + *'terminalscroll'* *'tlsl'* +'terminalscroll' 'tlsl' number (default 10000) + global + {not in Vi} + {not available when compiled without the + |+terminal| feature} + Number of scrollback lines to keep. When going over this limit the + first 10% of the scrollback lines are deleted. This is just to reduce + the memory usage. See |Terminal-Normal|. + *'termkey'* *'tk'* 'termkey' 'tk' string (default "") local to window diff --git a/runtime/doc/terminal.txt b/runtime/doc/terminal.txt index 63217c2fa0..23e210dc84 100644 --- a/runtime/doc/terminal.txt +++ b/runtime/doc/terminal.txt @@ -288,7 +288,7 @@ not when 'termsize' is "rowsXcols". Terminal-Job and Terminal-Normal mode ~ - *Terminal-mode* + *Terminal-mode* *Terminal-Job* When the job is running the contents of the terminal is under control of the job. That includes the cursor position. Typed keys are sent to the job. The terminal contents can change at any time. This is called Terminal-Job @@ -301,7 +301,9 @@ suspended. CTRL-\ CTRL-N does the same. Terminal-Job mode is where |:tmap| mappings are applied. Keys sent by |term_sendkeys()| are not subject to tmap, but keys from |feedkeys()| are. - *E946* +It is not possible to enter Insert mode from Terminal-Job mode. + + *Terminal-Normal* *E946* In Terminal-Normal mode you can move the cursor around with the usual Vim commands, Visually mark text, yank text, etc. But you cannot change the contents of the buffer. The commands that would start insert mode, such as @@ -312,7 +314,10 @@ In Terminal-Normal mode the statusline and window title show "(Terminal)". If the job ends while in Terminal-Normal mode this changes to "(Terminal-finished)". -It is not possible to enter Insert mode from Terminal-Job mode. +When the job outputs lines in the terminal, such that the contents scrolls off +the top, those lines are remembered and can be seen in Terminal-Normal mode. +The number of lines is limited by the 'terminalscroll' option. When going over +this limit, the first 10% of the scrolled lins are deleted and are lost. Cursor style ~ diff --git a/src/option.c b/src/option.c index 5ef346c8d4..9ebc511833 100644 --- a/src/option.c +++ b/src/option.c @@ -2748,6 +2748,15 @@ static struct vimoption options[] = #else (char_u*)NULL, PV_NONE, {(char_u *)FALSE, (char_u *)FALSE} +#endif + SCRIPTID_INIT}, + {"terminalscroll", "tlsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF, +#ifdef FEAT_TERMINAL + (char_u *)&p_tlsl, PV_NONE, + {(char_u *)10000L, (char_u *)10000L} +#else + (char_u *)NULL, PV_NONE, + {(char_u *)NULL, (char_u *)0L} #endif SCRIPTID_INIT}, {"termkey", "tk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF, diff --git a/src/option.h b/src/option.h index d2ee54534c..45f1a36bc2 100644 --- a/src/option.h +++ b/src/option.h @@ -849,6 +849,9 @@ EXTERN char_u *p_tcldll; /* 'tcldll' */ #ifdef FEAT_ARABIC EXTERN int p_tbidi; /* 'termbidi' */ #endif +#ifdef FEAT_TERMINAL +EXTERN long p_tlsl; /* 'terminalscroll' */ +#endif #ifdef FEAT_MBYTE EXTERN char_u *p_tenc; /* 'termencoding' */ #endif diff --git a/src/terminal.c b/src/terminal.c index 09d48872da..7162d684c8 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -40,8 +40,6 @@ * TODO: * - Win32: Make terminal used for :!cmd in the GUI work better. Allow for * redirection. Probably in call to channel_set_pipes(). - * - add an optional limit for the scrollback size. When reaching it remove - * 10% at the start. * - Copy text in the vterm to the Vim buffer once in a while, so that * completion works. * - in GUI vertical split causes problems. Cursor is flickering. (Hirohito @@ -2518,7 +2516,27 @@ handle_pushline(int cols, const VTermScreenCell *cells, void *user) { term_T *term = (term_T *)user; - /* TODO: Limit the number of lines that are stored. */ + /* If the number of lines that are stored goes over 'termscrollback' then + * delete the first 10%. */ + if (term->tl_scrollback.ga_len > p_tlsl) + { + int todo = p_tlsl / 10; + int i; + + curbuf = term->tl_buffer; + for (i = 0; i < todo; ++i) + { + vim_free(((sb_line_T *)term->tl_scrollback.ga_data + i)->sb_cells); + ml_delete(1, FALSE); + } + curbuf = curwin->w_buffer; + + term->tl_scrollback.ga_len -= todo; + mch_memmove(term->tl_scrollback.ga_data, + (sb_line_T *)term->tl_scrollback.ga_data + todo, + sizeof(sb_line_T) * term->tl_scrollback.ga_len); + } + if (ga_grow(&term->tl_scrollback, 1) == OK) { cellattr_T *p = NULL; diff --git a/src/version.c b/src/version.c index 255e24bd98..41b9721cae 100644 --- a/src/version.c +++ b/src/version.c @@ -762,6 +762,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1712, /**/ 1711, /**/ From b3623a382abc8f8e2bcfba4c1a2aa06b7578eb8d Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sat, 14 Apr 2018 18:59:50 +0200 Subject: [PATCH 09/10] patch 8.0.1713: terminal debugger doesn't handle arguments Problem: Terminal debugger doesn't handle arguments. Solution: Use and pass all the arguments to gdb, e.g. the core file or process number. (suggested by Christian Brabandt) Disallow starting the debugger twice. --- runtime/doc/terminal.txt | 7 +++++++ .../pack/dist/opt/termdebug/plugin/termdebug.vim | 15 +++++++++++---- src/version.c | 2 ++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/runtime/doc/terminal.txt b/runtime/doc/terminal.txt index 23e210dc84..8deba3922d 100644 --- a/runtime/doc/terminal.txt +++ b/runtime/doc/terminal.txt @@ -649,6 +649,13 @@ the same as any command running in a terminal window. When the debugger ends, typically by typing "quit" in the gdb window, the two opened windows are closed. +Only one debugger can be active at a time. + +To attach gdb to an already running executable, or use a core file, pass extra +arguments. E.g.: > + :Termdebug vim core + :Termdebug vim 98343 + Example session ~ *termdebug-example* diff --git a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim index 256f7ef60c..ded114a2d7 100644 --- a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim +++ b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim @@ -25,7 +25,7 @@ endif " The command that starts debugging, e.g. ":Termdebug vim". " To end type "quit" in the gdb window. -command -nargs=* -complete=file Termdebug call s:StartDebug() +command -nargs=* -complete=file Termdebug call s:StartDebug() " Name of the gdb command, defaults to "gdb". if !exists('termdebugger') @@ -43,7 +43,12 @@ else endif hi default debugBreakpoint term=reverse ctermbg=red guibg=red -func s:StartDebug(cmd) +func s:StartDebug(...) + if exists('s:gdbwin') + echoerr 'Terminal debugger already running' + return + endif + let s:startwin = win_getid(winnr()) let s:startsigncolumn = &signcolumn @@ -90,7 +95,7 @@ func s:StartDebug(cmd) " Open a terminal window to run the debugger. " Add -quiet to avoid the intro message causing a hit-enter prompt. - let cmd = [g:termdebugger, '-quiet', '-tty', pty, a:cmd] + let cmd = [g:termdebugger, '-quiet', '-tty', pty] + a:000 echomsg 'executing "' . join(cmd) . '"' let s:gdbbuf = term_start(cmd, { \ 'exit_cb': function('s:EndDebug'), @@ -112,7 +117,7 @@ func s:StartDebug(cmd) let try_count = 0 while 1 let response = '' - for lnum in range(1,20) + for lnum in range(1,200) if term_getline(s:gdbbuf, lnum) =~ 'new-ui mi ' let response = term_getline(s:gdbbuf, lnum + 1) if response =~ 'Undefined command' @@ -182,6 +187,7 @@ endfunc func s:EndDebug(job, status) exe 'bwipe! ' . s:ptybuf exe 'bwipe! ' . s:commbuf + unlet s:gdbwin let curwinid = win_getid(winnr()) @@ -295,6 +301,7 @@ func s:DeleteCommands() delcommand Evaluate delcommand Gdb delcommand Program + delcommand Source delcommand Winbar nunmap K diff --git a/src/version.c b/src/version.c index 41b9721cae..b76ccf4cef 100644 --- a/src/version.c +++ b/src/version.c @@ -762,6 +762,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1713, /**/ 1712, /**/ From 6e72cd0d7267b9545ef966a53e62706914a96042 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sat, 14 Apr 2018 21:31:35 +0200 Subject: [PATCH 10/10] patch 8.0.1714: term_setsize() does not give an error in a normal buffer Problem: Term_setsize() does not give an error in a normal buffer. Solution: Add an error message. --- src/terminal.c | 7 ++++++- src/testdir/test_terminal.vim | 22 ++++++++++++++++++++++ src/version.c | 2 ++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/terminal.c b/src/terminal.c index 7162d684c8..be594c405b 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -4629,7 +4629,12 @@ f_term_setsize(typval_T *argvars UNUSED, typval_T *rettv UNUSED) term_T *term; varnumber_T rows, cols; - if (buf == NULL || buf->b_term->tl_vterm == NULL) + if (buf == NULL) + { + EMSG(_("E955: Not a terminal buffer")); + return; + } + if (buf->b_term->tl_vterm == NULL) return; term = buf->b_term; rows = get_tv_number(&argvars[1]); diff --git a/src/testdir/test_terminal.vim b/src/testdir/test_terminal.vim index 137de7ddd6..95a131be74 100644 --- a/src/testdir/test_terminal.vim +++ b/src/testdir/test_terminal.vim @@ -271,6 +271,27 @@ func Test_terminal_scroll() call delete('Xtext') endfunc +func Test_terminal_scrollback() + let buf = Run_shell_in_terminal({}) + set terminalscroll=100 + call writefile(range(150), 'Xtext') + if has('win32') + call term_sendkeys(buf, "type Xtext\") + else + call term_sendkeys(buf, "cat Xtext\") + endif + let rows = term_getsize(buf)[0] + call WaitFor({-> term_getline(buf, rows - 1) =~ '149'}) + let lines = line('$') + call assert_true(lines <= 100) + call assert_true(lines > 90) + + call Stop_shell_in_terminal(buf) + call term_wait(buf) + exe buf . 'bwipe' + set terminalscroll& +endfunc + func Test_terminal_size() let cmd = Get_cat_123_cmd() @@ -298,6 +319,7 @@ func Test_terminal_size() call assert_equal([7, 30], term_getsize('')) bwipe! + call assert_fails("call term_setsize('', 7, 30)", "E955:") call term_start(cmd, {'term_rows': 6, 'term_cols': 36}) let size = term_getsize('') diff --git a/src/version.c b/src/version.c index b76ccf4cef..76596f2bf8 100644 --- a/src/version.c +++ b/src/version.c @@ -762,6 +762,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1714, /**/ 1713, /**/