Mercurial > vim
comparison src/ex_cmds2.c @ 8182:95d59081580f v7.4.1384
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Feb 21 23:02:49 2016 +0100
patch 7.4.1384
Problem: It is not easy to use a set of plugins and their dependencies.
Solution: Add packages, ":loadopt", 'packpath'.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 21 Feb 2016 23:15:05 +0100 |
parents | b6cb94ad97a4 |
children | a8e7b8328cb4 |
comparison
equal
deleted
inserted
replaced
8181:f478d4537f82 | 8182:95d59081580f |
---|---|
2903 ex_runtime(exarg_T *eap) | 2903 ex_runtime(exarg_T *eap) |
2904 { | 2904 { |
2905 source_runtime(eap->arg, eap->forceit); | 2905 source_runtime(eap->arg, eap->forceit); |
2906 } | 2906 } |
2907 | 2907 |
2908 static void source_callback(char_u *fname, void *cookie); | |
2909 | |
2910 static void | 2908 static void |
2911 source_callback(char_u *fname, void *cookie UNUSED) | 2909 source_callback(char_u *fname, void *cookie UNUSED) |
2912 { | 2910 { |
2913 (void)do_source(fname, FALSE, DOSO_NONE); | 2911 (void)do_source(fname, FALSE, DOSO_NONE); |
2914 } | 2912 } |
2923 source_runtime(char_u *name, int all) | 2921 source_runtime(char_u *name, int all) |
2924 { | 2922 { |
2925 return do_in_runtimepath(name, all, source_callback, NULL); | 2923 return do_in_runtimepath(name, all, source_callback, NULL); |
2926 } | 2924 } |
2927 | 2925 |
2928 /* | 2926 static int |
2929 * Find "name" in 'runtimepath'. When found, invoke the callback function for | 2927 do_in_path( |
2930 * it: callback(fname, "cookie") | 2928 char_u *path, |
2931 * When "all" is TRUE repeat for all matches, otherwise only the first one is | |
2932 * used. | |
2933 * Returns OK when at least one match found, FAIL otherwise. | |
2934 * | |
2935 * If "name" is NULL calls callback for each entry in runtimepath. Cookie is | |
2936 * passed by reference in this case, setting it to NULL indicates that callback | |
2937 * has done its job. | |
2938 */ | |
2939 int | |
2940 do_in_runtimepath( | |
2941 char_u *name, | 2929 char_u *name, |
2942 int all, | 2930 int all, |
2943 void (*callback)(char_u *fname, void *ck), | 2931 void (*callback)(char_u *fname, void *ck), |
2944 void *cookie) | 2932 void *cookie) |
2945 { | 2933 { |
2960 proc->pr_WindowPtr = (APTR)-1L; | 2948 proc->pr_WindowPtr = (APTR)-1L; |
2961 #endif | 2949 #endif |
2962 | 2950 |
2963 /* Make a copy of 'runtimepath'. Invoking the callback may change the | 2951 /* Make a copy of 'runtimepath'. Invoking the callback may change the |
2964 * value. */ | 2952 * value. */ |
2965 rtp_copy = vim_strsave(p_rtp); | 2953 rtp_copy = vim_strsave(path); |
2966 buf = alloc(MAXPATHL); | 2954 buf = alloc(MAXPATHL); |
2967 if (buf != NULL && rtp_copy != NULL) | 2955 if (buf != NULL && rtp_copy != NULL) |
2968 { | 2956 { |
2969 if (p_verbose > 1 && name != NULL) | 2957 if (p_verbose > 1 && name != NULL) |
2970 { | 2958 { |
2971 verbose_enter(); | 2959 verbose_enter(); |
2972 smsg((char_u *)_("Searching for \"%s\" in \"%s\""), | 2960 smsg((char_u *)_("Searching for \"%s\" in \"%s\""), |
2973 (char *)name, (char *)p_rtp); | 2961 (char *)name, (char *)path); |
2974 verbose_leave(); | 2962 verbose_leave(); |
2975 } | 2963 } |
2976 | 2964 |
2977 /* Loop over all entries in 'runtimepath'. */ | 2965 /* Loop over all entries in 'runtimepath'. */ |
2978 rtp = rtp_copy; | 2966 rtp = rtp_copy; |
3035 #ifdef AMIGA | 3023 #ifdef AMIGA |
3036 proc->pr_WindowPtr = save_winptr; | 3024 proc->pr_WindowPtr = save_winptr; |
3037 #endif | 3025 #endif |
3038 | 3026 |
3039 return did_one ? OK : FAIL; | 3027 return did_one ? OK : FAIL; |
3028 } | |
3029 | |
3030 /* | |
3031 * Find "name" in 'runtimepath'. When found, invoke the callback function for | |
3032 * it: callback(fname, "cookie") | |
3033 * When "all" is TRUE repeat for all matches, otherwise only the first one is | |
3034 * used. | |
3035 * Returns OK when at least one match found, FAIL otherwise. | |
3036 * | |
3037 * If "name" is NULL calls callback for each entry in runtimepath. Cookie is | |
3038 * passed by reference in this case, setting it to NULL indicates that callback | |
3039 * has done its job. | |
3040 */ | |
3041 int | |
3042 do_in_runtimepath( | |
3043 char_u *name, | |
3044 int all, | |
3045 void (*callback)(char_u *fname, void *ck), | |
3046 void *cookie) | |
3047 { | |
3048 return do_in_path(p_rtp, name, all, callback, cookie); | |
3049 } | |
3050 | |
3051 static void | |
3052 source_pack_plugin(char_u *fname, void *cookie UNUSED) | |
3053 { | |
3054 char_u *p6, *p5, *p4, *p3, *p2, *p1, *p; | |
3055 int c; | |
3056 char_u *new_rtp; | |
3057 int keep; | |
3058 int oldlen; | |
3059 int addlen; | |
3060 | |
3061 p4 = p3 = p2 = p1 = get_past_head(fname); | |
3062 for (p = p1; *p; mb_ptr_adv(p)) | |
3063 { | |
3064 if (vim_ispathsep_nocolon(*p)) | |
3065 { | |
3066 p6 = p5; p5 = p4; p4 = p3; p3 = p2; p2 = p1; p1 = p; | |
3067 } | |
3068 } | |
3069 | |
3070 /* now we have: | |
3071 * rtp/pack/name/ever/name/plugin/name.vim | |
3072 * p6 p5 p4 p3 p2 p1 | |
3073 */ | |
3074 | |
3075 /* find the part up to "pack" in 'runtimepath' */ | |
3076 c = *p6; | |
3077 *p6 = NUL; | |
3078 p = (char_u *)strstr((char *)p_rtp, (char *)fname); | |
3079 if (p == NULL) | |
3080 /* not found, append at the end */ | |
3081 p = p_rtp + STRLEN(p_rtp); | |
3082 else | |
3083 /* append after the matching directory. */ | |
3084 p += STRLEN(fname); | |
3085 *p6 = c; | |
3086 | |
3087 c = *p2; | |
3088 *p2 = NUL; | |
3089 if (strstr((char *)p_rtp, (char *)fname) == NULL) | |
3090 { | |
3091 /* directory not in 'runtimepath', add it */ | |
3092 oldlen = STRLEN(p_rtp); | |
3093 addlen = STRLEN(fname); | |
3094 new_rtp = alloc(oldlen + addlen + 2); | |
3095 if (new_rtp == NULL) | |
3096 { | |
3097 *p2 = c; | |
3098 return; | |
3099 } | |
3100 keep = (int)(p - p_rtp); | |
3101 mch_memmove(new_rtp, p_rtp, keep); | |
3102 new_rtp[keep] = ','; | |
3103 mch_memmove(new_rtp + keep + 1, fname, addlen + 1); | |
3104 if (p_rtp[keep] != NUL) | |
3105 mch_memmove(new_rtp + keep + 1 + addlen, p_rtp + keep, | |
3106 oldlen - keep + 1); | |
3107 free_string_option(p_rtp); | |
3108 p_rtp = new_rtp; | |
3109 } | |
3110 *p2 = c; | |
3111 | |
3112 (void)do_source(fname, FALSE, DOSO_NONE); | |
3113 } | |
3114 | |
3115 /* | |
3116 * Source the plugins in the package directories. | |
3117 */ | |
3118 void | |
3119 source_packages() | |
3120 { | |
3121 do_in_path(p_pp, (char_u *)"pack/*/ever/*/plugin/*.vim", | |
3122 TRUE, source_pack_plugin, NULL); | |
3123 } | |
3124 | |
3125 /* | |
3126 * ":loadplugin {name}" | |
3127 */ | |
3128 void | |
3129 ex_loadplugin(exarg_T *eap) | |
3130 { | |
3131 static char *pattern = "pack/*/opt/%s/plugin/*.vim"; | |
3132 int len; | |
3133 char *pat; | |
3134 | |
3135 len = STRLEN(pattern) + STRLEN(eap->arg); | |
3136 pat = (char *)alloc(len); | |
3137 if (pat == NULL) | |
3138 return; | |
3139 vim_snprintf(pat, len, pattern, eap->arg); | |
3140 do_in_path(p_pp, (char_u *)pat, TRUE, source_pack_plugin, NULL); | |
3141 vim_free(pat); | |
3040 } | 3142 } |
3041 | 3143 |
3042 #if defined(FEAT_EVAL) && defined(FEAT_AUTOCMD) | 3144 #if defined(FEAT_EVAL) && defined(FEAT_AUTOCMD) |
3043 /* | 3145 /* |
3044 * ":options" | 3146 * ":options" |