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.

a570244531
This commit is contained in:
James McCoy 2016-07-08 00:05:35 -04:00
parent e686b613ec
commit 520a4f06e2
3 changed files with 20 additions and 5 deletions

View File

@ -2468,7 +2468,7 @@ static void add_pack_plugin(char_u *fname, void *cookie)
} }
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)) {
@ -2496,22 +2496,34 @@ static void add_pack_plugin(char_u *fname, void *cookie)
} }
*p4 = c; *p4 = c;
// check if rtp/pack/name/start/name/after exists
char *afterdir = concat_fnames((char *)ffname, "after", true);
size_t afterlen = 0;
if (os_isdir((char_u *)afterdir)) {
afterlen = STRLEN(afterdir) + 1; // add one for comma
}
size_t oldlen = STRLEN(p_rtp); size_t oldlen = STRLEN(p_rtp);
size_t addlen = STRLEN(ffname); size_t addlen = STRLEN(ffname) + 1; // add one for comma
new_rtp = try_malloc(oldlen + addlen + 1); new_rtp = try_malloc(oldlen + addlen + afterlen + 1); // add one for NUL
if (new_rtp == NULL) { if (new_rtp == NULL) {
goto theend; goto theend;
} }
uintptr_t keep = (uintptr_t)(insp - p_rtp); uintptr_t keep = (uintptr_t)(insp - p_rtp);
memmove(new_rtp, p_rtp, keep); memmove(new_rtp, p_rtp, keep);
new_rtp[keep] = ','; new_rtp[keep] = ',';
memmove(new_rtp + keep + 1, ffname, addlen + 1); memmove(new_rtp + keep + 1, ffname, addlen);
if (p_rtp[keep] != NUL) { if (p_rtp[keep] != NUL) {
memmove(new_rtp + keep + 1 + addlen, p_rtp + keep, 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);
xfree(new_rtp); xfree(new_rtp);
xfree(afterdir);
} }
if (cookie != &APP_ADD_DIR) { if (cookie != &APP_ADD_DIR) {

View File

@ -76,6 +76,7 @@ static char *features[] = {
// clang-format off // clang-format off
static int included_patches[] = { static int included_patches[] = {
1960, 1960,
1840,
1832, 1832,
1831, 1831,
1809, 1809,

View File

@ -27,6 +27,7 @@ describe('packadd', function()
func Test_packadd() func Test_packadd()
call mkdir(s:plugdir . '/plugin', 'p') call mkdir(s:plugdir . '/plugin', '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
@ -45,6 +46,7 @@ describe('packadd', function()
call assert_true(17, g:ftdetect_works) call assert_true(17, g:ftdetect_works)
call assert_true(len(&rtp) > len(rtp)) call assert_true(len(&rtp) > len(rtp))
call assert_true(&rtp =~ (s:plugdir . '\($\|,\)')) call assert_true(&rtp =~ (s:plugdir . '\($\|,\)'))
call assert_true(&rtp =~ (s:plugdir . '/after$'))
" Check exception " Check exception
call assert_fails("packadd directorynotfound", 'E919:') call assert_fails("packadd directorynotfound", 'E919:')