Compare commits

..

6 Commits

Author SHA1 Message Date
Bram Moolenaar
0d3e24be56 patch 7.4.2012
Problem:    Test for getcompletion() does not pass on all systems.
Solution:   Only test what is supported.
2016-07-09 19:20:59 +02:00
Bram Moolenaar
aa4d73235b patch 7.4.2011
Problem:    It is not easy to get a list of command arguments.
Solution:   Add getcompletion(). (Yegappan Lakshmanan)
2016-07-09 18:50:29 +02:00
Bram Moolenaar
537ef08408 patch 7.4.2010
Problem:    There is a :cbottom command but no :lbottom command.
Solution:   Add :lbottom. (Yegappan Lakshmanan)
2016-07-09 17:56:19 +02:00
Bram Moolenaar
ed59aa60d3 patch 7.4.2009
Problem:    Messages test fails.
Solution:   Don't set redir_execute before returning.
2016-07-09 17:41:12 +02:00
Bram Moolenaar
79815f1ec7 patch 7.4.2008
Problem:    evalcmd() has a confusing name.
Solution:   Rename to execute().  Make silent optional.  Support a list of
            commands.
2016-07-09 17:07:29 +02:00
Bram Moolenaar
fc4ad61607 patch 7.4.2007
Problem:    Running the tests leaves a viminfo file behind.
Solution:   Make the viminfo option empty.
2016-07-09 15:38:32 +02:00
19 changed files with 432 additions and 144 deletions

View File

@@ -1,4 +1,4 @@
*eval.txt* For Vim version 7.4. Last change: 2016 Jul 06
*eval.txt* For Vim version 7.4. Last change: 2016 Jul 09
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1961,9 +1961,9 @@ diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
empty({expr}) Number |TRUE| if {expr} is empty
escape({string}, {chars}) String escape {chars} in {string} with '\'
eval({string}) any evaluate {string} into its value
evalcmd({command}) String execute {command} and get the output
eventhandler() Number |TRUE| if inside an event handler
executable({expr}) Number 1 if executable {expr} exists
execute({command}) String execute {command} and get the output
exepath({expr}) String full path of the command {expr}
exists({expr}) Number |TRUE| if {expr} exists
extend({expr1}, {expr2} [, {expr3}])
@@ -2008,6 +2008,7 @@ getcmdline() String return the current command-line
getcmdpos() Number return cursor position in command-line
getcmdtype() String return current command-line type
getcmdwintype() String return current command-line window type
getcompletion({pat}, {type}) List list of cmdline completion matches
getcurpos() List position of the cursor
getcwd([{winnr} [, {tabnr}]]) String get the current working directory
getfontname([{name}]) String name of font being used
@@ -3232,15 +3233,6 @@ eval({string}) Evaluate {string} and return the result. Especially useful to
them. Also works for |Funcref|s that refer to existing
functions.
evalcmd({command}) *evalcmd()*
Execute Ex {command} and return the output as a string. This
is equivalent to: >
redir => var
{command}
redir END
< To get a list of lines use: >
split(evalcmd(cmd), "\n")
eventhandler() *eventhandler()*
Returns 1 when inside an event handler. That is that Vim got
interrupted while waiting for the user to type a character,
@@ -3271,6 +3263,31 @@ executable({expr}) *executable()*
0 does not exist
-1 not implemented on this system
execute({command} [, {silent}]) *execute()*
Execute an Ex command or commands and return the output as a
string.
{command} can be a string or a List. In case of a List the
lines are executed one by one.
This is equivalent to: >
redir => var
{command}
redir END
<
The optional {silent} argument can have these values:
"" no `:silent` used
"silent" `:silent` used
"silent!" `:silent!` used
The default is 'silent'. Note that with "silent!", unlike
`:redir`, error messages are dropped.
*E930*
It is not possible to use `:redir` anywhere in {command}.
To get a list of lines use |split()| on the result: >
split(evalcmd('args'), "\n")
< When used recursively the output of the recursive call is not
included in the output of the higher level call.
exepath({expr}) *exepath()*
If {expr} is an executable and is either an absolute path, a
relative path or found in $PATH, return the full path.
@@ -4028,6 +4045,49 @@ getcmdwintype() *getcmdwintype()*
values are the same as |getcmdtype()|. Returns an empty string
when not in the command-line window.
getcompletion({pat}, {type}) *getcompletion()*
Return a list of command-line completion matches. {type}
specifies what for. The following completion types are
supported:
augroup autocmd groups
buffer buffer names
behave :behave suboptions
color color schemes
command Ex command (and arguments)
compiler compilers
cscope |:cscope| suboptions
dir directory names
environment environment variable names
event autocommand events
expression Vim expression
file file and directory names
file_in_path file and directory names in |'path'|
filetype filetype names |'filetype'|
function function name
help help subjects
highlight highlight groups
history :history suboptions
locale locale names (as output of locale -a)
mapping mapping name
menu menus
option options
shellcmd Shell command
sign |:sign| suboptions
syntax syntax file names |'syntax'|
syntime |:syntime| suboptions
tag tags
tag_listfiles tags, file names
user user names
var user variables
If {pat} is an empty string, then all the matches are returned.
Otherwise only items matching {pat} are returned. See
|wildcards| for the use of special characters in {pat}.
If there are no matches, an empty list is returned. An
invalid value for {type} produces an error.
*getcurpos()*
getcurpos() Get the position of the cursor. This is like getpos('.'), but
includes an extra item in the list:
@@ -7046,9 +7106,9 @@ synID({lnum}, {col}, {trans}) *synID()*
that's where the cursor can be in Insert mode, synID() returns
zero.
When {trans} is non-zero, transparent items are reduced to the
When {trans} is |TRUE|, transparent items are reduced to the
item that they reveal. This is useful when wanting to know
the effective color. When {trans} is zero, the transparent
the effective color. When {trans} is |FALSE|, the transparent
item is returned. This is useful when wanting to know which
syntax item is effective (e.g. inside parens).
Warning: This function can be very slow. Best speed is

