1
0
forked from aniani/vim

patch 7.4.1840

Problem:    When using packages an "after" directory cannot be used.
Solution:   Add the "after" directory of the package to 'runtimepath' if it
            exists.
This commit is contained in:
Bram Moolenaar
2016-05-24 19:37:29 +02:00
parent 2bbf8eff6f
commit a570244531
3 changed files with 23 additions and 6 deletions

View File

@@ -3326,13 +3326,15 @@ add_pack_plugin(char_u *fname, void *cookie)
int keep; int keep;
int oldlen; int oldlen;
int addlen; int addlen;
char_u *afterdir;
int afterlen = 0;
char_u *ffname = fix_fname(fname); char_u *ffname = fix_fname(fname);
if (ffname == NULL) if (ffname == NULL)
return; return;
if (cookie != &APP_LOAD && strstr((char *)p_rtp, (char *)ffname) == NULL) if (cookie != &APP_LOAD && strstr((char *)p_rtp, (char *)ffname) == NULL)
{ {
/* directory not in 'runtimepath', add it */ /* directory is not yet in 'runtimepath', add it */
p4 = p3 = p2 = p1 = get_past_head(ffname); p4 = p3 = p2 = p1 = get_past_head(ffname);
for (p = p1; *p; mb_ptr_adv(p)) for (p = p1; *p; mb_ptr_adv(p))
if (vim_ispathsep_nocolon(*p)) if (vim_ispathsep_nocolon(*p))
@@ -3360,20 +3362,31 @@ add_pack_plugin(char_u *fname, void *cookie)
} }
*p4 = c; *p4 = c;
/* check if rtp/pack/name/start/name/after exists */
afterdir = concat_fnames(ffname, (char_u *)"after", TRUE);
if (afterdir != NULL && mch_isdir(afterdir))
afterlen = STRLEN(afterdir) + 1; /* add one for comma */
oldlen = (int)STRLEN(p_rtp); oldlen = (int)STRLEN(p_rtp);
addlen = (int)STRLEN(ffname); addlen = (int)STRLEN(ffname) + 1; /* add one for comma */
new_rtp = alloc(oldlen + addlen + 2); new_rtp = alloc(oldlen + addlen + afterlen + 1); /* add one for NUL */
if (new_rtp == NULL) if (new_rtp == NULL)
goto theend; goto theend;
keep = (int)(insp - p_rtp); keep = (int)(insp - p_rtp);
mch_memmove(new_rtp, p_rtp, keep); mch_memmove(new_rtp, p_rtp, keep);
new_rtp[keep] = ','; new_rtp[keep] = ',';
mch_memmove(new_rtp + keep + 1, ffname, addlen + 1); mch_memmove(new_rtp + keep + 1, ffname, addlen);
if (p_rtp[keep] != NUL) if (p_rtp[keep] != NUL)
mch_memmove(new_rtp + keep + 1 + addlen, p_rtp + keep, mch_memmove(new_rtp + keep + addlen, p_rtp + keep,
oldlen - keep + 1); oldlen - keep + 1);
if (afterlen > 0)
{
STRCAT(new_rtp, ",");
STRCAT(new_rtp, afterdir);
}
set_option_value((char_u *)"rtp", 0L, new_rtp, 0); set_option_value((char_u *)"rtp", 0L, new_rtp, 0);
vim_free(new_rtp); vim_free(new_rtp);
vim_free(afterdir);
} }
if (cookie != &APP_ADD_DIR) if (cookie != &APP_ADD_DIR)

View File

@@ -13,6 +13,7 @@ endfunc
func Test_packadd() func Test_packadd()
call mkdir(s:plugdir . '/plugin/also', 'p') call mkdir(s:plugdir . '/plugin/also', 'p')
call mkdir(s:plugdir . '/ftdetect', 'p') call mkdir(s:plugdir . '/ftdetect', 'p')
call mkdir(s:plugdir . '/after', 'p')
set rtp& set rtp&
let rtp = &rtp let rtp = &rtp
filetype on filetype on
@@ -35,7 +36,8 @@ func Test_packadd()
call assert_equal(77, g:plugin_also_works) call assert_equal(77, g:plugin_also_works)
call assert_equal(17, g:ftdetect_works) call assert_equal(17, g:ftdetect_works)
call assert_true(len(&rtp) > len(rtp)) call assert_true(len(&rtp) > len(rtp))
call assert_true(&rtp =~ 'testdir/Xdir/pack/mine/opt/mytest\($\|,\)') call assert_true(&rtp =~ '/testdir/Xdir/pack/mine/opt/mytest\($\|,\)')
call assert_true(&rtp =~ '/testdir/Xdir/pack/mine/opt/mytest/after$')
" Check exception " Check exception
call assert_fails("packadd directorynotfound", 'E919:') call assert_fails("packadd directorynotfound", 'E919:')

View File

@@ -753,6 +753,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1840,
/**/ /**/
1839, 1839,
/**/ /**/