4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
11 Problem: ":vimgrep */*" fails when a BufRead autocommand changes directory.
13 Solution: Change back to the original directory after loading a file.
14 Also: use shorten_fname1() to avoid duplicating code.
15 Files: src/buffer.c, src/ex_docmd.c, src/fileio.c, src/gui_gtk.c,
16 src/gui_w48.c, src/proto/ex_docmd.pro, src/proto/fileio.pro,
20 *** ../vim-7.1.125/src/buffer.c Sat Sep 29 14:15:00 2007
21 --- src/buffer.c Wed Sep 26 20:05:38 2007
24 do_arg_all(count, forceit, keep_tabs)
26 int forceit; /* hide buffers in current windows */
27 ! int keep_tabs; /* keep curren tabs, for ":tab drop file" */
31 char_u *opened; /* array of flags for which args are open */
32 ! int opened_len; /* lenght of opened[] */
33 int use_firstwin = FALSE; /* use first window for arglist */
37 do_arg_all(count, forceit, keep_tabs)
39 int forceit; /* hide buffers in current windows */
40 ! int keep_tabs; /* keep current tabs, for ":tab drop file" */
44 char_u *opened; /* array of flags for which args are open */
45 ! int opened_len; /* length of opened[] */
46 int use_firstwin = FALSE; /* use first window for arglist */
51 /* Expand "~/" in the file name at "line + 1" to a full path.
52 * Then try shortening it by comparing with the current directory */
53 expand_env(xline, NameBuff, MAXPATHL);
54 ! mch_dirname(IObuff, IOSIZE);
55 ! sfname = shorten_fname(NameBuff, IObuff);
59 buf = buflist_new(NameBuff, sfname, (linenr_T)0, BLN_LISTED);
60 if (buf != NULL) /* just in case... */
62 /* Expand "~/" in the file name at "line + 1" to a full path.
63 * Then try shortening it by comparing with the current directory */
64 expand_env(xline, NameBuff, MAXPATHL);
65 ! sfname = shorten_fname1(NameBuff);
67 buf = buflist_new(NameBuff, sfname, (linenr_T)0, BLN_LISTED);
68 if (buf != NULL) /* just in case... */
69 *** ../vim-7.1.125/src/ex_docmd.c Wed Sep 26 22:35:06 2007
70 --- src/ex_docmd.c Wed Sep 26 20:29:36 2007
73 static void ex_swapname __ARGS((exarg_T *eap));
74 static void ex_syncbind __ARGS((exarg_T *eap));
75 static void ex_read __ARGS((exarg_T *eap));
76 - static void ex_cd __ARGS((exarg_T *eap));
77 static void ex_pwd __ARGS((exarg_T *eap));
78 static void ex_equal __ARGS((exarg_T *eap));
79 static void ex_sleep __ARGS((exarg_T *eap));
84 * ":cd", ":lcd", ":chdir" and ":lchdir".
92 * ":cd", ":lcd", ":chdir" and ":lchdir".
98 *** ../vim-7.1.125/src/fileio.c Sat Sep 29 14:15:00 2007
99 --- src/fileio.c Wed Sep 26 20:02:54 2007
103 int bw_fd; /* file descriptor */
104 char_u *bw_buf; /* buffer with data to be written */
105 ! int bw_len; /* lenght of data */
107 int bw_flags; /* FIO_ flags */
111 int bw_fd; /* file descriptor */
112 char_u *bw_buf; /* buffer with data to be written */
113 ! int bw_len; /* length of data */
115 int bw_flags; /* FIO_ flags */
120 return (int)(p - buf);
125 + * Try to find a shortname by comparing the fullname with the current
127 + * Returns "full_path" or pointer into "full_path" if shortened.
130 + shorten_fname1(full_path)
133 + char_u dirname[MAXPATHL];
134 + char_u *p = full_path;
136 + if (mch_dirname(dirname, MAXPATHL) == OK)
138 + p = shorten_fname(full_path, dirname);
139 + if (p == NULL || *p == NUL)
146 * Try to find a shortname by comparing the fullname with the current
147 *** ../vim-7.1.125/src/gui_gtk.c Tue Aug 14 14:59:41 2007
148 --- src/gui_gtk.c Wed Sep 26 20:07:58 2007
153 char_u dirbuf[MAXPATHL];
157 title = CONVERT_TO_UTF8(title);
163 /* shorten the file name if possible */
164 ! mch_dirname(dirbuf, MAXPATHL);
165 ! p = shorten_fname(gui.browse_fname, dirbuf);
167 ! p = gui.browse_fname;
168 ! return vim_strsave(p);
171 #if defined(HAVE_GTK2) || defined(PROTO)
175 /* shorten the file name if possible */
176 ! return vim_strsave(shorten_fname1(gui.browse_fname));
179 #if defined(HAVE_GTK2) || defined(PROTO)
184 /* shorten the file name if possible */
185 ! mch_dirname(dirbuf, MAXPATHL);
186 ! p = shorten_fname(dirname, dirbuf);
187 ! if (p == NULL || *p == NUL)
189 ! p = vim_strsave(p);
196 /* shorten the file name if possible */
197 ! p = vim_strsave(shorten_fname1(dirname));
201 *** ../vim-7.1.125/src/gui_w48.c Thu May 10 19:17:07 2007
202 --- src/gui_w48.c Wed Sep 26 20:09:33 2007
207 /* Shorten the file name if possible */
208 ! mch_dirname(IObuff, IOSIZE);
209 ! p = shorten_fname((char_u *)fileBuf, IObuff);
211 ! p = (char_u *)fileBuf;
212 ! return vim_strsave(p);
214 # endif /* FEAT_MBYTE */
219 /* Shorten the file name if possible */
220 ! return vim_strsave(shorten_fname1((char_u *)fileBuf));
222 # endif /* FEAT_MBYTE */
228 /* Shorten the file name if possible */
229 ! mch_dirname(IObuff, IOSIZE);
230 ! p = shorten_fname((char_u *)fileBuf, IObuff);
232 ! p = (char_u *)fileBuf;
233 ! return vim_strsave(p);
235 #endif /* FEAT_BROWSE */
240 /* Shorten the file name if possible */
241 ! return vim_strsave(shorten_fname1((char_u *)fileBuf));
243 #endif /* FEAT_BROWSE */
245 *** ../vim-7.1.125/src/proto/ex_docmd.pro Sun May 6 14:46:22 2007
246 --- src/proto/ex_docmd.pro Wed Sep 26 20:30:10 2007
250 void tabpage_new __ARGS((void));
251 void do_exedit __ARGS((exarg_T *eap, win_T *old_curwin));
252 void free_cd_dir __ARGS((void));
253 + void ex_cd __ARGS((exarg_T *eap));
254 void do_sleep __ARGS((long msec));
255 int vim_mkdir_emsg __ARGS((char_u *name, int prot));
256 FILE *open_exfile __ARGS((char_u *fname, int forceit, char *mode));
257 *** ../vim-7.1.125/src/proto/fileio.pro Sat Sep 29 14:15:00 2007
258 --- src/proto/fileio.pro Wed Sep 26 20:05:02 2007
262 int buf_write __ARGS((buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_T end, exarg_T *eap, int append, int forceit, int reset_changed, int filtering));
263 void msg_add_fname __ARGS((buf_T *buf, char_u *fname));
264 void msg_add_lines __ARGS((int insert_space, long lnum, long nchars));
265 + char_u *shorten_fname1 __ARGS((char_u *full_path));
266 char_u *shorten_fname __ARGS((char_u *full_path, char_u *dir_name));
267 void shorten_fnames __ARGS((int force));
268 void shorten_filenames __ARGS((char_u **fnames, int count));
269 *** ../vim-7.1.125/src/quickfix.c Sun Sep 16 13:26:56 2007
270 --- src/quickfix.c Sun Sep 30 13:58:38 2007
274 regmmatch_T regmatch;
287 + char_u dirname_start[MAXPATHL];
288 + char_u dirname_now[MAXPATHL];
289 + char_u *target_dir = NULL;
299 for (fi = 0; fi < fcount && !got_int && tomatch > 0; ++fi)
301 if (time(NULL) > seconds)
303 ! /* Display the file name every second or so. */
304 seconds = time(NULL);
306 ! p = msg_strtrunc(fnames[fi], TRUE);
308 ! msg_outtrans(fnames[fi]);
316 + /* Remember the current directory, because a BufRead autocommand that does
317 + * ":lcd %:p:h" changes the meaning of short path names. */
318 + mch_dirname(dirname_start, MAXPATHL);
321 for (fi = 0; fi < fcount && !got_int && tomatch > 0; ++fi)
323 + fname = shorten_fname1(fnames[fi]);
324 if (time(NULL) > seconds)
326 ! /* Display the file name every second or so, show the user we are
327 ! * working on it. */
328 seconds = time(NULL);
330 ! p = msg_strtrunc(fname, TRUE);
332 ! msg_outtrans(fname);
339 /* Load file into a buffer, so that 'fileencoding' is detected,
340 * autocommands applied, etc. */
341 ! buf = load_dummy_buffer(fnames[fi]);
344 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
347 /* Load file into a buffer, so that 'fileencoding' is detected,
348 * autocommands applied, etc. */
349 ! buf = load_dummy_buffer(fname);
351 ! /* When autocommands changed directory: go back. We assume it was
353 ! mch_dirname(dirname_now, MAXPATHL);
354 ! if (STRCMP(dirname_start, dirname_now) != 0)
358 ! ea.arg = dirname_start;
359 ! ea.cmdidx = CMD_lcd;
364 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
370 ! smsg((char_u *)_("Cannot open file \"%s\""), fnames[fi]);
378 ! smsg((char_u *)_("Cannot open file \"%s\""), fname);
384 while (vim_regexec_multi(®match, curwin, buf, lnum,
387 if (qf_add_entry(qi, &prevp,
392 regmatch.startpos[0].lnum + lnum, FALSE),
394 while (vim_regexec_multi(®match, curwin, buf, lnum,
398 if (qf_add_entry(qi, &prevp,
403 regmatch.startpos[0].lnum + lnum, FALSE),
410 + /* If the buffer is still loaded we need to use the
411 + * directory we jumped to below. */
412 + if (buf == first_match_buf
413 + && target_dir == NULL
414 + && STRCMP(dirname_start, dirname_now) != 0)
415 + target_dir = vim_strsave(dirname_now);
417 /* The buffer is still loaded, the Filetype autocommands
418 * need to be done now, in that buffer. And the modelines
419 * need to be done (again). But not the window-local
423 /* If we jumped to another buffer redrawing will already be
425 redraw_for_dummy = FALSE;
427 + /* Jump to the directory used after loading the buffer. */
428 + if (curbuf == first_match_buf && target_dir != NULL)
432 + ea.arg = target_dir;
433 + ea.cmdidx = CMD_lcd;
445 + vim_free(target_dir);
446 vim_free(regmatch.regprog);
449 *** ../vim-7.1.125/src/version.c Sat Sep 29 14:15:00 2007
450 --- src/version.c Sun Sep 30 13:41:30 2007
454 { /* Add new patch number below this line */
460 The MS-Windows registry is no more hostile than any other bunch of state
461 information... that is held in a binary format... a format that nobody
462 understands... and is replicated and cached in a complex and largely
463 undocumented way... and contains large amounts of duplicate and obfuscated
464 information... (Ben Peterson)
466 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
467 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
468 \\\ download, build and distribute -- http://www.A-A-P.org ///
469 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///