changeset 8524:2f57bbe870ea v7.4.1552

commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f Author: Bram Moolenaar <Bram@vim.org> Date: Sat Mar 12 22:11:39 2016 +0100 patch 7.4.1552 Problem: ":colorscheme" does not use 'packpath'. Solution: Also use in "start" and "opt" directories in 'packpath'.
author Christian Brabandt <cb@256bit.org>
date Sat, 12 Mar 2016 22:15:05 +0100
parents 299f84e1e738
children e68f52f1e740
files src/digraph.c src/eval.c src/ex_cmds2.c src/ex_docmd.c src/gui.c src/hardcopy.c src/if_py_both.h src/main.c src/option.c src/os_mswin.c src/spell.c src/syntax.c src/tag.c src/testdir/test_packadd.vim src/version.c src/vim.h
diffstat 16 files changed, 90 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/src/digraph.c
+++ b/src/digraph.c
@@ -2320,13 +2320,13 @@ keymap_init(void)
 	/* try finding "keymap/'keymap'_'encoding'.vim"  in 'runtimepath' */
 	vim_snprintf((char *)buf, buflen, "keymap/%s_%s.vim",
 						   curbuf->b_p_keymap, p_enc);
-	if (source_runtime(buf, FALSE) == FAIL)
+	if (source_runtime(buf, 0) == FAIL)
 # endif
 	{
 	    /* try finding "keymap/'keymap'.vim" in 'runtimepath'  */
 	    vim_snprintf((char *)buf, buflen, "keymap/%s.vim",
 							  curbuf->b_p_keymap);
-	    if (source_runtime(buf, FALSE) == FAIL)
+	    if (source_runtime(buf, 0) == FAIL)
 	    {
 		vim_free(buf);
 		return (char_u *)N_("E544: Keymap file not found");
--- a/src/eval.c
+++ b/src/eval.c
@@ -23942,7 +23942,7 @@ script_autoload(
 	}
 
 	/* Try loading the package from $VIMRUNTIME/autoload/<name>.vim */
-	if (source_runtime(scriptname, FALSE) == OK)
+	if (source_runtime(scriptname, 0) == OK)
 	    ret = TRUE;
     }
 
--- a/src/ex_cmds2.c
+++ b/src/ex_cmds2.c
@@ -2872,7 +2872,7 @@ ex_compiler(exarg_T *eap)
 	    do_unlet((char_u *)"b:current_compiler", TRUE);
 
 	    sprintf((char *)buf, "compiler/%s.vim", eap->arg);
-	    if (source_runtime(buf, TRUE) == FAIL)
+	    if (source_runtime(buf, DIP_ALL) == FAIL)
 		EMSG2(_("E666: compiler not supported: %s"), eap->arg);
 	    vim_free(buf);
 
@@ -2906,7 +2906,7 @@ ex_compiler(exarg_T *eap)
     void
 ex_runtime(exarg_T *eap)
 {
-    source_runtime(eap->arg, eap->forceit);
+    source_runtime(eap->arg, eap->forceit ? DIP_ALL : 0);
 }
 
     static void
@@ -2918,14 +2918,14 @@ source_callback(char_u *fname, void *coo
 /*
  * Source the file "name" from all directories in 'runtimepath'.
  * "name" can contain wildcards.
- * When "all" is TRUE: source all files, otherwise only the first one.
+ * When "flags" has DIP_ALL: source all files, otherwise only the first one.
  *
  * return FAIL when no file could be sourced, OK otherwise.
  */
     int
-source_runtime(char_u *name, int all)
+source_runtime(char_u *name, int flags)
 {
-    return do_in_runtimepath(name, all, source_callback, NULL);
+    return do_in_runtimepath(name, flags, source_callback, NULL);
 }
 
 /*
@@ -3052,8 +3052,8 @@ do_in_path(
 /*
  * Find "name" in 'runtimepath'.  When found, invoke the callback function for
  * it: callback(fname, "cookie")
- * When "all" is TRUE repeat for all matches, otherwise only the first one is
- * used.
+ * When "flags" has DIP_ALL repeat for all matches, otherwise only the first
+ * one is used.
  * Returns OK when at least one match found, FAIL otherwise.
  *
  * If "name" is NULL calls callback for each entry in runtimepath. Cookie is
@@ -3063,11 +3063,41 @@ do_in_path(
     int
 do_in_runtimepath(
     char_u	*name,
-    int		all,
+    int		flags,
     void	(*callback)(char_u *fname, void *ck),
     void	*cookie)
 {
-    return do_in_path(p_rtp, name, all ? DIP_ALL : 0, callback, cookie);
+    int		done;
+    char_u	*s;
+    int		len;
+    char	*start_dir = "pack/*/start/*/%s";
+    char	*opt_dir = "pack/*/opt/*/%s";
+
+    done = do_in_path(p_rtp, name, flags, callback, cookie);
+
+    if (done == FAIL && (flags & DIP_START))
+    {
+	len = STRLEN(start_dir) + STRLEN(name);
+	s = alloc(len);
+	if (s == NULL)
+	    return FAIL;
+	vim_snprintf((char *)s, len, start_dir, name);
+	done = do_in_path(p_pp, s, flags, callback, cookie);
+	vim_free(s);
+    }
+
+    if (done == FAIL && (flags & DIP_OPT))
+    {
+	len = STRLEN(opt_dir) + STRLEN(name);
+	s = alloc(len);
+	if (s == NULL)
+	    return FAIL;
+	vim_snprintf((char *)s, len, opt_dir, name);
+	done = do_in_path(p_pp, s, flags, callback, cookie);
+	vim_free(s);
+    }
+
+    return done;
 }
 
 /*
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -11777,16 +11777,16 @@ ex_filetype(exarg_T *eap)
     {
 	if (*arg == 'o' || !filetype_detect)
 	{
-	    source_runtime((char_u *)FILETYPE_FILE, TRUE);
+	    source_runtime((char_u *)FILETYPE_FILE, DIP_ALL);
 	    filetype_detect = TRUE;
 	    if (plugin)
 	    {
-		source_runtime((char_u *)FTPLUGIN_FILE, TRUE);
+		source_runtime((char_u *)FTPLUGIN_FILE, DIP_ALL);
 		filetype_plugin = TRUE;
 	    }
 	    if (indent)
 	    {
-		source_runtime((char_u *)INDENT_FILE, TRUE);
+		source_runtime((char_u *)INDENT_FILE, DIP_ALL);
 		filetype_indent = TRUE;
 	    }
 	}
@@ -11802,18 +11802,18 @@ ex_filetype(exarg_T *eap)
 	{
 	    if (plugin)
 	    {
-		source_runtime((char_u *)FTPLUGOF_FILE, TRUE);
+		source_runtime((char_u *)FTPLUGOF_FILE, DIP_ALL);
 		filetype_plugin = FALSE;
 	    }
 	    if (indent)
 	    {
-		source_runtime((char_u *)INDOFF_FILE, TRUE);
+		source_runtime((char_u *)INDOFF_FILE, DIP_ALL);
 		filetype_indent = FALSE;
 	    }
 	}
 	else
 	{
-	    source_runtime((char_u *)FTOFF_FILE, TRUE);
+	    source_runtime((char_u *)FTOFF_FILE, DIP_ALL);
 	    filetype_detect = FALSE;
 	}
     }
--- a/src/gui.c
+++ b/src/gui.c
@@ -4988,7 +4988,7 @@ gui_find_bitmap(char_u *name, char_u *bu
     if (STRLEN(name) > MAXPATHL - 14)
 	return FAIL;
     vim_snprintf((char *)buffer, MAXPATHL, "bitmaps/%s.%s", name, ext);
-    if (do_in_runtimepath(buffer, FALSE, gfp_setname, buffer) == FAIL
+    if (do_in_runtimepath(buffer, 0, gfp_setname, buffer) == FAIL
 							    || *buffer == NUL)
 	return FAIL;
     return OK;
--- a/src/hardcopy.c
+++ b/src/hardcopy.c
@@ -1741,7 +1741,7 @@ prt_find_resource(char *name, struct prt
     vim_strcat(buffer, (char_u *)name, MAXPATHL);
     vim_strcat(buffer, (char_u *)".ps", MAXPATHL);
     resource->filename[0] = NUL;
-    retval = (do_in_runtimepath(buffer, FALSE, prt_resource_name,
+    retval = (do_in_runtimepath(buffer, 0, prt_resource_name,
 							   resource->filename)
 	    && resource->filename[0] != NUL);
     vim_free(buffer);
--- a/src/if_py_both.h
+++ b/src/if_py_both.h
@@ -1061,7 +1061,7 @@ VimForeachRTP(PyObject *self UNUSED, PyO
     data.callable = callable;
     data.result = NULL;
 
-    do_in_runtimepath(NULL, FALSE, &map_rtp_callback, &data);
+    do_in_runtimepath(NULL, 0, &map_rtp_callback, &data);
 
     if (data.result == NULL)
     {
@@ -1150,7 +1150,7 @@ Vim_GetPaths(PyObject *self UNUSED)
     if (!(ret = PyList_New(0)))
 	return NULL;
 
-    do_in_runtimepath(NULL, FALSE, &map_finder_callback, ret);
+    do_in_runtimepath(NULL, 0, &map_finder_callback, ret);
 
     if (PyErr_Occurred())
     {
--- a/src/main.c
+++ b/src/main.c
@@ -628,9 +628,9 @@ vim_main2(int argc UNUSED, char **argv U
     if (p_lpl)
     {
 # ifdef VMS	/* Somehow VMS doesn't handle the "**". */
-	source_runtime((char_u *)"plugin/*.vim", TRUE);
+	source_runtime((char_u *)"plugin/*.vim", DIP_ALL);
 # else
-	source_runtime((char_u *)"plugin/**/*.vim", TRUE);
+	source_runtime((char_u *)"plugin/**/*.vim", DIP_ALL);
 # endif
 	TIME_MSG("loading plugins");
 
--- a/src/option.c
+++ b/src/option.c
@@ -7290,7 +7290,7 @@ did_set_string_option(
 		if (vim_strchr((char_u *)"_.,", *p) != NULL)
 		    break;
 	    vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
-	    source_runtime(fname, TRUE);
+	    source_runtime(fname, DIP_ALL);
 	}
 #endif
     }
--- a/src/os_mswin.c
+++ b/src/os_mswin.c
@@ -950,7 +950,7 @@ mch_icon_load_cb(char_u *fname, void *co
 mch_icon_load(HANDLE *iconp)
 {
     return do_in_runtimepath((char_u *)"bitmaps/vim.ico",
-					      FALSE, mch_icon_load_cb, iconp);
+						  0, mch_icon_load_cb, iconp);
 }
 
     int
--- a/src/spell.c
+++ b/src/spell.c
@@ -2478,7 +2478,7 @@ spell_load_lang(char_u *lang)
 					"spell/%s.%s.spl",
 #endif
 							   lang, spell_enc());
