1 To: vim_dev@googlegroups.com
4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: ":vimgrep" fails when 'autochdir' is set.
12 Solution: A more generic solution for changing directory. (Ben Fritz)
16 *** ../vim-7.3.508/src/quickfix.c 2012-03-07 20:13:44.000000000 +0100
17 --- src/quickfix.c 2012-04-25 18:52:24.000000000 +0200
20 static void qf_fill_buffer __ARGS((qf_info_T *qi));
22 static char_u *get_mef_name __ARGS((void));
23 ! static buf_T *load_dummy_buffer __ARGS((char_u *fname));
24 ! static void wipe_dummy_buffer __ARGS((buf_T *buf));
25 ! static void unload_dummy_buffer __ARGS((buf_T *buf));
26 static qf_info_T *ll_get_or_alloc_list __ARGS((win_T *));
28 /* Quickfix window check helper macro */
30 static void qf_fill_buffer __ARGS((qf_info_T *qi));
32 static char_u *get_mef_name __ARGS((void));
33 ! static void restore_start_dir __ARGS((char_u *dirname_start));
34 ! static buf_T *load_dummy_buffer __ARGS((char_u *fname, char_u *dirname_start, char_u *resulting_dir));
35 ! static void wipe_dummy_buffer __ARGS((buf_T *buf, char_u *dirname_start));
36 ! static void unload_dummy_buffer __ARGS((buf_T *buf, char_u *dirname_start));
37 static qf_info_T *ll_get_or_alloc_list __ARGS((win_T *));
39 /* Quickfix window check helper macro */
43 /* Load file into a buffer, so that 'fileencoding' is detected,
44 * autocommands applied, etc. */
45 ! buf = load_dummy_buffer(fname);
47 ! /* When autocommands changed directory: go back. We assume it was
49 ! mch_dirname(dirname_now, MAXPATHL);
50 ! if (STRCMP(dirname_start, dirname_now) != 0)
54 ! ea.arg = dirname_start;
55 ! ea.cmdidx = CMD_lcd;
60 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
63 /* Load file into a buffer, so that 'fileencoding' is detected,
64 * autocommands applied, etc. */
65 ! buf = load_dummy_buffer(fname, dirname_start, dirname_now);
68 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
72 /* Never keep a dummy buffer if there is another buffer
73 * with the same name. */
74 ! wipe_dummy_buffer(buf);
80 /* Never keep a dummy buffer if there is another buffer
81 * with the same name. */
82 ! wipe_dummy_buffer(buf, dirname_start);
91 ! wipe_dummy_buffer(buf);
94 else if (buf != first_match_buf || (flags & VGR_NOJUMP))
96 ! unload_dummy_buffer(buf);
101 * many swap files. */
104 ! wipe_dummy_buffer(buf, dirname_start);
107 else if (buf != first_match_buf || (flags & VGR_NOJUMP))
109 ! unload_dummy_buffer(buf, dirname_start);
118 ! * Load file "fname" into a dummy buffer and return the buffer pointer.
119 * Returns NULL if it fails.
120 - * Must call unload_dummy_buffer() or wipe_dummy_buffer() later!
123 ! load_dummy_buffer(fname)
127 buf_T *newbuf_to_wipe = NULL;
132 ! * Restore current working directory to "dirname_start" if they differ, taking
133 ! * into account whether it is set locally or globally.
136 ! restore_start_dir(dirname_start)
137 ! char_u *dirname_start;
139 ! char_u *dirname_now = alloc(MAXPATHL);
141 ! if (NULL != dirname_now)
143 ! mch_dirname(dirname_now, MAXPATHL);
144 ! if (STRCMP(dirname_start, dirname_now) != 0)
146 ! /* If the directory has changed, change it back by building up an
147 ! * appropriate ex command and executing it. */
150 ! ea.arg = dirname_start;
151 ! ea.cmdidx = (curwin->w_localdir == NULL) ? CMD_cd : CMD_lcd;
158 ! * Load file "fname" into a dummy buffer and return the buffer pointer,
159 ! * placing the directory resulting from the buffer load into the
160 ! * "resulting_dir" pointer. "resulting_dir" must be allocated by the caller
161 ! * prior to calling this function. Restores directory to "dirname_start" prior
162 ! * to returning, if autocmds or the 'autochdir' option have changed it.
164 ! * If creating the dummy buffer does not fail, must call unload_dummy_buffer()
165 ! * or wipe_dummy_buffer() later!
167 * Returns NULL if it fails.
170 ! load_dummy_buffer(fname, dirname_start, resulting_dir)
172 + char_u *dirname_start; /* in: old directory */
173 + char_u *resulting_dir; /* out: new directory */
176 buf_T *newbuf_to_wipe = NULL;
179 wipe_buffer(newbuf_to_wipe, FALSE);
182 if (!buf_valid(newbuf))
186 ! wipe_dummy_buffer(newbuf);
193 ! * Wipe out the dummy buffer that load_dummy_buffer() created.
196 ! wipe_dummy_buffer(buf)
199 if (curbuf != buf) /* safety check */
202 wipe_buffer(newbuf_to_wipe, FALSE);
206 + * When autocommands/'autochdir' option changed directory: go back.
207 + * Let the caller know what the resulting dir was first, in case it is
210 + mch_dirname(resulting_dir, MAXPATHL);
211 + restore_start_dir(dirname_start);
213 if (!buf_valid(newbuf))
217 ! wipe_dummy_buffer(newbuf, dirname_start);
224 ! * Wipe out the dummy buffer that load_dummy_buffer() created. Restores
225 ! * directory to "dirname_start" prior to returning, if autocmds or the
226 ! * 'autochdir' option have changed it.
229 ! wipe_dummy_buffer(buf, dirname_start)
231 + char_u *dirname_start;
233 if (curbuf != buf) /* safety check */
237 * new aborting error, interrupt, or uncaught exception. */
244 ! * Unload the dummy buffer that load_dummy_buffer() created.
247 ! unload_dummy_buffer(buf)
250 if (curbuf != buf) /* safety check */
251 close_buffer(NULL, buf, DOBUF_UNLOAD, FALSE);
254 #if defined(FEAT_EVAL) || defined(PROTO)
256 * new aborting error, interrupt, or uncaught exception. */
259 + /* When autocommands/'autochdir' option changed directory: go back. */
260 + restore_start_dir(dirname_start);
265 ! * Unload the dummy buffer that load_dummy_buffer() created. Restores
266 ! * directory to "dirname_start" prior to returning, if autocmds or the
267 ! * 'autochdir' option have changed it.
270 ! unload_dummy_buffer(buf, dirname_start)
272 + char_u *dirname_start;
274 if (curbuf != buf) /* safety check */
276 close_buffer(NULL, buf, DOBUF_UNLOAD, FALSE);
278 + /* When autocommands/'autochdir' option changed directory: go back. */
279 + restore_start_dir(dirname_start);
283 #if defined(FEAT_EVAL) || defined(PROTO)
284 *** ../vim-7.3.508/src/version.c 2012-04-25 18:24:24.000000000 +0200
285 --- src/version.c 2012-04-25 18:43:10.000000000 +0200
289 { /* Add new patch number below this line */
295 Arthur pulls Pin out. The MONK blesses the grenade as ...
296 ARTHUR: (quietly) One, two, five ...
299 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
301 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
302 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
303 \\\ an exciting new programming language -- http://www.Zimbu.org ///
304 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///