]>
Commit | Line | Data |
---|---|---|
25f687b8 AM |
1 | To: vim-dev@vim.org |
2 | Subject: patch 7.1.126 | |
3 | Fcc: outbox | |
4 | From: Bram Moolenaar <Bram@moolenaar.net> | |
5 | Mime-Version: 1.0 | |
6 | Content-Type: text/plain; charset=ISO-8859-1 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ------------ | |
9 | ||
10 | Patch 7.1.126 | |
11 | Problem: ":vimgrep */*" fails when a BufRead autocommand changes directory. | |
12 | (Bernhard Kuhn) | |
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, | |
17 | src/quickfix.c | |
18 | ||
19 | ||
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 | |
22 | *************** | |
23 | *** 4261,4272 **** | |
24 | do_arg_all(count, forceit, keep_tabs) | |
25 | int count; | |
26 | int forceit; /* hide buffers in current windows */ | |
27 | ! int keep_tabs; /* keep curren tabs, for ":tab drop file" */ | |
28 | { | |
29 | int i; | |
30 | win_T *wp, *wpnext; | |
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 */ | |
34 | int split_ret = OK; | |
35 | int p_ea_save; | |
36 | --- 4261,4272 ---- | |
37 | do_arg_all(count, forceit, keep_tabs) | |
38 | int count; | |
39 | int forceit; /* hide buffers in current windows */ | |
40 | ! int keep_tabs; /* keep current tabs, for ":tab drop file" */ | |
41 | { | |
42 | int i; | |
43 | win_T *wp, *wpnext; | |
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 */ | |
47 | int split_ret = OK; | |
48 | int p_ea_save; | |
49 | *************** | |
50 | *** 4946,4955 **** | |
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); | |
56 | ! if (sfname == NULL) | |
57 | ! sfname = NameBuff; | |
58 | ||
59 | buf = buflist_new(NameBuff, sfname, (linenr_T)0, BLN_LISTED); | |
60 | if (buf != NULL) /* just in case... */ | |
61 | --- 4946,4952 ---- | |
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); | |
66 | ||
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 | |
71 | *************** | |
72 | *** 276,282 **** | |
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)); | |
80 | --- 276,281 ---- | |
81 | *************** | |
82 | *** 7778,7784 **** | |
83 | /* | |
84 | * ":cd", ":lcd", ":chdir" and ":lchdir". | |
85 | */ | |
86 | ! static void | |
87 | ex_cd(eap) | |
88 | exarg_T *eap; | |
89 | { | |
90 | --- 7777,7783 ---- | |
91 | /* | |
92 | * ":cd", ":lcd", ":chdir" and ":lchdir". | |
93 | */ | |
94 | ! void | |
95 | ex_cd(eap) | |
96 | exarg_T *eap; | |
97 | { | |
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 | |
100 | *************** | |
101 | *** 114,120 **** | |
102 | { | |
103 | int bw_fd; /* file descriptor */ | |
104 | char_u *bw_buf; /* buffer with data to be written */ | |
105 | ! int bw_len; /* lenght of data */ | |
106 | #ifdef HAS_BW_FLAGS | |
107 | int bw_flags; /* FIO_ flags */ | |
108 | #endif | |
109 | --- 114,120 ---- | |
110 | { | |
111 | int bw_fd; /* file descriptor */ | |
112 | char_u *bw_buf; /* buffer with data to be written */ | |
113 | ! int bw_len; /* length of data */ | |
114 | #ifdef HAS_BW_FLAGS | |
115 | int bw_flags; /* FIO_ flags */ | |
116 | #endif | |
117 | *************** | |
118 | *** 5552,5557 **** | |
119 | --- 5553,5579 ---- | |
120 | return (int)(p - buf); | |
121 | } | |
122 | #endif | |
123 | + | |
124 | + /* | |
125 | + * Try to find a shortname by comparing the fullname with the current | |
126 | + * directory. | |
127 | + * Returns "full_path" or pointer into "full_path" if shortened. | |
128 | + */ | |
129 | + char_u * | |
130 | + shorten_fname1(full_path) | |
131 | + char_u *full_path; | |
132 | + { | |
133 | + char_u dirname[MAXPATHL]; | |
134 | + char_u *p = full_path; | |
135 | + | |
136 | + if (mch_dirname(dirname, MAXPATHL) == OK) | |
137 | + { | |
138 | + p = shorten_fname(full_path, dirname); | |
139 | + if (p == NULL || *p == NUL) | |
140 | + p = full_path; | |
141 | + } | |
142 | + return p; | |
143 | + } | |
144 | ||
145 | /* | |
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 | |
149 | *************** | |
150 | *** 1272,1278 **** | |
151 | GtkWidget *fc; | |
152 | #endif | |
153 | char_u dirbuf[MAXPATHL]; | |
154 | - char_u *p; | |
155 | ||
156 | # ifdef HAVE_GTK2 | |
157 | title = CONVERT_TO_UTF8(title); | |
158 | --- 1272,1277 ---- | |
159 | *************** | |
160 | *** 1363,1373 **** | |
161 | return NULL; | |
162 | ||
163 | /* shorten the file name if possible */ | |
164 | ! mch_dirname(dirbuf, MAXPATHL); | |
165 | ! p = shorten_fname(gui.browse_fname, dirbuf); | |
166 | ! if (p == NULL) | |
167 | ! p = gui.browse_fname; | |
168 | ! return vim_strsave(p); | |
169 | } | |
170 | ||
171 | #if defined(HAVE_GTK2) || defined(PROTO) | |
172 | --- 1362,1368 ---- | |
173 | return NULL; | |
174 | ||
175 | /* shorten the file name if possible */ | |
176 | ! return vim_strsave(shorten_fname1(gui.browse_fname)); | |
177 | } | |
178 | ||
179 | #if defined(HAVE_GTK2) || defined(PROTO) | |
180 | *************** | |
181 | *** 1427,1437 **** | |
182 | return NULL; | |
183 | ||
184 | /* shorten the file name if possible */ | |
185 | ! mch_dirname(dirbuf, MAXPATHL); | |
186 | ! p = shorten_fname(dirname, dirbuf); | |
187 | ! if (p == NULL || *p == NUL) | |
188 | ! p = dirname; | |
189 | ! p = vim_strsave(p); | |
190 | g_free(dirname); | |
191 | return p; | |
192 | ||
193 | --- 1422,1428 ---- | |
194 | return NULL; | |
195 | ||
196 | /* shorten the file name if possible */ | |
197 | ! p = vim_strsave(shorten_fname1(dirname)); | |
198 | g_free(dirname); | |
199 | return p; | |
200 | ||
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 | |
203 | *************** | |
204 | *** 3301,3311 **** | |
205 | SetFocus(s_hwnd); | |
206 | ||
207 | /* Shorten the file name if possible */ | |
208 | ! mch_dirname(IObuff, IOSIZE); | |
209 | ! p = shorten_fname((char_u *)fileBuf, IObuff); | |
210 | ! if (p == NULL) | |
211 | ! p = (char_u *)fileBuf; | |
212 | ! return vim_strsave(p); | |
213 | } | |
214 | # endif /* FEAT_MBYTE */ | |
215 | ||
216 | --- 3301,3307 ---- | |
217 | SetFocus(s_hwnd); | |
218 | ||
219 | /* Shorten the file name if possible */ | |
220 | ! return vim_strsave(shorten_fname1((char_u *)fileBuf)); | |
221 | } | |
222 | # endif /* FEAT_MBYTE */ | |
223 | ||
224 | *************** | |
225 | *** 3450,3460 **** | |
226 | SetFocus(s_hwnd); | |
227 | ||
228 | /* Shorten the file name if possible */ | |
229 | ! mch_dirname(IObuff, IOSIZE); | |
230 | ! p = shorten_fname((char_u *)fileBuf, IObuff); | |
231 | ! if (p == NULL) | |
232 | ! p = (char_u *)fileBuf; | |
233 | ! return vim_strsave(p); | |
234 | } | |
235 | #endif /* FEAT_BROWSE */ | |
236 | ||
237 | --- 3446,3452 ---- | |
238 | SetFocus(s_hwnd); | |
239 | ||
240 | /* Shorten the file name if possible */ | |
241 | ! return vim_strsave(shorten_fname1((char_u *)fileBuf)); | |
242 | } | |
243 | #endif /* FEAT_BROWSE */ | |
244 | ||
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 | |
247 | *************** | |
248 | *** 39,44 **** | |
249 | --- 39,45 ---- | |
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 | |
259 | *************** | |
260 | *** 6,11 **** | |
261 | --- 6,12 ---- | |
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 | |
271 | *************** | |
272 | *** 2972,2977 **** | |
273 | --- 2972,2978 ---- | |
274 | regmmatch_T regmatch; | |
275 | int fcount; | |
276 | char_u **fnames; | |
277 | + char_u *fname; | |
278 | char_u *s; | |
279 | char_u *p; | |
280 | int fi; | |
281 | *************** | |
282 | *** 2995,3000 **** | |
283 | --- 2996,3004 ---- | |
284 | int flags = 0; | |
285 | colnr_T col; | |
286 | long tomatch; | |
287 | + char_u dirname_start[MAXPATHL]; | |
288 | + char_u dirname_now[MAXPATHL]; | |
289 | + char_u *target_dir = NULL; | |
290 | ||
291 | switch (eap->cmdidx) | |
292 | { | |
293 | *************** | |
294 | *** 3069,3085 **** | |
295 | goto theend; | |
296 | } | |
297 | ||
298 | seconds = (time_t)0; | |
299 | for (fi = 0; fi < fcount && !got_int && tomatch > 0; ++fi) | |
300 | { | |
301 | if (time(NULL) > seconds) | |
302 | { | |
303 | ! /* Display the file name every second or so. */ | |
304 | seconds = time(NULL); | |
305 | msg_start(); | |
306 | ! p = msg_strtrunc(fnames[fi], TRUE); | |
307 | if (p == NULL) | |
308 | ! msg_outtrans(fnames[fi]); | |
309 | else | |
310 | { | |
311 | msg_outtrans(p); | |
312 | --- 3073,3095 ---- | |
313 | goto theend; | |
314 | } | |
315 | ||
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); | |
319 | + | |
320 | seconds = (time_t)0; | |
321 | for (fi = 0; fi < fcount && !got_int && tomatch > 0; ++fi) | |
322 | { | |
323 | + fname = shorten_fname1(fnames[fi]); | |
324 | if (time(NULL) > seconds) | |
325 | { | |
326 | ! /* Display the file name every second or so, show the user we are | |
327 | ! * working on it. */ | |
328 | seconds = time(NULL); | |
329 | msg_start(); | |
330 | ! p = msg_strtrunc(fname, TRUE); | |
331 | if (p == NULL) | |
332 | ! msg_outtrans(fname); | |
333 | else | |
334 | { | |
335 | msg_outtrans(p); | |
336 | *************** | |
337 | *** 3111,3117 **** | |
338 | ||
339 | /* Load file into a buffer, so that 'fileencoding' is detected, | |
340 | * autocommands applied, etc. */ | |
341 | ! buf = load_dummy_buffer(fnames[fi]); | |
342 | ||
343 | p_mls = save_mls; | |
344 | #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL) | |
345 | --- 3121,3139 ---- | |
346 | ||
347 | /* Load file into a buffer, so that 'fileencoding' is detected, | |
348 | * autocommands applied, etc. */ | |
349 | ! buf = load_dummy_buffer(fname); | |
350 | ! | |
351 | ! /* When autocommands changed directory: go back. We assume it was | |
352 | ! * ":lcd %:p:h". */ | |
353 | ! mch_dirname(dirname_now, MAXPATHL); | |
354 | ! if (STRCMP(dirname_start, dirname_now) != 0) | |
355 | ! { | |
356 | ! exarg_T ea; | |
357 | ! | |
358 | ! ea.arg = dirname_start; | |
359 | ! ea.cmdidx = CMD_lcd; | |
360 | ! ex_cd(&ea); | |
361 | ! } | |
362 | ||
363 | p_mls = save_mls; | |
364 | #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL) | |
365 | *************** | |
366 | *** 3125,3131 **** | |
367 | if (buf == NULL) | |
368 | { | |
369 | if (!got_int) | |
370 | ! smsg((char_u *)_("Cannot open file \"%s\""), fnames[fi]); | |
371 | } | |
372 | else | |
373 | { | |
374 | --- 3147,3153 ---- | |
375 | if (buf == NULL) | |
376 | { | |
377 | if (!got_int) | |
378 | ! smsg((char_u *)_("Cannot open file \"%s\""), fname); | |
379 | } | |
380 | else | |
381 | { | |
382 | *************** | |
383 | *** 3139,3147 **** | |
384 | while (vim_regexec_multi(®match, curwin, buf, lnum, | |
385 | col) > 0) | |
386 | { | |
387 | if (qf_add_entry(qi, &prevp, | |
388 | NULL, /* dir */ | |
389 | ! fnames[fi], | |
390 | 0, | |
391 | ml_get_buf(buf, | |
392 | regmatch.startpos[0].lnum + lnum, FALSE), | |
393 | --- 3161,3170 ---- | |
394 | while (vim_regexec_multi(®match, curwin, buf, lnum, | |
395 | col) > 0) | |
396 | { | |
397 | + ; | |
398 | if (qf_add_entry(qi, &prevp, | |
399 | NULL, /* dir */ | |
400 | ! fname, | |
401 | 0, | |
402 | ml_get_buf(buf, | |
403 | regmatch.startpos[0].lnum + lnum, FALSE), | |
404 | *************** | |
405 | *** 3209,3214 **** | |
406 | --- 3232,3244 ---- | |
407 | ||
408 | if (buf != NULL) | |
409 | { | |
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); | |
416 | + | |
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 | |
420 | *************** | |
421 | *** 3252,3257 **** | |
422 | --- 3282,3297 ---- | |
423 | /* If we jumped to another buffer redrawing will already be | |
424 | * taken care of. */ | |
425 | redraw_for_dummy = FALSE; | |
426 | + | |
427 | + /* Jump to the directory used after loading the buffer. */ | |
428 | + if (curbuf == first_match_buf && target_dir != NULL) | |
429 | + { | |
430 | + exarg_T ea; | |
431 | + | |
432 | + ea.arg = target_dir; | |
433 | + ea.cmdidx = CMD_lcd; | |
434 | + ex_cd(&ea); | |
435 | + } | |
436 | } | |
437 | } | |
438 | else | |
439 | *************** | |
440 | *** 3269,3274 **** | |
441 | --- 3309,3315 ---- | |
442 | } | |
443 | ||
444 | theend: | |
445 | + vim_free(target_dir); | |
446 | vim_free(regmatch.regprog); | |
447 | } | |
448 | ||
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 | |
451 | *************** | |
452 | *** 668,669 **** | |
453 | --- 668,671 ---- | |
454 | { /* Add new patch number below this line */ | |
455 | + /**/ | |
456 | + 126, | |
457 | /**/ | |
458 | ||
459 | -- | |
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) | |
465 | ||
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 /// |