-	r = do_in_runtimepath(fname_enc, FALSE, spell_load_cb, &sl);
+	r = do_in_runtimepath(fname_enc, 0, spell_load_cb, &sl);
 
 	if (r == FAIL && *sl.sl_lang != NUL)
 	{
@@ -2490,7 +2490,7 @@ spell_load_lang(char_u *lang)
 						  "spell/%s.ascii.spl",
 #endif
 									lang);
-	    r = do_in_runtimepath(fname_enc, FALSE, spell_load_cb, &sl);
+	    r = do_in_runtimepath(fname_enc, 0, spell_load_cb, &sl);
 
 #ifdef FEAT_AUTOCMD
 	    if (r == FAIL && *sl.sl_lang != NUL && round == 1
@@ -2519,7 +2519,7 @@ spell_load_lang(char_u *lang)
     {
 	/* At least one file was loaded, now load ALL the additions. */
 	STRCPY(fname_enc + STRLEN(fname_enc) - 3, "add.spl");
-	do_in_runtimepath(fname_enc, TRUE, spell_load_cb, &sl);
+	do_in_runtimepath(fname_enc, DIP_ALL, spell_load_cb, &sl);
     }
 }
 
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -4813,7 +4813,7 @@ syn_cmd_include(exarg_T *eap, int syncin
     prev_toplvl_grp = curwin->w_s->b_syn_topgrp;
     curwin->w_s->b_syn_topgrp = sgl_id;
     if (source ? do_source(eap->arg, FALSE, DOSO_NONE) == FAIL
-				: source_runtime(eap->arg, TRUE) == FAIL)
+				: source_runtime(eap->arg, DIP_ALL) == FAIL)
 	EMSG2(_(e_notopen), eap->arg);
     curwin->w_s->b_syn_topgrp = prev_toplvl_grp;
     current_syn_inc_tag = prev_syn_inc_tag;
