comparison src/quickfix.c @ 7092:64e30831fa42 v7.4.858

commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Sep 8 18:46:31 2015 +0200 patch 7.4.858 Problem: It's a bit clumsy to execute a command on a list of matches. Solution: Add the ":ldo", ":lfdo", ":cdo" and ":cfdo" commands. (Yegappan Lakshmanan)
author Christian Brabandt <cb@256bit.org>
date Tue, 08 Sep 2015 19:00:05 +0200
parents d1a87b307a50
children e7874551bb34
comparison
equal deleted inserted replaced
7091:0f1600f46238 7092:64e30831fa42
1371 } 1371 }
1372 1372
1373 /* 1373 /*
1374 * Check in which directory of the directory stack the given file can be 1374 * Check in which directory of the directory stack the given file can be
1375 * found. 1375 * found.
1376 * Returns a pointer to the directory name or NULL if not found 1376 * Returns a pointer to the directory name or NULL if not found.
1377 * Cleans up intermediate directory entries. 1377 * Cleans up intermediate directory entries.
1378 * 1378 *
1379 * TODO: How to solve the following problem? 1379 * TODO: How to solve the following problem?
1380 * If we have the this directory tree: 1380 * If we have the this directory tree:
1381 * ./ 1381 * ./
2988 } 2988 }
2989 return name; 2989 return name;
2990 } 2990 }
2991 2991
2992 /* 2992 /*
2993 * Returns the number of valid entries in the current quickfix/location list.
2994 */
2995 int
2996 qf_get_size(eap)
2997 exarg_T *eap;
2998 {
2999 qf_info_T *qi = &ql_info;
3000 qfline_T *qfp;
3001 int i, sz = 0;
3002 int prev_fnum = 0;
3003
3004 if (eap->cmdidx == CMD_ldo || eap->cmdidx == CMD_lfdo)
3005 {
3006 /* Location list */
3007 qi = GET_LOC_LIST(curwin);
3008 if (qi == NULL)
3009 return 0;
3010 }
3011
3012 for (i = 0, qfp = qi->qf_lists[qi->qf_curlist].qf_start;
3013 (i < qi->qf_lists[qi->qf_curlist].qf_count) && (qfp != NULL);
3014 ++i, qfp = qfp->qf_next)
3015 {
3016 if (qfp->qf_valid)
3017 {
3018 if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo)
3019 sz++; /* Count all valid entries */
3020 else if (qfp->qf_fnum > 0 && qfp->qf_fnum != prev_fnum)
3021 {
3022 /* Count the number of files */
3023 sz++;
3024 prev_fnum = qfp->qf_fnum;
3025 }
3026 }
3027 }
3028
3029 return sz;
3030 }
3031
3032 /*
3033 * Returns the current index of the quickfix/location list.
3034 * Returns 0 if there is an error.
3035 */
3036 int
3037 qf_get_cur_idx(eap)
3038 exarg_T *eap;
3039 {
3040 qf_info_T *qi = &ql_info;
3041
3042 if (eap->cmdidx == CMD_ldo || eap->cmdidx == CMD_lfdo)
3043 {
3044 /* Location list */
3045 qi = GET_LOC_LIST(curwin);
3046 if (qi == NULL)
3047 return 0;
3048 }
3049
3050 return qi->qf_lists[qi->qf_curlist].qf_index;
3051 }
3052
3053 /*
3054 * Returns the current index in the quickfix/location list (counting only valid
3055 * entries). If no valid entries are in the list, then returns 1.
3056 */
3057 int
3058 qf_get_cur_valid_idx(eap)
3059 exarg_T *eap;
3060 {
3061 qf_info_T *qi = &ql_info;
3062 qf_list_T *qfl;
3063 qfline_T *qfp;
3064 int i, eidx = 0;
3065 int prev_fnum = 0;
3066
3067 if (eap->cmdidx == CMD_ldo || eap->cmdidx == CMD_lfdo)
3068 {
3069 /* Location list */
3070 qi = GET_LOC_LIST(curwin);
3071 if (qi == NULL)
3072 return 1;
3073 }
3074
3075 qfl = &qi->qf_lists[qi->qf_curlist];
3076 qfp = qfl->qf_start;
3077
3078 /* check if the list has valid errors */
3079 if (qfl->qf_count <= 0 || qfl->qf_nonevalid)
3080 return 1;
3081
3082 for (i = 1; i <= qfl->qf_index && qfp!= NULL; i++, qfp = qfp->qf_next)
3083 {
3084 if (qfp->qf_valid)
3085 {
3086 if (eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo)
3087 {
3088 if (qfp->qf_fnum > 0 && qfp->qf_fnum != prev_fnum)
3089 {
3090 /* Count the number of files */
3091 eidx++;
3092 prev_fnum = qfp->qf_fnum;
3093 }
3094 }
3095 else
3096 eidx++;
3097 }
3098 }
3099
3100 return eidx ? eidx : 1;
3101 }
3102
3103 /*
3104 * Get the 'n'th valid error entry in the quickfix or location list.
3105 * Used by :cdo, :ldo, :cfdo and :lfdo commands.
3106 * For :cdo and :ldo returns the 'n'th valid error entry.
3107 * For :cfdo and :lfdo returns the 'n'th valid file entry.
3108 */
3109 static int
3110 qf_get_nth_valid_entry(qi, n, fdo)
3111 qf_info_T *qi;
3112 int n;
3113 int fdo;
3114 {
3115 qf_list_T *qfl = &qi->qf_lists[qi->qf_curlist];
3116 qfline_T *qfp = qfl->qf_start;
3117 int i, eidx;
3118 int prev_fnum = 0;
3119
3120 /* check if the list has valid errors */
3121 if (qfl->qf_count <= 0 || qfl->qf_nonevalid)
3122 return 1;
3123
3124 for (i = 1, eidx = 0; i <= qfl->qf_count && qfp!= NULL;
3125 i++, qfp = qfp->qf_next)
3126 {
3127 if (qfp->qf_valid)
3128 {
3129 if (fdo)
3130 {
3131 if (qfp->qf_fnum > 0 && qfp->qf_fnum != prev_fnum)
3132 {
3133 /* Count the number of files */
3134 eidx++;
3135 prev_fnum = qfp->qf_fnum;
3136 }
3137 }
3138 else
3139 eidx++;
3140 }
3141
3142 if (eidx == n)
3143 break;
3144 }
3145
3146 if (i <= qfl->qf_count)
3147 return i;
3148 else
3149 return 1;
3150 }
3151
3152 /*
2993 * ":cc", ":crewind", ":cfirst" and ":clast". 3153 * ":cc", ":crewind", ":cfirst" and ":clast".
2994 * ":ll", ":lrewind", ":lfirst" and ":llast". 3154 * ":ll", ":lrewind", ":lfirst" and ":llast".
3155 * ":cdo", ":ldo", ":cfdo" and ":lfdo"
2995 */ 3156 */
2996 void 3157 void
2997 ex_cc(eap) 3158 ex_cc(eap)
2998 exarg_T *eap; 3159 exarg_T *eap;
2999 { 3160 {
3000 qf_info_T *qi = &ql_info; 3161 qf_info_T *qi = &ql_info;
3162 int errornr;
3001 3163
3002 if (eap->cmdidx == CMD_ll 3164 if (eap->cmdidx == CMD_ll
3003 || eap->cmdidx == CMD_lrewind 3165 || eap->cmdidx == CMD_lrewind
3004 || eap->cmdidx == CMD_lfirst 3166 || eap->cmdidx == CMD_lfirst
3005 || eap->cmdidx == CMD_llast) 3167 || eap->cmdidx == CMD_llast
3168 || eap->cmdidx == CMD_ldo
3169 || eap->cmdidx == CMD_lfdo)
3006 { 3170 {
3007 qi = GET_LOC_LIST(curwin); 3171 qi = GET_LOC_LIST(curwin);
3008 if (qi == NULL) 3172 if (qi == NULL)
3009 { 3173 {
3010 EMSG(_(e_loclist)); 3174 EMSG(_(e_loclist));
3011 return; 3175 return;
3012 } 3176 }
3013 } 3177 }
3014 3178
3015 qf_jump(qi, 0, 3179 if (eap->addr_count > 0)
3016 eap->addr_count > 0 3180 errornr = (int)eap->line2;
3017 ? (int)eap->line2 3181 else
3018 : (eap->cmdidx == CMD_cc || eap->cmdidx == CMD_ll) 3182 {
3019 ? 0 3183 if (eap->cmdidx == CMD_cc || eap->cmdidx == CMD_ll)
3020 : (eap->cmdidx == CMD_crewind || eap->cmdidx == CMD_lrewind 3184 errornr = 0;
3021 || eap->cmdidx == CMD_cfirst || eap->cmdidx == CMD_lfirst) 3185 else if (eap->cmdidx == CMD_crewind || eap->cmdidx == CMD_lrewind
3022 ? 1 3186 || eap->cmdidx == CMD_cfirst || eap->cmdidx == CMD_lfirst)
3023 : 32767, 3187 errornr = 1;
3024 eap->forceit); 3188 else
3189 errornr = 32767;
3190 }
3191
3192 /* For cdo and ldo commands, jump to the nth valid error.
3193 * For cfdo and lfdo commands, jump to the nth valid file entry.
3194 */
3195 if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo ||
3196 eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo)
3197 errornr = qf_get_nth_valid_entry(qi,
3198 eap->addr_count > 0 ? (int)eap->line1 : 1,
3199 eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo);
3200
3201 qf_jump(qi, 0, errornr, eap->forceit);
3025 } 3202 }
3026 3203
3027 /* 3204 /*
3028 * ":cnext", ":cnfile", ":cNext" and ":cprevious". 3205 * ":cnext", ":cnfile", ":cNext" and ":cprevious".
3029 * ":lnext", ":lNext", ":lprevious", ":lnfile", ":lNfile" and ":lpfile". 3206 * ":lnext", ":lNext", ":lprevious", ":lnfile", ":lNfile" and ":lpfile".
3207 * Also, used by ":cdo", ":ldo", ":cfdo" and ":lfdo" commands.
3030 */ 3208 */
3031 void 3209 void
3032 ex_cnext(eap) 3210 ex_cnext(eap)
3033 exarg_T *eap; 3211 exarg_T *eap;
3034 { 3212 {
3035 qf_info_T *qi = &ql_info; 3213 qf_info_T *qi = &ql_info;
3214 int errornr;
3036 3215
3037 if (eap->cmdidx == CMD_lnext 3216 if (eap->cmdidx == CMD_lnext
3038 || eap->cmdidx == CMD_lNext 3217 || eap->cmdidx == CMD_lNext
3039 || eap->cmdidx == CMD_lprevious 3218 || eap->cmdidx == CMD_lprevious
3040 || eap->cmdidx == CMD_lnfile 3219 || eap->cmdidx == CMD_lnfile
3041 || eap->cmdidx == CMD_lNfile 3220 || eap->cmdidx == CMD_lNfile
3042 || eap->cmdidx == CMD_lpfile) 3221 || eap->cmdidx == CMD_lpfile
3222 || eap->cmdidx == CMD_ldo
3223 || eap->cmdidx == CMD_lfdo)
3043 { 3224 {
3044 qi = GET_LOC_LIST(curwin); 3225 qi = GET_LOC_LIST(curwin);
3045 if (qi == NULL) 3226 if (qi == NULL)
3046 { 3227 {
3047 EMSG(_(e_loclist)); 3228 EMSG(_(e_loclist));
3048 return; 3229 return;
3049 } 3230 }
3050 } 3231 }
3051 3232
3052 qf_jump(qi, (eap->cmdidx == CMD_cnext || eap->cmdidx == CMD_lnext) 3233 if (eap->addr_count > 0 &&
3234 (eap->cmdidx != CMD_cdo && eap->cmdidx != CMD_ldo &&
3235 eap->cmdidx != CMD_cfdo && eap->cmdidx != CMD_lfdo))
3236 errornr = (int)eap->line2;
3237 else
3238 errornr = 1;
3239
3240 qf_jump(qi, (eap->cmdidx == CMD_cnext || eap->cmdidx == CMD_lnext
3241 || eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo)
3053 ? FORWARD 3242 ? FORWARD
3054 : (eap->cmdidx == CMD_cnfile || eap->cmdidx == CMD_lnfile) 3243 : (eap->cmdidx == CMD_cnfile || eap->cmdidx == CMD_lnfile
3244 || eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo)
3055 ? FORWARD_FILE 3245 ? FORWARD_FILE
3056 : (eap->cmdidx == CMD_cpfile || eap->cmdidx == CMD_lpfile 3246 : (eap->cmdidx == CMD_cpfile || eap->cmdidx == CMD_lpfile
3057 || eap->cmdidx == CMD_cNfile || eap->cmdidx == CMD_lNfile) 3247 || eap->cmdidx == CMD_cNfile || eap->cmdidx == CMD_lNfile)
3058 ? BACKWARD_FILE 3248 ? BACKWARD_FILE
3059 : BACKWARD, 3249 : BACKWARD,
3060 eap->addr_count > 0 ? (int)eap->line2 : 1, eap->forceit); 3250 errornr, eap->forceit);
3061 } 3251 }
3062 3252
3063 /* 3253 /*
3064 * ":cfile"/":cgetfile"/":caddfile" commands. 3254 * ":cfile"/":cgetfile"/":caddfile" commands.
3065 * ":lfile"/":lgetfile"/":laddfile" commands. 3255 * ":lfile"/":lgetfile"/":laddfile" commands.