Skip to content

Commit 52f9c19

Browse files
committed
patch 7.4.1554
Problem: Completion for :colorscheme does not use 'packpath'. Solution: Make it work, add a test. (Hirohito Higashi)
1 parent 8dcf259 commit 52f9c19

3 files changed

Lines changed: 69 additions & 7 deletions

File tree

src/ex_getln.c

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static int ExpandFromContext(expand_T *xp, char_u *, int *, char_u ***, int);
111111
static int expand_showtail(expand_T *xp);
112112
#ifdef FEAT_CMDL_COMPL
113113
static int expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, int flagsarg);
114-
static int ExpandRTDir(char_u *pat, int *num_file, char_u ***file, char *dirname[]);
114+
static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file, char *dirname[]);
115115
static int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file);
116116
# ifdef FEAT_CMDHIST
117117
static char_u *get_history_arg(expand_T *xp, int idx);
@@ -4628,22 +4628,23 @@ ExpandFromContext(
46284628
if (xp->xp_context == EXPAND_COLORS)
46294629
{
46304630
char *directories[] = {"colors", NULL};
4631-
return ExpandRTDir(pat, num_file, file, directories);
4631+
return ExpandRTDir(pat, DIP_START + DIP_OPT, num_file, file,
4632+
directories);
46324633
}
46334634
if (xp->xp_context == EXPAND_COMPILER)
46344635
{
46354636
char *directories[] = {"compiler", NULL};
4636-
return ExpandRTDir(pat, num_file, file, directories);
4637+
return ExpandRTDir(pat, 0, num_file, file, directories);
46374638
}
46384639
if (xp->xp_context == EXPAND_OWNSYNTAX)
46394640
{
46404641
char *directories[] = {"syntax", NULL};
4641-
return ExpandRTDir(pat, num_file, file, directories);
4642+
return ExpandRTDir(pat, 0, num_file, file, directories);
46424643
}
46434644
if (xp->xp_context == EXPAND_FILETYPE)
46444645
{
46454646
char *directories[] = {"syntax", "indent", "ftplugin", NULL};
4646-
return ExpandRTDir(pat, num_file, file, directories);
4647+
return ExpandRTDir(pat, 0, num_file, file, directories);
46474648
}
46484649
# if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL)
46494650
if (xp->xp_context == EXPAND_USER_LIST)
@@ -5119,13 +5120,19 @@ ExpandUserList(
51195120
#endif
51205121

51215122
/*
5122-
* Expand color scheme, compiler or filetype names:
5123-
* 'runtimepath'/{dirnames}/{pat}.vim
5123+
* Expand color scheme, compiler or filetype names.
5124+
* Search from 'runtimepath':
5125+
* 'runtimepath'/{dirnames}/{pat}.vim
5126+
* When "flags" has DIP_START: search also from 'start' of 'packpath':
5127+
* 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim
5128+
* When "flags" has DIP_OPT: search also from 'opt' of 'packpath':
5129+
* 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim
51245130
* "dirnames" is an array with one or more directory names.
51255131
*/
51265132
static int
51275133
ExpandRTDir(
51285134
char_u *pat,
5135+
int flags,
51295136
int *num_file,
51305137
char_u ***file,
51315138
char *dirnames[])
@@ -5155,6 +5162,36 @@ ExpandRTDir(
51555162
vim_free(s);
51565163
}
51575164

5165+
if (flags & DIP_START) {
5166+
for (i = 0; dirnames[i] != NULL; ++i)
5167+
{
5168+
s = alloc((unsigned)(STRLEN(dirnames[i]) + pat_len + 22));
5169+
if (s == NULL)
5170+
{
5171+
ga_clear_strings(&ga);
5172+
return FAIL;
5173+
}
5174+
sprintf((char *)s, "pack/*/start/*/%s/%s*.vim", dirnames[i], pat);
5175+
globpath(p_pp, s, &ga, 0);
5176+
vim_free(s);
5177+
}
5178+
}
5179+
5180+
if (flags & DIP_OPT) {
5181+
for (i = 0; dirnames[i] != NULL; ++i)
5182+
{
5183+
s = alloc((unsigned)(STRLEN(dirnames[i]) + pat_len + 20));
5184+
if (s == NULL)
5185+
{
5186+
ga_clear_strings(&ga);
5187+
return FAIL;
5188+
}
5189+
sprintf((char *)s, "pack/*/opt/*/%s/%s*.vim", dirnames[i], pat);
5190+
globpath(p_pp, s, &ga, 0);
5191+
vim_free(s);
5192+
}
5193+
}
5194+
51585195
for (i = 0; i < ga.ga_len; ++i)
51595196
{
51605197
match = ((char_u **)ga.ga_data)[i];

src/testdir/test_packadd.vim

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,29 @@ func Test_colorscheme()
135135
call assert_equal(1, g:found_three)
136136
endfunc
137137

138+
func Test_colorscheme_completion()
139+
let colordirrun = &packpath . '/runtime/colors'
140+
let colordirstart = &packpath . '/pack/mine/start/foo/colors'
141+
let colordiropt = &packpath . '/pack/mine/opt/bar/colors'
142+
call mkdir(colordirrun, 'p')
143+
call mkdir(colordirstart, 'p')
144+
call mkdir(colordiropt, 'p')
145+
call writefile(['let g:found_one = 1'], colordirrun . '/one.vim')
146+
call writefile(['let g:found_two = 1'], colordirstart . '/two.vim')
147+
call writefile(['let g:found_three = 1'], colordiropt . '/three.vim')
148+
exe 'set rtp=' . &packpath . '/runtime'
149+
150+
let li=[]
151+
call feedkeys(":colorscheme " . repeat("\<Tab>", 1) . "')\<C-B>call add(li, '\<CR>", 't')
152+
call feedkeys(":colorscheme " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't')
153+
call feedkeys(":colorscheme " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't')
154+
call feedkeys(":colorscheme " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx')
155+
call assert_equal("colorscheme one", li[0])
156+
call assert_equal("colorscheme three", li[1])
157+
call assert_equal("colorscheme two", li[2])
158+
call assert_equal("colorscheme ", li[3])
159+
endfunc
160+
138161
func Test_runtime()
139162
let rundir = &packpath . '/runtime/extra'
140163
let startdir = &packpath . '/pack/mine/start/foo/extra'

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,8 @@ static char *(features[]) =
743743

744744
static int included_patches[] =
745745
{ /* Add new patch number below this line */
746+
/**/
747+
1554,
746748
/**/
747749
1553,
748750
/**/

0 commit comments

Comments
 (0)