@@ -7075,7 +7075,7 @@ init_highlight(
 	else
 	{
 	    ++recursive;
-	    (void)source_runtime((char_u *)"syntax/syncolor.vim", TRUE);
+	    (void)source_runtime((char_u *)"syntax/syncolor.vim", DIP_ALL);
 	    --recursive;
 	}
     }
@@ -7104,7 +7104,7 @@ load_colors(char_u *name)
     if (buf != NULL)
     {
 	sprintf((char *)buf, "colors/%s.vim", name);
-	retval = source_runtime(buf, FALSE);
+	retval = source_runtime(buf, DIP_START + DIP_OPT);
 	vim_free(buf);
 #ifdef FEAT_AUTOCMD
 	apply_autocmds(EVENT_COLORSCHEME, name, curbuf->b_fname, FALSE, curbuf);
--- a/src/tag.c
+++ b/src/tag.c
@@ -2638,7 +2638,7 @@ get_tagfname(
 #else
 		    "doc/tags"
 #endif
-					      , TRUE, found_tagfile_cb, NULL);
+					   , DIP_ALL, found_tagfile_cb, NULL);
 	}
 
 	if (tnp->tn_hf_idx >= tag_fnames.ga_len)
--- a/src/testdir/test_packadd.vim
+++ b/src/testdir/test_packadd.vim
@@ -114,3 +114,23 @@ func Test_helptags()
   let tags2 = readfile(docdir2 . '/tags') 
   call assert_true(tags2[0] =~ 'look-away')
 endfunc
