Mercurial > vim
comparison src/ex_cmds2.c @ 14681:285b051979a6 v8.1.0353
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
commit https://github.com/vim/vim/commit/99396d4cbf78d313a454c7448acc07412d2e45b7
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Sep 8 18:21:16 2018 +0200
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)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 08 Sep 2018 18:30:06 +0200 |
parents | 0d5726f2913b |
children | 0a3b9ecf7cb8 |
comparison
equal
deleted
inserted
replaced
14680:ac64c88a6033 | 14681:285b051979a6 |
---|---|
3689 */ | 3689 */ |
3690 static int | 3690 static int |
3691 add_pack_dir_to_rtp(char_u *fname) | 3691 add_pack_dir_to_rtp(char_u *fname) |
3692 { | 3692 { |
3693 char_u *p4, *p3, *p2, *p1, *p; | 3693 char_u *p4, *p3, *p2, *p1, *p; |
3694 char_u *insp; | 3694 char_u *entry; |
3695 char_u *insp = NULL; | |
3695 int c; | 3696 int c; |
3696 char_u *new_rtp; | 3697 char_u *new_rtp; |
3697 int keep; | 3698 int keep; |
3698 size_t oldlen; | 3699 size_t oldlen; |
3699 size_t addlen; | 3700 size_t addlen; |
3701 size_t new_rtp_len; | |
3700 char_u *afterdir = NULL; | 3702 char_u *afterdir = NULL; |
3701 size_t afterlen = 0; | 3703 size_t afterlen = 0; |
3704 char_u *after_insp = NULL; | |
3702 char_u *ffname = NULL; | 3705 char_u *ffname = NULL; |
3703 size_t fname_len; | 3706 size_t fname_len; |
3704 char_u *buf = NULL; | 3707 char_u *buf = NULL; |
3705 char_u *rtp_ffname; | 3708 char_u *rtp_ffname; |
3706 int match; | 3709 int match; |
3723 ffname = fix_fname(fname); | 3726 ffname = fix_fname(fname); |
3724 *p4 = c; | 3727 *p4 = c; |
3725 if (ffname == NULL) | 3728 if (ffname == NULL) |
3726 return FAIL; | 3729 return FAIL; |
3727 | 3730 |
3728 /* Find "ffname" in "p_rtp", ignoring '/' vs '\' differences. */ | 3731 // Find "ffname" in "p_rtp", ignoring '/' vs '\' differences. |
3732 // Also stop at the first "after" directory. | |
3729 fname_len = STRLEN(ffname); | 3733 fname_len = STRLEN(ffname); |
3730 insp = p_rtp; | |
3731 buf = alloc(MAXPATHL); | 3734 buf = alloc(MAXPATHL); |
3732 if (buf == NULL) | 3735 if (buf == NULL) |
3733 goto theend; | 3736 goto theend; |
3734 while (*insp != NUL) | 3737 for (entry = p_rtp; *entry != NUL; ) |
3735 { | 3738 { |
3736 copy_option_part(&insp, buf, MAXPATHL, ","); | 3739 char_u *cur_entry = entry; |
3737 add_pathsep(buf); | 3740 |
3738 rtp_ffname = fix_fname(buf); | 3741 copy_option_part(&entry, buf, MAXPATHL, ","); |
3739 if (rtp_ffname == NULL) | 3742 if (insp == NULL) |
3740 goto theend; | 3743 { |
3741 match = vim_fnamencmp(rtp_ffname, ffname, fname_len) == 0; | 3744 add_pathsep(buf); |
3742 vim_free(rtp_ffname); | 3745 rtp_ffname = fix_fname(buf); |
3743 if (match) | 3746 if (rtp_ffname == NULL) |
3747 goto theend; | |
3748 match = vim_fnamencmp(rtp_ffname, ffname, fname_len) == 0; | |
3749 vim_free(rtp_ffname); | |
3750 if (match) | |
3751 // Insert "ffname" after this entry (and comma). | |
3752 insp = entry; | |
3753 } | |
3754 | |
3755 if ((p = (char_u *)strstr((char *)buf, "after")) != NULL | |
3756 && p > buf | |
3757 && vim_ispathsep(p[-1]) | |
3758 && (vim_ispathsep(p[5]) || p[5] == NUL || p[5] == ',')) | |
3759 { | |
3760 if (insp == NULL) | |
3761 // Did not find "ffname" before the first "after" directory, | |
3762 // insert it before this entry. | |
3763 insp = cur_entry; | |
3764 after_insp = cur_entry; | |
3744 break; | 3765 break; |
3745 } | 3766 } |
3746 | 3767 } |
3747 if (*insp == NUL) | 3768 |
3748 /* not found, append at the end */ | 3769 if (insp == NULL) |
3770 // Both "fname" and "after" not found, append at the end. | |
3749 insp = p_rtp + STRLEN(p_rtp); | 3771 insp = p_rtp + STRLEN(p_rtp); |
3750 else | 3772 |
3751 /* append after the matching directory. */ | 3773 // check if rtp/pack/name/start/name/after exists |
3752 --insp; | |
3753 | |
3754 /* check if rtp/pack/name/start/name/after exists */ | |
3755 afterdir = concat_fnames(fname, (char_u *)"after", TRUE); | 3774 afterdir = concat_fnames(fname, (char_u *)"after", TRUE); |
3756 if (afterdir != NULL && mch_isdir(afterdir)) | 3775 if (afterdir != NULL && mch_isdir(afterdir)) |
3757 afterlen = STRLEN(afterdir) + 1; /* add one for comma */ | 3776 afterlen = STRLEN(afterdir) + 1; // add one for comma |
3758 | 3777 |
3759 oldlen = STRLEN(p_rtp); | 3778 oldlen = STRLEN(p_rtp); |
3760 addlen = STRLEN(fname) + 1; /* add one for comma */ | 3779 addlen = STRLEN(fname) + 1; // add one for comma |
3761 new_rtp = alloc((int)(oldlen + addlen + afterlen + 1)); | 3780 new_rtp = alloc((int)(oldlen + addlen + afterlen + 1)); // add one for NUL |
3762 /* add one for NUL */ | |
3763 if (new_rtp == NULL) | 3781 if (new_rtp == NULL) |
3764 goto theend; | 3782 goto theend; |
3783 | |
3784 // We now have 'rtp' parts: {keep}{keep_after}{rest}. | |
3785 // Create new_rtp, first: {keep},{fname} | |
3765 keep = (int)(insp - p_rtp); | 3786 keep = (int)(insp - p_rtp); |
3766 mch_memmove(new_rtp, p_rtp, keep); | 3787 mch_memmove(new_rtp, p_rtp, keep); |
3767 new_rtp[keep] = ','; | 3788 new_rtp_len = keep; |
3768 mch_memmove(new_rtp + keep + 1, fname, addlen); | 3789 if (*insp == NUL) |
3790 new_rtp[new_rtp_len++] = ','; // add comma before | |
3791 mch_memmove(new_rtp + new_rtp_len, fname, addlen - 1); | |
3792 new_rtp_len += addlen - 1; | |
3793 if (*insp != NUL) | |
3794 new_rtp[new_rtp_len++] = ','; // add comma after | |
3795 | |
3796 if (afterlen > 0 && after_insp != NULL) | |
3797 { | |
3798 int keep_after = (int)(after_insp - p_rtp); | |
3799 | |
3800 // Add to new_rtp: {keep},{fname}{keep_after},{afterdir} | |
3801 mch_memmove(new_rtp + new_rtp_len, p_rtp + keep, | |
3802 keep_after - keep); | |
3803 new_rtp_len += keep_after - keep; | |
3804 mch_memmove(new_rtp + new_rtp_len, afterdir, afterlen - 1); | |
3805 new_rtp_len += afterlen - 1; | |
3806 new_rtp[new_rtp_len++] = ','; | |
3807 keep = keep_after; | |
3808 } | |
3809 | |
3769 if (p_rtp[keep] != NUL) | 3810 if (p_rtp[keep] != NUL) |
3770 mch_memmove(new_rtp + keep + addlen, p_rtp + keep, oldlen - keep + 1); | 3811 // Append rest: {keep},{fname}{keep_after},{afterdir}{rest} |
3771 if (afterlen > 0) | 3812 mch_memmove(new_rtp + new_rtp_len, p_rtp + keep, oldlen - keep + 1); |
3772 { | 3813 else |
3814 new_rtp[new_rtp_len] = NUL; | |
3815 | |
3816 if (afterlen > 0 && after_insp == NULL) | |
3817 { | |
3818 // Append afterdir when "after" was not found: | |
3819 // {keep},{fname}{rest},{afterdir} | |
3773 STRCAT(new_rtp, ","); | 3820 STRCAT(new_rtp, ","); |
3774 STRCAT(new_rtp, afterdir); | 3821 STRCAT(new_rtp, afterdir); |
3775 } | 3822 } |
3823 | |
3776 set_option_value((char_u *)"rtp", 0L, new_rtp, 0); | 3824 set_option_value((char_u *)"rtp", 0L, new_rtp, 0); |
3777 vim_free(new_rtp); | 3825 vim_free(new_rtp); |
3778 retval = OK; | 3826 retval = OK; |
3779 | 3827 |
3780 theend: | 3828 theend: |