summaryrefslogtreecommitdiff
path: root/source/ap/vim/patches/7.3.509
blob: 8dfe9c09d6eff338f8f7a8007dd9b5d8a13bb92f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
To: vim_dev@googlegroups.com
Subject: Patch 7.3.509
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 7.3.509
Problem:    ":vimgrep" fails when 'autochdir' is set.
Solution:   A more generic solution for changing directory. (Ben Fritz)
Files:	    src/quickfix.c


*** ../vim-7.3.508/src/quickfix.c	2012-03-07 20:13:44.000000000 +0100
--- src/quickfix.c	2012-04-25 18:52:24.000000000 +0200
***************
*** 130,138 ****
  static void	qf_fill_buffer __ARGS((qf_info_T *qi));
  #endif
  static char_u	*get_mef_name __ARGS((void));
! static buf_T	*load_dummy_buffer __ARGS((char_u *fname));
! static void	wipe_dummy_buffer __ARGS((buf_T *buf));
! static void	unload_dummy_buffer __ARGS((buf_T *buf));
  static qf_info_T *ll_get_or_alloc_list __ARGS((win_T *));
  
  /* Quickfix window check helper macro */
--- 130,139 ----
  static void	qf_fill_buffer __ARGS((qf_info_T *qi));
  #endif
  static char_u	*get_mef_name __ARGS((void));
! static void	restore_start_dir __ARGS((char_u *dirname_start));
! static buf_T	*load_dummy_buffer __ARGS((char_u *fname, char_u *dirname_start, char_u *resulting_dir));
! static void	wipe_dummy_buffer __ARGS((buf_T *buf, char_u *dirname_start));
! static void	unload_dummy_buffer __ARGS((buf_T *buf, char_u *dirname_start));
  static qf_info_T *ll_get_or_alloc_list __ARGS((win_T *));
  
  /* Quickfix window check helper macro */
***************
*** 3237,3255 ****
  
  	    /* Load file into a buffer, so that 'fileencoding' is detected,
  	     * autocommands applied, etc. */
! 	    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)
--- 3238,3244 ----
  
  	    /* Load file into a buffer, so that 'fileencoding' is detected,
  	     * autocommands applied, etc. */
! 	    buf = load_dummy_buffer(fname, dirname_start, dirname_now);
  
  	    p_mls = save_mls;
  #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
***************
*** 3320,3326 ****
  		{
  		    /* Never keep a dummy buffer if there is another buffer
  		     * with the same name. */
! 		    wipe_dummy_buffer(buf);
  		    buf = NULL;
  		}
  		else if (!cmdmod.hide
--- 3309,3315 ----
  		{
  		    /* Never keep a dummy buffer if there is another buffer
  		     * with the same name. */
! 		    wipe_dummy_buffer(buf, dirname_start);
  		    buf = NULL;
  		}
  		else if (!cmdmod.hide
***************
*** 3336,3347 ****
  		     * many swap files. */
  		    if (!found_match)
  		    {
! 			wipe_dummy_buffer(buf);
  			buf = NULL;
  		    }
  		    else if (buf != first_match_buf || (flags & VGR_NOJUMP))
  		    {
! 			unload_dummy_buffer(buf);
  			buf = NULL;
  		    }
  		}
--- 3325,3336 ----
  		     * many swap files. */
  		    if (!found_match)
  		    {
! 			wipe_dummy_buffer(buf, dirname_start);
  			buf = NULL;
  		    }
  		    else if (buf != first_match_buf || (flags & VGR_NOJUMP))
  		    {
! 			unload_dummy_buffer(buf, dirname_start);
  			buf = NULL;
  		    }
  		}
***************
*** 3487,3499 ****
  }
  
  /*
!  * Load file "fname" into a dummy buffer and return the buffer pointer.
   * Returns NULL if it fails.
-  * Must call unload_dummy_buffer() or wipe_dummy_buffer() later!
   */
      static buf_T *
! load_dummy_buffer(fname)
      char_u	*fname;
  {
      buf_T	*newbuf;
      buf_T	*newbuf_to_wipe = NULL;
--- 3476,3523 ----
  }
  
  /*
!  * Restore current working directory to "dirname_start" if they differ, taking
!  * into account whether it is set locally or globally.
!  */
!     static void
! restore_start_dir(dirname_start)
!     char_u	*dirname_start;
! {
!     char_u *dirname_now = alloc(MAXPATHL);
! 
!     if (NULL != dirname_now)
!     {
! 	mch_dirname(dirname_now, MAXPATHL);
! 	if (STRCMP(dirname_start, dirname_now) != 0)
! 	{
! 	    /* If the directory has changed, change it back by building up an
! 	     * appropriate ex command and executing it. */
! 	    exarg_T ea;
! 
! 	    ea.arg = dirname_start;
! 	    ea.cmdidx = (curwin->w_localdir == NULL) ? CMD_cd : CMD_lcd;
! 	    ex_cd(&ea);
! 	}
!     }
! }
! 
! /*
!  * Load file "fname" into a dummy buffer and return the buffer pointer,
!  * placing the directory resulting from the buffer load into the
!  * "resulting_dir" pointer. "resulting_dir" must be allocated by the caller
!  * prior to calling this function. Restores directory to "dirname_start" prior
!  * to returning, if autocmds or the 'autochdir' option have changed it.
!  *
!  * If creating the dummy buffer does not fail, must call unload_dummy_buffer()
!  * or wipe_dummy_buffer() later!
!  *
   * Returns NULL if it fails.
   */
      static buf_T *
