updated for version 7.1-126
diff --git a/src/quickfix.c b/src/quickfix.c
index c3cee13..32c6cd0 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -2972,6 +2972,7 @@
     regmmatch_T	regmatch;
     int		fcount;
     char_u	**fnames;
+    char_u	*fname;
     char_u	*s;
     char_u	*p;
     int		fi;
@@ -2995,6 +2996,9 @@
     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 @@
 	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 @@
 
 	    /* 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 @@
 	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 @@
 		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 @@
 
 		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 @@
 		/* 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 @@
     }
 
 theend:
+    vim_free(target_dir);
     vim_free(regmatch.regprog);
 }