Skip to content

Commit 7f8989d

Browse files
committed
patch 7.4.1552
Problem: ":colorscheme" does not use 'packpath'. Solution: Also use in "start" and "opt" directories in 'packpath'.
1 parent 6bef530 commit 7f8989d

16 files changed

+90
-36
lines changed

src/digraph.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2320,13 +2320,13 @@ keymap_init(void)
23202320
/* try finding "keymap/'keymap'_'encoding'.vim" in 'runtimepath' */
23212321
vim_snprintf((char *)buf, buflen, "keymap/%s_%s.vim",
23222322
curbuf->b_p_keymap, p_enc);
2323-
if (source_runtime(buf, FALSE) == FAIL)
2323+
if (source_runtime(buf, 0) == FAIL)
23242324
# endif
23252325
{
23262326
/* try finding "keymap/'keymap'.vim" in 'runtimepath' */
23272327
vim_snprintf((char *)buf, buflen, "keymap/%s.vim",
23282328
curbuf->b_p_keymap);
2329-
if (source_runtime(buf, FALSE) == FAIL)
2329+
if (source_runtime(buf, 0) == FAIL)
23302330
{
23312331
vim_free(buf);
23322332
return (char_u *)N_("E544: Keymap file not found");

src/eval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23942,7 +23942,7 @@ script_autoload(
2394223942
}
2394323943

2394423944
/* Try loading the package from $VIMRUNTIME/autoload/<name>.vim */
23945-
if (source_runtime(scriptname, FALSE) == OK)
23945+
if (source_runtime(scriptname, 0) == OK)
2394623946
ret = TRUE;
2394723947
}
2394823948

src/ex_cmds2.c

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2872,7 +2872,7 @@ ex_compiler(exarg_T *eap)
28722872
do_unlet((char_u *)"b:current_compiler", TRUE);
28732873

28742874
sprintf((char *)buf, "compiler/%s.vim", eap->arg);
2875-
if (source_runtime(buf, TRUE) == FAIL)
2875+
if (source_runtime(buf, DIP_ALL) == FAIL)
28762876
EMSG2(_("E666: compiler not supported: %s"), eap->arg);
28772877
vim_free(buf);
28782878

@@ -2906,7 +2906,7 @@ ex_compiler(exarg_T *eap)
29062906
void
29072907
ex_runtime(exarg_T *eap)
29082908
{
2909-
source_runtime(eap->arg, eap->forceit);
2909+
source_runtime(eap->arg, eap->forceit ? DIP_ALL : 0);
29102910
}
29112911

29122912
static void
@@ -2918,14 +2918,14 @@ source_callback(char_u *fname, void *cookie UNUSED)
29182918
/*
29192919
* Source the file "name" from all directories in 'runtimepath'.
29202920
* "name" can contain wildcards.
2921-
* When "all" is TRUE: source all files, otherwise only the first one.
2921+
* When "flags" has DIP_ALL: source all files, otherwise only the first one.
29222922
*
29232923
* return FAIL when no file could be sourced, OK otherwise.
29242924
*/
29252925
int
2926-
source_runtime(char_u *name, int all)
2926+
source_runtime(char_u *name, int flags)
29272927
{
2928-
return do_in_runtimepath(name, all, source_callback, NULL);
2928+
return do_in_runtimepath(name, flags, source_callback, NULL);
29292929
}
29302930

29312931
/*
@@ -3052,8 +3052,8 @@ do_in_path(
30523052
/*
30533053
* Find "name" in 'runtimepath'. When found, invoke the callback function for
30543054
* it: callback(fname, "cookie")
3055-
* When "all" is TRUE repeat for all matches, otherwise only the first one is
3056-
* used.
3055+
* When "flags" has DIP_ALL repeat for all matches, otherwise only the first
3056+
* one is used.
30573057
* Returns OK when at least one match found, FAIL otherwise.
30583058
*
30593059
* If "name" is NULL calls callback for each entry in runtimepath. Cookie is
@@ -3063,11 +3063,41 @@ do_in_path(
30633063
int
30643064
do_in_runtimepath(
30653065
char_u *name,
3066-
int all,
3066+
int flags,
30673067
void (*callback)(char_u *fname, void *ck),
30683068
void *cookie)
30693069
{
3070-
return do_in_path(p_rtp, name, all ? DIP_ALL : 0, callback, cookie);
3070+
int done;
3071+
char_u *s;
3072+
int len;
3073+
char *start_dir = "pack/*/start/*/%s";
3074+
char *opt_dir = "pack/*/opt/*/%s";
3075+
3076+
done = do_in_path(p_rtp, name, flags, callback, cookie);
3077+
3078+
if (done == FAIL && (flags & DIP_START))
3079+
{
3080+
len = STRLEN(start_dir) + STRLEN(name);
3081+
s = alloc(len);
3082+
if (s == NULL)
3083+
return FAIL;
3084+
vim_snprintf((char *)s, len, start_dir, name);
3085+
done = do_in_path(p_pp, s, flags, callback, cookie);
3086+
vim_free(s);
3087+
}
3088+
3089+
if (done == FAIL && (flags & DIP_OPT))
3090+
{
3091+
len = STRLEN(opt_dir) + STRLEN(name);
3092+
s = alloc(len);
3093+
if (s == NULL)
3094+
return FAIL;
3095+
vim_snprintf((char *)s, len, opt_dir, name);
3096+
done = do_in_path(p_pp, s, flags, callback, cookie);
3097+
vim_free(s);
3098+
}
3099+
3100+
return done;
30713101
}
30723102

30733103
/*

src/ex_docmd.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11777,16 +11777,16 @@ ex_filetype(exarg_T *eap)
1177711777
{
1177811778
if (*arg == 'o' || !filetype_detect)
1177911779
{
11780-
source_runtime((char_u *)FILETYPE_FILE, TRUE);
11780+
source_runtime((char_u *)FILETYPE_FILE, DIP_ALL);
1178111781
filetype_detect = TRUE;
1178211782
if (plugin)
1178311783
{
11784-
source_runtime((char_u *)FTPLUGIN_FILE, TRUE);
11784+
source_runtime((char_u *)FTPLUGIN_FILE, DIP_ALL);
1178511785
filetype_plugin = TRUE;
1178611786
}
1178711787
if (indent)
1178811788
{
11789-
source_runtime((char_u *)INDENT_FILE, TRUE);
11789+
source_runtime((char_u *)INDENT_FILE, DIP_ALL);
1179011790
filetype_indent = TRUE;
1179111791
}
1179211792
}
@@ -11802,18 +11802,18 @@ ex_filetype(exarg_T *eap)
1180211802
{
1180311803
if (plugin)
1180411804
{
11805-
source_runtime((char_u *)FTPLUGOF_FILE, TRUE);
11805+
source_runtime((char_u *)FTPLUGOF_FILE, DIP_ALL);
1180611806
filetype_plugin = FALSE;
1180711807
}
1180811808
if (indent)
1180911809
{
11810-
source_runtime((char_u *)INDOFF_FILE, TRUE);
11810+
source_runtime((char_u *)INDOFF_FILE, DIP_ALL);
1181111811
filetype_indent = FALSE;
1181211812
}
1181311813
}
1181411814
else
1181511815
{
11816-
source_runtime((char_u *)FTOFF_FILE, TRUE);
11816+
source_runtime((char_u *)FTOFF_FILE, DIP_ALL);
1181711817
filetype_detect = FALSE;
1181811818
}
1181911819
}

src/gui.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4988,7 +4988,7 @@ gui_find_bitmap(char_u *name, char_u *buffer, char *ext)
49884988
if (STRLEN(name) > MAXPATHL - 14)
49894989
return FAIL;
49904990
vim_snprintf((char *)buffer, MAXPATHL, "bitmaps/%s.%s", name, ext);
4991-
if (do_in_runtimepath(buffer, FALSE, gfp_setname, buffer) == FAIL
4991+
if (do_in_runtimepath(buffer, 0, gfp_setname, buffer) == FAIL
49924992
|| *buffer == NUL)
49934993
return FAIL;
49944994
return OK;

src/hardcopy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,7 @@ prt_find_resource(char *name, struct prt_ps_resource_S *resource)
17411741
vim_strcat(buffer, (char_u *)name, MAXPATHL);
17421742
vim_strcat(buffer, (char_u *)".ps", MAXPATHL);
17431743
resource->filename[0] = NUL;
1744-
retval = (do_in_runtimepath(buffer, FALSE, prt_resource_name,
1744+
retval = (do_in_runtimepath(buffer, 0, prt_resource_name,
17451745
resource->filename)
17461746
&& resource->filename[0] != NUL);
17471747
vim_free(buffer);

src/if_py_both.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ VimForeachRTP(PyObject *self UNUSED, PyObject *callable)
10611061
data.callable = callable;
10621062
data.result = NULL;
10631063

1064-
do_in_runtimepath(NULL, FALSE, &map_rtp_callback, &data);
1064+
do_in_runtimepath(NULL, 0, &map_rtp_callback, &data);
10651065

10661066
if (data.result == NULL)
10671067
{
@@ -1150,7 +1150,7 @@ Vim_GetPaths(PyObject *self UNUSED)
11501150
if (!(ret = PyList_New(0)))
11511151
return NULL;
11521152

1153-
do_in_runtimepath(NULL, FALSE, &map_finder_callback, ret);
1153+
do_in_runtimepath(NULL, 0, &map_finder_callback, ret);
11541154

11551155
if (PyErr_Occurred())
11561156
{

src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,9 +628,9 @@ vim_main2(int argc UNUSED, char **argv UNUSED)
628628
if (p_lpl)
629629
{
630630
# ifdef VMS /* Somehow VMS doesn't handle the "**". */
631-
source_runtime((char_u *)"plugin/*.vim", TRUE);
631+
source_runtime((char_u *)"plugin/*.vim", DIP_ALL);
632632
# else
633-
source_runtime((char_u *)"plugin/**/*.vim", TRUE);
633+
source_runtime((char_u *)"plugin/**/*.vim", DIP_ALL);
634634
# endif
635635
TIME_MSG("loading plugins");
636636

src/option.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7290,7 +7290,7 @@ did_set_string_option(
72907290
if (vim_strchr((char_u *)"_.,", *p) != NULL)
72917291
break;
72927292
vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
7293-
source_runtime(fname, TRUE);
7293+
source_runtime(fname, DIP_ALL);
72947294
}
72957295
#endif
72967296
}