! load_dummy_buffer(fname, dirname_start, resulting_dir)
      char_u	*fname;
+     char_u	*dirname_start;  /* in: old directory */
+     char_u	*resulting_dir;  /* out: new directory */
  {
      buf_T	*newbuf;
      buf_T	*newbuf_to_wipe = NULL;
***************
*** 3548,3569 ****
  	    wipe_buffer(newbuf_to_wipe, FALSE);
      }
  
      if (!buf_valid(newbuf))
  	return NULL;
      if (failed)
      {
! 	wipe_dummy_buffer(newbuf);
  	return NULL;
      }
      return newbuf;
  }
  
  /*
!  * Wipe out the dummy buffer that load_dummy_buffer() created.
   */
      static void
! wipe_dummy_buffer(buf)
      buf_T	*buf;
  {
      if (curbuf != buf)		/* safety check */
      {
--- 3572,3604 ----
  	    wipe_buffer(newbuf_to_wipe, FALSE);
      }
  
+     /*
+      * When autocommands/'autochdir' option changed directory: go back.
+      * Let the caller know what the resulting dir was first, in case it is
+      * important.
+      */
+     mch_dirname(resulting_dir, MAXPATHL);
+     restore_start_dir(dirname_start);
+ 
      if (!buf_valid(newbuf))
  	return NULL;
      if (failed)
      {
! 	wipe_dummy_buffer(newbuf, dirname_start);
  	return NULL;
      }
      return newbuf;
  }
  
  /*
!  * Wipe out the dummy buffer that load_dummy_buffer() created. Restores
!  * directory to "dirname_start" prior to returning, if autocmds or the
!  * 'autochdir' option have changed it.
   */
      static void
! wipe_dummy_buffer(buf, dirname_start)
      buf_T	*buf;
+     char_u	*dirname_start;
  {
      if (curbuf != buf)		/* safety check */
      {
***************
*** 3583,3600 ****
  	 * new aborting error, interrupt, or uncaught exception. */
  	leave_cleanup(&cs);
  #endif
      }
  }
  
  /*
!  * Unload the dummy buffer that load_dummy_buffer() created.
   */
      static void
! unload_dummy_buffer(buf)
      buf_T	*buf;
  {
      if (curbuf != buf)		/* safety check */
  	close_buffer(NULL, buf, DOBUF_UNLOAD, FALSE);
  }
  
  #if defined(FEAT_EVAL) || defined(PROTO)
--- 3618,3645 ----
  	 * new aborting error, interrupt, or uncaught exception. */
  	leave_cleanup(&cs);
  #endif
+ 	/* When autocommands/'autochdir' option changed directory: go back. */
+ 	restore_start_dir(dirname_start);
      }
  }
  
  /*
!  * Unload the dummy buffer that load_dummy_buffer() created. Restores
!  * directory to "dirname_start" prior to returning, if autocmds or the
!  * 'autochdir' option have changed it.
   */
      static void
! unload_dummy_buffer(buf, dirname_start)
      buf_T	*buf;
+     char_u	*dirname_start;
  {
      if (curbuf != buf)		/* safety check */
+     {
  	close_buffer(NULL, buf, DOBUF_UNLOAD, FALSE);
+ 
+ 	/* When autocommands/'autochdir' option changed directory: go back. */
+ 	restore_start_dir(dirname_start);
+     }
  }
  
  #if defined(FEAT_EVAL) || defined(PROTO)
*** ../vim-7.3.508/src/version.c	2012-04-25 18:24:24.000000000 +0200
--- src/version.c	2012-04-25 18:43:10.000000000 +0200
***************
*** 716,717 ****
--- 716,719 ----
  {   /* Add new patch number below this line */
+ /**/
+     509,
  /**/

-- 
   Arthur pulls Pin out.  The MONK blesses the grenade as ...
ARTHUR:  (quietly) One, two, five ...
GALAHAD: Three, sir!
ARTHUR:  Three.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///