summaryrefslogtreecommitdiff
path: root/src/quickfix.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2007-09-30 12:02:55 +0000
committerBram Moolenaar <Bram@vim.org>2007-09-30 12:02:55 +0000
commitd089d9b33ac62ccc2783928a66c8f20499470920 (patch)
treea39eb1ed68513118c3e25482af67b556dbec02e0 /src/quickfix.c
parent78ab331e0d8a76f553830f0347ac27311e4dc0f8 (diff)
downloadvim-git-d089d9b33ac62ccc2783928a66c8f20499470920.tar.gz
updated for version 7.1-126v7.1.126
Diffstat (limited to 'src/quickfix.c')
-rw-r--r--src/quickfix.c53
1 files changed, 47 insertions, 6 deletions
diff --git a/src/quickfix.c b/src/quickfix.c
index c3cee13a1..32c6cd08d 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -2972,6 +2972,7 @@ ex_vimgrep(eap)
regmmatch_T regmatch;
int fcount;
char_u **fnames;
+ char_u *fname;
char_u *s;
char_u *p;
int fi;
@@ -2995,6 +2996,9 @@ ex_vimgrep(eap)
int flags = 0;
colnr_T col;
long tomatch;
+ char_u dirname_start[MAXPATHL];
+ char_u dirname_now[MAXPATHL];
+ char_u *target_dir = NULL;
switch (eap->cmdidx)
{
@@ -3069,17 +3073,23 @@ ex_vimgrep(eap)
goto theend;
}
+ /* Remember the current directory, because a BufRead autocommand that does
+ * ":lcd %:p:h" changes the meaning of short path names. */
+ mch_dirname(dirname_start, MAXPATHL);
+
seconds = (time_t)0;
for (fi = 0; fi < fcount && !got_int && tomatch > 0; ++fi)
{
+ fname = shorten_fname1(fnames[fi]);
if (time(NULL) > seconds)
{
- /* Display the file name every second or so. */
+ /* Display the file name every second or so, show the user we are
+ * working on it. */
seconds = time(NULL);
msg_start();
- p = msg_strtrunc(fnames[fi], TRUE);
+ p = msg_strtrunc(fname, TRUE);
if (p == NULL)
- msg_outtrans(fnames[fi]);
+ msg_outtrans(fname);
else
{
msg_outtrans(p);
@@ -3111,7 +3121,19 @@ ex_vimgrep(eap)
/* Load file into a buffer, so that 'fileencoding' is detected,
* autocommands applied, etc. */
- buf = load_dummy_buffer(fnames[fi]);
+ buf = load_dummy_buffer(fname);
+
+ /* When autocommands changed directory: go back. We assume it was
+ * ":lcd %:p:h". */
+ mch_dirname(dirname_now, MAXPATHL);
+ if (STRCMP(dirname_start, dirname_now) != 0)
+ {
+ exarg_T ea;
+
+ ea.arg = dirname_start;
+ ea.cmdidx = CMD_lcd;
+ ex_cd(&ea);
+ }
p_mls = save_mls;
#if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
@@ -3125,7 +3147,7 @@ ex_vimgrep(eap)
if (buf == NULL)
{
if (!got_int)
- smsg((char_u *)_("Cannot open file \"%s\""), fnames[fi]);
+ smsg((char_u *)_("Cannot open file \"%s\""), fname);
}
else
{
@@ -3139,9 +3161,10 @@ ex_vimgrep(eap)
while (vim_regexec_multi(&regmatch, curwin, buf, lnum,
col) > 0)
{
+ ;
if (qf_add_entry(qi, &prevp,
NULL, /* dir */
- fnames[fi],
+ fname,
0,
ml_get_buf(buf,
regmatch.startpos[0].lnum + lnum, FALSE),
@@ -3209,6 +3232,13 @@ ex_vimgrep(eap)
if (buf != NULL)
{
+ /* If the buffer is still loaded we need to use the
+ * directory we jumped to below. */
+ if (buf == first_match_buf
+ && target_dir == NULL
+ && STRCMP(dirname_start, dirname_now) != 0)
+ target_dir = vim_strsave(dirname_now);
+
/* The buffer is still loaded, the Filetype autocommands
* need to be done now, in that buffer. And the modelines
* need to be done (again). But not the window-local
@@ -3252,6 +3282,16 @@ ex_vimgrep(eap)
/* If we jumped to another buffer redrawing will already be
* taken care of. */
redraw_for_dummy = FALSE;
+
+ /* Jump to the directory used after loading the buffer. */
+ if (curbuf == first_match_buf && target_dir != NULL)
+ {
+ exarg_T ea;
+
+ ea.arg = target_dir;
+ ea.cmdidx = CMD_lcd;
+ ex_cd(&ea);
+ }
}
}
else
@@ -3269,6 +3309,7 @@ ex_vimgrep(eap)
}
theend:
+ vim_free(target_dir);
vim_free(regmatch.regprog);
}