Compare commits

...

10 Commits

Author SHA1 Message Date
Bram Moolenaar
8a37b03289 patch 8.0.1464: completing directory after :find does not add slash
Problem:    Completing directory after :find does not add slash.
Solution:   Adjust the flags for globpath(). (Genki Sky)
2018-02-03 20:43:08 +01:00
Bram Moolenaar
ec48a9c589 patch 8.0.1463: test fails without 'autochdir' option
Problem:    Test fails without 'autochdir' option.
Solution:   Skip test if 'autochdir' is not supported.
2018-02-03 20:11:40 +01:00
Bram Moolenaar
f4aba797cb patch 8.0.1462: missing yet another file in patch
Problem:    Missing yet another file in patch.
Solution:   Add changes to missing file.
2018-02-03 19:17:36 +01:00
Bram Moolenaar
15833239a4 patch 8.0.1461: missing another file in patch
Problem:    Missing another file in patch.
Solution:   Add changes to missing file.
2018-02-03 18:33:17 +01:00
Bram Moolenaar
b5cb65ba2b patch 8.0.1460: missing file in patch
Problem:    Missing file in patch.
Solution:   Add changes to missing file.
2018-02-03 18:01:37 +01:00
Bram Moolenaar
b7407d3fc9 patch 8.0.1459: cannot handle change of directory
Problem:    Cannot handle change of directory.
Solution:   Add the DirChanged autocommand event. (Andy Massimino,
            closes #888)  Avoid changing directory for 'autochdir' too often.
2018-02-03 17:36:27 +01:00
Bram Moolenaar
ddb349369d patch 8.0.1458: filetype detection test does not check all scripts
Problem:    Filetype detection test does not check all scripts.
Solution:   Add most scripts to the test
2018-02-03 15:55:49 +01:00
Bram Moolenaar
8fd2ffc530 patch 8.0.1457: clojure now supports a shebang line
Problem:    Clojure now supports a shebang line.
Solution:   Detect clojure script from the shebang line. (David Burgin,
            closes #2570)
2018-02-03 15:43:15 +01:00
Bram Moolenaar
8dce6c54c8 patch 8.0.1456: timer test on travis Mac is still flaky
Problem:    Timer test on travis Mac is still flaky.
Solution:   Increase time range a bit more.
2018-02-03 15:38:42 +01:00
Bram Moolenaar
4bfa8af141 patch 8.0.1455: if $SHELL contains a space then 'shell' is incorrect
Problem:    If $SHELL contains a space then the default value of 'shell' is
            incorrect. (Matthew Horan)
Solution:   Escape spaces in $SHELL. (Christian Brabandt, closes #459)
2018-02-03 15:14:46 +01:00
23 changed files with 235 additions and 29 deletions

View File

@@ -295,6 +295,8 @@ Name triggered by ~
|FileChangedShellPost| After handling a file changed since editing started
|FileChangedRO| before making the first change to a read-only file
|DirChanged| after the working directory has changed
|ShellCmdPost| after executing a shell command
|ShellFilterPost| after filtering with a shell command
@@ -633,6 +635,16 @@ FileChangedRO Before making the first change to a read-only
*E881*
If the number of lines changes saving for undo
may fail and the change will be aborted.
*DirChanged*
DirChanged The working directory has changed in response
to the |:cd| or |:lcd| commands, or as a
result of the 'autochdir' option.
The pattern can be:
"window" to trigger on `:lcd
"global" to trigger on `:cd`
"auto" to trigger on 'autochdir'.
"drop" to trigger on editing a file
<afile> is set to the new directory name.
*FileChangedShell*
FileChangedShell When Vim notices that the modification time of
a file has changed since editing started.

View File

@@ -6630,14 +6630,21 @@ A jump table for the options with a short description can be found at |Q_op|.
It is allowed to give an argument to the command, e.g. "csh -f".
See |option-backslash| about including spaces and backslashes.
Environment variables are expanded |:set_env|.
If the name of the shell contains a space, you might need to enclose
it in quotes. Example: >
it in quotes or escape the space. Example with quotes: >
:set shell=\"c:\program\ files\unix\sh.exe\"\ -f
< Note the backslash before each quote (to avoid starting a comment) and
each space (to avoid ending the option value). Also note that the
"-f" is not inside the quotes, because it is not part of the command
name. And Vim automagically recognizes the backslashes that are path
name. Vim automagically recognizes the backslashes that are path
separators.
Example with escaped space (Vim will do this when initializing the
option from $SHELL): >
:set shell=/bin/with\\\ space/sh
< The resulting value of 'shell' is "/bin/with\ space/sh", two
backslashes are consumed by `:set`.
Under MS-Windows, when the executable ends in ".com" it must be
included. Thus setting the shell to "command.com" or "4dos.com"
works, but "command" and "4dos" do not work for all commands (e.g.,

View File

@@ -1,7 +1,7 @@
" Vim support file to detect file types in scripts
"
" Maintainer: Bram Moolenaar <Bram@vim.org>
" Last change: 2017 Nov 11
" Last change: 2018 Feb 03
" This file is called by an autocommand for every file that has just been
" loaded into a buffer. It checks if the type of file can be recognized by
@@ -104,6 +104,10 @@ if s:line1 =~# "^#!"
elseif s:name =~# '^pike\%(\>\|[0-9]\)'
set ft=pike
" Pike
elseif s:name =~# '^pike\%(\>\|[0-9]\)'
set ft=pike
" Lua
elseif s:name =~# 'lua'
set ft=lua
@@ -176,6 +180,10 @@ if s:line1 =~# "^#!"
elseif s:name =~# 'scala\>'
set ft=scala
" Clojure
elseif s:name =~# 'clojure'
set ft=clojure
endif
unlet s:name

View File

@@ -595,7 +595,7 @@ aucmd_abort:
#ifdef FEAT_DIFF
if (diffopt_hiddenoff() && !unload_buf && buf->b_nwindows == 0)
diff_buf_delete(buf); /* Clear 'diff' for hidden buffer. */
diff_buf_delete(buf); /* Clear 'diff' for hidden buffer. */
#endif
/* Return when a window is displaying the buffer or when it's not
@@ -657,9 +657,6 @@ aucmd_abort:
--buf->b_nwindows;
#endif
/* Change directories when the 'acd' option is set. */
DO_AUTOCHDIR
/*
* Remove the buffer from the list.
*/
@@ -1862,7 +1859,7 @@ do_autochdir(void)
{
if ((starting == 0 || test_autochdir)
&& curbuf->b_ffname != NULL
&& vim_chdirfile(curbuf->b_ffname) == OK)
&& vim_chdirfile(curbuf->b_ffname, "auto") == OK)
shorten_fnames(TRUE);
}
#endif

View File

@@ -4368,8 +4368,22 @@ do_ecmd(
if (p_im)
need_start_insertmode = TRUE;
/* Change directories when the 'acd' option is set. */
DO_AUTOCHDIR
#ifdef FEAT_AUTOCHDIR
/* Change directories when the 'acd' option is set and we aren't already in
* that directory (should already be done above). Expect getcwd() to be
* faster than calling shorten_fnames() unnecessarily. */
if (p_acd && curbuf->b_ffname != NULL)
{
char_u curdir[MAXPATHL];
char_u filedir[MAXPATHL];
vim_strncpy(filedir, curbuf->b_ffname, MAXPATHL - 1);
*gettail_sep(filedir) = NUL;
if (mch_dirname(curdir, MAXPATHL) != FAIL
&& vim_fnamecmp(curdir, filedir) != 0)
do_autochdir();
}
#endif
#if defined(FEAT_SUN_WORKSHOP) || defined(FEAT_NETBEANS_INTG)
if (curbuf->b_ffname != NULL)

View File

@@ -9048,11 +9048,19 @@ ex_cd(exarg_T *eap)
EMSG(_(e_failed));
else
{
post_chdir(eap->cmdidx == CMD_lcd || eap->cmdidx == CMD_lchdir);
int is_local_chdir = eap->cmdidx == CMD_lcd
|| eap->cmdidx == CMD_lchdir;
post_chdir(is_local_chdir);
/* Echo the new current directory if the command was typed. */
if (KeyTyped || p_verbose >= 5)
ex_pwd(eap);
#ifdef FEAT_AUTOCMD
apply_autocmds(EVENT_DIRCHANGED,
is_local_chdir ? (char_u *)"window" : (char_u *)"global",
new_dir, FALSE, curbuf);
#endif
}
vim_free(tofree);
}
@@ -9932,7 +9940,7 @@ ex_mkrc(
*dirnow = NUL;
if (*dirnow != NUL && (ssop_flags & SSOP_SESDIR))
{
if (vim_chdirfile(fname) == OK)
if (vim_chdirfile(fname, NULL) == OK)
shorten_fnames(TRUE);
}
else if (*dirnow != NUL

View File

@@ -7798,6 +7798,7 @@ static struct event_name
{"CursorHoldI", EVENT_CURSORHOLDI},
{"CursorMoved", EVENT_CURSORMOVED},
{"CursorMovedI", EVENT_CURSORMOVEDI},
{"DirChanged", EVENT_DIRCHANGED},
{"EncodingChanged", EVENT_ENCODINGCHANGED},
{"FileEncoding", EVENT_ENCODINGCHANGED},
{"FileAppendPost", EVENT_FILEAPPENDPOST},
@@ -9588,7 +9589,7 @@ apply_autocmds_group(
{
sfname = vim_strsave(fname);
/* Don't try expanding FileType, Syntax, FuncUndefined, WindowID,
* ColorScheme or QuickFixCmd* */
* ColorScheme, QuickFixCmd* or DirChanged */
if (event == EVENT_FILETYPE
|| event == EVENT_SYNTAX
|| event == EVENT_FUNCUNDEFINED
@@ -9597,7 +9598,8 @@ apply_autocmds_group(
|| event == EVENT_QUICKFIXCMDPRE
|| event == EVENT_COLORSCHEME
|| event == EVENT_OPTIONSET
|| event == EVENT_QUICKFIXCMDPOST)
|| event == EVENT_QUICKFIXCMDPOST
|| event == EVENT_DIRCHANGED)
fname = vim_strsave(fname);
else
fname = FullName_save(fname, FALSE);

View File

@@ -5528,7 +5528,7 @@ gui_handle_drop(
if (mch_chdir((char *)p) == 0)
shorten_fnames(TRUE);
}
else if (vim_chdirfile(p) == OK)
else if (vim_chdirfile(p, "drop") == OK)
shorten_fnames(TRUE);
vim_free(p);
}

View File

@@ -1105,7 +1105,8 @@ HandleODocAE(const AppleEvent *theAEvent, AppleEvent *theReply, long refCon)
}
/* Change directory to the location of the first file. */
if (GARGCOUNT > 0 && vim_chdirfile(alist_name(&GARGLIST[0])) == OK)
if (GARGCOUNT > 0
&& vim_chdirfile(alist_name(&GARGLIST[0]), "drop") == OK)
shorten_fnames(TRUE);
goto finished;

View File

@@ -264,7 +264,7 @@ main
* Hint: to avoid this when typing a command use a forward slash.
* If the cd fails, it doesn't matter.
*/
(void)vim_chdirfile(params.fname);
(void)vim_chdirfile(params.fname, "drop");
if (start_dir != NULL)
mch_dirname(start_dir, MAXPATHL);
}
@@ -314,7 +314,7 @@ main
&& STRCMP(NameBuff, "/") == 0)
{
if (params.fname != NULL)
(void)vim_chdirfile(params.fname);
(void)vim_chdirfile(params.fname, "drop");
else
{
expand_env((char_u *)"$HOME", NameBuff, MAXPATHL);

View File

@@ -10761,6 +10761,7 @@ expand_in_path(
char_u *curdir;
garray_T path_ga;
char_u *paths = NULL;
int glob_flags = 0;
if ((curdir = alloc((unsigned)MAXPATHL)) == NULL)
return 0;
@@ -10777,7 +10778,11 @@ expand_in_path(
if (paths == NULL)
return 0;
globpath(paths, pattern, gap, (flags & EW_ICASE) ? WILD_ICASE : 0);
if (flags & EW_ICASE)
glob_flags |= WILD_ICASE;
if (flags & EW_ADDSLASH)
glob_flags |= WILD_ADD_SLASH;
globpath(paths, pattern, gap, glob_flags);
vim_free(paths);
return gap->ga_len;

View File

@@ -3389,13 +3389,20 @@ same_directory(char_u *f1, char_u *f2)
* Return OK or FAIL.
*/
int
vim_chdirfile(char_u *fname)
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;
return mch_chdir((char *)dir) == 0 ? OK : FAIL;
res = mch_chdir((char *)dir) == 0 ? OK : FAIL;
#ifdef FEAT_AUTOCMD
if (res == OK && trigger_autocmd != NULL)
apply_autocmds(EVENT_DIRCHANGED, (char_u *)trigger_autocmd,
dir, FALSE, curbuf);
#endif
return res;
}
#endif

View File

@@ -2663,7 +2663,7 @@ netbeans_file_opened(buf_T *bufp)
nbdebug(("EVT: %s", buffer));
nb_send(buffer, "netbeans_file_opened");
if (p_acd && vim_chdirfile(bufp->b_ffname) == OK)
if (p_acd && vim_chdirfile(bufp->b_ffname, "auto") == OK)
shorten_fnames(TRUE);
}

View File

@@ -3265,6 +3265,7 @@ static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
static void set_option_default(int, int opt_flags, int compatible);
static void set_options_default(int opt_flags);
static void set_string_default_esc(char *name, char_u *val, int escape);
static char_u *term_bg_default(void);
static void did_set_option(int opt_idx, int opt_flags, int new_value);
static char_u *illegal_char(char_u *, int);
@@ -3371,7 +3372,7 @@ set_init_1(void)
# endif
#endif
)
set_string_default("sh", p);
set_string_default_esc("sh", p, TRUE);
#ifdef FEAT_WILDIGN
/*
@@ -3859,14 +3860,18 @@ set_options_default(
/*
* Set the Vi-default value of a string option.
* Used for 'sh', 'backupskip' and 'term'.
* When "escape" is TRUE escape spaces with a backslash.
*/
void
set_string_default(char *name, char_u *val)
static void
set_string_default_esc(char *name, char_u *val, int escape)
{
char_u *p;
int opt_idx;
p = vim_strsave(val);
if (escape && vim_strchr(val, ' ') != NULL)
p = vim_strsave_escaped(val, (char_u *)" ");
else
p = vim_strsave(val);
if (p != NULL) /* we don't want a NULL */
{
opt_idx = findoption((char_u *)name);
@@ -3880,6 +3885,12 @@ set_string_default(char *name, char_u *val)
}
}
void
set_string_default(char *name, char_u *val)
{
set_string_default_esc(name, val, FALSE);
}
/*
* Set the Vi-default value of a number option.
* Used for 'lines' and 'columns'.

View File

@@ -7193,7 +7193,7 @@ fix_arg_enc(void)
{
do_cmdline_cmd((char_u *)":rewind");
if (GARGCOUNT == 1 && used_file_full_path)
(void)vim_chdirfile(alist_name(&GARGLIST[0]));
(void)vim_chdirfile(alist_name(&GARGLIST[0]), "drop");
}
set_alist_count();

View File

@@ -82,7 +82,7 @@ int call_shell(char_u *cmd, int opt);
int get_real_state(void);
int after_pathsep(char_u *b, char_u *p);
int same_directory(char_u *f1, char_u *f2);
int vim_chdirfile(char_u *fname);
int vim_chdirfile(char_u *fname, char *trigger_autocmd);
int vim_stat(const char *name, stat_T *stp);
char_u *parse_shape_opt(int what);
int get_shape_idx(int mouse);

View File

@@ -1190,3 +1190,62 @@ func Test_nocatch_wipe_dummy_buffer()
call assert_fails('lv½ /x', 'E480')
au!
endfunc
function s:Before_test_dirchanged()
augroup test_dirchanged
autocmd!
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
endfunc
function Test_dirchanged_global()
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
function Test_dirchanged_local()
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
function Test_dirchanged_auto()
if !exists('+autochdir')
return
endif
call s:Before_test_dirchanged()
call test_autochdir()
autocmd test_dirchanged DirChanged auto call add(s:li, "auto:")
autocmd test_dirchanged DirChanged auto call add(s:li, expand("<afile>"))
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()
endfunc

View File

@@ -542,6 +542,40 @@ let s:script_checks = {
\ 'strace': [['execve("/usr/bin/pstree", ["pstree"], 0x7ff0 /* 63 vars */) = 0'],
\ ['15:17:47 execve("/usr/bin/pstree", ["pstree"], ... "_=/usr/bin/strace"]) = 0'],
\ ['__libc_start_main and something']],
\ 'clojure': [['#!/path/clojure']],
\ 'scala': [['#!/path/scala']],
\ 'tcsh': [['#!/path/tcsh']],
\ 'zsh': [['#!/path/zsh']],
\ 'tcl': [['#!/path/tclsh'],
\ ['#!/path/wish'],
\ ['#!/path/expectk'],
\ ['#!/path/itclsh'],
\ ['#!/path/itkwish']],
\ 'expect': [['#!/path/expect']],
\ 'gnuplot': [['#!/path/gnuplot']],
\ 'make': [['#!/path/make']],
\ 'pike': [['#!/path/pike'],
\ ['#!/path/pike0'],
\ ['#!/path/pike9']],
\ 'lua': [['#!/path/lua']],
\ 'perl6': [['#!/path/perl6']],
\ 'perl': [['#!/path/perl']],
\ 'php': [['#!/path/php']],
\ 'python': [['#!/path/python']],
\ 'groovy': [['#!/path/groovy']],
\ 'ruby': [['#!/path/ruby']],
\ 'javascript': [['#!/path/node'],
\ ['#!/path/nodejs'],
\ ['#!/path/rhino']],
\ 'bc': [['#!/path/bc']],
\ 'sed': [['#!/path/sed']],
\ 'ocaml': [['#!/path/ocaml']],
\ 'awk': [['#!/path/awk']],
\ 'wml': [['#!/path/wml']],
\ 'scheme': [['#!/path/scheme']],
\ 'cfengine': [['#!/path/cfengine']],
\ 'erlang': [['#!/path/escript']],
\ 'haskell': [['#!/path/haskell']],
\ }
func Test_script_detection()

View File

@@ -86,6 +86,12 @@ func Test_find_complete()
call feedkeys(":find f\t\n", "xt")
call assert_equal('Holy Grail', getline(1))
" Test that find completion on directory appends a slash
call feedkeys(":find in/pa\tfile.txt\n", "xt")
call assert_equal('E.T.', getline(1))
call feedkeys(":find ./i\tstuff.txt\n", "xt")
call assert_equal('Another Holy Grail', getline(1))
" Test shortening of
"
" foo/x/bar/voyager.txt

View File

@@ -226,6 +226,20 @@ func Test_read_stdin()
call delete('Xtestout')
endfunc
func Test_set_shell()
let after = [
\ 'call writefile([&shell], "Xtestout")',
\ 'quit!',
\ ]
let $SHELL = '/bin/with space/sh'
if RunVimPiped([], after, '', '')
let lines = readfile('Xtestout')
" MS-Windows adds a space after the word
call assert_equal('/bin/with\ space/sh', lines[0])
endif
call delete('Xtestout')
endfunc
func Test_progpath()
" Tests normally run with "./vim" or "../vim", these must have been expanded
" to a full path.

View File

@@ -124,7 +124,7 @@ func Test_paused()
if has('reltime')
if has('mac')
" The travis Mac machines appear to be very busy.
call assert_inrange(0, 40, slept)
call assert_inrange(0, 50, slept)
else
call assert_inrange(0, 30, slept)
endif

View File

@@ -771,6 +771,26 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1464,
/**/
1463,
/**/
1462,
/**/
1461,
/**/
1460,
/**/
1459,
/**/
1458,
/**/
1457,
/**/
1456,
/**/
1455,
/**/
1454,
/**/

View File

@@ -1276,6 +1276,7 @@ enum auto_event
EVENT_CMDWINLEAVE, /* before leaving the cmdline window */
EVENT_COLORSCHEME, /* after loading a colorscheme */
EVENT_COMPLETEDONE, /* after finishing insert complete */
EVENT_DIRCHANGED, /* after changing directory as a result of user cmd */
EVENT_FILEAPPENDPOST, /* after appending to a file */
EVENT_FILEAPPENDPRE, /* before appending to a file */
EVENT_FILEAPPENDCMD, /* append to a file using command */