From c207fd2535717030d78f9b92839e5f2ac004cc78 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 29 Jun 2022 10:37:40 +0100 Subject: [PATCH 1/8] patch 9.0.0002: map functionality outside of map.c Problem: Map functionality outside of map.c. Solution: Move f_hasmapto() to map.c. Rename a function. (closes #10611) --- src/buffer.c | 4 ++-- src/evalfunc.c | 35 ----------------------------------- src/map.c | 44 +++++++++++++++++++++++++++++++++++++++----- src/proto/map.pro | 3 ++- src/version.c | 2 ++ 5 files changed, 45 insertions(+), 43 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index e775398d02..bbbfdb7814 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1004,8 +1004,8 @@ free_buffer_stuff( #ifdef FEAT_NETBEANS_INTG netbeans_file_killed(buf); #endif - map_clear_int(buf, MAP_ALL_MODES, TRUE, FALSE); // clear local mappings - map_clear_int(buf, MAP_ALL_MODES, TRUE, TRUE); // clear local abbrevs + map_clear_mode(buf, MAP_ALL_MODES, TRUE, FALSE); // clear local mappings + map_clear_mode(buf, MAP_ALL_MODES, TRUE, TRUE); // clear local abbrevs VIM_CLEAR(buf->b_start_fenc); } diff --git a/src/evalfunc.c b/src/evalfunc.c index cb12a46c3f..0b8fd43966 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -75,7 +75,6 @@ static void f_getregtype(typval_T *argvars, typval_T *rettv); static void f_gettagstack(typval_T *argvars, typval_T *rettv); static void f_gettext(typval_T *argvars, typval_T *rettv); static void f_haslocaldir(typval_T *argvars, typval_T *rettv); -static void f_hasmapto(typval_T *argvars, typval_T *rettv); static void f_hlID(typval_T *argvars, typval_T *rettv); static void f_hlexists(typval_T *argvars, typval_T *rettv); static void f_hostname(typval_T *argvars, typval_T *rettv); @@ -6653,40 +6652,6 @@ f_haslocaldir(typval_T *argvars, typval_T *rettv) rettv->vval.v_number = 0; } -/* - * "hasmapto()" function - */ - static void -f_hasmapto(typval_T *argvars, typval_T *rettv) -{ - char_u *name; - char_u *mode; - char_u buf[NUMBUFLEN]; - int abbr = FALSE; - - if (in_vim9script() - && (check_for_string_arg(argvars, 0) == FAIL - || check_for_opt_string_arg(argvars, 1) == FAIL - || (argvars[1].v_type != VAR_UNKNOWN - && check_for_opt_bool_arg(argvars, 2) == FAIL))) - return; - - name = tv_get_string(&argvars[0]); - if (argvars[1].v_type == VAR_UNKNOWN) - mode = (char_u *)"nvo"; - else - { - mode = tv_get_string_buf(&argvars[1], buf); - if (argvars[2].v_type != VAR_UNKNOWN) - abbr = (int)tv_get_bool(&argvars[2]); - } - - if (map_to_exists(name, mode, abbr)) - rettv->vval.v_number = TRUE; - else - rettv->vval.v_number = FALSE; -} - /* * "highlightID(name)" function */ diff --git a/src/map.c b/src/map.c index 2850a3fe24..ff4c4968da 100644 --- a/src/map.c +++ b/src/map.c @@ -908,13 +908,13 @@ get_map_mode(char_u **cmdp, int forceit) } /* - * Clear all mappings or abbreviations. - * 'abbr' should be FALSE for mappings, TRUE for abbreviations. + * Clear all mappings (":mapclear") or abbreviations (":abclear"). + * "abbr" should be FALSE for mappings, TRUE for abbreviations. */ static void map_clear( char_u *cmdp, - char_u *arg UNUSED, + char_u *arg, int forceit, int abbr) { @@ -929,14 +929,14 @@ map_clear( } mode = get_map_mode(&cmdp, forceit); - map_clear_int(curbuf, mode, local, abbr); + map_clear_mode(curbuf, mode, local, abbr); } /* * Clear all mappings in "mode". */ void -map_clear_int( +map_clear_mode( buf_T *buf, // buffer for local mappings int mode, // mode in which to delete int local, // TRUE for buffer-local mappings @@ -2272,6 +2272,40 @@ check_map( return NULL; } +/* + * "hasmapto()" function + */ + void +f_hasmapto(typval_T *argvars, typval_T *rettv) +{ + char_u *name; + char_u *mode; + char_u buf[NUMBUFLEN]; + int abbr = FALSE; + + if (in_vim9script() + && (check_for_string_arg(argvars, 0) == FAIL + || check_for_opt_string_arg(argvars, 1) == FAIL + || (argvars[1].v_type != VAR_UNKNOWN + && check_for_opt_bool_arg(argvars, 2) == FAIL))) + return; + + name = tv_get_string(&argvars[0]); + if (argvars[1].v_type == VAR_UNKNOWN) + mode = (char_u *)"nvo"; + else + { + mode = tv_get_string_buf(&argvars[1], buf); + if (argvars[2].v_type != VAR_UNKNOWN) + abbr = (int)tv_get_bool(&argvars[2]); + } + + if (map_to_exists(name, mode, abbr)) + rettv->vval.v_number = TRUE; + else + rettv->vval.v_number = FALSE; +} + /* * Fill in the empty dictionary with items as defined by maparg builtin. */ diff --git a/src/proto/map.pro b/src/proto/map.pro index 5caa859214..1ed088dc64 100644 --- a/src/proto/map.pro +++ b/src/proto/map.pro @@ -3,7 +3,7 @@ mapblock_T *get_maphash_list(int state, int c); mapblock_T *get_buf_maphash_list(int state, int c); int is_maphash_valid(void); int do_map(int maptype, char_u *arg, int mode, int abbrev); -void map_clear_int(buf_T *buf, int mode, int local, int abbr); +void map_clear_mode(buf_T *buf, int mode, int local, int abbr); int mode_str2flags(char_u *modechars); int map_to_exists(char_u *str, char_u *modechars, int abbr); int map_to_exists_mode(char_u *rhs, int mode, int abbr); @@ -17,6 +17,7 @@ int makemap(FILE *fd, buf_T *buf); int put_escstr(FILE *fd, char_u *strstart, int what); void check_map_keycodes(void); char_u *check_map(char_u *keys, int mode, int exact, int ign_mod, int abbr, mapblock_T **mp_ptr, int *local_ptr); +void f_hasmapto(typval_T *argvars, typval_T *rettv); void f_maplist(typval_T *argvars, typval_T *rettv); void f_maparg(typval_T *argvars, typval_T *rettv); void f_mapcheck(typval_T *argvars, typval_T *rettv); diff --git a/src/version.c b/src/version.c index 30abf3488d..74e080ff39 100644 --- a/src/version.c +++ b/src/version.c @@ -735,6 +735,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 2, /**/ 1, /**/ From ee47eaceaa148e07b566ff420f9a3c2edde2fa34 Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Wed, 29 Jun 2022 12:55:36 +0100 Subject: [PATCH 2/8] patch 9.0.0003: functions are global while they could be local Problem: Functions are global while they could be local. Solution: Add "static". Add a few tests. (Yegappan Lakshmanan, closes #10612) --- src/crypt.c | 10 +++++++--- src/evalvars.c | 2 +- src/gui.c | 5 +++-- src/highlight.c | 2 +- src/proto/crypt.pro | 3 --- src/proto/evalvars.pro | 1 - src/proto/gui.pro | 2 -- src/proto/highlight.pro | 1 - src/proto/scriptfile.pro | 1 - src/proto/userfunc.pro | 1 - src/scriptfile.c | 2 +- src/testdir/test_fold.vim | 2 ++ src/testdir/test_quickfix.vim | 7 +++++-- src/testdir/test_vim9_builtin.vim | 16 ++++++++++++++++ src/userfunc.c | 3 ++- src/version.c | 2 ++ 16 files changed, 40 insertions(+), 20 deletions(-) diff --git a/src/crypt.c b/src/crypt.c index bed76a96d4..b2b50d4632 100644 --- a/src/crypt.c +++ b/src/crypt.c @@ -73,6 +73,10 @@ typedef struct { char_u *p2, int last); } cryptmethod_T; +static int crypt_sodium_init(cryptstate_T *state, char_u *key, char_u *salt, int salt_len, char_u *seed, int seed_len); +static long crypt_sodium_buffer_decode(cryptstate_T *state, char_u *from, size_t len, char_u **buf_out, int last); +static long crypt_sodium_buffer_encode(cryptstate_T *state, char_u *from, size_t len, char_u **buf_out, int last); + // index is method_nr of cryptstate_T, CRYPT_M_* static cryptmethod_T cryptmethods[CRYPT_M_COUNT] = { // PK_Zip; very weak @@ -850,7 +854,7 @@ crypt_append_msg( } } - int + static int crypt_sodium_init( cryptstate_T *state UNUSED, char_u *key UNUSED, @@ -1030,7 +1034,7 @@ fail: * Encrypt "from[len]" into "to[len]". * "from" and "to" can be equal to encrypt in place. */ - long + static long crypt_sodium_buffer_encode( cryptstate_T *state UNUSED, char_u *from UNUSED, @@ -1080,7 +1084,7 @@ crypt_sodium_buffer_encode( * Decrypt "from[len]" into "to[len]". * "from" and "to" can be equal to encrypt in place. */ - long + static long crypt_sodium_buffer_decode( cryptstate_T *state UNUSED, char_u *from UNUSED, diff --git a/src/evalvars.c b/src/evalvars.c index f7939cbb7a..779627c45a 100644 --- a/src/evalvars.c +++ b/src/evalvars.c @@ -648,7 +648,7 @@ eval_one_expr_in_str(char_u *p, garray_T *gap, int evaluate) * Used for a heredoc assignment. * Returns NULL for an error. */ - char_u * + static char_u * eval_all_expr_in_str(char_u *str) { garray_T ga; diff --git a/src/gui.c b/src/gui.c index 4408545db3..e708a27763 100644 --- a/src/gui.c +++ b/src/gui.c @@ -32,6 +32,7 @@ static void gui_do_scrollbar(win_T *wp, int which, int enable); static void gui_update_horiz_scrollbar(int); static void gui_set_fg_color(char_u *name); static void gui_set_bg_color(char_u *name); +static void init_gui_options(void); static win_T *xy2win(int x, int y, mouse_find_T popup); #ifdef GUI_MAY_FORK @@ -1395,7 +1396,7 @@ gui_update_cursor( } #if defined(FEAT_MENU) || defined(PROTO) - void + static void gui_position_menu(void) { # if !defined(FEAT_GUI_GTK) && !defined(FEAT_GUI_MOTIF) @@ -4815,7 +4816,7 @@ gui_bg_default(void) /* * Option initializations that can only be done after opening the GUI window. */ - void + static void init_gui_options(void) { // Set the 'background' option according to the lightness of the diff --git a/src/highlight.c b/src/highlight.c index 75a310f53e..bf876d16f1 100644 --- a/src/highlight.c +++ b/src/highlight.c @@ -566,7 +566,7 @@ static int color_numbers_8[28] = {0, 4, 2, 6, * "boldp" will be set to TRUE or FALSE for a foreground color when using 8 * colors, otherwise it will be unchanged. */ - int + static int lookup_color(int idx, int foreground, int *boldp) { int color = color_numbers_16[idx]; diff --git a/src/proto/crypt.pro b/src/proto/crypt.pro index d6c7b7ffde..7913694912 100644 --- a/src/proto/crypt.pro +++ b/src/proto/crypt.pro @@ -24,9 +24,6 @@ void crypt_check_method(int method); void crypt_check_current_method(void); char_u *crypt_get_key(int store, int twice); void crypt_append_msg(buf_T *buf); -int crypt_sodium_init(cryptstate_T *state, char_u *key, char_u *salt, int salt_len, char_u *seed, int seed_len); -long crypt_sodium_buffer_encode(cryptstate_T *state, char_u *from, size_t len, char_u **buf_out, int last); -long crypt_sodium_buffer_decode(cryptstate_T *state, char_u *from, size_t len, char_u **buf_out, int last); int crypt_sodium_munlock(void *const addr, const size_t len); void crypt_sodium_randombytes_buf(void *const buf, const size_t size); /* vim: set ft=c : */ diff --git a/src/proto/evalvars.pro b/src/proto/evalvars.pro index 4683c15ffa..253af6de6c 100644 --- a/src/proto/evalvars.pro +++ b/src/proto/evalvars.pro @@ -14,7 +14,6 @@ int get_spellword(list_T *list, char_u **pp); void prepare_vimvar(int idx, typval_T *save_tv); void restore_vimvar(int idx, typval_T *save_tv); char_u *eval_one_expr_in_str(char_u *p, garray_T *gap, int evaluate); -char_u *eval_all_expr_in_str(char_u *str); list_T *heredoc_get(exarg_T *eap, char_u *cmd, int script_get, int vim9compile); void ex_var(exarg_T *eap); void ex_let(exarg_T *eap); diff --git a/src/proto/gui.pro b/src/proto/gui.pro index 2a0ac806f0..1a04248447 100644 --- a/src/proto/gui.pro +++ b/src/proto/gui.pro @@ -9,7 +9,6 @@ int gui_init_font(char_u *font_list, int fontset); int gui_get_wide_font(void); void gui_set_ligatures(void); void gui_update_cursor(int force, int clear_selection); -void gui_position_menu(void); int gui_get_base_width(void); int gui_get_base_height(void); void gui_resize_shell(int pixel_width, int pixel_height); @@ -51,7 +50,6 @@ void gui_check_colors(void); guicolor_T gui_get_color(char_u *name); int gui_get_lightness(guicolor_T pixel); char_u *gui_bg_default(void); -void init_gui_options(void); void gui_new_scrollbar_colors(void); void gui_focus_change(int in_focus); void gui_mouse_moved(int x, int y); diff --git a/src/proto/highlight.pro b/src/proto/highlight.pro index 5635a17384..33f90c6525 100644 --- a/src/proto/highlight.pro +++ b/src/proto/highlight.pro @@ -4,7 +4,6 @@ char_u *highlight_group_name(int id); int highlight_link_id(int id); void init_highlight(int both, int reset); int load_colors(char_u *name); -int lookup_color(int idx, int foreground, int *boldp); void do_highlight(char_u *line, int forceit, int init); void free_highlight(void); void restore_cterm_colors(void); diff --git a/src/proto/scriptfile.pro b/src/proto/scriptfile.pro index a38f258709..205028d127 100644 --- a/src/proto/scriptfile.pro +++ b/src/proto/scriptfile.pro @@ -40,7 +40,6 @@ void ex_scriptversion(exarg_T *eap); void ex_finish(exarg_T *eap); void do_finish(exarg_T *eap, int reanimate); int source_finished(char_u *(*fgetline)(int, void *, int, getline_opt_T), void *cookie); -char_u *script_name_after_autoload(scriptitem_T *si); char_u *get_autoload_prefix(scriptitem_T *si); char_u *may_prefix_autoload(char_u *name); char_u *autoload_name(char_u *name); diff --git a/src/proto/userfunc.pro b/src/proto/userfunc.pro index 537276013a..427d47b241 100644 --- a/src/proto/userfunc.pro +++ b/src/proto/userfunc.pro @@ -38,7 +38,6 @@ void user_func_error(int error, char_u *name, funcexe_T *funcexe); int call_func(char_u *funcname, int len, typval_T *rettv, int argcount_in, typval_T *argvars_in, funcexe_T *funcexe); char_u *printable_func_name(ufunc_T *fp); char_u *trans_function_name(char_u **pp, int *is_global, int skip, int flags, funcdict_T *fdp, partial_T **partial, type_T **type); -char_u *untrans_function_name(char_u *name); char_u *get_scriptlocal_funcname(char_u *funcname); char_u *alloc_printable_func_name(char_u *fname); char_u *save_function_name(char_u **name, int *is_global, int skip, int flags, funcdict_T *fudi); diff --git a/src/scriptfile.c b/src/scriptfile.c index f3a5783db5..952f2efd05 100644 --- a/src/scriptfile.c +++ b/src/scriptfile.c @@ -2346,7 +2346,7 @@ source_finished( * Find the path of a script below the "autoload" directory. * Returns NULL if there is no "/autoload/" in the script name. */ - char_u * + static char_u * script_name_after_autoload(scriptitem_T *si) { char_u *p = si->sn_name; diff --git a/src/testdir/test_fold.vim b/src/testdir/test_fold.vim index 3bdd99fc0e..2618084025 100644 --- a/src/testdir/test_fold.vim +++ b/src/testdir/test_fold.vim @@ -1476,6 +1476,8 @@ func Test_fold_split() call assert_equal([0, 1, 1, 2, 2], range(1, 5)->map('foldlevel(v:val)')) call append(2, 'line 2.5') call assert_equal([0, 1, 0, 1, 2, 2], range(1, 6)->map('foldlevel(v:val)')) + 3d + call assert_equal([0, 1, 1, 2, 2], range(1, 5)->map('foldlevel(v:val)')) bw! endfunc diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim index 182d570474..2a973754de 100644 --- a/src/testdir/test_quickfix.vim +++ b/src/testdir/test_quickfix.vim @@ -3363,8 +3363,11 @@ func Test_bufoverflow() cgetexpr ['Compiler: ' . repeat('a', 1015), 'File1:10:Hello World'] set efm=%DEntering\ directory\ %f,%f:%l:%m - cgetexpr ['Entering directory ' . repeat('a', 1006), - \ 'File1:10:Hello World'] + let lines =<< trim eval END + Entering directory $"{repeat('a', 1006)}" + File1:10:Hello World + END + cgetexpr lines set efm&vim endfunc diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim index e83e320c73..0243595853 100644 --- a/src/testdir/test_vim9_builtin.vim +++ b/src/testdir/test_vim9_builtin.vim @@ -3364,6 +3364,22 @@ def Test_searchdecl() v9.CheckDefAndScriptFailure(['searchdecl(1)'], ['E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1']) v9.CheckDefAndScriptFailure(['searchdecl("a", 2)'], ['E1013: Argument 2: type mismatch, expected bool but got number', 'E1212: Bool required for argument 2']) v9.CheckDefAndScriptFailure(['searchdecl("a", true, 2)'], ['E1013: Argument 3: type mismatch, expected bool but got number', 'E1212: Bool required for argument 3']) + + # search for an empty string declaration + var lines: list =<< trim END + int var1; + + { + int var2; + var1 = 10; + } + END + new + setline(1, lines) + cursor(5, 4) + searchdecl('') + assert_equal([3, 1], [line('.'), col('.')]) + bw! enddef def Test_searchpair() diff --git a/src/userfunc.c b/src/userfunc.c index 9b960b7752..9f8442277f 100644 --- a/src/userfunc.c +++ b/src/userfunc.c @@ -32,6 +32,7 @@ static funccall_T *previous_funccal = NULL; static void funccal_unref(funccall_T *fc, ufunc_T *fp, int force); static void func_clear(ufunc_T *fp, int force); static int func_free(ufunc_T *fp, int force); +static char_u *untrans_function_name(char_u *name); void func_init() @@ -4073,7 +4074,7 @@ theend: * This can be used to first search for a script-local function and fall back * to the global function if not found. */ - char_u * + static char_u * untrans_function_name(char_u *name) { char_u *p; diff --git a/src/version.c b/src/version.c index 74e080ff39..2faf3bdfcc 100644 --- a/src/version.c +++ b/src/version.c @@ -735,6 +735,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 3, /**/ 2, /**/ From d14bb1aef9a142f403aa16298c23db2751de9391 Mon Sep 17 00:00:00 2001 From: Matvey Tarasov Date: Wed, 29 Jun 2022 13:18:27 +0100 Subject: [PATCH 3/8] patch 9.0.0004: plural messages not translated properly Problem: Plural messages not translated properly. Solution: Use ngettext() in a few more places. (Matvey Tarasov, closes #10606) --- src/version.c | 2 ++ src/vim9execute.c | 24 ++++++++---------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/version.c b/src/version.c index 2faf3bdfcc..dd99f8575a 100644 --- a/src/version.c +++ b/src/version.c @@ -735,6 +735,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 4, /**/ 3, /**/ diff --git a/src/vim9execute.c b/src/vim9execute.c index 217a97797f..9dd5937e47 100644 --- a/src/vim9execute.c +++ b/src/vim9execute.c @@ -478,20 +478,16 @@ call_dfunc( arg_to_add = ufunc->uf_args.ga_len - argcount; if (arg_to_add < 0) { - if (arg_to_add == -1) - emsg(_(e_one_argument_too_many)); - else - semsg(_(e_nr_arguments_too_many), -arg_to_add); + semsg(NGETTEXT(e_one_argument_too_many, e_nr_arguments_too_many, + -arg_to_add), -arg_to_add); return FAIL; } else if (arg_to_add > ufunc->uf_def_args.ga_len) { int missing = arg_to_add - ufunc->uf_def_args.ga_len; - if (missing == 1) - emsg(_(e_one_argument_too_few)); - else - semsg(_(e_nr_arguments_too_few), missing); + semsg(NGETTEXT(e_one_argument_too_few, e_nr_arguments_too_few, + missing), missing); return FAIL; } @@ -5170,19 +5166,15 @@ call_def_function( idx = argc - ufunc->uf_args.ga_len; if (idx > 0 && ufunc->uf_va_name == NULL) { - if (idx == 1) - emsg(_(e_one_argument_too_many)); - else - semsg(_(e_nr_arguments_too_many), idx); + semsg(NGETTEXT(e_one_argument_too_many, e_nr_arguments_too_many, + idx), idx); goto failed_early; } idx = argc - ufunc->uf_args.ga_len + ufunc->uf_def_args.ga_len; if (idx < 0) { - if (idx == -1) - emsg(_(e_one_argument_too_few)); - else - semsg(_(e_nr_arguments_too_few), -idx); + semsg(NGETTEXT(e_one_argument_too_few, e_nr_arguments_too_few, + -idx), -idx); goto failed_early; } From 040674129f3382822eeb7b590380efa5228124a8 Mon Sep 17 00:00:00 2001 From: Hugo Osvaldo Barrera Date: Wed, 29 Jun 2022 13:48:49 +0100 Subject: [PATCH 4/8] patch 9.0.0005: hare files are not recognized Problem: Hare files are not recognized. Solution: Add a filetype pattern. (Hugo Osvaldo Barrera, closes #10630) --- runtime/filetype.vim | 3 +++ src/testdir/test_filetype.vim | 1 + src/version.c | 2 ++ 3 files changed, 6 insertions(+) diff --git a/runtime/filetype.vim b/runtime/filetype.vim index c9ee28bfba..6280d32e53 100644 --- a/runtime/filetype.vim +++ b/runtime/filetype.vim @@ -789,6 +789,9 @@ au BufNewFile,BufRead *.hsm setf hamster " Handlebars au BufNewFile,BufRead *.hbs setf handlebars +" Hare +au BufNewFile,BufRead *.ha setf hare + " Haskell au BufNewFile,BufRead *.hs,*.hsc,*.hs-boot,*.hsig setf haskell au BufNewFile,BufRead *.lhs setf lhaskell diff --git a/src/testdir/test_filetype.vim b/src/testdir/test_filetype.vim index 6c2343b1e2..545e33f7be 100644 --- a/src/testdir/test_filetype.vim +++ b/src/testdir/test_filetype.vim @@ -234,6 +234,7 @@ let s:filename_checks = { \ 'haml': ['file.haml'], \ 'hamster': ['file.hsm'], \ 'handlebars': ['file.hbs'], + \ 'hare': ['file.ha'], \ 'haskell': ['file.hs', 'file.hsc', 'file.hs-boot', 'file.hsig'], \ 'haste': ['file.ht'], \ 'hastepreproc': ['file.htpp'], diff --git a/src/version.c b/src/version.c index dd99f8575a..0e6758f742 100644 --- a/src/version.c +++ b/src/version.c @@ -735,6 +735,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 5, /**/ 4, /**/ From 8b5901e2f9466eb6f38f5b251e871f609f65e252 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Wed, 29 Jun 2022 14:39:12 +0100 Subject: [PATCH 5/8] patch 9.0.0006: not all Visual Basic files are recognized Problem: Not all Visual Basic files are recognized. Solution: Change detection of *.cls files. (Doug Kearns) --- runtime/autoload/dist/ft.vim | 54 +++++++++++++++++++++++++++-------- runtime/doc/filetype.txt | 1 + runtime/filetype.vim | 13 +++------ src/testdir/test_filetype.vim | 42 ++++++++++++++++++++++++++- src/version.c | 2 ++ 5 files changed, 90 insertions(+), 22 deletions(-) diff --git a/runtime/autoload/dist/ft.vim b/runtime/autoload/dist/ft.vim index 01cde4631e..5f48f4b10d 100644 --- a/runtime/autoload/dist/ft.vim +++ b/runtime/autoload/dist/ft.vim @@ -72,22 +72,35 @@ export def FTbas() # most frequent FreeBASIC-specific keywords in distro files var fb_keywords = '\c^\s*\%(extern\|var\|enum\|private\|scope\|union\|byref\|operator\|constructor\|delete\|namespace\|public\|property\|with\|destructor\|using\)\>\%(\s*[:=(]\)\@!' - var fb_preproc = '\c^\s*\%(#\a\+\|option\s\+\%(byval\|dynamic\|escape\|\%(no\)\=gosub\|nokeyword\|private\|static\)\>\)' + var fb_preproc = '\c^\s*\%(' .. + # preprocessor + '#\s*\a\+\|' .. + # compiler option + 'option\s\+\%(byval\|dynamic\|escape\|\%(no\)\=gosub\|nokeyword\|private\|static\)\>\|' .. + # metacommand + '\%(''\|rem\)\s*\$lang\>\|' .. + # default datatype + 'def\%(byte\|longint\|short\|ubyte\|uint\|ulongint\|ushort\)\>' .. + '\)' var fb_comment = "^\\s*/'" + # OPTION EXPLICIT, without the leading underscore, is common to many dialects var qb64_preproc = '\c^\s*\%($\a\+\|option\s\+\%(_explicit\|_\=explicitarray\)\>\)' - var lines = getline(1, min([line("$"), 100])) - - if match(lines, fb_preproc) > -1 || match(lines, fb_comment) > -1 || match(lines, fb_keywords) > -1 - setf freebasic - elseif match(lines, qb64_preproc) > -1 - setf qb64 - elseif match(lines, ft_visual_basic_content) > -1 - setf vb - else - setf basic - endif + for lnum in range(1, min([line("$"), 100])) + var line = getline(lnum) + if line =~ ft_visual_basic_content + setf vb + return + elseif line =~ fb_preproc || line =~ fb_comment || line =~ fb_keywords + setf freebasic + return + elseif line =~ qb64_preproc + setf qb64 + return + endif + endfor + setf basic enddef export def FTbtm() @@ -126,6 +139,23 @@ export def FTcfg() endif enddef +export def FTcls() + if exists("g:filetype_cls") + exe "setf " .. g:filetype_cls + return + endif + + if getline(1) =~ '^%' + setf tex + elseif getline(1)[0] == '#' && getline(1) =~ 'rexx' + setf rexx + elseif getline(1) == 'VERSION 1.0 CLASS' + setf vb + else + setf st + endif +enddef + export def FTlpc() if exists("g:lpc_syntax_for_c") var lnum = 1 diff --git a/runtime/doc/filetype.txt b/runtime/doc/filetype.txt index 06eff2da1a..282a7966cb 100644 --- a/runtime/doc/filetype.txt +++ b/runtime/doc/filetype.txt @@ -143,6 +143,7 @@ variables can be used to overrule the filetype used for certain extensions: *.asp g:filetype_asp |ft-aspvbs-syntax| |ft-aspperl-syntax| *.bas g:filetype_bas |ft-basic-syntax| *.cfg g:filetype_cfg + *.cls g:filetype_cls *.csh g:filetype_csh |ft-csh-syntax| *.dat g:filetype_dat *.frm g:filetype_frm |ft-form-syntax| diff --git a/runtime/filetype.vim b/runtime/filetype.vim index 6280d32e53..1648e82ab7 100644 --- a/runtime/filetype.vim +++ b/runtime/filetype.vim @@ -1798,16 +1798,11 @@ au BufNewFile,BufRead *.il,*.ils,*.cdf setf skill au BufNewFile,BufRead .slrnrc setf slrnrc au BufNewFile,BufRead *.score setf slrnsc -" Smalltalk (and TeX) +" Smalltalk au BufNewFile,BufRead *.st setf st -au BufNewFile,BufRead *.cls - \ if getline(1) =~ '^%' | - \ setf tex | - \ elseif getline(1)[0] == '#' && getline(1) =~ 'rexx' | - \ setf rexx | - \ else | - \ setf st | - \ endif + +" Smalltalk (and Rexx, TeX, and Visual Basic) +au BufNewFile,BufRead *.cls call dist#ft#FTcls() " Smarty templates au BufNewFile,BufRead *.tpl setf smarty diff --git a/src/testdir/test_filetype.vim b/src/testdir/test_filetype.vim index 545e33f7be..d8ddeff250 100644 --- a/src/testdir/test_filetype.vim +++ b/src/testdir/test_filetype.vim @@ -837,7 +837,7 @@ func Test_bas_file() " Visual Basic - call writefile(['Attribute VB_NAME = "Testing"'], 'Xfile.bas') + call writefile(['Attribute VB_NAME = "Testing"', 'Enum Foo', 'End Enum'], 'Xfile.bas') split Xfile.bas call assert_equal('vb', &filetype) bwipe! @@ -1719,5 +1719,45 @@ func Test_xpm_file() filetype off endfunc +func Test_cls_file() + filetype on + + call writefile(['looks like Smalltalk'], 'Xfile.cls') + split Xfile.cls + call assert_equal('st', &filetype) + bwipe! + + " Test dist#ft#FTcls() + + let g:filetype_cls = 'vb' + split Xfile.cls + call assert_equal('vb', &filetype) + bwipe! + unlet g:filetype_cls + + " TeX + + call writefile(['%'], 'Xfile.cls') + split Xfile.cls + call assert_equal('tex', &filetype) + bwipe! + + " Rexx + + call writefile(['# rexx'], 'Xfile.cls') + split Xfile.cls + call assert_equal('rexx', &filetype) + bwipe! + + " Visual Basic + + call writefile(['VERSION 1.0 CLASS'], 'Xfile.cls') + split Xfile.cls + call assert_equal('vb', &filetype) + bwipe! + + call delete('Xfile.cls') + filetype off +endfunc " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/version.c b/src/version.c index 0e6758f742..98227fa445 100644 --- a/src/version.c +++ b/src/version.c @@ -735,6 +735,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 6, /**/ 5, /**/ From 84f546363068e4ddfe14a8a2a2322bb8d3a25417 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Wed, 29 Jun 2022 18:39:11 +0100 Subject: [PATCH 6/8] patch 9.0.0007: no support for double, dotted and dashed underlines Problem: No support for double, dotted and dashed underlines. Solution: Add the termcap entries and highlight modes. (closes #9553) --- runtime/doc/options.txt | 5 ++++- runtime/doc/syntax.txt | 20 ++++++++++++++++++-- runtime/doc/term.txt | 7 +++++-- src/evalfunc.c | 25 +++++++++++++++++++------ src/gui.c | 2 ++ src/hardcopy.c | 1 + src/highlight.c | 33 +++++++++++++++++++++++---------- src/optiondefs.h | 5 ++++- src/screen.c | 22 +++++++++++++++++----- src/term.c | 4 ++++ src/termdefs.h | 6 ++++++ src/testdir/test_highlight.vim | 10 ++++++---- src/testdir/test_options.vim | 12 ++++++++++++ src/testdir/test_syn_attr.vim | 7 +++++++ src/version.c | 2 ++ src/vim.h | 11 +++++++---- 16 files changed, 137 insertions(+), 35 deletions(-) diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 84ab1fb8b9..1d14c44333 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -4211,7 +4211,10 @@ A jump table for the options with a short description can be found at |Q_op|. b bold (termcap entry "md" and "me") s standout (termcap entry "so" and "se") u underline (termcap entry "us" and "ue") - c undercurl (termcap entry "Cs" and "Ce") + c undercurl (termcap entry "Us" and "Ce") + 2 double underline (termcap entry "Ds" and "Ce") + d dotted underline (termcap entry "ds" and "Ce") + = dashed underline (termcap entry "Ds" and "Ce") t strikethrough (termcap entry "Ts" and "Te") n no highlighting - no highlighting diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt index c3d677769d..1229b19084 100644 --- a/runtime/doc/syntax.txt +++ b/runtime/doc/syntax.txt @@ -5002,14 +5002,18 @@ the same syntax file on all terminals, and use the optimal highlighting. 1. highlight arguments for normal terminals *bold* *underline* *undercurl* - *inverse* *italic* *standout* - *nocombine* *strikethrough* + *underdouble* *underdotted* + *underdashed* *inverse* *italic* + *standout* *nocombine* *strikethrough* term={attr-list} *attr-list* *highlight-term* *E418* attr-list is a comma-separated list (without spaces) of the following items (in any order): bold underline undercurl not always available + underdouble not always available + underdotted not always available + underdashed not always available strikethrough not always available reverse inverse same as reverse @@ -5020,6 +5024,7 @@ term={attr-list} *attr-list* *highlight-term* *E418* Note that "bold" can be used here and by using a bold font. They have the same effect. + *underline-codes* "undercurl" is a curly underline. When "undercurl" is not possible then "underline" is used. In general "undercurl" and "strikethrough" are only available in the GUI and some terminals. The color is set @@ -5028,6 +5033,17 @@ term={attr-list} *attr-list* *highlight-term* *E418* let &t_Cs = "\e[4:3m" let &t_Ce = "\e[4:0m" +< "underdouble" is a double underline, "underdotted" is a dotted + underline and "underdashed" is a dashed underline. These are only + supported by some terminals. If your terminal supports them you may + have to specify the codes like this: > + let &t_Us = "\e[4:2m" + let &t_ds = "\e[4:4m" + let &t_Ds = "\e[4:5m" +< They are reset with |t_Ce|, the same as curly underline (undercurl). + When t_Us, t_ds or t_Ds is not set then underline will be used as a + fallback. + start={term-list} *highlight-start* *E422* stop={term-list} *term-list* *highlight-stop* diff --git a/runtime/doc/term.txt b/runtime/doc/term.txt index f103405728..c4199c2db9 100644 --- a/runtime/doc/term.txt +++ b/runtime/doc/term.txt @@ -372,8 +372,11 @@ OUTPUT CODES *terminal-output-codes* Added by Vim (there are no standard codes for these): t_AU set underline color (ANSI) *t_AU* *'t_AU'* - t_Ce undercurl end *t_Ce* *'t_Ce'* - t_Cs undercurl mode *t_Cs* *'t_Cs'* + t_Ce undercurl and underline end *t_Ce* *'t_Ce'* + t_Cs undercurl (curly underline) mode *t_Cs* *'t_Cs'* + t_Us double underline mode *t_Us* *'t_Us'* + t_ds dotted underline mode *t_ds* *'t_ds'* + t_Ds dashed underline mode *t_Ds* *'t_Ds'* t_Te strikethrough end *t_Te* *'t_Te'* t_Ts strikethrough mode *t_Ts* *'t_Ts'* t_IS set icon text start *t_IS* *'t_IS'* diff --git a/src/evalfunc.c b/src/evalfunc.c index 0b8fd43966..f51aade495 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -10104,14 +10104,27 @@ f_synIDattr(typval_T *argvars UNUSED, typval_T *rettv) break; case 'u': - if (TOLOWER_ASC(what[1]) == 'l') // ul - p = highlight_color(id, what, modec); - else if (STRLEN(what) <= 5 || TOLOWER_ASC(what[5]) != 'c') + if (STRLEN(what) >= 9) + { + if (TOLOWER_ASC(what[5]) == 'l') // underline - p = highlight_has_attr(id, HL_UNDERLINE, modec); - else + p = highlight_has_attr(id, HL_UNDERLINE, modec); + else if (TOLOWER_ASC(what[5]) != 'd') // undercurl - p = highlight_has_attr(id, HL_UNDERCURL, modec); + p = highlight_has_attr(id, HL_UNDERCURL, modec); + else if (TOLOWER_ASC(what[6]) != 'o') + // underdashed + p = highlight_has_attr(id, HL_UNDERDASHED, modec); + else if (TOLOWER_ASC(what[7]) == 'u') + // underdouble + p = highlight_has_attr(id, HL_UNDERDOUBLE, modec); + else + // underdotted + p = highlight_has_attr(id, HL_UNDERDOTTED, modec); + } + else + // ul + p = highlight_color(id, what, modec); break; } diff --git a/src/gui.c b/src/gui.c index e708a27763..d7e768f319 100644 --- a/src/gui.c +++ b/src/gui.c @@ -2501,6 +2501,8 @@ gui_outstr_nowrap( if (hl_mask_todo & HL_UNDERCURL) draw_flags |= DRAW_UNDERC; + // TODO: HL_UNDERDOUBLE, HL_UNDERDOTTED, HL_UNDERDASHED + // Do we strikethrough the text? if (hl_mask_todo & HL_STRIKETHROUGH) draw_flags |= DRAW_STRIKE; diff --git a/src/hardcopy.c b/src/hardcopy.c index e2e5211624..dd1f2e071e 100644 --- a/src/hardcopy.c +++ b/src/hardcopy.c @@ -293,6 +293,7 @@ prt_get_attr( pattr->italic = (highlight_has_attr(hl_id, HL_ITALIC, modec) != NULL); pattr->underline = (highlight_has_attr(hl_id, HL_UNDERLINE, modec) != NULL); pattr->undercurl = (highlight_has_attr(hl_id, HL_UNDERCURL, modec) != NULL); + // TODO: HL_UNDERDOUBLE, HL_UNDERDOTTED, HL_UNDERDASHED # if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) if (USE_24BIT) diff --git a/src/highlight.c b/src/highlight.c index bf876d16f1..575451e705 100644 --- a/src/highlight.c +++ b/src/highlight.c @@ -25,10 +25,16 @@ * following names, separated by commas (but no spaces!). */ static char *(hl_name_table[]) = - {"bold", "standout", "underline", "undercurl", - "italic", "reverse", "inverse", "nocombine", "strikethrough", "NONE"}; + {"bold", "standout", "underline", + "undercurl", "underdouble", "underdotted", "underdashed", + "italic", "reverse", "inverse", "nocombine", "strikethrough", "NONE"}; static int hl_attr_table[] = - {HL_BOLD, HL_STANDOUT, HL_UNDERLINE, HL_UNDERCURL, HL_ITALIC, HL_INVERSE, HL_INVERSE, HL_NOCOMBINE, HL_STRIKETHROUGH, 0}; + {HL_BOLD, HL_STANDOUT, HL_UNDERLINE, + HL_UNDERCURL, HL_UNDERDOUBLE, HL_UNDERDOTTED, HL_UNDERDASHED, + HL_ITALIC, HL_INVERSE, HL_INVERSE, HL_NOCOMBINE, HL_STRIKETHROUGH, 0}; +// length of all attribute names, plus commas, together (and a bit more) +#define MAX_ATTR_LEN 120 + #define ATTR_COMBINE(attr_a, attr_b) ((((attr_b) & HL_NOCOMBINE) ? (attr_b) : (attr_a)) | (attr_b)) /* @@ -2963,7 +2969,7 @@ highlight_list_arg( char_u *sarg, char *name) { - char_u buf[100]; + char_u buf[MAX_ATTR_LEN]; char_u *ts; int i; @@ -2984,8 +2990,8 @@ highlight_list_arg( if (iarg & hl_attr_table[i]) { if (buf[0] != NUL) - vim_strcat(buf, (char_u *)",", 100); - vim_strcat(buf, (char_u *)hl_name_table[i], 100); + vim_strcat(buf, (char_u *)",", MAX_ATTR_LEN); + vim_strcat(buf, (char_u *)hl_name_table[i], MAX_ATTR_LEN); iarg &= ~hl_attr_table[i]; // don't want "inverse" } } @@ -3287,7 +3293,8 @@ set_hl_attr( at_en.ae_u.cterm.bg_rgb = GUI_MCH_GET_RGB2(sgp->sg_gui_bg); // Only use the underline/undercurl color when used, it may clear the // background color if not supported. - if (sgp->sg_cterm & (HL_UNDERLINE | HL_UNDERCURL)) + if (sgp->sg_cterm & (HL_UNDERLINE | HL_UNDERCURL + | HL_UNDERDOUBLE | HL_UNDERDOTTED | HL_UNDERDASHED)) at_en.ae_u.cterm.ul_rgb = GUI_MCH_GET_RGB2(sgp->sg_gui_sp); else at_en.ae_u.cterm.ul_rgb = INVALCOLOR; @@ -3801,6 +3808,12 @@ highlight_changed(void) break; case 'c': attr |= HL_UNDERCURL; break; + case '2': attr |= HL_UNDERDOUBLE; + break; + case 'd': attr |= HL_UNDERDOTTED; + break; + case '=': attr |= HL_UNDERDASHED; + break; case 't': attr |= HL_STRIKETHROUGH; break; case ':': ++p; // highlight group name @@ -4362,9 +4375,9 @@ hlg_add_or_update(dict_T *dict) { char_u *name; int error; - char_u term_attr[80]; - char_u cterm_attr[80]; - char_u gui_attr[80]; + char_u term_attr[MAX_ATTR_LEN]; + char_u cterm_attr[MAX_ATTR_LEN]; + char_u gui_attr[MAX_ATTR_LEN]; char_u *start; char_u *stop; char_u *ctermfg; diff --git a/src/optiondefs.h b/src/optiondefs.h index aca3737550..03e472ff9e 100644 --- a/src/optiondefs.h +++ b/src/optiondefs.h @@ -2893,9 +2893,9 @@ static struct vimoption options[] = p_term("t_BD", T_BD) p_term("t_cd", T_CD) p_term("t_ce", T_CE) + p_term("t_Ce", T_UCE) p_term("t_cl", T_CL) p_term("t_cm", T_CM) - p_term("t_Ce", T_UCE) p_term("t_Co", T_CCO) p_term("t_CS", T_CCS) p_term("t_Cs", T_UCS) @@ -2905,6 +2905,8 @@ static struct vimoption options[] = p_term("t_db", T_DB) p_term("t_DL", T_CDL) p_term("t_dl", T_DL) + p_term("t_ds", T_DS) + p_term("t_Ds", T_CDS) p_term("t_EC", T_CEC) p_term("t_EI", T_CEI) p_term("t_fs", T_FS) @@ -2952,6 +2954,7 @@ static struct vimoption options[] = p_term("t_u7", T_U7) p_term("t_ue", T_UE) p_term("t_us", T_US) + p_term("t_Us", T_USS) p_term("t_ut", T_UT) p_term("t_vb", T_VB) p_term("t_ve", T_VE) diff --git a/src/screen.c b/src/screen.c index 82a0e91ddc..01518882f2 100644 --- a/src/screen.c +++ b/src/screen.c @@ -1855,8 +1855,17 @@ screen_start_highlight(int attr) out_str(T_SO); if ((attr & HL_UNDERCURL) && *T_UCS != NUL) // undercurl out_str(T_UCS); - if (((attr & HL_UNDERLINE) // underline or undercurl - || ((attr & HL_UNDERCURL) && *T_UCS == NUL)) + if ((attr & HL_UNDERDOUBLE) && *T_USS != NUL) // double underline + out_str(T_USS); + if ((attr & HL_UNDERDOTTED) && *T_DS != NUL) // dotted underline + out_str(T_DS); + if ((attr & HL_UNDERDASHED) && *T_CDS != NUL) // dashed underline + out_str(T_CDS); + if (((attr & HL_UNDERLINE) // underline or undercurl, etc. + || ((attr & HL_UNDERCURL) && *T_UCS == NUL) + || ((attr & HL_UNDERDOUBLE) && *T_USS == NUL) + || ((attr & HL_UNDERDOTTED) && *T_DS == NUL) + || ((attr & HL_UNDERDASHED) && *T_CDS == NUL)) && *T_US != NUL) out_str(T_US); if ((attr & HL_ITALIC) && *T_CZH != NUL) // italic @@ -1951,6 +1960,8 @@ screen_stop_highlight(void) else #endif { + int is_under; + if (screen_attr > HL_ALL) // special HL attr. { attrentry_T *aep; @@ -2030,15 +2041,16 @@ screen_stop_highlight(void) else out_str(T_SE); } - if ((screen_attr & HL_UNDERCURL) && *T_UCE != NUL) + is_under = (screen_attr & (HL_UNDERCURL + | HL_UNDERDOUBLE | HL_UNDERDOTTED | HL_UNDERDASHED)); + if (is_under && *T_UCE != NUL) { if (STRCMP(T_UCE, T_ME) == 0) do_ME = TRUE; else out_str(T_UCE); } - if ((screen_attr & HL_UNDERLINE) - || ((screen_attr & HL_UNDERCURL) && *T_UCE == NUL)) + if ((screen_attr & HL_UNDERLINE) || (is_under && *T_UCE == NUL)) { if (STRCMP(T_UE, T_ME) == 0) do_ME = TRUE; diff --git a/src/term.c b/src/term.c index b365831146..754ef822d8 100644 --- a/src/term.c +++ b/src/term.c @@ -1187,6 +1187,9 @@ static struct builtin_term builtin_termcaps[] = {(int)KS_US, "[US]"}, {(int)KS_UCE, "[UCE]"}, {(int)KS_UCS, "[UCS]"}, + {(int)KS_USS, "[USS]"}, + {(int)KS_DS, "[DS]"}, + {(int)KS_CDS, "[CDS]"}, {(int)KS_STE, "[STE]"}, {(int)KS_STS, "[STS]"}, {(int)KS_MS, "[MS]"}, @@ -1669,6 +1672,7 @@ get_term_entries(int *height, int *width) {KS_MD, "md"}, {KS_SE, "se"}, {KS_SO, "so"}, {KS_CZH,"ZH"}, {KS_CZR,"ZR"}, {KS_UE, "ue"}, {KS_US, "us"}, {KS_UCE, "Ce"}, {KS_UCS, "Cs"}, + {KS_USS, "Us"}, {KS_DS, "ds"}, {KS_CDS, "Ds"}, {KS_STE,"Te"}, {KS_STS,"Ts"}, {KS_CM, "cm"}, {KS_SR, "sr"}, {KS_CRI,"RI"}, {KS_VB, "vb"}, {KS_KS, "ks"}, diff --git a/src/termdefs.h b/src/termdefs.h index a3d8299990..133641b5c0 100644 --- a/src/termdefs.h +++ b/src/termdefs.h @@ -55,6 +55,9 @@ enum SpecialKey KS_US, // underscore (underline) mode KS_UCE, // exit undercurl mode KS_UCS, // undercurl mode + KS_USS, // double underline mode + KS_DS, // dotted underline mode + KS_CDS, // dashed underline mode KS_STE, // exit strikethrough mode KS_STS, // strikethrough mode KS_MS, // save to move cur in reverse mode @@ -160,6 +163,9 @@ extern char_u *(term_strings[]); // current terminal strings #define T_US (TERM_STR(KS_US)) // underscore (underline) mode #define T_UCE (TERM_STR(KS_UCE)) // exit undercurl mode #define T_UCS (TERM_STR(KS_UCS)) // undercurl mode +#define T_USS (TERM_STR(KS_USS)) // double underline mode +#define T_DS (TERM_STR(KS_DS)) // dotted underline mode +#define T_CDS (TERM_STR(KS_CDS)) // dashed underline mode #define T_STE (TERM_STR(KS_STE)) // exit strikethrough mode #define T_STS (TERM_STR(KS_STS)) // strikethrough mode #define T_MS (TERM_STR(KS_MS)) // save to move cur in reverse mode diff --git a/src/testdir/test_highlight.vim b/src/testdir/test_highlight.vim index 3400052a7c..ef9c70e7e9 100644 --- a/src/testdir/test_highlight.vim +++ b/src/testdir/test_highlight.vim @@ -888,8 +888,8 @@ endfunc " Test for setting various 'term' attributes func Test_highlight_term_attr() - hi HlGrp3 term=bold,underline,undercurl,strikethrough,reverse,italic,standout - call assert_equal('hi HlGrp3 term=bold,standout,underline,undercurl,italic,reverse,strikethrough', HighlightArgs('HlGrp3')) + hi HlGrp3 term=bold,underline,undercurl,underdouble,underdotted,underdashed,strikethrough,reverse,italic,standout + call assert_equal('hi HlGrp3 term=bold,standout,underline,undercurl,underdouble,underdotted,underdashed,italic,reverse,strikethrough', HighlightArgs('HlGrp3')) hi HlGrp3 term=NONE call assert_equal('hi HlGrp3 cleared', HighlightArgs('HlGrp3')) hi clear @@ -1174,12 +1174,14 @@ func Test_hlset() " Test for setting all the 'term', 'cterm' and 'gui' attributes of a " highlight group let lines =<< trim END - VAR attr = {'bold': v:true, 'underline': v:true, 'undercurl': v:true, + VAR attr = {'bold': v:true, 'underline': v:true, + \ 'undercurl': v:true, 'underdouble': v:true, + \ 'underdotted': v:true, 'underdashed': v:true, \ 'strikethrough': v:true, 'reverse': v:true, 'italic': v:true, \ 'standout': v:true, 'nocombine': v:true} call hlset([{'name': 'myhlg2', 'term': attr, 'cterm': attr, 'gui': attr}]) VAR id2 = hlID('myhlg2') - VAR expected = "myhlg2 xxx term=bold,standout,underline,undercurl,italic,reverse,nocombine,strikethrough cterm=bold,standout,underline,undercurl,italic,reverse,nocombine,strikethrough gui=bold,standout,underline,undercurl,italic,reverse,nocombine,strikethrough" + VAR expected = "myhlg2 xxx term=bold,standout,underline,undercurl,underdouble,underdotted,underdashed,italic,reverse,nocombine,strikethrough cterm=bold,standout,underline,undercurl,underdouble,underdotted,underdashed,italic,reverse,nocombine,strikethrough gui=bold,standout,underline,undercurl,underdouble,underdotted,underdashed,italic,reverse,nocombine,strikethrough" VAR output = execute('highlight myhlg2') LET output = output->split("\n")->join()->substitute('\s\+', ' ', 'g') call assert_equal(expected, output) diff --git a/src/testdir/test_options.vim b/src/testdir/test_options.vim index 0a533152b9..fbe592d165 100644 --- a/src/testdir/test_options.vim +++ b/src/testdir/test_options.vim @@ -955,6 +955,18 @@ func Test_opt_set_keycode() set =xyz call assert_equal('xyz', &t_k9) set & + + " should we test all of them? + set t_Ce=testCe + set t_Cs=testCs + set t_Us=testUs + set t_ds=testds + set t_Ds=testDs + call assert_equal('testCe', &t_Ce) + call assert_equal('testCs', &t_Cs) + call assert_equal('testUs', &t_Us) + call assert_equal('testds', &t_ds) + call assert_equal('testDs', &t_Ds) endfunc " Test for changing options in a sandbox diff --git a/src/testdir/test_syn_attr.vim b/src/testdir/test_syn_attr.vim index db9c9e93af..366f39f468 100644 --- a/src/testdir/test_syn_attr.vim +++ b/src/testdir/test_syn_attr.vim @@ -11,10 +11,17 @@ func Test_missing_attr() hi Mine term=reverse cterm=inverse call assert_equal('1', synIDattr(hlID("Mine"), "reverse", 'term')) call assert_equal('1', synIDattr(hlID("Mine"), "inverse", 'cterm')) + hi Mine term=underline cterm=standout gui=undercurl call assert_equal('1', synIDattr(hlID("Mine"), "underline", 'term')) call assert_equal('1', synIDattr(hlID("Mine"), "standout", 'cterm')) call assert_equal('1', synIDattr("Mine"->hlID(), "undercurl", 'gui')) + + hi Mine term=underdouble cterm=underdotted gui=underdashed + call assert_equal('1', synIDattr(hlID("Mine"), "underdouble", 'term')) + call assert_equal('1', synIDattr(hlID("Mine"), "underdotted", 'cterm')) + call assert_equal('1', synIDattr("Mine"->hlID(), "underdashed", 'gui')) + hi Mine gui=strikethrough call assert_equal('1', synIDattr(hlID("Mine"), "strikethrough", 'gui')) hi Mine term=NONE cterm=NONE gui=NONE diff --git a/src/version.c b/src/version.c index 98227fa445..e6255059d6 100644 --- a/src/version.c +++ b/src/version.c @@ -735,6 +735,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 7, /**/ 6, /**/ diff --git a/src/vim.h b/src/vim.h index 97ce6390eb..a4da18505c 100644 --- a/src/vim.h +++ b/src/vim.h @@ -659,10 +659,13 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring); #define HL_ITALIC 0x04 #define HL_UNDERLINE 0x08 #define HL_UNDERCURL 0x10 -#define HL_STANDOUT 0x20 -#define HL_NOCOMBINE 0x40 -#define HL_STRIKETHROUGH 0x80 -#define HL_ALL 0xff +#define HL_UNDERDOUBLE 0x20 +#define HL_UNDERDOTTED 0x40 +#define HL_UNDERDASHED 0x80 +#define HL_STANDOUT 0x100 +#define HL_NOCOMBINE 0x200 +#define HL_STRIKETHROUGH 0x400 +#define HL_ALL 0x7ff // special attribute addition: Put message in history #define MSG_HIST 0x1000 From 83e11800cc3775de3135ac7d823137c8c1e87fa1 Mon Sep 17 00:00:00 2001 From: David Gow Date: Wed, 29 Jun 2022 20:24:49 +0100 Subject: [PATCH 7/8] patch 9.0.0008: cannot specify the variable name for "xxd -i" Problem: Cannot specify the variable name for "xxd -i". Solution: Add the "-name" argument. (David Gow, closes #10599) --- runtime/doc/xxd.1 | 4 ++++ src/testdir/test_xxd.vim | 47 ++++++++++++++++++++++++++++++++++++++++ src/version.c | 2 ++ src/xxd/xxd.c | 32 ++++++++++++++++++++++----- 4 files changed, 79 insertions(+), 6 deletions(-) diff --git a/runtime/doc/xxd.1 b/runtime/doc/xxd.1 index fb0ac44b10..b0cb183785 100644 --- a/runtime/doc/xxd.1 +++ b/runtime/doc/xxd.1 @@ -113,6 +113,10 @@ Stop after writing .RI < len > octets. .TP +.I "\-n name " | " \-name name" +Override the variable name output when \-i is used. The array is named +\fIname\fP and the length is named \fIname\fP_len. +.TP .I \-o offset Add .RI < offset > diff --git a/src/testdir/test_xxd.vim b/src/testdir/test_xxd.vim index bdcbd082ce..b27639d3f8 100644 --- a/src/testdir/test_xxd.vim +++ b/src/testdir/test_xxd.vim @@ -219,6 +219,53 @@ func Test_xxd() call assert_equal(expected, getline(1,'$'), s:Mess(s:test)) endfor + " Test 17: Print C include with custom variable name + let s:test += 1 + call writefile(['TESTabcd09'], 'XXDfile') + for arg in ['-nvarName', '-n varName', '-name varName'] + %d + exe '0r! ' . s:xxd_cmd . ' -i ' . arg . ' XXDfile' + $d + let expected =<< trim [CODE] + unsigned char varName[] = { + 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a + }; + unsigned int varName_len = 11; + [CODE] + + call assert_equal(expected, getline(1,'$'), s:Mess(s:test)) + endfor + + " using "-n name" reading from stdin + %d + exe '0r! ' . s:xxd_cmd . ' -i < XXDfile -n StdIn' + $d + let expected =<< trim [CODE] + unsigned char StdIn[] = { + 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a + }; + unsigned int StdIn_len = 11; + [CODE] + call assert_equal(expected, getline(1,'$'), s:Mess(s:test)) + + + " Test 18: Print C include: custom variable names can be capitalized + let s:test += 1 + for arg in ['-C', '-capitalize'] + call writefile(['TESTabcd09'], 'XXDfile') + %d + exe '0r! ' . s:xxd_cmd . ' -i ' . arg . ' -n varName XXDfile' + $d + let expected =<< trim [CODE] + unsigned char VARNAME[] = { + 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a + }; + unsigned int VARNAME_LEN = 11; + [CODE] + call assert_equal(expected, getline(1,'$'), s:Mess(s:test)) + endfor + + %d bwipe! call delete('XXDfile') diff --git a/src/version.c b/src/version.c index e6255059d6..ea1cc16c71 100644 --- a/src/version.c +++ b/src/version.c @@ -735,6 +735,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 8, /**/ 7, /**/ diff --git a/src/xxd/xxd.c b/src/xxd/xxd.c index 0e056c93d7..8429b98ec5 100644 --- a/src/xxd/xxd.c +++ b/src/xxd/xxd.c @@ -55,6 +55,7 @@ * 11.01.2019 Add full 64/32 bit range to -o and output by Christer Jensen. * 04.02.2020 Add -d for decimal offsets by Aapo Rantalainen * 14.01.2022 Disable extra newlines with -c0 -p by Erik Auerswald. + * 20.06.2022 Permit setting the variable names used by -i by David Gow * * (c) 1990-1998 by Juergen Weigert (jnweiger@gmail.com) * @@ -226,6 +227,7 @@ exit_with_usage(void) fprintf(stderr, " -h print this summary.\n"); fprintf(stderr, " -i output in C include file style.\n"); fprintf(stderr, " -l len stop after octets.\n"); + fprintf(stderr, " -n name set the variable name used in C include output (-i).\n"); fprintf(stderr, " -o off add to the displayed file position.\n"); fprintf(stderr, " -ps output in postscript plain hexdump style.\n"); fprintf(stderr, " -r reverse operation: convert (or patch) hexdump into binary.\n"); @@ -497,6 +499,7 @@ main(int argc, char *argv[]) unsigned long displayoff = 0; static char l[LLEN+1]; /* static because it may be too big for stack */ char *pp; + char *varname = NULL; int addrlen = 9; #ifdef AMIGA @@ -635,6 +638,19 @@ main(int argc, char *argv[]) argc--; } } + else if (!STRNCMP(pp, "-n", 2)) + { + if (pp[2] && STRNCMP("ame", pp + 2, 3)) + varname = pp + 2; + else + { + if (!argv[2]) + exit_with_usage(); + varname = argv[2]; + argv++; + argc--; + } + } else if (!strcmp(pp, "--")) /* end of options */ { argv++; @@ -753,10 +769,14 @@ main(int argc, char *argv[]) if (hextype == HEX_CINCLUDE) { - if (fp != stdin) + /* A user-set variable name overrides fp == stdin */ + if (varname == NULL && fp != stdin) + varname = argv[1]; + + if (varname != NULL) { - FPRINTF_OR_DIE((fpo, "unsigned char %s", isdigit((int)argv[1][0]) ? "__" : "")); - for (e = 0; (c = argv[1][e]) != 0; e++) + FPRINTF_OR_DIE((fpo, "unsigned char %s", isdigit((int)varname[0]) ? "__" : "")); + for (e = 0; (c = varname[e]) != 0; e++) putc_or_die(isalnum(c) ? CONDITIONAL_CAPITALIZE(c) : '_', fpo); fputs_or_die("[] = {\n", fpo); } @@ -773,11 +793,11 @@ main(int argc, char *argv[]) if (p) fputs_or_die("\n", fpo); - if (fp != stdin) + if (varname != NULL) { fputs_or_die("};\n", fpo); - FPRINTF_OR_DIE((fpo, "unsigned int %s", isdigit((int)argv[1][0]) ? "__" : "")); - for (e = 0; (c = argv[1][e]) != 0; e++) + FPRINTF_OR_DIE((fpo, "unsigned int %s", isdigit((int)varname[0]) ? "__" : "")); + for (e = 0; (c = varname[e]) != 0; e++) putc_or_die(isalnum(c) ? CONDITIONAL_CAPITALIZE(c) : '_', fpo); FPRINTF_OR_DIE((fpo, "_%s = %d;\n", capitalize ? "LEN" : "len", p)); } From 083692d598139228e101b8c521aaef7bcf256e9a Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Wed, 29 Jun 2022 21:16:58 +0100 Subject: [PATCH 8/8] patch 9.0.0009: going past the end of a menu item with only modifier Problem: Going past the end of a menu item with only modifier. Solution: Check for NUL. --- src/message.c | 4 ++-- src/testdir/test_menu.vim | 13 +++++++++++++ src/version.c | 2 ++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/message.c b/src/message.c index 02380e9177..becb2804d0 100644 --- a/src/message.c +++ b/src/message.c @@ -1820,8 +1820,8 @@ str2special( *sp = str + 1; } else - // single-byte character or illegal byte - *sp = str + 1; + // single-byte character, NUL or illegal byte + *sp = str + (*str == NUL ? 0 : 1); // Make special keys and C0 control characters in <> form, also . // Use only for lhs of a mapping. diff --git a/src/testdir/test_menu.vim b/src/testdir/test_menu.vim index c867162e5b..df717cc8a7 100644 --- a/src/testdir/test_menu.vim +++ b/src/testdir/test_menu.vim @@ -528,4 +528,17 @@ func Test_tmenu() tunmenu Test endfunc +func Test_only_modifier() + exe "tmenu a.b \x80\xfc0" + let exp =<< trim [TEXT] + --- Menus --- + 500 a + 500 b + t - + [TEXT] + call assert_equal(exp, split(execute('tmenu'), "\n")) + + tunmenu a.b +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/version.c b/src/version.c index ea1cc16c71..003984ab66 100644 --- a/src/version.c +++ b/src/version.c @@ -735,6 +735,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 9, /**/ 8, /**/