From 089f4f8e4a297aa8e7c689331ffd16ffe415120a Mon Sep 17 00:00:00 2001 From: skippi Date: Sun, 18 Oct 2020 21:36:30 -0500 Subject: vim-patch:8.1.1769: 'shellslash' is also used for completion Problem: 'shellslash' is also used for completion. Solution: Add the 'completeslash' option. (Yasuhiro Matsumoto, closes vim/vim#3612) https://github.com/vim/vim/commit/ac3150d385e6e3f3fe76642aac3cda954d30583f --- src/nvim/buffer_defs.h | 3 +++ src/nvim/edit.c | 15 +++++++++++ src/nvim/ex_getln.c | 15 +++++++++++ src/nvim/hashtab.h | 1 + src/nvim/option.c | 15 +++++++++++ src/nvim/option_defs.h | 4 +++ src/nvim/options.lua | 9 +++++++ src/nvim/testdir/test_ins_complete.vim | 46 ++++++++++++++++++++++++++++++++++ 8 files changed, 108 insertions(+) (limited to 'src') diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index 1223f2bdab..8e855cb644 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -661,6 +661,9 @@ struct file_buffer { char_u *b_p_com; ///< 'comments' char_u *b_p_cms; ///< 'commentstring' char_u *b_p_cpt; ///< 'complete' +#ifdef BACKSLASH_IN_FILENAME + char_u *b_p_csl; ///< 'completeslash' +#endif char_u *b_p_cfu; ///< 'completefunc' char_u *b_p_ofu; ///< 'omnifunc' char_u *b_p_tfu; ///< 'tagfunc' diff --git a/src/nvim/edit.c b/src/nvim/edit.c index b3261cfce6..ac0e6cc9f6 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -4171,6 +4171,21 @@ static int ins_compl_get_exp(pos_T *ini) EW_FILE|EW_DIR|EW_ADDSLASH|EW_SILENT) == OK) { // May change home directory back to "~". tilde_replace(compl_pattern, num_matches, matches); +#ifdef BACKSLASH_IN_FILENAME + if (curbuf->b_p_csl[0] != NUL) { + for (int i = 0; i < num_matches; i++) { + char_u *ptr = matches[i]; + while (*ptr != NUL) { + if (curbuf->b_p_csl[0] == 's' && *ptr == '\\') { + *ptr = '/'; + } else if (curbuf->b_p_csl[0] == 'b' && *ptr == '/') { + *ptr = '\\'; + } + ptr += utfc_ptr2len(ptr); + } + } + } +#endif ins_compl_add_matches(num_matches, matches, p_fic || p_wic); } break; diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 940f446a7b..c56adc8bd4 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -5052,6 +5052,21 @@ ExpandFromContext ( ret = expand_wildcards_eval(&pat, num_file, file, flags); if (free_pat) xfree(pat); +#ifdef BACKSLASH_IN_FILENAME + if (p_csl[0] != NUL) { + for (int i = 0; i < *num_file; i++) { + char_u *ptr = (*file)[i]; + while (*ptr != NUL) { + if (p_csl[0] == 's' && *ptr == '\\') { + *ptr = '/'; + } else if (p_csl[0] == 'b' && *ptr == '/') { + *ptr = '\\'; + } + ptr += utfc_ptr2len(ptr); + } + } + } +#endif return ret; } diff --git a/src/nvim/hashtab.h b/src/nvim/hashtab.h index 19633d455f..c82a6cc121 100644 --- a/src/nvim/hashtab.h +++ b/src/nvim/hashtab.h @@ -51,6 +51,7 @@ typedef struct hashitem_S { /// Initial size for a hashtable. /// Our items are relatively small and growing is expensive, thus start with 16. /// Must be a power of 2. +/// This allows for storing 10 items (2/3 of 16) before a resize is needed. #define HT_INIT_SIZE 16 /// An array-based hashtable. diff --git a/src/nvim/option.c b/src/nvim/option.c index 4569eb1dda..5faf67febf 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -312,6 +312,9 @@ static char *(p_fdm_values[]) = { "manual", "expr", "marker", "indent", static char *(p_fcl_values[]) = { "all", NULL }; static char *(p_cot_values[]) = { "menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL }; +#ifdef BACKSLASH_IN_FILENAME +static char *(p_csl_values[]) = { "slash", "backslash", NULL }; +#endif static char *(p_icm_values[]) = { "nosplit", "split", NULL }; static char *(p_scl_values[]) = { "yes", "no", "auto", "auto:1", "auto:2", "auto:3", "auto:4", "auto:5", "auto:6", "auto:7", "auto:8", "auto:9", @@ -3188,6 +3191,12 @@ ambw_end: } else { completeopt_was_set(); } +#ifdef BACKSLASH_IN_FILENAME + } else if (varp == &curbuf->b_p_csl) { // 'completeslash' + if (check_opt_strings(p_csl, p_csl_values, false) != OK) { + errmsg = e_invarg; + } +#endif } else if (varp == &curwin->w_p_scl) { // 'signcolumn' if (check_opt_strings(*varp, p_scl_values, false) != OK) { @@ -5866,6 +5875,9 @@ static char_u *get_varp(vimoption_T *p) case PV_COM: return (char_u *)&(curbuf->b_p_com); case PV_CMS: return (char_u *)&(curbuf->b_p_cms); case PV_CPT: return (char_u *)&(curbuf->b_p_cpt); +# ifdef BACKSLASH_IN_FILENAME + case PV_CSL: return (char_u *)&(curbuf->b_p_csl); +# endif case PV_CFU: return (char_u *)&(curbuf->b_p_cfu); case PV_OFU: return (char_u *)&(curbuf->b_p_ofu); case PV_EOL: return (char_u *)&(curbuf->b_p_eol); @@ -6153,6 +6165,9 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_inf = p_inf; buf->b_p_swf = cmdmod.noswapfile ? false : p_swf; buf->b_p_cpt = vim_strsave(p_cpt); +# ifdef BACKSLASH_IN_FILENAME + buf->b_p_csl = vim_strsave(p_csl); +# endif buf->b_p_cfu = vim_strsave(p_cfu); buf->b_p_ofu = vim_strsave(p_ofu); buf->b_p_tfu = vim_strsave(p_tfu); diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index 6630bda710..4042b79262 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -373,6 +373,9 @@ EXTERN long p_columns; // 'columns' EXTERN int p_confirm; // 'confirm' EXTERN int p_cp; // 'compatible' EXTERN char_u *p_cot; // 'completeopt' +# ifdef BACKSLASH_IN_FILENAME +EXTERN char_u *p_csl; // 'completeslash' +# endif EXTERN long p_pb; // 'pumblend' EXTERN long p_ph; // 'pumheight' EXTERN long p_pw; // 'pumwidth' @@ -744,6 +747,7 @@ enum { , BV_CPT , BV_DICT , BV_TSR + , BV_CSL , BV_CFU , BV_DEF , BV_INC diff --git a/src/nvim/options.lua b/src/nvim/options.lua index 02df0ab276..65ef7a4527 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -452,6 +452,15 @@ return { varname='p_cot', defaults={if_true={vi="menu,preview"}} }, + { + full_name='completeslash', abbreviation='csl', + type='string', scope={'buffer'}, + vi_def=true, + vim=true, + varname='p_csl', + enable_if='BACKSLASH_IN_FILENAME', + defaults={if_true={vi=""}} + }, { full_name='confirm', abbreviation='cf', type='bool', scope={'global'}, diff --git a/src/nvim/testdir/test_ins_complete.vim b/src/nvim/testdir/test_ins_complete.vim index b8632b9595..45b0d159d4 100644 --- a/src/nvim/testdir/test_ins_complete.vim +++ b/src/nvim/testdir/test_ins_complete.vim @@ -365,6 +365,52 @@ func Test_compl_in_cmdwin() set wildmenu& wildchar& endfunc +" Test for insert path completion with completeslash option +func Test_ins_completeslash() + if !has('win32') + return + endif + + call mkdir('Xdir') + + let orig_shellslash = &shellslash + set cpt& + + new + + set noshellslash + + set completeslash= + exe "normal oXd\\" + call assert_equal('Xdir\', getline('.')) + + set completeslash=backslash + exe "normal oXd\\" + call assert_equal('Xdir\', getline('.')) + + set completeslash=slash + exe "normal oXd\\" + call assert_equal('Xdir/', getline('.')) + + set shellslash + + set completeslash= + exe "normal oXd\\" + call assert_equal('Xdir/', getline('.')) + + set completeslash=backslash + exe "normal oXd\\" + call assert_equal('Xdir\', getline('.')) + + set completeslash=slash + exe "normal oXd\\" + call assert_equal('Xdir/', getline('.')) + %bw! + call delete('Xdir', 'rf') + + let &shellslash = orig_shellslash +endfunc + func Test_pum_with_folds_two_tabs() CheckScreendump -- cgit From c203f89ace4617681fe0feb9f535c74ed0910796 Mon Sep 17 00:00:00 2001 From: skippi Date: Sun, 25 Oct 2020 18:43:20 -0500 Subject: vim-patch:8.1.1772: options test still fails on MS-Windows Problem: Options test still fails on MS-Windows. Solution: Check buffer-local value of 'completeslash'. https://github.com/vim/vim/commit/b78564d0221089e6dfc9c9d58239c18b991ca9fe --- src/nvim/option.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/option.c b/src/nvim/option.c index 5faf67febf..ca902d5669 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3192,8 +3192,9 @@ ambw_end: completeopt_was_set(); } #ifdef BACKSLASH_IN_FILENAME - } else if (varp == &curbuf->b_p_csl) { // 'completeslash' - if (check_opt_strings(p_csl, p_csl_values, false) != OK) { + } else if (gvarp == &p_csl) { // 'completeslash' + if (check_opt_strings(p_csl, p_csl_values, false) != OK + || check_opt_strings(curbuf->b_p_csl, p_csl_values, false) != OK) { errmsg = e_invarg; } #endif -- cgit From f8fd3d44ac7a89d5573b93a16896abb457e528e0 Mon Sep 17 00:00:00 2001 From: skippi Date: Sun, 25 Oct 2020 18:48:41 -0500 Subject: vim-patch:8.1.1791: 'completeslash' also applies to globpath() Problem: 'completeslash' also applies to globpath(). Solution: Add the WILD_IGNORE_COMPLETESLASH flag. (test by Yasuhiro Matsumoto, closes vim/vim#4760) --- src/nvim/eval/funcs.c | 2 +- src/nvim/ex_getln.c | 4 ++-- src/nvim/testdir/test_ins_complete.vim | 13 ++++++++----- 3 files changed, 11 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index d2e9c68965..e5912efb13 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -4007,7 +4007,7 @@ static void f_glob(typval_T *argvars, typval_T *rettv, FunPtr fptr) /// "globpath()" function static void f_globpath(typval_T *argvars, typval_T *rettv, FunPtr fptr) { - int flags = 0; // Flags for globpath. + int flags = WILD_IGNORE_COMPLETESLASH; // Flags for globpath. bool error = false; // Return a string, or a list if the optional third argument is non-zero. diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index c56adc8bd4..d67e9b2d7e 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4990,7 +4990,7 @@ ExpandFromContext ( char_u *pat, int *num_file, char_u ***file, - int options /* EW_ flags */ + int options // WILD_ flags ) { regmatch_T regmatch; @@ -5053,7 +5053,7 @@ ExpandFromContext ( if (free_pat) xfree(pat); #ifdef BACKSLASH_IN_FILENAME - if (p_csl[0] != NUL) { + if (p_csl[0] != NUL && (options & WILD_IGNORE_COMPLETESLASH) == 0) { for (int i = 0; i < *num_file; i++) { char_u *ptr = (*file)[i]; while (*ptr != NUL) { diff --git a/src/nvim/testdir/test_ins_complete.vim b/src/nvim/testdir/test_ins_complete.vim index 45b0d159d4..be79b33f9c 100644 --- a/src/nvim/testdir/test_ins_complete.vim +++ b/src/nvim/testdir/test_ins_complete.vim @@ -367,17 +367,15 @@ endfunc " Test for insert path completion with completeslash option func Test_ins_completeslash() - if !has('win32') - return - endif - + CheckMSWindows + call mkdir('Xdir') let orig_shellslash = &shellslash set cpt& new - + set noshellslash set completeslash= @@ -408,7 +406,12 @@ func Test_ins_completeslash() %bw! call delete('Xdir', 'rf') + set noshellslash + set completeslash=slash + call assert_true(stridx(globpath(&rtp, 'syntax/*.vim', 1, 1)[0], '\') != -1) + let &shellslash = orig_shellslash + set completeslash= endfunc func Test_pum_with_folds_two_tabs() -- cgit From 6a0cb2a948cd7b523a2dc545b165acf6f44d10fb Mon Sep 17 00:00:00 2001 From: skippi Date: Mon, 19 Oct 2020 20:55:27 -0500 Subject: vim-patch:8.2.1747: result of expand() unexpectedly depends on 'completeslash' Problem: Result of expand() unexpectedly depends on 'completeslash'. Solution: Temporarily reset 'completeslash'. (Yasuhiro Matsumoto, closes vim/vim#7021) https://github.com/vim/vim/commit/8f187fc6304222956f94a700758a490cc8c0af99 --- src/nvim/eval/funcs.c | 9 +++++++++ src/nvim/testdir/test_ins_complete.vim | 13 +++++++++++++ 2 files changed, 22 insertions(+) (limited to 'src') diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index e5912efb13..83ef9c8762 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -2071,6 +2071,12 @@ static void f_expand(typval_T *argvars, typval_T *rettv, FunPtr fptr) expand_T xpc; bool error = false; char_u *result; +#ifdef BACKSLASH_IN_FILENAME + char_u *p_csl_save = p_csl; + + // avoid using 'completeslash' here + p_csl = empty_option; +#endif rettv->v_type = VAR_STRING; if (argvars[1].v_type != VAR_UNKNOWN @@ -2123,6 +2129,9 @@ static void f_expand(typval_T *argvars, typval_T *rettv, FunPtr fptr) rettv->vval.v_string = NULL; } } +#ifdef BACKSLASH_IN_FILENAME + p_csl = p_csl_save; +#endif } diff --git a/src/nvim/testdir/test_ins_complete.vim b/src/nvim/testdir/test_ins_complete.vim index be79b33f9c..57a0a7aaf4 100644 --- a/src/nvim/testdir/test_ins_complete.vim +++ b/src/nvim/testdir/test_ins_complete.vim @@ -414,6 +414,19 @@ func Test_ins_completeslash() set completeslash= endfunc +func Test_issue_7021() + CheckMSWindows + + let orig_shellslash = &shellslash + set noshellslash + + set completeslash=slash + call assert_false(expand('~') =~ '/') + + let &shellslash = orig_shellslash + set completeslash= +endfunc + func Test_pum_with_folds_two_tabs() CheckScreendump -- cgit