View File

@@ -1139,6 +1139,7 @@ tag command action ~
|:caddfile| :caddf[ile] add error message to current quickfix list
|:call| :cal[l] call a function
|:catch| :cat[ch] part of a :try command
|:cbottom| :cbo[ttom] scroll to the bottom of the quickfix window
|:cbuffer| :cb[uffer] parse error messages and jump to first error
|:cc| :cc go to specific error
|:cclose| :ccl[ose] close quickfix window
@@ -1299,6 +1300,7 @@ tag command action ~
|:last| :la[st] go to the last file in the argument list
|:language| :lan[guage] set the language (locale)
|:later| :lat[er] go to newer change, redo
|:lbottom| :lbo[ttom] scroll to the bottom of the location window
|:lbuffer| :lb[uffer] parse locations and jump to first location
|:lcd| :lc[d] change directory locally
|:lchdir| :lch[dir] change directory locally

View File

@@ -1,4 +1,4 @@
*quickfix.txt* For Vim version 7.4. Last change: 2016 Jul 02
*quickfix.txt* For Vim version 7.4. Last change: 2016 Jul 07
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -437,12 +437,17 @@ EXECUTE A COMMAND IN ALL THE BUFFERS IN QUICKFIX OR LOCATION LIST:
:lw[indow] [height] Same as ":cwindow", except use the window showing the
location list for the current window.
*:cbo* *:cbottom*
:cbo[ttom] Put the cursor in the last line of the quickfix window
and scroll to make it visible. This is useful for
when errors are added by an asynchronous callback.
Only call it once in a while if there are many
updates to avoid a lot of redrawing.
*:lbo* *:lbottom*
:lbo[ttom] Same as ":cbottom", except use the window showing the
location list for the current window.
Normally the quickfix window is at the bottom of the screen. If there are
vertical splits, it's at the bottom of the rightmost column of windows. To
make it always occupy the full width: >

View File

