Skip to content

Commit e44348c

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 82c5f3e + 1583323 commit e44348c

21 files changed

Lines changed: 245 additions & 33 deletions

runtime/doc/autocmd.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ Name triggered by ~
295295
|FileChangedShellPost| After handling a file changed since editing started
296296
|FileChangedRO| before making the first change to a read-only file
297297

298+
|DirChanged| after the working directory has changed
299+
298300
|ShellCmdPost| after executing a shell command
299301
|ShellFilterPost| after filtering with a shell command
300302

@@ -633,6 +635,16 @@ FileChangedRO Before making the first change to a read-only
633635
*E881*
634636
If the number of lines changes saving for undo
635637
may fail and the change will be aborted.
638+
*DirChanged*
639+
DirChanged The working directory has changed in response
640+
to the |:cd| or |:lcd| commands, or as a
641+
result of the 'autochdir' option.
642+
The pattern can be:
643+
"window" to trigger on `:lcd
644+
"global" to trigger on `:cd`
645+
"auto" to trigger on 'autochdir'.
646+
"drop" to trigger on editing a file
647+
<afile> is set to the new directory name.
636648
*FileChangedShell*
637649
FileChangedShell When Vim notices that the modification time of
638650
a file has changed since editing started.

runtime/doc/options.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6791,14 +6791,21 @@ A jump table for the options with a short description can be found at |Q_op|.
67916791
It is allowed to give an argument to the command, e.g. "csh -f".
67926792
See |option-backslash| about including spaces and backslashes.
67936793
Environment variables are expanded |:set_env|.
6794+
67946795
If the name of the shell contains a space, you might need to enclose
6795-
it in quotes. Example: >
6796+
it in quotes or escape the space. Example with quotes: >
67966797
:set shell=\"c:\program\ files\unix\sh.exe\"\ -f
67976798
< Note the backslash before each quote (to avoid starting a comment) and
67986799
each space (to avoid ending the option value). Also note that the
67996800
"-f" is not inside the quotes, because it is not part of the command
6800-
name. And Vim automagically recognizes the backslashes that are path
6801+
name. Vim automagically recognizes the backslashes that are path
68016802
separators.
6803+
Example with escaped space (Vim will do this when initializing the
6804+
option from $SHELL): >
6805+
:set shell=/bin/with\\\ space/sh
6806+
< The resulting value of 'shell' is "/bin/with\ space/sh", two
6807+
backslashes are consumed by `:set`.
6808+
68026809
Under MS-Windows, when the executable ends in ".com" it must be
68036810
included. Thus setting the shell to "command.com" or "4dos.com"
68046811
works, but "command" and "4dos" do not work for all commands (e.g.,

runtime/scripts.vim

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" Vim support file to detect file types in scripts
22
"
33
" Maintainer: Bram Moolenaar <[email protected]>
4-
" Last change: 2017 Nov 11
4+
" Last change: 2018 Feb 03
55

66
" This file is called by an autocommand for every file that has just been
77
" loaded into a buffer. It checks if the type of file can be recognized by
@@ -104,6 +104,10 @@ if s:line1 =~# "^#!"
104104
elseif s:name =~# '^pike\%(\>\|[0-9]\)'
105105
set ft=pike
106106

107+
" Pike
108+
elseif s:name =~# '^pike\%(\>\|[0-9]\)'
109+
set ft=pike
110+
107111
" Lua
108112
elseif s:name =~# 'lua'
109113
set ft=lua
@@ -176,6 +180,10 @@ if s:line1 =~# "^#!"
176180
elseif s:name =~# 'scala\>'
177181
set ft=scala
178182

183+
" Clojure
184+
elseif s:name =~# 'clojure'
185+
set ft=clojure
186+
179187
endif
180188
unlet s:name
181189

src/buffer.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ close_buffer(
595595

596596
#ifdef FEAT_DIFF
597597
if (diffopt_hiddenoff() && !unload_buf && buf->b_nwindows == 0)
598-
diff_buf_delete(buf); /* Clear 'diff' for hidden buffer. */
598+
diff_buf_delete(buf); /* Clear 'diff' for hidden buffer. */
599599
#endif
600600

601601
/* Return when a window is displaying the buffer or when it's not
@@ -661,9 +661,6 @@ close_buffer(
661661
odb_buffer_close(buf);
662662
#endif
663663

664-
/* Change directories when the 'acd' option is set. */
665-
DO_AUTOCHDIR
666-
667664
/*
668665
* Remove the buffer from the list.
669666
*/
@@ -1866,7 +1863,7 @@ do_autochdir(void)
18661863
{
18671864
if ((starting == 0 || test_autochdir)
18681865
&& curbuf->b_ffname != NULL
1869-
&& vim_chdirfile(curbuf->b_ffname) == OK)
1866+
&& vim_chdirfile(curbuf->b_ffname, "auto") == OK)
18701867
shorten_fnames(TRUE);
18711868
}
18721869
#endif

src/ex_cmds.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4368,8 +4368,22 @@ do_ecmd(
43684368
if (p_im)
43694369
need_start_insertmode = TRUE;
43704370

4371-
/* Change directories when the 'acd' option is set. */
4372-
DO_AUTOCHDIR
4371+
#ifdef FEAT_AUTOCHDIR
4372+
/* Change directories when the 'acd' option is set and we aren't already in
4373+
* that directory (should already be done above). Expect getcwd() to be
4374+
* faster than calling shorten_fnames() unnecessarily. */
4375+
if (p_acd && curbuf->b_ffname != NULL)
4376+
{
4377+
char_u curdir[MAXPATHL];
4378+
char_u filedir[MAXPATHL];
4379+
4380+
vim_strncpy(filedir, curbuf->b_ffname, MAXPATHL - 1);
4381+
*gettail_sep(filedir) = NUL;
4382+
if (mch_dirname(curdir, MAXPATHL) != FAIL
4383+
&& vim_fnamecmp(curdir, filedir) != 0)
4384+
do_autochdir();
4385+
}
4386+
#endif
43734387

43744388
#if defined(FEAT_SUN_WORKSHOP) || defined(FEAT_NETBEANS_INTG)
43754389
if (curbuf->b_ffname != NULL)

src/ex_docmd.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9067,11 +9067,19 @@ ex_cd(exarg_T *eap)
90679067
EMSG(_(e_failed));
90689068
else
90699069
{
9070-
post_chdir(eap->cmdidx == CMD_lcd || eap->cmdidx == CMD_lchdir);
9070+
int is_local_chdir = eap->cmdidx == CMD_lcd
9071+
|| eap->cmdidx == CMD_lchdir;
9072+
9073+
post_chdir(is_local_chdir);
90719074

90729075
/* Echo the new current directory if the command was typed. */
90739076
if (KeyTyped || p_verbose >= 5)
90749077
ex_pwd(eap);
9078+
#ifdef FEAT_AUTOCMD
9079+
apply_autocmds(EVENT_DIRCHANGED,
9080+
is_local_chdir ? (char_u *)"window" : (char_u *)"global",
9081+
new_dir, FALSE, curbuf);
9082+
#endif
90759083
}
90769084
vim_free(tofree);
90779085
}
@@ -9959,7 +9967,7 @@ ex_mkrc(
99599967
*dirnow = NUL;
99609968
if (*dirnow != NUL && (ssop_flags & SSOP_SESDIR))
99619969
{
9962-
if (vim_chdirfile(fname) == OK)
9970+
if (vim_chdirfile(fname, NULL) == OK)
99639971
shorten_fnames(TRUE);
99649972
}
99659973
else if (*dirnow != NUL

src/fileio.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7836,6 +7836,7 @@ static struct event_name
78367836
{"CursorHoldI", EVENT_CURSORHOLDI},
78377837
{"CursorMoved", EVENT_CURSORMOVED},
78387838
{"CursorMovedI", EVENT_CURSORMOVEDI},
7839+
{"DirChanged", EVENT_DIRCHANGED},
78397840
{"EncodingChanged", EVENT_ENCODINGCHANGED},
78407841
{"FileEncoding", EVENT_ENCODINGCHANGED},
78417842
{"FileAppendPost", EVENT_FILEAPPENDPOST},
@@ -9626,7 +9627,7 @@ apply_autocmds_group(
96269627
{
96279628
sfname = vim_strsave(fname);
96289629
/* Don't try expanding FileType, Syntax, FuncUndefined, WindowID,
9629-
* ColorScheme or QuickFixCmd* */
9630+
* ColorScheme, QuickFixCmd* or DirChanged */
96309631
if (event == EVENT_FILETYPE
96319632
|| event == EVENT_SYNTAX
96329633
|| event == EVENT_FUNCUNDEFINED
@@ -9635,7 +9636,8 @@ apply_autocmds_group(
96359636
|| event == EVENT_QUICKFIXCMDPRE
96369637
|| event == EVENT_COLORSCHEME
96379638
|| event == EVENT_OPTIONSET
9638-
|| event == EVENT_QUICKFIXCMDPOST)
9639+
|| event == EVENT_QUICKFIXCMDPOST
9640+
|| event == EVENT_DIRCHANGED)
96399641
fname = vim_strsave(fname);
96409642
else
96419643
fname = FullName_save(fname, FALSE);

src/gui_mac.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,8 @@ HandleODocAE(const AppleEvent *theAEvent, AppleEvent *theReply, long refCon)
11051105
}
11061106

11071107
/* Change directory to the location of the first file. */
1108-
if (GARGCOUNT > 0 && vim_chdirfile(alist_name(&GARGLIST[0])) == OK)
1108+
if (GARGCOUNT > 0
1109+
&& vim_chdirfile(alist_name(&GARGLIST[0]), "drop") == OK)
11091110
shorten_fnames(TRUE);
11101111

11111112
goto finished;

src/main.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ main
279279
* Hint: to avoid this when typing a command use a forward slash.
280280
* If the cd fails, it doesn't matter.
281281
*/
282-
(void)vim_chdirfile(params.fname);
282+
(void)vim_chdirfile(params.fname, "drop");
283283
if (start_dir != NULL)
284284
mch_dirname(start_dir, MAXPATHL);
285285
}
@@ -330,7 +330,7 @@ main
330330
&& STRCMP(NameBuff, "/") == 0)
331331
{
332332
if (params.fname != NULL)
333-
(void)vim_chdirfile(params.fname);
333+
(void)vim_chdirfile(params.fname, "drop");
334334
else
335335
{
336336
expand_env((char_u *)"$HOME", NameBuff, MAXPATHL);
@@ -375,6 +375,13 @@ main
375375
*/
376376
check_tty(&params);
377377

378+
#ifdef _IOLBF
379+
/* Ensure output works usefully without a tty: buffer lines instead of
380+
* fully buffered. */
381+
if (silent_mode)
382+
setvbuf(stdout, NULL, _IOLBF, 0);
383+
#endif
384+
378385
/* This message comes before term inits, but after setting "silent_mode"
379386
* when the input is not a tty. */
380387
if (GARGCOUNT > 1 && !silent_mode)
@@ -2616,7 +2623,7 @@ command_line_scan(mparm_T *parmp)
26162623

26172624
/*
26182625
* Print a warning if stdout is not a terminal.
2619-
* When starting in Ex mode and commands come from a file, set Silent mode.
2626+
* When starting in Ex mode and commands come from a file, set silent_mode.
26202627
*/
26212628
static void
26222629
check_tty(mparm_T *parmp)

src/misc2.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3395,13 +3395,20 @@ same_directory(char_u *f1, char_u *f2)
33953395
* Return OK or FAIL.
33963396
*/
33973397
int
3398-
vim_chdirfile(char_u *fname)
3398+
vim_chdirfile(char_u *fname, char *trigger_autocmd UNUSED)
33993399
{
34003400
char_u dir[MAXPATHL];
3401+
int res;
34013402

34023403
vim_strncpy(dir, fname, MAXPATHL - 1);
34033404
*gettail_sep(dir) = NUL;
3404-
return mch_chdir((char *)dir) == 0 ? OK : FAIL;
3405+
res = mch_chdir((char *)dir) == 0 ? OK : FAIL;
3406+
#ifdef FEAT_AUTOCMD
3407+
if (res == OK && trigger_autocmd != NULL)
3408+
apply_autocmds(EVENT_DIRCHANGED, (char_u *)trigger_autocmd,
3409+
dir, FALSE, curbuf);
3410+
#endif
3411+
return res;
34053412
}
34063413
#endif
34073414

0 commit comments

Comments
 (0)