Mercurial > vim
comparison src/quickfix.c @ 1411:0e6b369b9760 v7.1.126
updated for version 7.1-126
author | vimboss |
---|---|
date | Sun, 30 Sep 2007 12:02:55 +0000 |
parents | 3e0f9984e98e |
children | cc4fe241baa3 |
comparison
equal
deleted
inserted
replaced
1410:cdd82acd75b4 | 1411:0e6b369b9760 |
---|---|
2970 exarg_T *eap; | 2970 exarg_T *eap; |
2971 { | 2971 { |
2972 regmmatch_T regmatch; | 2972 regmmatch_T regmatch; |
2973 int fcount; | 2973 int fcount; |
2974 char_u **fnames; | 2974 char_u **fnames; |
2975 char_u *fname; | |
2975 char_u *s; | 2976 char_u *s; |
2976 char_u *p; | 2977 char_u *p; |
2977 int fi; | 2978 int fi; |
2978 qf_info_T *qi = &ql_info; | 2979 qf_info_T *qi = &ql_info; |
2979 qfline_T *prevp = NULL; | 2980 qfline_T *prevp = NULL; |
2993 #ifdef FEAT_AUTOCMD | 2994 #ifdef FEAT_AUTOCMD |
2994 char_u *au_name = NULL; | 2995 char_u *au_name = NULL; |
2995 int flags = 0; | 2996 int flags = 0; |
2996 colnr_T col; | 2997 colnr_T col; |
2997 long tomatch; | 2998 long tomatch; |
2999 char_u dirname_start[MAXPATHL]; | |
3000 char_u dirname_now[MAXPATHL]; | |
3001 char_u *target_dir = NULL; | |
2998 | 3002 |
2999 switch (eap->cmdidx) | 3003 switch (eap->cmdidx) |
3000 { | 3004 { |
3001 case CMD_vimgrep: au_name = (char_u *)"vimgrep"; break; | 3005 case CMD_vimgrep: au_name = (char_u *)"vimgrep"; break; |
3002 case CMD_lvimgrep: au_name = (char_u *)"lvimgrep"; break; | 3006 case CMD_lvimgrep: au_name = (char_u *)"lvimgrep"; break; |
3067 { | 3071 { |
3068 EMSG(_(e_nomatch)); | 3072 EMSG(_(e_nomatch)); |
3069 goto theend; | 3073 goto theend; |
3070 } | 3074 } |
3071 | 3075 |
3076 /* Remember the current directory, because a BufRead autocommand that does | |
3077 * ":lcd %:p:h" changes the meaning of short path names. */ | |
3078 mch_dirname(dirname_start, MAXPATHL); | |
3079 | |
3072 seconds = (time_t)0; | 3080 seconds = (time_t)0; |
3073 for (fi = 0; fi < fcount && !got_int && tomatch > 0; ++fi) | 3081 for (fi = 0; fi < fcount && !got_int && tomatch > 0; ++fi) |
3074 { | 3082 { |
3083 fname = shorten_fname1(fnames[fi]); | |
3075 if (time(NULL) > seconds) | 3084 if (time(NULL) > seconds) |
3076 { | 3085 { |
3077 /* Display the file name every second or so. */ | 3086 /* Display the file name every second or so, show the user we are |
3087 * working on it. */ | |
3078 seconds = time(NULL); | 3088 seconds = time(NULL); |
3079 msg_start(); | 3089 msg_start(); |
3080 p = msg_strtrunc(fnames[fi], TRUE); | 3090 p = msg_strtrunc(fname, TRUE); |
3081 if (p == NULL) | 3091 if (p == NULL) |
3082 msg_outtrans(fnames[fi]); | 3092 msg_outtrans(fname); |
3083 else | 3093 else |
3084 { | 3094 { |
3085 msg_outtrans(p); | 3095 msg_outtrans(p); |
3086 vim_free(p); | 3096 vim_free(p); |
3087 } | 3097 } |
3109 save_mls = p_mls; | 3119 save_mls = p_mls; |
3110 p_mls = 0; | 3120 p_mls = 0; |
3111 | 3121 |
3112 /* Load file into a buffer, so that 'fileencoding' is detected, | 3122 /* Load file into a buffer, so that 'fileencoding' is detected, |
3113 * autocommands applied, etc. */ | 3123 * autocommands applied, etc. */ |
3114 buf = load_dummy_buffer(fnames[fi]); | 3124 buf = load_dummy_buffer(fname); |
3125 | |
3126 /* When autocommands changed directory: go back. We assume it was | |
3127 * ":lcd %:p:h". */ | |
3128 mch_dirname(dirname_now, MAXPATHL); | |
3129 if (STRCMP(dirname_start, dirname_now) != 0) | |
3130 { | |
3131 exarg_T ea; | |
3132 | |
3133 ea.arg = dirname_start; | |
3134 ea.cmdidx = CMD_lcd; | |
3135 ex_cd(&ea); | |
3136 } | |
3115 | 3137 |
3116 p_mls = save_mls; | 3138 p_mls = save_mls; |
3117 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL) | 3139 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL) |
3118 au_event_restore(save_ei); | 3140 au_event_restore(save_ei); |
3119 #endif | 3141 #endif |
3123 using_dummy = FALSE; | 3145 using_dummy = FALSE; |
3124 | 3146 |
3125 if (buf == NULL) | 3147 if (buf == NULL) |
3126 { | 3148 { |
3127 if (!got_int) | 3149 if (!got_int) |
3128 smsg((char_u *)_("Cannot open file \"%s\""), fnames[fi]); | 3150 smsg((char_u *)_("Cannot open file \"%s\""), fname); |
3129 } | 3151 } |
3130 else | 3152 else |
3131 { | 3153 { |
3132 /* Try for a match in all lines of the buffer. | 3154 /* Try for a match in all lines of the buffer. |
3133 * For ":1vimgrep" look for first match only. */ | 3155 * For ":1vimgrep" look for first match only. */ |
3137 { | 3159 { |
3138 col = 0; | 3160 col = 0; |
3139 while (vim_regexec_multi(®match, curwin, buf, lnum, | 3161 while (vim_regexec_multi(®match, curwin, buf, lnum, |
3140 col) > 0) | 3162 col) > 0) |
3141 { | 3163 { |
3164 ; | |
3142 if (qf_add_entry(qi, &prevp, | 3165 if (qf_add_entry(qi, &prevp, |
3143 NULL, /* dir */ | 3166 NULL, /* dir */ |
3144 fnames[fi], | 3167 fname, |
3145 0, | 3168 0, |
3146 ml_get_buf(buf, | 3169 ml_get_buf(buf, |
3147 regmatch.startpos[0].lnum + lnum, FALSE), | 3170 regmatch.startpos[0].lnum + lnum, FALSE), |
3148 regmatch.startpos[0].lnum + lnum, | 3171 regmatch.startpos[0].lnum + lnum, |
3149 regmatch.startpos[0].col + 1, | 3172 regmatch.startpos[0].col + 1, |
3207 } | 3230 } |
3208 } | 3231 } |
3209 | 3232 |
3210 if (buf != NULL) | 3233 if (buf != NULL) |
3211 { | 3234 { |
3235 /* If the buffer is still loaded we need to use the | |
3236 * directory we jumped to below. */ | |
3237 if (buf == first_match_buf | |
3238 && target_dir == NULL | |
3239 && STRCMP(dirname_start, dirname_now) != 0) | |
3240 target_dir = vim_strsave(dirname_now); | |
3241 | |
3212 /* The buffer is still loaded, the Filetype autocommands | 3242 /* The buffer is still loaded, the Filetype autocommands |
3213 * need to be done now, in that buffer. And the modelines | 3243 * need to be done now, in that buffer. And the modelines |
3214 * need to be done (again). But not the window-local | 3244 * need to be done (again). But not the window-local |
3215 * options! */ | 3245 * options! */ |
3216 aucmd_prepbuf(&aco, buf); | 3246 aucmd_prepbuf(&aco, buf); |
3250 qf_jump(qi, 0, 0, eap->forceit); | 3280 qf_jump(qi, 0, 0, eap->forceit); |
3251 if (buf != curbuf) | 3281 if (buf != curbuf) |
3252 /* If we jumped to another buffer redrawing will already be | 3282 /* If we jumped to another buffer redrawing will already be |
3253 * taken care of. */ | 3283 * taken care of. */ |
3254 redraw_for_dummy = FALSE; | 3284 redraw_for_dummy = FALSE; |
3285 | |
3286 /* Jump to the directory used after loading the buffer. */ | |
3287 if (curbuf == first_match_buf && target_dir != NULL) | |
3288 { | |
3289 exarg_T ea; | |
3290 | |
3291 ea.arg = target_dir; | |
3292 ea.cmdidx = CMD_lcd; | |
3293 ex_cd(&ea); | |
3294 } | |
3255 } | 3295 } |
3256 } | 3296 } |
3257 else | 3297 else |
3258 EMSG2(_(e_nomatch2), s); | 3298 EMSG2(_(e_nomatch2), s); |
3259 | 3299 |
3267 redraw_later(NOT_VALID); | 3307 redraw_later(NOT_VALID); |
3268 #endif | 3308 #endif |
3269 } | 3309 } |
3270 | 3310 |
3271 theend: | 3311 theend: |
3312 vim_free(target_dir); | |
3272 vim_free(regmatch.regprog); | 3313 vim_free(regmatch.regprog); |
3273 } | 3314 } |
3274 | 3315 |
3275 /* | 3316 /* |
3276 * Skip over the pattern argument of ":vimgrep /pat/[g][j]". | 3317 * Skip over the pattern argument of ":vimgrep /pat/[g][j]". |