+
+func Test_colorscheme()
+  let colordirrun = &packpath . '/runtime/colors'
+  let colordirstart = &packpath . '/pack/mine/start/foo/colors'
+  let colordiropt = &packpath . '/pack/mine/opt/bar/colors'
+  call mkdir(colordirrun, 'p')
+  call mkdir(colordirstart, 'p')
+  call mkdir(colordiropt, 'p')
+  call writefile(['let g:found_one = 1'], colordirrun . '/one.vim')
+  call writefile(['let g:found_two = 1'], colordirstart . '/two.vim')
+  call writefile(['let g:found_three = 1'], colordiropt . '/three.vim')
+  exe 'set rtp=' . &packpath . '/runtime'
+
+  colorscheme one
+  call assert_equal(1, g:found_one)
+  colorscheme two
+  call assert_equal(1, g:found_two)
+  colorscheme three
+  call assert_equal(1, g:found_three)
+endfunc
--- a/src/version.c
+++ b/src/version.c
@@ -744,6 +744,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1552,
+/**/
     1551,
 /**/
     1550,
--- a/src/vim.h
+++ b/src/vim.h
@@ -2289,8 +2289,10 @@ int vim_main2(int argc, char **argv);
 #endif
 
 /* Used for flags of do_in_path() */
-#define DIP_ALL	1	/* all matches, not just the first one */
-#define DIP_DIR	2	/* find directories instead of files. */
-#define DIP_ERR	4	/* give an error message when none found. */
+#define DIP_ALL	    0x01	/* all matches, not just the first one */
+#define DIP_DIR	    0x02	/* find directories instead of files. */
+#define DIP_ERR	    0x04	/* give an error message when none found. */
+#define DIP_START   0x08	/* also use "start" directory in 'packpath' */
+#define DIP_OPT	    0x10	/* also use "opt" directory in 'packpath' */
 
 #endif /* VIM__H */