@@ -2023,8 +2023,8 @@ test_arglist \
test_cmdline \
test_cursor_func \
test_delete \
test_evalcmd \
test_ex_undo \
test_execute_func \
test_expand \
test_expand_dllpath \
test_expr \

View File

@@ -555,9 +555,9 @@ static void f_diff_hlID(typval_T *argvars, typval_T *rettv);
static void f_empty(typval_T *argvars, typval_T *rettv);
static void f_escape(typval_T *argvars, typval_T *rettv);
static void f_eval(typval_T *argvars, typval_T *rettv);
static void f_evalcmd(typval_T *argvars, typval_T *rettv);
static void f_eventhandler(typval_T *argvars, typval_T *rettv);
static void f_executable(typval_T *argvars, typval_T *rettv);
static void f_execute(typval_T *argvars, typval_T *rettv);
static void f_exepath(typval_T *argvars, typval_T *rettv);
static void f_exists(typval_T *argvars, typval_T *rettv);
#ifdef FEAT_FLOAT
@@ -593,6 +593,9 @@ static void f_getchar(typval_T *argvars, typval_T *rettv);
static void f_getcharmod(typval_T *argvars, typval_T *rettv);
static void f_getcharsearch(typval_T *argvars, typval_T *rettv);
static void f_getcmdline(typval_T *argvars, typval_T *rettv);
#if defined(FEAT_CMDL_COMPL)
static void f_getcompletion(typval_T *argvars, typval_T *rettv);
#endif
static void f_getcmdpos(typval_T *argvars, typval_T *rettv);
static void f_getcmdtype(typval_T *argvars, typval_T *rettv);
static void f_getcmdwintype(typval_T *argvars, typval_T *rettv);
@@ -8564,9 +8567,9 @@ static struct fst
{"empty", 1, 1, f_empty},
{"escape", 2, 2, f_escape},
{"eval", 1, 1, f_eval},
{"evalcmd", 1, 1, f_evalcmd},
{"eventhandler", 0, 0, f_eventhandler},
{"executable", 1, 1, f_executable},
{"execute", 1, 2, f_execute},
{"exepath", 1, 1, f_exepath},
{"exists", 1, 1, f_exists},
#ifdef FEAT_FLOAT
@@ -8606,6 +8609,9 @@ static struct fst
{"getcmdpos", 0, 0, f_getcmdpos},
{"getcmdtype", 0, 0, f_getcmdtype},
{"getcmdwintype", 0, 0, f_getcmdwintype},
#if defined(FEAT_CMDL_COMPL)
{"getcompletion", 2, 2, f_getcompletion},
#endif
{"getcurpos", 0, 0, f_getcurpos},
{"getcwd", 0, 2, f_getcwd},
{"getfontname", 0, 1, f_getfontname},
@@ -11345,65 +11351,6 @@ f_eval(typval_T *argvars, typval_T *rettv)
EMSG(_(e_trailing));
}
static garray_T redir_evalcmd_ga;
/*
* Append "value[value_len]" to the evalcmd() output.
*/
void
evalcmd_redir_str(char_u *value, int value_len)
{
int len;
if (value_len == -1)
len = (int)STRLEN(value); /* Append the entire string */
else
len = value_len; /* Append only "value_len" characters */
if (ga_grow(&redir_evalcmd_ga, len) == OK)
{
mch_memmove((char *)redir_evalcmd_ga.ga_data
+ redir_evalcmd_ga.ga_len, value, len);
redir_evalcmd_ga.ga_len += len;
}
}
/*
* "evalcmd()" function
*/
static void
f_evalcmd(typval_T *argvars, typval_T *rettv)
{
char_u *s;
int save_msg_silent = msg_silent;
int save_redir_evalcmd = redir_evalcmd;
garray_T save_ga;
rettv->vval.v_string = NULL;
rettv->v_type = VAR_STRING;
s = get_tv_string_chk(&argvars[0]);
if (s != NULL)
{
if (redir_evalcmd)
save_ga = redir_evalcmd_ga;
ga_init2(&redir_evalcmd_ga, (int)sizeof(char), 500);
redir_evalcmd = TRUE;
++msg_silent;
do_cmdline_cmd(s);
rettv->vval.v_string = redir_evalcmd_ga.ga_data;
msg_silent = save_msg_silent;
redir_evalcmd = save_redir_evalcmd;
if (redir_evalcmd)
redir_evalcmd_ga = save_ga;
/* "silent reg" or "silent echo x" leaves msg_col somewhere in the
* line. Put it back in the first column. */
msg_col = 0;
}
}
/*
* "eventhandler()" function
*/
@@ -11426,6 +11373,132 @@ f_executable(typval_T *argvars, typval_T *rettv)
|| (gettail(name) != name && mch_can_exe(name, NULL, FALSE));
}
static garray_T redir_execute_ga;
/*
* Append "value[value_len]" to the execute() output.
*/
void
execute_redir_str(char_u *value, int value_len)
{
int len;
if (value_len == -1)
len = (int)STRLEN(value); /* Append the entire string */
else
len = value_len; /* Append only "value_len" characters */
if (ga_grow(&redir_execute_ga, len) == OK)
{
mch_memmove((char *)redir_execute_ga.ga_data
+ redir_execute_ga.ga_len, value, len);
redir_execute_ga.ga_len += len;
}
}
/*
* Get next line from a list.
* Called by do_cmdline() to get the next line.
* Returns allocated string, or NULL for end of function.
*/
static char_u *
get_list_line(
int c UNUSED,
void *cookie,
int indent UNUSED)
{
listitem_T **p = (listitem_T **)cookie;
listitem_T *item = *p;
char_u buf[NUMBUFLEN];
char_u *s;
if (item == NULL)
return NULL;
s = get_tv_string_buf_chk(&item->li_tv, buf);
*p = item->li_next;
return s == NULL ? NULL : vim_strsave(s);
}
/*
* "execute()" function
*/
static void
f_execute(typval_T *argvars, typval_T *rettv)
{
char_u *cmd = NULL;
list_T *list = NULL;
int save_msg_silent = msg_silent;
int save_emsg_silent = emsg_silent;
int save_emsg_noredir = emsg_noredir;
int save_redir_execute = redir_execute;
garray_T save_ga;
rettv->vval.v_string = NULL;
rettv->v_type = VAR_STRING;
if (argvars[0].v_type == VAR_LIST)
{
list = argvars[0].vval.v_list;
if (list == NULL || list->lv_first == NULL)
/* empty list, no commands, empty output */
return;
++list->lv_refcount;
}
else
{
cmd = get_tv_string_chk(&argvars[0]);
if (cmd == NULL)
return;
}
if (argvars[1].v_type != VAR_UNKNOWN)
{
char_u buf[NUMBUFLEN];
char_u *s = get_tv_string_buf_chk(&argvars[1], buf);
if (s == NULL)
return;
if (STRNCMP(s, "silent", 6) == 0)
++msg_silent;
if (STRCMP(s, "silent!") == 0)
{
emsg_silent = TRUE;
emsg_noredir = TRUE;
}
}
else
++msg_silent;
if (redir_execute)
save_ga = redir_execute_ga;
ga_init2(&redir_execute_ga, (int)sizeof(char), 500);
redir_execute = TRUE;
if (cmd != NULL)
do_cmdline_cmd(cmd);
else
{
listitem_T *item = list->lv_first;
do_cmdline(NULL, get_list_line, (void *)&item,
DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT|DOCMD_KEYTYPED);
--list->lv_refcount;
}
rettv->vval.v_string = redir_execute_ga.ga_data;
msg_silent = save_msg_silent;
emsg_silent = save_emsg_silent;
emsg_noredir = save_emsg_noredir;
redir_execute = save_redir_execute;
if (redir_execute)
redir_execute_ga = save_ga;
/* "silent reg" or "silent echo x" leaves msg_col somewhere in the
* line. Put it back in the first column. */
msg_col = 0;
}
/*
* "exepath()" function
*/
@@ -13016,6 +13089,55 @@ f_getcmdwintype(typval_T *argvars UNUSED, typval_T *rettv)
#endif
}
#if defined(FEAT_CMDL_COMPL)
/*
* "getcompletion()" function
*/
static void
f_getcompletion(typval_T *argvars, typval_T *rettv)
{
char_u *pat;
expand_T xpc;
int options = WILD_KEEP_ALL | WILD_SILENT | WILD_USE_NL
| WILD_LIST_NOTFOUND | WILD_NO_BEEP;
if (p_wic)
options |= WILD_ICASE;
ExpandInit(&xpc);
xpc.xp_pattern = get_tv_string(&argvars[0]);
xpc.xp_pattern_len = STRLEN(xpc.xp_pattern);
xpc.xp_context = cmdcomplete_str_to_type(get_tv_string(&argvars[1]));
if (xpc.xp_context == EXPAND_NOTHING)
{
if (argvars[1].v_type == VAR_STRING)
EMSG2(_(e_invarg2), argvars[1].vval.v_string);
else
EMSG(_(e_invarg));
return;
}
if (xpc.xp_context == EXPAND_MENUS)
{
set_context_in_menu_cmd(&xpc, (char_u *)"menu", xpc.xp_pattern, FALSE);
xpc.xp_pattern_len = STRLEN(xpc.xp_pattern);
}
pat = addstar(xpc.xp_pattern, xpc.xp_pattern_len, xpc.xp_context);
if ((rettv_list_alloc(rettv) != FAIL) && (pat != NULL))
{
int i;
ExpandOne(&xpc, pat, NULL, options, WILD_ALL_KEEP);
for (i = 0; i < xpc.xp_numfiles; i++)
list_append_string(rettv->vval.v_list, xpc.xp_files[i], -1);
}
vim_free(pat);
ExpandCleanup(&xpc);
}
#endif
/*
* "getcwd()" function
*/
@@ -21102,8 +21224,8 @@ f_timer_stop(typval_T *argvars, typval_T *rettv UNUSED)
if (argvars[0].v_type != VAR_NUMBER)
{
EMSG(_(e_number_exp));
return;
EMSG(_(e_number_exp));
return;
}
timer = find_timer((int)get_tv_number(&argvars[0]));
if (timer != NULL)