src/os_mswin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ mch_icon_load_cb(char_u *fname, void *cookie)
950950
mch_icon_load(HANDLE *iconp)
951951
{
952952
return do_in_runtimepath((char_u *)"bitmaps/vim.ico",
953-
FALSE, mch_icon_load_cb, iconp);
953+
0, mch_icon_load_cb, iconp);
954954
}
955955

956956
int

src/spell.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,7 +2478,7 @@ spell_load_lang(char_u *lang)
24782478
"spell/%s.%s.spl",
24792479
#endif
24802480
lang, spell_enc());
2481-
r = do_in_runtimepath(fname_enc, FALSE, spell_load_cb, &sl);
2481+
r = do_in_runtimepath(fname_enc, 0, spell_load_cb, &sl);
24822482

24832483
if (r == FAIL && *sl.sl_lang != NUL)
24842484
{
@@ -2490,7 +2490,7 @@ spell_load_lang(char_u *lang)
24902490
"spell/%s.ascii.spl",
24912491
#endif
24922492
lang);
2493-
r = do_in_runtimepath(fname_enc, FALSE, spell_load_cb, &sl);
2493+
r = do_in_runtimepath(fname_enc, 0, spell_load_cb, &sl);
24942494

24952495
#ifdef FEAT_AUTOCMD
24962496
if (r == FAIL && *sl.sl_lang != NUL && round == 1
@@ -2519,7 +2519,7 @@ spell_load_lang(char_u *lang)
25192519
{
25202520
/* At least one file was loaded, now load ALL the additions. */
25212521
STRCPY(fname_enc + STRLEN(fname_enc) - 3, "add.spl");
2522-
do_in_runtimepath(fname_enc, TRUE, spell_load_cb, &sl);
2522+
do_in_runtimepath(fname_enc, DIP_ALL, spell_load_cb, &sl);
25232523
}
25242524
}
25252525

