diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 59b73f6cc2..722e05d7a1 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2423,6 +2423,7 @@ term_dumpload({filename} [, {options}]) term_dumpwrite({buf}, {filename} [, {options}]) none dump terminal window contents term_getaltscreen({buf}) Number get the alternate screen flag +term_getansicolors({buf}) List get ANSI palette in GUI color mode term_getattr({attr}, {what}) Number get the value of attribute {what} term_getcursor({buf}) List get the cursor position of a terminal term_getjob({buf}) Job get the job associated with a terminal @@ -2435,6 +2436,8 @@ term_gettty({buf}, [{input}]) String get the tty name of a terminal term_list() List get the list of terminal buffers term_scrape({buf}, {row}) List get row of a terminal screen term_sendkeys({buf}, {keys}) none send keystrokes to a terminal +term_setansicolors({buf}, {colors}) + none set ANSI palette in GUI color mode term_setkill({buf}, {how}) none set signal to stop job in terminal term_setrestore({buf}, {command}) none set command to restore terminal term_start({cmd}, {options}) Job open a terminal window and run a job @@ -8248,6 +8251,18 @@ term_getaltscreen({buf}) *term_getaltscreen()* {buf} is used as with |term_getsize()|. {only available when compiled with the |+terminal| feature} +term_getansicolors({buf}) *term_getansicolors()* + Get the ANSI color palette in use by terminal {buf}. + Returns a List of length 16 where each element is a String + representing a color in hexadecimal "#rrggbb" format. + Also see |term_setansicolors()| and |g:terminal_ansi_colors|. + If neither was used returns the default colors. + + {buf} is used as with |term_getsize()|. If the buffer does not + exist or is not a terminal window, an empty list is returned. + {only available when compiled with the |+terminal| feature and + with GUI enabled and/or the |+termguicolors| feature} + term_getattr({attr}, {what}) *term_getattr()* Given {attr}, a value returned by term_scrape() in the "attr" item, return whether {what} is on. {what} can be one of: @@ -8379,6 +8394,19 @@ term_sendkeys({buf}, {keys}) *term_sendkeys()* means the character CTRL-X. {only available when compiled with the |+terminal| feature} +term_setansicolors({buf}, {colors}) *term_setansicolors()* + Set the ANSI color palette used by terminal {buf}. + {colors} must be a List of 16 valid color names or hexadecimal + color codes, like those accepted by |highlight-guifg|. + Also see |term_getansicolors()| and |g:terminal_ansi_colors|. + + 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 + ANSI colors of the underlying terminal. + {only available when compiled with the |+terminal| feature and + with GUI enabled and/or the |+termguicolors| feature} + term_setkill({buf}, {how}) *term_setkill()* When exiting Vim or trying to close the terminal window in another way, {how} defines whether the job in the terminal can @@ -8463,6 +8491,9 @@ term_start({cmd}, {options}) *term_start()* CTRL-D is used on MS-Windows. For Python use CTRL-Z or "exit()". For a shell use "exit". A CR is always added. + "ansi_colors" A list of 16 color names or hex codes + defining the ANSI palette used in GUI + color modes. See |g:terminal_ansi_colors|. {only available when compiled with the |+terminal| feature} diff --git a/runtime/doc/terminal.txt b/runtime/doc/terminal.txt index 2d1af11266..551a3740c2 100644 --- a/runtime/doc/terminal.txt +++ b/runtime/doc/terminal.txt @@ -136,6 +136,16 @@ terminal window will start with a white or black background. To use a different color the Terminal highlight group can be used, for example: > hi Terminal ctermbg=lightgrey ctermfg=blue guibg=lightgrey guifg=blue +< + *g:terminal_ansi_colors* +In GUI mode or with |termguicolors|, the 16 ANSI colors used by default in new +terminal windows may be configured using the variable +`g:terminal_ansi_colors`, which should be a list of 16 color names or +hexadecimal color codes, similar to those accepted by |highlight-guifg|. When +not using GUI colors, the terminal window always uses the 16 ANSI colors of +the underlying terminal. +The |term_setansicolors()| function can be used to change the colors, and +|term_getansicolors()| to get the currently used colors. Syntax ~ diff --git a/src/Makefile b/src/Makefile index a485be82bb..8364edd718 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2105,6 +2105,10 @@ benchmark: unittesttargets: $(MAKE) -f Makefile $(UNITTEST_TARGETS) +# Swap these lines to run individual tests with gvim instead of vim. +VIMTESTTARGET = $(VIMTARGET) +# VIMTESTTARGET = $(GVIMTARGET) + # Execute the unittests one by one. unittest unittests: $(RUN_UNITTESTS) @@ -2132,7 +2136,7 @@ test1 \ test70 test72 \ test85 test86 test87 test88 \ test94 test95 test99 test108: - cd testdir; rm -f $@.out; $(MAKE) -f Makefile $@.out VIMPROG=../$(VIMTARGET) $(GUI_TESTARG) SCRIPTSOURCE=../$(SCRIPTSOURCE) + cd testdir; rm -f $@.out; $(MAKE) -f Makefile $@.out VIMPROG=../$(VIMTESTTARGET) $(GUI_TESTARG) SCRIPTSOURCE=../$(SCRIPTSOURCE) # Run individual NEW style test. # These do not depend on the executable, compile it when needed. @@ -2144,6 +2148,7 @@ test_arglist \ test_autocmd \ test_autoload \ test_backspace_opt \ + test_blockedit \ test_breakindent \ test_bufline \ test_bufwintabinfo \ @@ -2324,17 +2329,18 @@ test_arglist \ test_windows_home \ test_wordcount \ test_writefile \ + test_xxd \ test_alot_latin \ test_alot_utf8 \ test_alot: - cd testdir; rm -f $@.res test.log messages; $(MAKE) -f Makefile $@.res VIMPROG=../$(VIMTARGET) $(GUI_TESTARG) SCRIPTSOURCE=../$(SCRIPTSOURCE) + cd testdir; rm -f $@.res test.log messages; $(MAKE) -f Makefile $@.res VIMPROG=../$(VIMTESTTARGET) $(GUI_TESTARG) SCRIPTSOURCE=../$(SCRIPTSOURCE) @if test -f testdir/test.log; then \ cat testdir/test.log; \ fi cat testdir/messages newtests: - cd testdir; rm -f $@.res test.log messages; $(MAKE) -f Makefile newtestssilent VIMPROG=../$(VIMTARGET) $(GUI_TESTARG) SCRIPTSOURCE=../$(SCRIPTSOURCE) + cd testdir; rm -f $@.res test.log messages; $(MAKE) -f Makefile newtestssilent VIMPROG=../$(VIMTESTTARGET) $(GUI_TESTARG) SCRIPTSOURCE=../$(SCRIPTSOURCE) @if test -f testdir/test.log; then \ cat testdir/test.log; \ fi diff --git a/src/auto/configure b/src/auto/configure index 6a7431d9eb..eb24979f40 100755 --- a/src/auto/configure +++ b/src/auto/configure @@ -6004,7 +6004,7 @@ fi # Check whether --with-python-config-dir was given. if test "${with_python_config_dir+set}" = set; then : - withval=$with_python_config_dir; vi_cv_path_python_conf="${withval}" + withval=$with_python_config_dir; vi_cv_path_python_conf="${withval}"; have_python_config_dir=1 fi @@ -6107,9 +6107,13 @@ $as_echo "$vi_cv_dll_name_python" >&6; } PYTHON_LIBS="${vi_cv_path_python_plibs}" if test "${vi_cv_path_python_pfx}" = "${vi_cv_path_python_epfx}"; then - PYTHON_CFLAGS="-I${vi_cv_path_python_pfx}/include/python${vi_cv_var_python_version} -DPYTHON_HOME='\"${vi_cv_path_python_pfx}\"'" + PYTHON_CFLAGS="-I${vi_cv_path_python_pfx}/include/python${vi_cv_var_python_version}" else - PYTHON_CFLAGS="-I${vi_cv_path_python_pfx}/include/python${vi_cv_var_python_version} -I${vi_cv_path_python_epfx}/include/python${vi_cv_var_python_version} -DPYTHON_HOME='\"${vi_cv_path_python_pfx}\"'" + PYTHON_CFLAGS="-I${vi_cv_path_python_pfx}/include/python${vi_cv_var_python_version} -I${vi_cv_path_python_epfx}/include/python${vi_cv_var_python_version}" + fi + if test "X$have_python_config_dir" = "X1" -a "$enable_pythoninterp" = "dynamic"; then + PYTHON_CFLAGS="${PYTHON_CFLAGS} -DPYTHON_HOME='\"${vi_cv_path_python_pfx}\"'" + fi PYTHON_SRC="if_python.c" PYTHON_OBJ="objects/if_python.o" @@ -6368,7 +6372,7 @@ fi # Check whether --with-python3-config-dir was given. if test "${with_python3_config_dir+set}" = set; then : - withval=$with_python3_config_dir; vi_cv_path_python3_conf="${withval}" + withval=$with_python3_config_dir; vi_cv_path_python3_conf="${withval}"; have_python3_config_dir=1 fi @@ -6446,10 +6450,13 @@ $as_echo "$vi_cv_dll_name_python3" >&6; } PYTHON3_LIBS="${vi_cv_path_python3_plibs}" if test "${vi_cv_path_python3_pfx}" = "${vi_cv_path_python3_epfx}"; then - PYTHON3_CFLAGS="-I${vi_cv_path_python3_pfx}/include/python${vi_cv_var_python3_version}${vi_cv_var_python3_abiflags} -DPYTHON3_HOME='L\"${vi_cv_path_python3_pfx}\"'" + PYTHON3_CFLAGS="-I${vi_cv_path_python3_pfx}/include/python${vi_cv_var_python3_version}${vi_cv_var_python3_abiflags}" else - PYTHON3_CFLAGS="-I${vi_cv_path_python3_pfx}/include/python${vi_cv_var_python3_version}${vi_cv_var_python3_abiflags} -I${vi_cv_path_python3_epfx}/include/python${vi_cv_var_python3_version}${vi_cv_var_python3_abiflags} -DPYTHON3_HOME='L\"${vi_cv_path_python3_pfx}\"'" + PYTHON3_CFLAGS="-I${vi_cv_path_python3_pfx}/include/python${vi_cv_var_python3_version}${vi_cv_var_python3_abiflags} -I${vi_cv_path_python3_epfx}/include/python${vi_cv_var_python3_version}${vi_cv_var_python3_abiflags}" fi + if test "X$have_python3_config_dir" = "X1" -a "$enable_python3interp" = "dynamic"; then + PYTHON3_CFLAGS="${PYTHON3_CFLAGS} -DPYTHON3_HOME='L\"${vi_cv_path_python3_pfx}\"'" + fi PYTHON3_SRC="if_python3.c" PYTHON3_OBJ="objects/if_python3.o" diff --git a/src/buffer.c b/src/buffer.c index 21b39adcaa..dad8fdb94a 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1768,7 +1768,7 @@ enter_buffer(buf_T *buf) #endif /* Change directories when the 'acd' option is set. */ - DO_AUTOCHDIR + DO_AUTOCHDIR; #ifdef FEAT_KEYMAP if (curbuf->b_kmap_state & KEYMAP_INIT) diff --git a/src/channel.c b/src/channel.c index a911708520..79976cd9e2 100644 --- a/src/channel.c +++ b/src/channel.c @@ -179,8 +179,8 @@ ch_log(channel_T *ch, const char *fmt, ...) static void ch_error(channel_T *ch, const char *fmt, ...) -#ifdef __GNUC__ -__attribute__((format(printf, 2, 3))) +#ifdef USE_PRINTF_FORMAT_ATTRIBUTE + __attribute__((format(printf, 2, 3))) #endif ; @@ -4844,6 +4844,50 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported, int supported2) opt->jo_set2 |= JO2_TERM_KILL; opt->jo_term_kill = get_tv_string_chk(item); } +# if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) + else if (STRCMP(hi->hi_key, "ansi_colors") == 0) + { + int n = 0; + listitem_T *li; + long_u rgb[16]; + + if (!(supported2 & JO2_ANSI_COLORS)) + break; + + if (item == NULL || item->v_type != VAR_LIST + || item->vval.v_list == NULL) + { + EMSG2(_(e_invargval), "ansi_colors"); + return FAIL; + } + + li = item->vval.v_list->lv_first; + for (; li != NULL && n < 16; li = li->li_next, n++) + { + char_u *color_name; + guicolor_T guicolor; + + color_name = get_tv_string_chk(&li->li_tv); + if (color_name == NULL) + return FAIL; + + guicolor = GUI_GET_COLOR(color_name); + if (guicolor == INVALCOLOR) + return FAIL; + + rgb[n] = GUI_MCH_GET_RGB(guicolor); + } + + if (n != 16 || li != NULL) + { + EMSG2(_(e_invargval), "ansi_colors"); + return FAIL; + } + + opt->jo_set2 |= JO2_ANSI_COLORS; + memcpy(opt->jo_ansi_colors, rgb, sizeof(rgb)); + } +# endif #endif else if (STRCMP(hi->hi_key, "env") == 0) { diff --git a/src/configure.ac b/src/configure.ac index e931f58ab9..4e59dae163 100644 --- a/src/configure.ac +++ b/src/configure.ac @@ -1187,7 +1187,7 @@ if test "$enable_pythoninterp" = "yes" -o "$enable_pythoninterp" = "dynamic"; th AC_ARG_WITH(python-config-dir, [ --with-python-config-dir=PATH Python's config directory], - [ vi_cv_path_python_conf="${withval}" ] ) + [ vi_cv_path_python_conf="${withval}"; have_python_config_dir=1 ] ) AC_CACHE_CHECK(Python's configuration directory,vi_cv_path_python_conf, [ @@ -1281,9 +1281,14 @@ eof PYTHON_LIBS="${vi_cv_path_python_plibs}" if test "${vi_cv_path_python_pfx}" = "${vi_cv_path_python_epfx}"; then - PYTHON_CFLAGS="-I${vi_cv_path_python_pfx}/include/python${vi_cv_var_python_version} -DPYTHON_HOME='\"${vi_cv_path_python_pfx}\"'" + PYTHON_CFLAGS="-I${vi_cv_path_python_pfx}/include/python${vi_cv_var_python_version}" else - PYTHON_CFLAGS="-I${vi_cv_path_python_pfx}/include/python${vi_cv_var_python_version} -I${vi_cv_path_python_epfx}/include/python${vi_cv_var_python_version} -DPYTHON_HOME='\"${vi_cv_path_python_pfx}\"'" + PYTHON_CFLAGS="-I${vi_cv_path_python_pfx}/include/python${vi_cv_var_python_version} -I${vi_cv_path_python_epfx}/include/python${vi_cv_var_python_version}" + fi + if test "X$have_python_config_dir" = "X1" -a "$enable_pythoninterp" = "dynamic"; then + dnl Define PYTHON_HOME if --with-python-config-dir was used + PYTHON_CFLAGS="${PYTHON_CFLAGS} -DPYTHON_HOME='\"${vi_cv_path_python_pfx}\"'" + fi PYTHON_SRC="if_python.c" PYTHON_OBJ="objects/if_python.o" @@ -1439,7 +1444,7 @@ if test "$enable_python3interp" = "yes" -o "$enable_python3interp" = "dynamic"; AC_ARG_WITH(python3-config-dir, [ --with-python3-config-dir=PATH Python's config directory], - [ vi_cv_path_python3_conf="${withval}" ] ) + [ vi_cv_path_python3_conf="${withval}"; have_python3_config_dir=1 ] ) AC_CACHE_CHECK(Python's configuration directory,vi_cv_path_python3_conf, [ @@ -1500,10 +1505,14 @@ eof PYTHON3_LIBS="${vi_cv_path_python3_plibs}" if test "${vi_cv_path_python3_pfx}" = "${vi_cv_path_python3_epfx}"; then - PYTHON3_CFLAGS="-I${vi_cv_path_python3_pfx}/include/python${vi_cv_var_python3_version}${vi_cv_var_python3_abiflags} -DPYTHON3_HOME='L\"${vi_cv_path_python3_pfx}\"'" + PYTHON3_CFLAGS="-I${vi_cv_path_python3_pfx}/include/python${vi_cv_var_python3_version}${vi_cv_var_python3_abiflags}" else - PYTHON3_CFLAGS="-I${vi_cv_path_python3_pfx}/include/python${vi_cv_var_python3_version}${vi_cv_var_python3_abiflags} -I${vi_cv_path_python3_epfx}/include/python${vi_cv_var_python3_version}${vi_cv_var_python3_abiflags} -DPYTHON3_HOME='L\"${vi_cv_path_python3_pfx}\"'" + PYTHON3_CFLAGS="-I${vi_cv_path_python3_pfx}/include/python${vi_cv_var_python3_version}${vi_cv_var_python3_abiflags} -I${vi_cv_path_python3_epfx}/include/python${vi_cv_var_python3_version}${vi_cv_var_python3_abiflags}" fi + if test "X$have_python3_config_dir" = "X1" -a "$enable_python3interp" = "dynamic"; then + dnl Define PYTHON3_HOME if --with-python-config-dir was used + PYTHON3_CFLAGS="${PYTHON3_CFLAGS} -DPYTHON3_HOME='L\"${vi_cv_path_python3_pfx}\"'" + fi PYTHON3_SRC="if_python3.c" PYTHON3_OBJ="objects/if_python3.o" diff --git a/src/dosinst.c b/src/dosinst.c index 6a12e3dc88..ae5517da94 100644 --- a/src/dosinst.c +++ b/src/dosinst.c @@ -23,7 +23,14 @@ #define GVIMEXT32_PATH "GvimExt32\\gvimext.dll" /* Macro to do an error check I was typing over and over */ -#define CHECK_REG_ERROR(code) if (code != ERROR_SUCCESS) { printf("%ld error number: %ld\n", (long)__LINE__, (long)code); return 1; } +#define CHECK_REG_ERROR(code) \ + do { \ + if (code != ERROR_SUCCESS) \ + { \ + printf("%ld error number: %ld\n", (long)__LINE__, (long)code); \ + return 1; \ + } \ + } while (0) int has_vim = 0; /* installable vim.exe exists */ int has_gvim = 0; /* installable gvim.exe exists */ diff --git a/src/evalfunc.c b/src/evalfunc.c index 41298ea038..65162dbbda 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -856,6 +856,9 @@ static struct fst {"term_dumpload", 1, 2, f_term_dumpload}, {"term_dumpwrite", 2, 3, f_term_dumpwrite}, {"term_getaltscreen", 1, 1, f_term_getaltscreen}, +# if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) + {"term_getansicolors", 1, 1, f_term_getansicolors}, +# endif {"term_getattr", 2, 2, f_term_getattr}, {"term_getcursor", 1, 1, f_term_getcursor}, {"term_getjob", 1, 1, f_term_getjob}, @@ -868,6 +871,9 @@ static struct fst {"term_list", 0, 0, f_term_list}, {"term_scrape", 2, 2, f_term_scrape}, {"term_sendkeys", 2, 2, f_term_sendkeys}, +# if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) + {"term_setansicolors", 2, 2, f_term_setansicolors}, +# endif {"term_setkill", 2, 2, f_term_setkill}, {"term_setrestore", 2, 2, f_term_setrestore}, {"term_start", 1, 2, f_term_start}, diff --git a/src/ex_cmds.c b/src/ex_cmds.c index e13d34cc0f..111fe01d22 100644 --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -2996,7 +2996,7 @@ rename_buffer(char_u *new_fname) apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, curbuf); /* Change directories when the 'acd' option is set. */ - DO_AUTOCHDIR + DO_AUTOCHDIR; return OK; } @@ -3254,7 +3254,7 @@ do_write(exarg_T *eap) * got changed or set. */ if (eap->cmdidx == CMD_saveas || name_was_missing) { - DO_AUTOCHDIR + DO_AUTOCHDIR; } } @@ -4147,7 +4147,7 @@ do_ecmd( #endif /* Change directories when the 'acd' option is set. */ - DO_AUTOCHDIR + DO_AUTOCHDIR; /* * Careful: open_buffer() and apply_autocmds() may change the current diff --git a/src/gui_at_sb.c b/src/gui_at_sb.c index 659e93463c..1816daa09e 100644 --- a/src/gui_at_sb.c +++ b/src/gui_at_sb.c @@ -645,7 +645,11 @@ Redisplay(Widget w, XEvent *event, Region region) static Boolean CompareEvents(XEvent *oldEvent, XEvent *newEvent) { -#define Check(field) if (newEvent->field != oldEvent->field) return False; +#define Check(field) \ + do { \ + if (newEvent->field != oldEvent->field) \ + return False; \ + } while (0) Check(xany.display); Check(xany.type); diff --git a/src/macros.h b/src/macros.h index f5440b17e0..fcd1a829da 100644 --- a/src/macros.h +++ b/src/macros.h @@ -230,9 +230,9 @@ #endif #ifdef STARTUPTIME -# define TIME_MSG(s) { if (time_fd != NULL) time_msg(s, NULL); } +# define TIME_MSG(s) do { if (time_fd != NULL) time_msg(s, NULL); } while (0) #else -# define TIME_MSG(s) +# define TIME_MSG(s) do { /**/ } while (0) #endif #ifdef FEAT_VREPLACE @@ -289,9 +289,9 @@ #endif #ifdef FEAT_AUTOCHDIR -# define DO_AUTOCHDIR if (p_acd) do_autochdir(); +# define DO_AUTOCHDIR do { if (p_acd) do_autochdir(); } while (0) #else -# define DO_AUTOCHDIR +# define DO_AUTOCHDIR do { /**/ } while (0) #endif #define RESET_BINDING(wp) (wp)->w_p_scb = FALSE; (wp)->w_p_crb = FALSE diff --git a/src/main.c b/src/main.c index aa026e0e9c..aca98971d7 100644 --- a/src/main.c +++ b/src/main.c @@ -874,7 +874,7 @@ vim_main2(void) no_wait_return = FALSE; /* 'autochdir' has been postponed */ - DO_AUTOCHDIR + DO_AUTOCHDIR; #ifdef FEAT_TERMRESPONSE /* Requesting the termresponse is postponed until here, so that a "-c q" diff --git a/src/memline.c b/src/memline.c index 5ecb32c107..4be1036f05 100644 --- a/src/memline.c +++ b/src/memline.c @@ -8,8 +8,8 @@ */ /* for debugging */ -/* #define CHECK(c, s) if (c) EMSG(s) */ -#define CHECK(c, s) +/* #define CHECK(c, s) do { if (c) EMSG(s); } while (0) */ +#define CHECK(c, s) do { /**/ } while (0) /* * memline.c: Contains the functions for appending, deleting and changing the diff --git a/src/ops.c b/src/ops.c index b1c1d36935..fe29e8ae74 100644 --- a/src/ops.c +++ b/src/ops.c @@ -1093,7 +1093,7 @@ do_record(int c) if (Recording == FALSE) /* start recording */ { - /* registers 0-9, a-z and " are allowed */ + /* registers 0-9, a-z and " are allowed */ if (c < 0 || (!ASCII_ISALNUM(c) && c != '"')) retval = FAIL; else @@ -2702,6 +2702,7 @@ op_insert(oparg_T *oap, long count1) if (oap->block_mode) { struct block_def bd2; + int did_indent = FALSE; /* If indent kicked in, the firstline might have changed * but only do that, if the indent actually increased. */ @@ -2710,11 +2711,14 @@ op_insert(oparg_T *oap, long count1) { bd.textcol += ind_post - ind_pre; bd.start_vcol += ind_post - ind_pre; + did_indent = TRUE; } /* The user may have moved the cursor before inserting something, try - * to adjust the block for that. */ - if (oap->start.lnum == curbuf->b_op_start_orig.lnum && !bd.is_MAX) + * to adjust the block for that. But only do it, if the difference + * does not come from indent kicking in. */ + if (oap->start.lnum == curbuf->b_op_start_orig.lnum + && !bd.is_MAX && !did_indent) { if (oap->op_type == OP_INSERT && oap->start.col diff --git a/src/option.c b/src/option.c index c0fadfd59a..3e8fb5c077 100644 --- a/src/option.c +++ b/src/option.c @@ -8624,7 +8624,7 @@ set_bool_option( else if ((int *)varp == &p_acd) { /* Change directories when the 'acd' option is set now. */ - DO_AUTOCHDIR + DO_AUTOCHDIR; } #endif diff --git a/src/os_vms.c b/src/os_vms.c index 02c594c5bd..84f84ac710 100644 --- a/src/os_vms.c +++ b/src/os_vms.c @@ -83,7 +83,7 @@ static void set_tty(int row, int col); #define EXPL_ALLOC_INC 64 #define EQN(S1,S2,LN) (strncmp(S1,S2,LN) == 0) -#define SKIP_FOLLOWING_SLASHES(Str) while (Str[1] == '/') ++Str +#define SKIP_FOLLOWING_SLASHES(Str) do { while (Str[1] == '/') ++Str; } while (0) /* diff --git a/src/proto.h b/src/proto.h index e968752257..76a1bed219 100644 --- a/src/proto.h +++ b/src/proto.h @@ -120,7 +120,7 @@ int _RTLENTRYF # endif vim_snprintf_add(char *, size_t, char *, ...) -#ifdef __GNUC__ +#ifdef USE_PRINTF_FORMAT_ATTRIBUTE __attribute__((format(printf, 3, 4))) #endif ; @@ -130,7 +130,7 @@ int _RTLENTRYF # endif vim_snprintf(char *, size_t, char *, ...) -#ifdef __GNUC__ +#ifdef USE_PRINTF_FORMAT_ATTRIBUTE __attribute__((format(printf, 3, 4))) #endif ; @@ -223,7 +223,7 @@ void qsort(void *base, size_t elm_count, size_t elm_size, int (*cmp)(const void /* Not generated automatically, to add extra attribute. */ void ch_log(channel_T *ch, const char *fmt, ...) -#ifdef __GNUC__ +#ifdef USE_PRINTF_FORMAT_ATTRIBUTE __attribute__((format(printf, 2, 3))) #endif ; diff --git a/src/proto/terminal.pro b/src/proto/terminal.pro index 0ef7783cdb..f7cea5a161 100644 --- a/src/proto/terminal.pro +++ b/src/proto/terminal.pro @@ -32,6 +32,7 @@ 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); @@ -44,6 +45,7 @@ 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_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); void f_term_start(typval_T *argvars, typval_T *rettv); diff --git a/src/screen.c b/src/screen.c index c51d795868..5d3c1c1a5a 100644 --- a/src/screen.c +++ b/src/screen.c @@ -2705,15 +2705,21 @@ fold_line( } #ifdef FEAT_RIGHTLEFT -# define RL_MEMSET(p, v, l) if (wp->w_p_rl) \ - for (ri = 0; ri < l; ++ri) \ - ScreenAttrs[off + (wp->w_width - (p) - (l)) + ri] = v; \ - else \ - for (ri = 0; ri < l; ++ri) \ - ScreenAttrs[off + (p) + ri] = v +# define RL_MEMSET(p, v, l) \ + do { \ + if (wp->w_p_rl) \ + for (ri = 0; ri < l; ++ri) \ + ScreenAttrs[off + (wp->w_width - (p) - (l)) + ri] = v; \ + else \ + for (ri = 0; ri < l; ++ri) \ + ScreenAttrs[off + (p) + ri] = v; \ + } while (0) #else -# define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \ - ScreenAttrs[off + (p) + ri] = v +# define RL_MEMSET(p, v, l) \ + do { \ + for (ri = 0; ri < l; ++ri) \ + ScreenAttrs[off + (p) + ri] = v; \ + } while (0) #endif /* Set all attributes of the 'number' or 'relativenumber' column and the diff --git a/src/structs.h b/src/structs.h index cea23cc89f..ee423e0178 100644 --- a/src/structs.h +++ b/src/structs.h @@ -1711,7 +1711,7 @@ struct channel_S { #define JO2_EOF_CHARS 0x1000 /* "eof_chars" */ #define JO2_NORESTORE 0x2000 /* "norestore" */ #define JO2_TERM_KILL 0x4000 /* "term_kill" */ -#define JO2_ALL 0x7FFF +#define JO2_ANSI_COLORS 0x8000 /* "ansi_colors" */ #define JO_MODE_ALL (JO_MODE + JO_IN_MODE + JO_OUT_MODE + JO_ERR_MODE) #define JO_CB_ALL \ @@ -1780,6 +1780,9 @@ typedef struct int jo_term_finish; char_u *jo_eof_chars; char_u *jo_term_kill; +# if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) + long_u jo_ansi_colors[16]; +# endif #endif } jobopt_T; diff --git a/src/terminal.c b/src/terminal.c index 07d487d15c..1d946ada7a 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -38,15 +38,13 @@ * in tl_scrollback are no longer used. * * TODO: - * - Add a way to set the 16 ANSI colors, to be used for 'termguicolors' and in - * the GUI. * - 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 * completion works. - * - Adding WinBar to terminal window doesn't display, text isn't shifted down. - * a job that uses 16 colors while Vim is using > 256. * - in GUI vertical split causes problems. Cursor is flickering. (Hirohito * Higashi, 2017 Sep 19) * - after resizing windows overlap. (Boris Staletic, #2164) @@ -66,8 +64,6 @@ * http://bazaar.launchpad.net/~leonerd/pangoterm/trunk/view/head:/main.c#L134 * - when 'encoding' is not utf-8, or the job is using another encoding, setup * conversions. - * - add an optional limit for the scrollback size. When reaching it remove - * 10% at the start. */ #include "vim.h" @@ -227,8 +223,8 @@ set_term_and_win_size(term_T *term) * at the command line and scroll up as needed, using tl_toprow. */ term->tl_rows = Rows; term->tl_cols = Columns; + return; } - else #endif if (*curwin->w_p_tms != NUL) { @@ -3148,6 +3144,75 @@ init_default_colors(term_T *term) } } +#if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) +/* + * Set the 16 ANSI colors from array of RGB values + */ + static void +set_vterm_palette(VTerm *vterm, long_u *rgb) +{ + int index = 0; + VTermState *state = vterm_obtain_state(vterm); + for (; index < 16; index++) + { + VTermColor color; + color.red = (unsigned)(rgb[index] >> 16); + color.green = (unsigned)(rgb[index] >> 8) & 255; + color.blue = (unsigned)rgb[index] & 255; + vterm_state_set_palette_color(state, index, &color); + } +} + +/* + * Set the ANSI color palette from a list of colors + */ + static int +set_ansi_colors_list(VTerm *vterm, list_T *list) +{ + int n = 0; + long_u rgb[16]; + listitem_T *li = list->lv_first; + + for (; li != NULL && n < 16; li = li->li_next, n++) + { + char_u *color_name; + guicolor_T guicolor; + + color_name = get_tv_string_chk(&li->li_tv); + if (color_name == NULL) + return FAIL; + + guicolor = GUI_GET_COLOR(color_name); + if (guicolor == INVALCOLOR) + return FAIL; + + rgb[n] = GUI_MCH_GET_RGB(guicolor); + } + + if (n != 16 || li != NULL) + return FAIL; + + set_vterm_palette(vterm, rgb); + + return OK; +} + +/* + * Initialize the ANSI color palette from g:terminal_ansi_colors[0:15] + */ + static void +init_vterm_ansi_colors(VTerm *vterm) +{ + dictitem_T *var = find_var((char_u *)"g:terminal_ansi_colors", NULL, TRUE); + + if (var != NULL + && (var->di_tv.v_type != VAR_LIST + || var->di_tv.vval.v_list == NULL + || set_ansi_colors_list(vterm, var->di_tv.vval.v_list) == FAIL)) + EMSG2(_(e_invarg2), "g:terminal_ansi_colors"); +} +#endif + /* * Handles a "drop" command from the job in the terminal. * "item" is the file name, "item->li_next" may have options. @@ -3334,6 +3399,26 @@ static VTermParserCallbacks parser_fallbacks = { NULL /* resize */ }; +/* + * Use Vim's allocation functions for vterm so profiling works. + */ + static void * +vterm_malloc(size_t size, void *data UNUSED) +{ + return alloc_clear((unsigned) size); +} + + static void +vterm_memfree(void *ptr, void *data UNUSED) +{ + vim_free(ptr); +} + +static VTermAllocatorFunctions vterm_allocator = { + &vterm_malloc, + &vterm_memfree +}; + /* * Create a new vterm and initialize it. */ @@ -3345,7 +3430,7 @@ create_vterm(term_T *term, int rows, int cols) VTermState *state; VTermValue value; - vterm = vterm_new(rows, cols); + vterm = vterm_new_with_allocator(rows, cols, &vterm_allocator, NULL); term->tl_vterm = vterm; screen = vterm_obtain_screen(vterm); vterm_screen_set_callbacks(screen, &screen_callbacks, term); @@ -3359,6 +3444,9 @@ create_vterm(term_T *term, int rows, int cols) &term->tl_default_color.fg, &term->tl_default_color.bg); + if (t_colors >= 16) + vterm_state_set_bold_highbright(vterm_obtain_state(vterm), 1); + /* Required to initialize most things. */ vterm_screen_reset(screen, 1 /* hard */); @@ -3933,9 +4021,9 @@ get_separator(int text_width, char_u *fname) int fname_size; char_u *p = fname; int i; - int off; + size_t off; - textline = alloc(width + STRLEN(fname) + 1); + textline = alloc(width + (int)STRLEN(fname) + 1); if (textline == NULL) return NULL; @@ -4749,6 +4837,68 @@ f_term_sendkeys(typval_T *argvars, typval_T *rettv) } } +#if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) || defined(PROTO) +/* + * "term_getansicolors(buf)" function + */ + void +f_term_getansicolors(typval_T *argvars, typval_T *rettv) +{ + buf_T *buf = term_get_buf(argvars, "term_getansicolors()"); + term_T *term; + VTermState *state; + VTermColor color; + char_u hexbuf[10]; + int index; + list_T *list; + + if (rettv_list_alloc(rettv) == FAIL) + return; + + if (buf == NULL) + return; + term = buf->b_term; + if (term->tl_vterm == NULL) + return; + + list = rettv->vval.v_list; + state = vterm_obtain_state(term->tl_vterm); + for (index = 0; index < 16; index++) + { + vterm_state_get_palette_color(state, index, &color); + sprintf((char *)hexbuf, "#%02x%02x%02x", + color.red, color.green, color.blue); + if (list_append_string(list, hexbuf, 7) == FAIL) + return; + } +} + +/* + * "term_setansicolors(buf, list)" function + */ + void +f_term_setansicolors(typval_T *argvars, typval_T *rettv UNUSED) +{ + buf_T *buf = term_get_buf(argvars, "term_setansicolors()"); + term_T *term; + + if (buf == NULL) + return; + term = buf->b_term; + if (term->tl_vterm == NULL) + return; + + if (argvars[1].v_type != VAR_LIST || argvars[1].vval.v_list == NULL) + { + EMSG(_(e_listreq)); + return; + } + + if (set_ansi_colors_list(term->tl_vterm, argvars[1].vval.v_list) == FAIL) + EMSG(_(e_invarg)); +} +#endif + /* * "term_setrestore(buf, command)" function */ @@ -4811,7 +4961,8 @@ f_term_start(typval_T *argvars, typval_T *rettv) JO2_TERM_NAME + JO2_TERM_FINISH + JO2_HIDDEN + JO2_TERM_OPENCMD + JO2_TERM_COLS + JO2_TERM_ROWS + JO2_VERTICAL + JO2_CURWIN + JO2_CWD + JO2_ENV + JO2_EOF_CHARS - + JO2_NORESTORE + JO2_TERM_KILL) == FAIL) + + JO2_NORESTORE + JO2_TERM_KILL + + JO2_ANSI_COLORS) == FAIL) return; buf = term_start(&argvars[0], NULL, &opt, 0); @@ -5139,6 +5290,13 @@ term_and_job_init( create_vterm(term, term->tl_rows, term->tl_cols); +#if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) + if (opt->jo_set2 & JO2_ANSI_COLORS) + set_vterm_palette(term->tl_vterm, opt->jo_ansi_colors); + else + init_vterm_ansi_colors(term->tl_vterm); +#endif + channel_set_job(channel, job, opt); job_set_options(job, opt); @@ -5311,6 +5469,13 @@ term_and_job_init( { create_vterm(term, term->tl_rows, term->tl_cols); +#if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) + if (opt->jo_set2 & JO2_ANSI_COLORS) + set_vterm_palette(term->tl_vterm, opt->jo_ansi_colors); + else + init_vterm_ansi_colors(term->tl_vterm); +#endif + /* This may change a string in "argvar". */ term->tl_job = job_start(argvar, argv, opt); if (term->tl_job != NULL) diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak index 159bf1ece6..e36089af87 100644 --- a/src/testdir/Make_all.mak +++ b/src/testdir/Make_all.mak @@ -72,6 +72,7 @@ NEW_TESTS = test_arabic.res \ test_autocmd.res \ test_autoload.res \ test_backspace_opt.res \ + test_blockedit.res \ test_breakindent.res \ test_bufwintabinfo.res \ test_cdo.res \ @@ -187,6 +188,7 @@ NEW_TESTS = test_arabic.res \ test_windows_home.res \ test_wordcount.res \ test_writefile.res \ + test_xxd.res \ test_alot_latin.res \ test_alot_utf8.res \ test_alot.res diff --git a/src/testdir/Makefile b/src/testdir/Makefile index 90e0cdb2d6..459b868783 100644 --- a/src/testdir/Makefile +++ b/src/testdir/Makefile @@ -4,6 +4,7 @@ # Use console or GUI. VIMPROG = ../vim +XXDPROG = ../xxd/xxd # VIMPROG = ../gvim SCRIPTSOURCE = ../../runtime @@ -145,3 +146,6 @@ test_gui_init.res: test_gui_init.vim opt_test.vim: ../option.c gen_opt_test.vim $(VIMPROG) -u NONE -S gen_opt_test.vim --noplugin --not-a-term ../option.c + +test_xxd.res: + XXD=$(XXDPROG); export XXD; $(RUN_VIMTEST) $(NO_INITS) -S runtest.vim test_xxd.vim diff --git a/src/testdir/runtest.vim b/src/testdir/runtest.vim index 3a32f4582b..5b8126d5d1 100644 --- a/src/testdir/runtest.vim +++ b/src/testdir/runtest.vim @@ -199,7 +199,11 @@ func FinishTesting() write endif - let message = 'Executed ' . s:done . (s:done > 1 ? ' tests' : ' test') + if s:done == 0 + let message = 'NO tests executed' + else + let message = 'Executed ' . s:done . (s:done > 1 ? ' tests' : ' test') + endif echo message call add(s:messages, message) if s:fail > 0 diff --git a/src/testdir/screendump.vim b/src/testdir/screendump.vim index 764345a98c..e1e660b373 100644 --- a/src/testdir/screendump.vim +++ b/src/testdir/screendump.vim @@ -70,7 +70,7 @@ endfunc func StopVimInTerminal(buf) call assert_equal("running", term_getstatus(a:buf)) call term_sendkeys(a:buf, "\\:qa!\") - call WaitFor('term_getstatus(' . a:buf . ') == "finished"') + call WaitFor('term_getstatus(' . a:buf . ') == "finished"', 3000) only! endfunc diff --git a/src/testdir/test_blockedit.vim b/src/testdir/test_blockedit.vim new file mode 100644 index 0000000000..4a8d59952e --- /dev/null +++ b/src/testdir/test_blockedit.vim @@ -0,0 +1,20 @@ +" Test for block inserting +" +" TODO: rewrite test39.in into this new style test + +func Test_blockinsert_indent() + new + filetype plugin indent on + setlocal sw=2 et ft=vim + call setline(1, ['let a=[', ' ''eins'',', ' ''zwei'',', ' ''drei'']']) + call cursor(2, 3) + exe "norm! \2jI\\ \" + call assert_equal(['let a=[', ' \ ''eins'',', ' \ ''zwei'',', ' \ ''drei'']'], + \ getline(1,'$')) + " reset to sane state + filetype off + bwipe! +endfunc + + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_terminal.vim b/src/testdir/test_terminal.vim index 8df2ce545b..40b83ac486 100644 --- a/src/testdir/test_terminal.vim +++ b/src/testdir/test_terminal.vim @@ -1265,3 +1265,73 @@ func Test_terminal_api_call_fails() call ch_logfile('', '') call delete('Xlog') endfunc + +func Test_terminal_ansicolors_default() + let colors = [ + \ '#000000', '#e00000', + \ '#00e000', '#e0e000', + \ '#0000e0', '#e000e0', + \ '#00e0e0', '#e0e0e0', + \ '#808080', '#ff4040', + \ '#40ff40', '#ffff40', + \ '#4040ff', '#ff40ff', + \ '#40ffff', '#ffffff', + \] + + let buf = Run_shell_in_terminal({}) + call assert_equal(colors, term_getansicolors(buf)) + call Stop_shell_in_terminal(buf) + call term_wait(buf) + + exe buf . 'bwipe' +endfunc + +let s:test_colors = [ + \ '#616e64', '#0d0a79', + \ '#6d610d', '#0a7373', + \ '#690d0a', '#6d696e', + \ '#0d0a6f', '#616e0d', + \ '#0a6479', '#6d0d0a', + \ '#617373', '#0d0a69', + \ '#6d690d', '#0a6e6f', + \ '#610d0a', '#6e6479', + \] + +func Test_terminal_ansicolors_global() + let g:terminal_ansi_colors = reverse(copy(s:test_colors)) + let buf = Run_shell_in_terminal({}) + call assert_equal(g:terminal_ansi_colors, term_getansicolors(buf)) + call Stop_shell_in_terminal(buf) + call term_wait(buf) + + exe buf . 'bwipe' + unlet g:terminal_ansi_colors +endfunc + +func Test_terminal_ansicolors_func() + let g:terminal_ansi_colors = reverse(copy(s:test_colors)) + let buf = Run_shell_in_terminal({'ansi_colors': s:test_colors}) + call assert_equal(s:test_colors, term_getansicolors(buf)) + + call term_setansicolors(buf, g:terminal_ansi_colors) + call assert_equal(g:terminal_ansi_colors, term_getansicolors(buf)) + + let colors = [ + \ 'ivory', 'AliceBlue', + \ 'grey67', 'dark goldenrod', + \ 'SteelBlue3', 'PaleVioletRed4', + \ 'MediumPurple2', 'yellow2', + \ 'RosyBrown3', 'OrangeRed2', + \ 'white smoke', 'navy blue', + \ 'grey47', 'gray97', + \ 'MistyRose2', 'DodgerBlue4', + \] + call term_setansicolors(buf, colors) + + let colors[4] = 'Invalid' + call assert_fails('call term_setansicolors(buf, colors)', 'E474:') + + call Stop_shell_in_terminal(buf) + call term_wait(buf) + exe buf . 'bwipe' +endfunc diff --git a/src/testdir/test_xxd.vim b/src/testdir/test_xxd.vim new file mode 100644 index 0000000000..0ddcff0366 --- /dev/null +++ b/src/testdir/test_xxd.vim @@ -0,0 +1,111 @@ +" Test for the xxd command +if empty($XXD) && executable('..\xxd\xxd.exe') + let s:xxd_cmd = '..\xxd\xxd.exe' +elseif empty($XXD) || !executable($XXD) + finish +else + let s:xxd_cmd = $XXD +endif + +func! PrepareBuffer(lines) + new + call append(0, a:lines) + $d +endfunc + +func! s:Mess(counter) + return printf("Failed xxd test %d:", a:counter) +endfunc + +func! Test_xxd() + call PrepareBuffer(range(1,30)) + set ff=unix + w XXDfile + + " Test 1: simple, filter the result through xxd + let s:test = 1 + exe '%!' . s:xxd_cmd . ' %' + let expected = [ + \ '00000000: 310a 320a 330a 340a 350a 360a 370a 380a 1.2.3.4.5.6.7.8.', + \ '00000010: 390a 3130 0a31 310a 3132 0a31 330a 3134 9.10.11.12.13.14', + \ '00000020: 0a31 350a 3136 0a31 370a 3138 0a31 390a .15.16.17.18.19.', + \ '00000030: 3230 0a32 310a 3232 0a32 330a 3234 0a32 20.21.22.23.24.2', + \ '00000040: 350a 3236 0a32 370a 3238 0a32 390a 3330 5.26.27.28.29.30', + \ '00000050: 0a .'] + call assert_equal(expected, getline(1,'$'), s:Mess(s:test)) + + " Test 2: reverse the result + let s:test += 1 + exe '%!' . s:xxd_cmd . ' -r' + call assert_equal(map(range(1,30), {v,c -> string(c)}), getline(1,'$'), s:Mess(s:test)) + + " Test 3: Skip the first 30 bytes + let s:test += 1 + exe '%!' . s:xxd_cmd . ' -s 0x30 %' + call assert_equal(expected[3:], getline(1,'$'), s:Mess(s:test)) + + " Test 4: Skip the first 30 bytes + let s:test += 1 + exe '%!' . s:xxd_cmd . ' -s -0x31 %' + call assert_equal(expected[2:], getline(1,'$'), s:Mess(s:test)) + + " Test 5: Print 120 bytes as continuous hexdump with 20 octets per line + let s:test += 1 + %d + exe '0r! ' . s:xxd_cmd . ' -l 120 -ps -c 20 ../../runtime/doc/xxd.1' + $d + let expected = [ + \ '2e54482058584420312022417567757374203139', + \ '39362220224d616e75616c207061676520666f72', + \ '20787864220a2e5c220a2e5c222032317374204d', + \ '617920313939360a2e5c22204d616e2070616765', + \ '20617574686f723a0a2e5c2220202020546f6e79', + \ '204e7567656e74203c746f6e79407363746e7567'] + call assert_equal(expected, getline(1,'$'), s:Mess(s:test)) + + " Test 6: Print the date from xxd.1 + let s:test += 1 + %d + exe '0r! ' . s:xxd_cmd . ' -s 0x36 -l 13 -c 13 ../../runtime/doc/xxd.1' + $d + call assert_equal('00000036: 3231 7374 204d 6179 2031 3939 36 21st May 1996', getline(1), s:Mess(s:test)) + + " Test 7: Print C include + let s:test += 1 + call writefile(['TESTabcd09'], 'XXDfile') + %d + exe '0r! ' . s:xxd_cmd . ' -i XXDfile' + $d + let expected = ['unsigned char XXDfile[] = {', + \ ' 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a', '};', + \ 'unsigned int XXDfile_len = 11;'] + call assert_equal(expected, getline(1,'$'), s:Mess(s:test)) + + " Test 8: Print C include capitalized + let s:test += 1 + call writefile(['TESTabcd09'], 'XXDfile') + %d + exe '0r! ' . s:xxd_cmd . ' -i -C XXDfile' + $d + let expected = ['unsigned char XXDFILE[] = {', + \ ' 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a', '};', + \ 'unsigned int XXDFILE_LEN = 11;'] + call assert_equal(expected, getline(1,'$'), s:Mess(s:test)) + + " Test 9: Create a file with containing a single 'A' + let s:test += 1 + call delete('XXDfile') + bwipe! XXDfile + if has('unix') + call system('echo "010000: 41"|' . s:xxd_cmd . ' -r -s -0x10000 > XXDfile') + else + call writefile(['010000: 41'], 'Xinput') + silent exe '!' . s:xxd_cmd . ' -r -s -0x10000 < Xinput > XXDfile' + call delete('Xinput') + endif + call PrepareBuffer(readfile('XXDfile')[0]) + call assert_equal('A', getline(1), s:Mess(s:test)) + call delete('XXDfile') + %d + bw! +endfunc diff --git a/src/version.c b/src/version.c index 95b0a63794..a97108cf3f 100644 --- a/src/version.c +++ b/src/version.c @@ -777,6 +777,38 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1695, +/**/ + 1694, +/**/ + 1693, +/**/ + 1692, +/**/ + 1691, +/**/ + 1690, +/**/ + 1689, +/**/ + 1688, +/**/ + 1687, +/**/ + 1686, +/**/ + 1685, +/**/ + 1684, +/**/ + 1683, +/**/ + 1682, +/**/ + 1681, +/**/ + 1680, /**/ 1679, /**/ diff --git a/src/vim.h b/src/vim.h index a730b88ebe..047c2bcc4e 100644 --- a/src/vim.h +++ b/src/vim.h @@ -2087,6 +2087,10 @@ typedef struct _stat64 stat_T; typedef struct stat stat_T; #endif +#if defined(__GNUC__) && !defined(__MINGW32__) +# define USE_PRINTF_FORMAT_ATTRIBUTE +#endif + typedef enum { ASSERT_EQUAL, diff --git a/src/window.c b/src/window.c index 7a8060e038..b05c1acbe5 100644 --- a/src/window.c +++ b/src/window.c @@ -99,9 +99,16 @@ do_window( Prenum1 = Prenum; #ifdef FEAT_CMDWIN -# define CHECK_CMDWIN if (cmdwin_type != 0) { EMSG(_(e_cmdwin)); break; } +# define CHECK_CMDWIN \ + do { \ + if (cmdwin_type != 0) \ + { \ + EMSG(_(e_cmdwin)); \ + return; \ + } \ + } while (0) #else -# define CHECK_CMDWIN +# define CHECK_CMDWIN do { /**/ } while (0) #endif switch (nchar) @@ -110,7 +117,7 @@ do_window( case 'S': case Ctrl_S: case 's': - CHECK_CMDWIN + CHECK_CMDWIN; reset_VIsual_and_resel(); /* stop Visual mode */ #ifdef FEAT_QUICKFIX /* When splitting the quickfix window open a new buffer in it, @@ -127,7 +134,7 @@ do_window( /* split current window in two parts, vertically */ case Ctrl_V: case 'v': - CHECK_CMDWIN + CHECK_CMDWIN; reset_VIsual_and_resel(); /* stop Visual mode */ #ifdef FEAT_QUICKFIX /* When splitting the quickfix window open a new buffer in it, @@ -144,7 +151,7 @@ do_window( /* split current window and edit alternate file */ case Ctrl_HAT: case '^': - CHECK_CMDWIN + CHECK_CMDWIN; reset_VIsual_and_resel(); /* stop Visual mode */ cmd_with_count("split #", cbuf, sizeof(cbuf), Prenum); do_cmdline_cmd(cbuf); @@ -153,7 +160,7 @@ do_window( /* open new window */ case Ctrl_N: case 'n': - CHECK_CMDWIN + CHECK_CMDWIN; reset_VIsual_and_resel(); /* stop Visual mode */ #ifdef FEAT_QUICKFIX newwindow: @@ -191,7 +198,7 @@ newwindow: /* close preview window */ case Ctrl_Z: case 'z': - CHECK_CMDWIN + CHECK_CMDWIN; reset_VIsual_and_resel(); /* stop Visual mode */ do_cmdline_cmd((char_u *)"pclose"); break; @@ -211,7 +218,7 @@ newwindow: /* close all but current window */ case Ctrl_O: case 'o': - CHECK_CMDWIN + CHECK_CMDWIN; reset_VIsual_and_resel(); /* stop Visual mode */ cmd_with_count("only", cbuf, sizeof(cbuf), Prenum); do_cmdline_cmd(cbuf); @@ -222,7 +229,7 @@ newwindow: case 'w': /* cursor to previous window with wrap around */ case 'W': - CHECK_CMDWIN + CHECK_CMDWIN; if (ONE_WINDOW && Prenum != 1) /* just one window */ beep_flush(); else @@ -260,7 +267,7 @@ newwindow: case 'j': case K_DOWN: case Ctrl_J: - CHECK_CMDWIN + CHECK_CMDWIN; win_goto_ver(FALSE, Prenum1); break; @@ -268,7 +275,7 @@ newwindow: case 'k': case K_UP: case Ctrl_K: - CHECK_CMDWIN + CHECK_CMDWIN; win_goto_ver(TRUE, Prenum1); break; @@ -277,7 +284,7 @@ newwindow: case K_LEFT: case Ctrl_H: case K_BS: - CHECK_CMDWIN + CHECK_CMDWIN; win_goto_hor(TRUE, Prenum1); break; @@ -285,7 +292,7 @@ newwindow: case 'l': case K_RIGHT: case Ctrl_L: - CHECK_CMDWIN + CHECK_CMDWIN; win_goto_hor(FALSE, Prenum1); break; @@ -338,21 +345,21 @@ newwindow: /* exchange current and next window */ case 'x': case Ctrl_X: - CHECK_CMDWIN + CHECK_CMDWIN; win_exchange(Prenum); break; /* rotate windows downwards */ case Ctrl_R: case 'r': - CHECK_CMDWIN + CHECK_CMDWIN; reset_VIsual_and_resel(); /* stop Visual mode */ win_rotate(FALSE, (int)Prenum1); /* downwards */ break; /* rotate windows upwards */ case 'R': - CHECK_CMDWIN + CHECK_CMDWIN; reset_VIsual_and_resel(); /* stop Visual mode */ win_rotate(TRUE, (int)Prenum1); /* upwards */ break; @@ -362,7 +369,7 @@ newwindow: case 'J': case 'H': case 'L': - CHECK_CMDWIN + CHECK_CMDWIN; win_totop((int)Prenum, ((nchar == 'H' || nchar == 'L') ? WSP_VERT : 0) | ((nchar == 'H' || nchar == 'K') ? WSP_TOP : WSP_BOT)); @@ -428,7 +435,7 @@ newwindow: /* jump to tag and split window if tag exists (in preview window) */ #if defined(FEAT_QUICKFIX) case '}': - CHECK_CMDWIN + CHECK_CMDWIN; if (Prenum) g_do_tagpreview = Prenum; else @@ -437,7 +444,7 @@ newwindow: /* FALLTHROUGH */ case ']': case Ctrl_RSB: - CHECK_CMDWIN + CHECK_CMDWIN; /* keep Visual mode, can select words to use as a tag */ if (Prenum) postponed_split = Prenum; @@ -459,7 +466,7 @@ newwindow: case 'F': case Ctrl_F: wingotofile: - CHECK_CMDWIN + CHECK_CMDWIN; ptr = grab_file_name(Prenum1, &lnum); if (ptr != NULL) @@ -503,7 +510,7 @@ wingotofile: /* FALLTHROUGH */ case 'd': /* Go to definition, using 'define' */ case Ctrl_D: - CHECK_CMDWIN + CHECK_CMDWIN; if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0) break; find_pattern_in_path(ptr, 0, len, TRUE, @@ -534,7 +541,7 @@ wingotofile: /* CTRL-W g extended commands */ case 'g': case Ctrl_G: - CHECK_CMDWIN + CHECK_CMDWIN; #ifdef USE_ON_FLY_SCROLL dont_scroll = TRUE; /* disallow scrolling here */ #endif @@ -4278,9 +4285,9 @@ win_enter_ext( win_T *wp, int undo_sync, int curwin_invalid, - int trigger_new_autocmds UNUSED, - int trigger_enter_autocmds UNUSED, - int trigger_leave_autocmds UNUSED) + int trigger_new_autocmds, + int trigger_enter_autocmds, + int trigger_leave_autocmds) { int other_buffer = FALSE; @@ -4390,7 +4397,7 @@ win_enter_ext( #endif /* Change directories when the 'acd' option is set. */ - DO_AUTOCHDIR + DO_AUTOCHDIR; }