0
0
mirror of https://github.com/vim/vim.git synced 2025-09-27 04:14:06 -04:00

patch 8.1.0353: an "after" directory of a package is appended to 'rtp'

Problem:    An "after" directory of a package is appended to 'rtp', which
            will be after the user's "after" directory. ()
Solution:   Insert the package "after" directory before any other "after"
            directory in 'rtp'. (closes #3409)
This commit is contained in:
Bram Moolenaar
2018-09-08 18:21:16 +02:00
parent d4a1aabe37
commit 99396d4cbf
3 changed files with 96 additions and 28 deletions

View File

@@ -3691,14 +3691,17 @@ source_all_matches(char_u *pat)
add_pack_dir_to_rtp(char_u *fname) add_pack_dir_to_rtp(char_u *fname)
{ {
char_u *p4, *p3, *p2, *p1, *p; char_u *p4, *p3, *p2, *p1, *p;
char_u *insp; char_u *entry;
char_u *insp = NULL;
int c; int c;
char_u *new_rtp; char_u *new_rtp;
int keep; int keep;
size_t oldlen; size_t oldlen;
size_t addlen; size_t addlen;
size_t new_rtp_len;
char_u *afterdir = NULL; char_u *afterdir = NULL;
size_t afterlen = 0; size_t afterlen = 0;
char_u *after_insp = NULL;
char_u *ffname = NULL; char_u *ffname = NULL;
size_t fname_len; size_t fname_len;
char_u *buf = NULL; char_u *buf = NULL;
@@ -3725,54 +3728,99 @@ add_pack_dir_to_rtp(char_u *fname)
if (ffname == NULL) if (ffname == NULL)
return FAIL; return FAIL;
/* Find "ffname" in "p_rtp", ignoring '/' vs '\' differences. */ // Find "ffname" in "p_rtp", ignoring '/' vs '\' differences.
// Also stop at the first "after" directory.
fname_len = STRLEN(ffname); fname_len = STRLEN(ffname);
insp = p_rtp;
buf = alloc(MAXPATHL); buf = alloc(MAXPATHL);
if (buf == NULL) if (buf == NULL)
goto theend; goto theend;
while (*insp != NUL) for (entry = p_rtp; *entry != NUL; )
{ {
copy_option_part(&insp, buf, MAXPATHL, ","); char_u *cur_entry = entry;
add_pathsep(buf);
rtp_ffname = fix_fname(buf); copy_option_part(&entry, buf, MAXPATHL, ",");
if (rtp_ffname == NULL) if (insp == NULL)
goto theend; {
match = vim_fnamencmp(rtp_ffname, ffname, fname_len) == 0; add_pathsep(buf);
vim_free(rtp_ffname); rtp_ffname = fix_fname(buf);
if (match) if (rtp_ffname == NULL)
goto theend;
match = vim_fnamencmp(rtp_ffname, ffname, fname_len) == 0;
vim_free(rtp_ffname);
if (match)
// Insert "ffname" after this entry (and comma).
insp = entry;
}
if ((p = (char_u *)strstr((char *)buf, "after")) != NULL
&& p > buf
&& vim_ispathsep(p[-1])
&& (vim_ispathsep(p[5]) || p[5] == NUL || p[5] == ','))
{
if (insp == NULL)
// Did not find "ffname" before the first "after" directory,
// insert it before this entry.
insp = cur_entry;
after_insp = cur_entry;
break; break;
}
} }
if (*insp == NUL) if (insp == NULL)
/* not found, append at the end */ // Both "fname" and "after" not found, append at the end.
insp = p_rtp + STRLEN(p_rtp); insp = p_rtp + STRLEN(p_rtp);
else
/* append after the matching directory. */
--insp;
/* check if rtp/pack/name/start/name/after exists */ // check if rtp/pack/name/start/name/after exists
afterdir = concat_fnames(fname, (char_u *)"after", TRUE); afterdir = concat_fnames(fname, (char_u *)"after", TRUE);
if (afterdir != NULL && mch_isdir(afterdir)) if (afterdir != NULL && mch_isdir(afterdir))
afterlen = STRLEN(afterdir) + 1; /* add one for comma */ afterlen = STRLEN(afterdir) + 1; // add one for comma
oldlen = STRLEN(p_rtp); oldlen = STRLEN(p_rtp);
addlen = STRLEN(fname) + 1; /* add one for comma */ addlen = STRLEN(fname) + 1; // add one for comma
new_rtp = alloc((int)(oldlen + addlen + afterlen + 1)); new_rtp = alloc((int)(oldlen + addlen + afterlen + 1)); // add one for NUL
/* add one for NUL */
if (new_rtp == NULL) if (new_rtp == NULL)
goto theend; goto theend;
// We now have 'rtp' parts: {keep}{keep_after}{rest}.
// Create new_rtp, first: {keep},{fname}
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_len = keep;
mch_memmove(new_rtp + keep + 1, fname, addlen); if (*insp == NUL)
if (p_rtp[keep] != NUL) new_rtp[new_rtp_len++] = ','; // add comma before
mch_memmove(new_rtp + keep + addlen, p_rtp + keep, oldlen - keep + 1); mch_memmove(new_rtp + new_rtp_len, fname, addlen - 1);
if (afterlen > 0) new_rtp_len += addlen - 1;
if (*insp != NUL)
new_rtp[new_rtp_len++] = ','; // add comma after
if (afterlen > 0 && after_insp != NULL)
{ {
int keep_after = (int)(after_insp - p_rtp);
// Add to new_rtp: {keep},{fname}{keep_after},{afterdir}
mch_memmove(new_rtp + new_rtp_len, p_rtp + keep,
keep_after - keep);
new_rtp_len += keep_after - keep;
mch_memmove(new_rtp + new_rtp_len, afterdir, afterlen - 1);
new_rtp_len += afterlen - 1;
new_rtp[new_rtp_len++] = ',';
keep = keep_after;
}
if (p_rtp[keep] != NUL)
// Append rest: {keep},{fname}{keep_after},{afterdir}{rest}
mch_memmove(new_rtp + new_rtp_len, p_rtp + keep, oldlen - keep + 1);
else
new_rtp[new_rtp_len] = NUL;
if (afterlen > 0 && after_insp == NULL)
{
// Append afterdir when "after" was not found:
// {keep},{fname}{rest},{afterdir}
STRCAT(new_rtp, ","); STRCAT(new_rtp, ",");
STRCAT(new_rtp, afterdir); 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);
retval = OK; retval = OK;

View File

@@ -12,6 +12,11 @@ func TearDown()
endfunc endfunc
func Test_packadd() func Test_packadd()
if !exists('s:plugdir')
echomsg 'when running this test manually, call SetUp() first'
return
endif
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') call mkdir(s:plugdir . '/after', 'p')
@@ -19,6 +24,14 @@ func Test_packadd()
let rtp = &rtp let rtp = &rtp
filetype on filetype on
let rtp_entries = split(rtp, ',')
for entry in rtp_entries
if entry =~? '\<after\>'
let first_after_entry = entry
break
endif
endfor
exe 'split ' . s:plugdir . '/plugin/test.vim' exe 'split ' . s:plugdir . '/plugin/test.vim'
call setline(1, 'let g:plugin_works = 42') call setline(1, 'let g:plugin_works = 42')
wq wq
@@ -38,7 +51,12 @@ func Test_packadd()
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_match('/testdir/Xdir/pack/mine/opt/mytest\($\|,\)', &rtp) call assert_match('/testdir/Xdir/pack/mine/opt/mytest\($\|,\)', &rtp)
call assert_match('/testdir/Xdir/pack/mine/opt/mytest/after$', &rtp)
let new_after = match(&rtp, '/testdir/Xdir/pack/mine/opt/mytest/after,')
let old_after = match(&rtp, ',' . first_after_entry . '\>')
call assert_true(new_after > 0, 'rtp is ' . &rtp)
call assert_true(old_after > 0, 'rtp is ' . &rtp)
call assert_true(new_after < old_after, 'rtp is ' . &rtp)
" NOTE: '/.../opt/myte' forwardly matches with '/.../opt/mytest' " NOTE: '/.../opt/myte' forwardly matches with '/.../opt/mytest'
call mkdir(fnamemodify(s:plugdir, ':h') . '/myte', 'p') call mkdir(fnamemodify(s:plugdir, ':h') . '/myte', 'p')

View File

@@ -794,6 +794,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 */
/**/
353,
/**/ /**/
352, 352,
/**/ /**/