View File

@@ -724,6 +724,9 @@ EX(CMD_laddfile, "laddfile", ex_cfile,
EX(CMD_later, "later", ex_later,
TRLBAR|EXTRA|NOSPC|CMDWIN,
ADDR_LINES),
EX(CMD_lbottom, "lbottom", ex_cbottom,
TRLBAR,
ADDR_LINES),
EX(CMD_lbuffer, "lbuffer", ex_cbuffer,
BANG|RANGE|NOTADR|WORD1|TRLBAR,
ADDR_LINES),

View File

@@ -7049,6 +7049,18 @@ parse_compl_arg(
# endif
return OK;
}
int
cmdcomplete_str_to_type(char_u *complete_str)
{
int i;
for (i = 0; command_complete[i].expand != 0; ++i)
if (STRCMP(complete_str, command_complete[i].name) == 0)
return command_complete[i].expand;
return EXPAND_NOTHING;
}
#endif
static void
@@ -9456,9 +9468,9 @@ ex_redir(exarg_T *eap)
char_u *arg = eap->arg;
#ifdef FEAT_EVAL
if (redir_evalcmd)
if (redir_execute)
{
EMSG(_("E930: Cannot use :redir inside evalcmd()"));
EMSG(_("E930: Cannot use :redir inside execute()"));
return;
}
#endif

View File

@@ -971,6 +971,7 @@ EXTERN cmdmod_T cmdmod; /* Ex command modifiers */
EXTERN int msg_silent INIT(= 0); /* don't print messages */
EXTERN int emsg_silent INIT(= 0); /* don't print error messages */
EXTERN int emsg_noredir INIT(= 0); /* don't redirect error messages */
EXTERN int cmd_silent INIT(= FALSE); /* don't echo the command line */
#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) \
@@ -1106,7 +1107,7 @@ EXTERN FILE *redir_fd INIT(= NULL); /* message redirection file */
#ifdef FEAT_EVAL
EXTERN int redir_reg INIT(= 0); /* message redirection register */
EXTERN int redir_vname INIT(= 0); /* message redirection variable */
EXTERN int redir_evalcmd INIT(= 0); /* evalcmd() redirection */
EXTERN int redir_execute INIT(= 0); /* execute() redirection */
#endif
#ifdef FEAT_LANGMAP

View File

@@ -566,22 +566,25 @@ emsg(char_u *s)
*/
if (emsg_silent != 0)
{
msg_start();
p = get_emsg_source();
if (p != NULL)
if (emsg_noredir == 0)
{
STRCAT(p, "\n");
redir_write(p, -1);
vim_free(p);
msg_start();
p = get_emsg_source();
if (p != NULL)
{
STRCAT(p, "\n");
redir_write(p, -1);
vim_free(p);
}
p = get_emsg_lnum();
if (p != NULL)
{
STRCAT(p, "\n");
redir_write(p, -1);
vim_free(p);
}
redir_write(s, -1);
}
p = get_emsg_lnum();
if (p != NULL)
{
STRCAT(p, "\n");
redir_write(p, -1);
vim_free(p);
}
redir_write(s, -1);
return TRUE;
}
@@ -3063,8 +3066,8 @@ redir_write(char_u *str, int maxlen)
while (cur_col < msg_col)
{
#ifdef FEAT_EVAL
if (redir_evalcmd)
evalcmd_redir_str((char_u *)" ", -1);
if (redir_execute)
execute_redir_str((char_u *)" ", -1);
else if (redir_reg)
write_reg_contents(redir_reg, (char_u *)" ", -1, TRUE);
else if (redir_vname)
@@ -3080,8 +3083,8 @@ redir_write(char_u *str, int maxlen)
}
#ifdef FEAT_EVAL
if (redir_evalcmd)
evalcmd_redir_str(s, maxlen);
if (redir_execute)
execute_redir_str(s, maxlen);
else if (redir_reg)
write_reg_contents(redir_reg, s, maxlen, TRUE);
else if (redir_vname)
@@ -3092,7 +3095,7 @@ redir_write(char_u *str, int maxlen)
while (*s != NUL && (maxlen < 0 || (int)(s - str) < maxlen))
{
#ifdef FEAT_EVAL
if (!redir_reg && !redir_vname && !redir_evalcmd)
if (!redir_reg && !redir_vname && !redir_execute)
#endif
if (redir_fd != NULL)
putc(*s, redir_fd);
@@ -3117,7 +3120,7 @@ redirecting(void)
{
return redir_fd != NULL || *p_vfile != NUL
#ifdef FEAT_EVAL
|| redir_reg || redir_vname || redir_evalcmd
|| redir_reg || redir_vname || redir_execute
#endif
;
}

View File

@@ -88,7 +88,7 @@ char_u *get_expr_name(expand_T *xp, int idx);
int call_func(char_u *funcname, int len, typval_T *rettv, int argcount_in, typval_T *argvars_in, linenr_T firstline, linenr_T lastline, int *doesrange, int evaluate, partial_T *partial, dict_T *selfdict_in);
buf_T *buflist_find_by_name(char_u *name, int curtab_only);
int func_call(char_u *name, typval_T *args, partial_T *partial, dict_T *selfdict, typval_T *rettv);
void evalcmd_redir_str(char_u *value, int value_len);
void execute_redir_str(char_u *value, int value_len);
void dict_extend(dict_T *d1, dict_T *d2, char_u *action);
void mzscheme_call_vim(char_u *name, typval_T *args, typval_T *rettv);
float_T vim_round(float_T f);

View File

@@ -25,6 +25,7 @@ char_u *get_user_cmd_nargs(expand_T *xp, int idx);
char_u *get_user_cmd_complete(expand_T *xp, int idx);
int parse_addr_type_arg(char_u *value, int vallen, long *argt, int *addr_type_arg);
int parse_compl_arg(char_u *value, int vallen, int *complp, long *argt, char_u **compl_arg);
int cmdcomplete_str_to_type(char_u *complete_str);
void not_exiting(void);
void tabpage_close(int forceit);
void tabpage_close_other(tabpage_T *tp, int forceit);

View File

@@ -2831,13 +2831,25 @@ qf_win_goto(win_T *win, linenr_T lnum)
}
/*
* :cbottom command.
* :cbottom/:lbottom commands.
*/
void
ex_cbottom(exarg_T *eap UNUSED)
{
win_T *win = qf_find_win(&ql_info);
qf_info_T *qi = &ql_info;
win_T *win;
if (eap->cmdidx == CMD_lbottom)
{
qi = GET_LOC_LIST(curwin);
if (qi == NULL)
{
EMSG(_(e_loclist));
return;
}
}
win = qf_find_win(qi);
if (win != NULL && win->w_cursor.lnum != win->w_buffer->b_ml.ml_line_count)
qf_win_goto(win, win->w_buffer->b_ml.ml_line_count);
}

View File

@@ -149,6 +149,9 @@ for s:test in sort(s:tests)
endif
endfor
" Don't write viminfo on exit.
set viminfo=
if s:fail == 0
" Success, create the .res file so that make knows it's done.
exe 'split ' . fnamemodify(g:testname, ':r') . '.res'

View File

@@ -5,7 +5,7 @@ source test_assign.vim
source test_autocmd.vim
source test_cursor_func.vim
source test_delete.vim
source test_evalcmd.vim
source test_execute_func.vim
source test_ex_undo.vim
source test_expand.vim
source test_expr.vim

View File

@@ -24,3 +24,26 @@ func Test_complete_wildmenu()
call delete('Xtestfile2')
set nowildmenu
endfunc
func Test_getcompletion()
if !has('cmdline_compl')
return
endif
let groupcount = len(getcompletion('', 'event'))
call assert_true(groupcount > 0)
let matchcount = len(getcompletion('File', 'event'))
call assert_true(matchcount > 0)
call assert_true(groupcount > matchcount)
if has('menu')
source $VIMRUNTIME/menu.vim
let matchcount = len(getcompletion('', 'menu'))
call assert_true(matchcount > 0)
call assert_equal(['File.'], getcompletion('File', 'menu'))
call assert_true(matchcount > 0)
let matchcount = len(getcompletion('File.', 'menu'))
call assert_true(matchcount > 0)
endif
call assert_fails('call getcompletion("", "burp")', 'E475:')
endfunc

View File

@@ -1,33 +0,0 @@
" test evalcmd()
func NestedEval()
let nested = evalcmd('echo "nested\nlines"')
echo 'got: "' . nested . '"'
endfunc
func NestedRedir()
redir => var
echo 'broken'
redir END
endfunc
func Test_evalcmd()
call assert_equal("\nnocompatible", evalcmd('set compatible?'))
call assert_equal("\nsomething\nnice", evalcmd('echo "something\nnice"'))
call assert_equal("noendofline", evalcmd('echon "noendofline"'))
call assert_equal("", evalcmd(123))
call assert_equal("\ngot: \"\nnested\nlines\"", evalcmd('call NestedEval()'))
redir => redired
echo 'this'
let evaled = evalcmd('echo "that"')
echo 'theend'
redir END
call assert_equal("\nthis\ntheend", redired)
call assert_equal("\nthat", evaled)
call assert_fails('call evalcmd("doesnotexist")', 'E492:')
call assert_fails('call evalcmd(3.4)', 'E806:')
call assert_fails('call evalcmd("call NestedRedir()")', 'E930:')
endfunc

View File

@@ -0,0 +1,51 @@
" test execute()
func NestedEval()
let nested = execute('echo "nested\nlines"')
echo 'got: "' . nested . '"'
endfunc
func NestedRedir()
redir => var
echo 'broken'
redir END
endfunc
func Test_execute_string()
call assert_equal("\nnocompatible", execute('set compatible?'))
call assert_equal("\nsomething\nnice", execute('echo "something\nnice"'))
call assert_equal("noendofline", execute('echon "noendofline"'))
call assert_equal("", execute(123))
call assert_equal("\ngot: \"\nnested\nlines\"", execute('call NestedEval()'))
redir => redired
echo 'this'
let evaled = execute('echo "that"')
echo 'theend'
redir END
call assert_equal("\nthis\ntheend", redired)
call assert_equal("\nthat", evaled)
call assert_fails('call execute("doesnotexist")', 'E492:')
call assert_fails('call execute(3.4)', 'E806:')
call assert_fails('call execute("call NestedRedir()")', 'E930:')
call assert_equal("\nsomething", execute('echo "something"', ''))
call assert_equal("\nsomething", execute('echo "something"', 'silent'))
call assert_equal("\nsomething", execute('echo "something"', 'silent!'))
call assert_equal("", execute('burp', 'silent!'))
call assert_fails('call execute("echo \"x\"", 3.4)', 'E806:')
call assert_equal("", execute(test_null_string()))
endfunc
func Test_execute_list()
call assert_equal("\nsomething\nnice", execute(['echo "something"', 'echo "nice"']))
let l = ['for n in range(0, 3)',
\ 'echo n',
\ 'endfor']
call assert_equal("\n0\n1\n2\n3", execute(l))
call assert_equal("", execute([]))
call assert_equal("", execute(test_null_list()))
endfunc

View File

@@ -15,6 +15,7 @@ function! s:setup_commands(cchar)
command! -nargs=* Xnewer <mods>cnewer <args>
command! -nargs=* Xopen <mods>copen <args>
command! -nargs=* Xwindow <mods>cwindow <args>
command! -nargs=* Xbottom <mods>cbottom <args>
command! -nargs=* Xclose <mods>cclose <args>
command! -nargs=* -bang Xfile <mods>cfile<bang> <args>
command! -nargs=* Xgetfile <mods>cgetfile <args>
@@ -44,6 +45,7 @@ function! s:setup_commands(cchar)
command! -nargs=* Xnewer <mods>lnewer <args>
command! -nargs=* Xopen <mods>lopen <args>
command! -nargs=* Xwindow <mods>lwindow <args>
command! -nargs=* Xbottom <mods>lbottom <args>
command! -nargs=* Xclose <mods>lclose <args>
command! -nargs=* -bang Xfile <mods>lfile<bang> <args>
command! -nargs=* Xgetfile <mods>lgetfile <args>
@@ -200,6 +202,7 @@ function XwindowTests(cchar)
Xwindow
call assert_true(winnr('$') == 2 && winnr() == 2 &&
\ getline('.') ==# 'Xtestfile1|1 col 3| Line1')
redraw!
" Close the window
Xclose
@@ -1415,15 +1418,23 @@ echo string(loc_two)
call delete('Xtwo', 'rf')
endfunc
function Test_cbottom()
call setqflist([{'filename': 'foo', 'lnum': 42}])
copen
function XbottomTests(cchar)
call s:setup_commands(a:cchar)
call g:Xsetlist([{'filename': 'foo', 'lnum': 42}])
Xopen
let wid = win_getid()
call assert_equal(1, line('.'))
wincmd w
call setqflist([{'filename': 'var', 'lnum': 24}], 'a')
cbottom
call g:Xsetlist([{'filename': 'var', 'lnum': 24}], 'a')
Xbottom
call win_gotoid(wid)
call assert_equal(2, line('.'))
cclose
Xclose
endfunc
" Tests for the :cbottom and :lbottom commands
function Test_cbottom()
call XbottomTests('c')
call XbottomTests('l')
endfunction

View File

@@ -758,6 +758,18 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
2012,
/**/
2011,
/**/
2010,
/**/
2009,
/**/
2008,
/**/
2007,
/**/
2006,
/**/