src/syntax.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4813,7 +4813,7 @@ syn_cmd_include(exarg_T *eap, int syncing UNUSED)
48134813
prev_toplvl_grp = curwin->w_s->b_syn_topgrp;
48144814
curwin->w_s->b_syn_topgrp = sgl_id;
48154815
if (source ? do_source(eap->arg, FALSE, DOSO_NONE) == FAIL
4816-
: source_runtime(eap->arg, TRUE) == FAIL)
4816+
: source_runtime(eap->arg, DIP_ALL) == FAIL)
48174817
EMSG2(_(e_notopen), eap->arg);
48184818
curwin->w_s->b_syn_topgrp = prev_toplvl_grp;
48194819
current_syn_inc_tag = prev_syn_inc_tag;
@@ -7075,7 +7075,7 @@ init_highlight(
70757075
else
70767076
{
70777077
++recursive;
7078-
(void)source_runtime((char_u *)"syntax/syncolor.vim", TRUE);
7078+
(void)source_runtime((char_u *)"syntax/syncolor.vim", DIP_ALL);
70797079
--recursive;
70807080
}
70817081
}
@@ -7104,7 +7104,7 @@ load_colors(char_u *name)
71047104
if (buf != NULL)
71057105
{
71067106
sprintf((char *)buf, "colors/%s.vim", name);
7107-
retval = source_runtime(buf, FALSE);
7107+
retval = source_runtime(buf, DIP_START + DIP_OPT);
71087108
vim_free(buf);
71097109
#ifdef FEAT_AUTOCMD
71107110
apply_autocmds(EVENT_COLORSCHEME, name, curbuf->b_fname, FALSE, curbuf);

src/tag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2638,7 +2638,7 @@ get_tagfname(
26382638
#else
26392639
"doc/tags"
26402640
#endif
2641-
, TRUE, found_tagfile_cb, NULL);
2641+
, DIP_ALL, found_tagfile_cb, NULL);
26422642
}
26432643

