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
|
To: vim_dev@googlegroups.com
Subject: Patch 8.1.0602
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------
Patch 8.1.0602
Problem: DirChanged is also triggered when the directory didn't change.
(Daniel Hahler)
Solution: Compare the current with the new directory. (closes #3697)
Files: src/ex_docmd.c, src/testdir/test_autocmd.vim, src/misc2.c,
src/testdir/test_autochdir.vim
*** ../vim-8.1.0601/src/ex_docmd.c 2018-12-14 18:52:57.165528788 +0100
--- src/ex_docmd.c 2018-12-16 15:29:11.614092524 +0100
***************
*** 9126,9133 ****
void
ex_cd(exarg_T *eap)
{
! char_u *new_dir;
! char_u *tofree;
new_dir = eap->arg;
#if !defined(UNIX) && !defined(VMS)
--- 9126,9134 ----
void
ex_cd(exarg_T *eap)
{
! char_u *new_dir;
! char_u *tofree;
! int dir_differs;
new_dir = eap->arg;
#if !defined(UNIX) && !defined(VMS)
***************
*** 9183,9189 ****
new_dir = NameBuff;
}
#endif
! if (new_dir == NULL || vim_chdir(new_dir))
EMSG(_(e_failed));
else
{
--- 9184,9192 ----
new_dir = NameBuff;
}
#endif
! dir_differs = new_dir == NULL || prev_dir == NULL
! || STRCMP(prev_dir, new_dir) != 0;
! if (new_dir == NULL || (dir_differs && vim_chdir(new_dir)))
EMSG(_(e_failed));
else
{
***************
*** 9195,9203 ****
/* Echo the new current directory if the command was typed. */
if (KeyTyped || p_verbose >= 5)
ex_pwd(eap);
! apply_autocmds(EVENT_DIRCHANGED,
! is_local_chdir ? (char_u *)"window" : (char_u *)"global",
! new_dir, FALSE, curbuf);
}
vim_free(tofree);
}
--- 9198,9208 ----
/* Echo the new current directory if the command was typed. */
if (KeyTyped || p_verbose >= 5)
ex_pwd(eap);
!
! if (dir_differs)
! apply_autocmds(EVENT_DIRCHANGED,
! is_local_chdir ? (char_u *)"window" : (char_u *)"global",
! new_dir, FALSE, curbuf);
}
vim_free(tofree);
}
*** ../vim-8.1.0601/src/testdir/test_autocmd.vim 2018-08-08 22:08:28.326846653 +0200
--- src/testdir/test_autocmd.vim 2018-12-16 15:06:01.850719909 +0100
***************
*** 1205,1217 ****
augroup END
let s:li = []
let s:dir_this = getcwd()
! let s:dir_other = s:dir_this . '/foo'
! call mkdir(s:dir_other)
endfunc
function s:After_test_dirchanged()
exe 'cd' s:dir_this
! call delete(s:dir_other, 'd')
augroup test_dirchanged
autocmd!
augroup END
--- 1205,1220 ----
augroup END
let s:li = []
let s:dir_this = getcwd()
! let s:dir_foo = s:dir_this . '/foo'
! call mkdir(s:dir_foo)
! let s:dir_bar = s:dir_this . '/bar'
! call mkdir(s:dir_bar)
endfunc
function s:After_test_dirchanged()
exe 'cd' s:dir_this
! call delete(s:dir_foo, 'd')
! call delete(s:dir_bar, 'd')
augroup test_dirchanged
autocmd!
augroup END
***************
*** 1221,1230 ****
call s:Before_test_dirchanged()
autocmd test_dirchanged DirChanged global call add(s:li, "cd:")
autocmd test_dirchanged DirChanged global call add(s:li, expand("<afile>"))
! exe 'cd' s:dir_other
! call assert_equal(["cd:", s:dir_other], s:li)
! exe 'lcd' s:dir_other
! call assert_equal(["cd:", s:dir_other], s:li)
call s:After_test_dirchanged()
endfunc
--- 1224,1235 ----
call s:Before_test_dirchanged()
autocmd test_dirchanged DirChanged global call add(s:li, "cd:")
autocmd test_dirchanged DirChanged global call add(s:li, expand("<afile>"))
! exe 'cd' s:dir_foo
! call assert_equal(["cd:", s:dir_foo], s:li)
! exe 'cd' s:dir_foo
! call assert_equal(["cd:", s:dir_foo], s:li)
! exe 'lcd' s:dir_bar
! call assert_equal(["cd:", s:dir_foo], s:li)
call s:After_test_dirchanged()
endfunc
***************
*** 1232,1241 ****
call s:Before_test_dirchanged()
autocmd test_dirchanged DirChanged window call add(s:li, "lcd:")
autocmd test_dirchanged DirChanged window call add(s:li, expand("<afile>"))
! exe 'cd' s:dir_other
call assert_equal([], s:li)
! exe 'lcd' s:dir_other
! call assert_equal(["lcd:", s:dir_other], s:li)
call s:After_test_dirchanged()
endfunc
--- 1237,1248 ----
call s:Before_test_dirchanged()
autocmd test_dirchanged DirChanged window call add(s:li, "lcd:")
autocmd test_dirchanged DirChanged window call add(s:li, expand("<afile>"))
! exe 'cd' s:dir_foo
call assert_equal([], s:li)
! exe 'lcd' s:dir_bar
! call assert_equal(["lcd:", s:dir_bar], s:li)
! exe 'lcd' s:dir_bar
! call assert_equal(["lcd:", s:dir_bar], s:li)
call s:After_test_dirchanged()
endfunc
***************
*** 1250,1258 ****
set acd
exe 'cd ..'
call assert_equal([], s:li)
! exe 'edit ' . s:dir_other . '/Xfile'
! call assert_equal(s:dir_other, getcwd())
! call assert_equal(["auto:", s:dir_other], s:li)
set noacd
bwipe!
call s:After_test_dirchanged()
--- 1257,1265 ----
set acd
exe 'cd ..'
call assert_equal([], s:li)
! exe 'edit ' . s:dir_foo . '/Xfile'
! call assert_equal(s:dir_foo, getcwd())
! call assert_equal(["auto:", s:dir_foo], s:li)
set noacd
bwipe!
call s:After_test_dirchanged()
*** ../vim-8.1.0601/src/misc2.c 2018-12-14 21:31:58.012319694 +0100
--- src/misc2.c 2018-12-16 15:12:14.376386072 +0100
***************
*** 3390,3406 ****
* Return OK or FAIL.
*/
int
! vim_chdirfile(char_u *fname, char *trigger_autocmd UNUSED)
{
! char_u dir[MAXPATHL];
int res;
! vim_strncpy(dir, fname, MAXPATHL - 1);
! *gettail_sep(dir) = NUL;
! res = mch_chdir((char *)dir) == 0 ? OK : FAIL;
! if (res == OK && trigger_autocmd != NULL)
! apply_autocmds(EVENT_DIRCHANGED, (char_u *)trigger_autocmd,
! dir, FALSE, curbuf);
return res;
}
#endif
--- 3390,3418 ----
* Return OK or FAIL.
*/
int
! vim_chdirfile(char_u *fname, char *trigger_autocmd)
{
! char_u old_dir[MAXPATHL];
! char_u new_dir[MAXPATHL];
int res;
! if (mch_dirname(old_dir, MAXPATHL) != OK)
! *old_dir = NUL;
!
! vim_strncpy(new_dir, fname, MAXPATHL - 1);
! *gettail_sep(new_dir) = NUL;
!
! if (STRCMP(old_dir, new_dir) == 0)
! // nothing to do
! res = OK;
! else
! {
! res = mch_chdir((char *)new_dir) == 0 ? OK : FAIL;
!
! if (res == OK && trigger_autocmd != NULL)
! apply_autocmds(EVENT_DIRCHANGED, (char_u *)trigger_autocmd,
! new_dir, FALSE, curbuf);
! }
return res;
}
#endif
*** ../vim-8.1.0601/src/testdir/test_autochdir.vim 2017-10-27 00:47:53.000000000 +0200
--- src/testdir/test_autochdir.vim 2018-12-16 15:21:27.396965776 +0100
***************
*** 8,18 ****
--- 8,26 ----
let cwd = getcwd()
call test_autochdir()
set acd
+
+ let s:li = []
+ autocmd DirChanged auto call add(s:li, "autocd")
+ autocmd DirChanged auto call add(s:li, expand("<afile>"))
+
new
w samples/Xtest
call assert_equal("Xtest", expand('%'))
call assert_equal("samples", substitute(getcwd(), '.*/\(\k*\)', '\1', ''))
+ call assert_equal(["autocd", getcwd()], s:li)
+
bwipe!
+ au! DirChanged
set noacd
exe 'cd ' . cwd
call delete('samples/Xtest')
*** ../vim-8.1.0601/src/version.c 2018-12-16 14:37:35.845271247 +0100
--- src/version.c 2018-12-16 15:37:07.343129132 +0100
***************
*** 801,802 ****
--- 801,804 ----
{ /* Add new patch number below this line */
+ /**/
+ 602,
/**/
--
hundred-and-one symptoms of being an internet addict:
26. You check your mail. It says "no new messages." So you check it again.
/// 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 ///
|