26442644
if (tnp->tn_hf_idx >= tag_fnames.ga_len)

src/testdir/test_packadd.vim

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,23 @@ func Test_helptags()
114114
let tags2 = readfile(docdir2 . '/tags')
115115
call assert_true(tags2[0] =~ 'look-away')
116116
endfunc
117+
118+
func Test_colorscheme()
119+
let colordirrun = &packpath . '/runtime/colors'
120+
let colordirstart = &packpath . '/pack/mine/start/foo/colors'
121+
let colordiropt = &packpath . '/pack/mine/opt/bar/colors'
122+
call mkdir(colordirrun, 'p')
123+
call mkdir(colordirstart, 'p')
124+
call mkdir(colordiropt, 'p')
125+
call writefile(['let g:found_one = 1'], colordirrun . '/one.vim')
126+
call writefile(['let g:found_two = 1'], colordirstart . '/two.vim')
127+
call writefile(['let g:found_three = 1'], colordiropt . '/three.vim')
128+
exe 'set rtp=' . &packpath . '/runtime'
129+
130+
colorscheme one
131+
call assert_equal(1, g:found_one)
132+
colorscheme two
133+
call assert_equal(1, g:found_two)
134+
colorscheme three
135+
call assert_equal(1, g:found_three)
136+
endfunc

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+
1552,
746748
/**/
747749
1551,
748750
/**/

src/vim.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2289,8 +2289,10 @@ int vim_main2(int argc, char **argv);
22892289
#endif
22902290

22912291
/* Used for flags of do_in_path() */
2292-
#define DIP_ALL 1 /* all matches, not just the first one */
2293-
#define DIP_DIR 2 /* find directories instead of files. */
2294-
#define DIP_ERR 4 /* give an error message when none found. */
2292+
#define DIP_ALL 0x01 /* all matches, not just the first one */
2293+
#define DIP_DIR 0x02 /* find directories instead of files. */
2294+
#define DIP_ERR 0x04 /* give an error message when none found. */
2295+
#define DIP_START 0x08 /* also use "start" directory in 'packpath' */
2296+
#define DIP_OPT 0x10 /* also use "opt" directory in 'packpath' */
22952297

22962298
#endif /* VIM__H */

0 commit comments

Comments
 (0)