mirror of
https://github.com/neovim/neovim.git
synced 2025-10-02 07:58:35 +00:00
Merge #4697 'capture() function'.
This commit is contained in:
@@ -6713,6 +6713,7 @@ static struct fst {
|
||||
{ "byteidx", 2, 2, f_byteidx },
|
||||
{ "byteidxcomp", 2, 2, f_byteidxcomp },
|
||||
{ "call", 2, 3, f_call },
|
||||
{ "capture", 1, 1, f_capture },
|
||||
{ "ceil", 1, 1, f_ceil },
|
||||
{ "changenr", 0, 0, f_changenr },
|
||||
{ "char2nr", 1, 2, f_char2nr },
|
||||
@@ -8083,6 +8084,38 @@ static void f_call(typval_T *argvars, typval_T *rettv)
|
||||
(void)func_call(func, &argvars[1], selfdict, rettv);
|
||||
}
|
||||
|
||||
// "capture(command)" function
|
||||
static void f_capture(typval_T *argvars, typval_T *rettv)
|
||||
{
|
||||
int save_msg_silent = msg_silent;
|
||||
garray_T *save_capture_ga = capture_ga;
|
||||
|
||||
if (check_secure()) {
|
||||
return;
|
||||
}
|
||||
|
||||
garray_T capture_local;
|
||||
capture_ga = &capture_local;
|
||||
ga_init(capture_ga, (int)sizeof(char), 80);
|
||||
|
||||
msg_silent++;
|
||||
if (argvars[0].v_type != VAR_LIST) {
|
||||
do_cmdline_cmd((char *)get_tv_string(&argvars[0]));
|
||||
} else if (argvars[0].vval.v_list != NULL) {
|
||||
for (listitem_T *li = argvars[0].vval.v_list->lv_first;
|
||||
li != NULL; li = li->li_next) {
|
||||
do_cmdline_cmd((char *)get_tv_string(&li->li_tv));
|
||||
}
|
||||
}
|
||||
msg_silent = save_msg_silent;
|
||||
|
||||
ga_append(capture_ga, NUL);
|
||||
rettv->v_type = VAR_STRING;
|
||||
rettv->vval.v_string = capture_ga->ga_data;
|
||||
|
||||
capture_ga = save_capture_ga;
|
||||
}
|
||||
|
||||
/*
|
||||
* "ceil({float})" function
|
||||
*/
|
||||
|
@@ -985,10 +985,11 @@ EXTERN int keep_help_flag INIT(= FALSE); /* doing :ta from help file */
|
||||
*/
|
||||
EXTERN char_u *empty_option INIT(= (char_u *)"");
|
||||
|
||||
EXTERN int redir_off INIT(= FALSE); /* no redirection for a moment */
|
||||
EXTERN FILE *redir_fd INIT(= NULL); /* message redirection file */
|
||||
EXTERN int redir_reg INIT(= 0); /* message redirection register */
|
||||
EXTERN int redir_vname INIT(= 0); /* message redirection variable */
|
||||
EXTERN int redir_off INIT(= false); // no redirection for a moment
|
||||
EXTERN FILE *redir_fd INIT(= NULL); // message redirection file
|
||||
EXTERN int redir_reg INIT(= 0); // message redirection register
|
||||
EXTERN int redir_vname INIT(= 0); // message redirection variable
|
||||
EXTERN garray_T *capture_ga INIT(= NULL); // capture() buffer
|
||||
|
||||
EXTERN char_u langmap_mapchar[256]; /* mapping for language keys */
|
||||
|
||||
|
@@ -2392,6 +2392,19 @@ static void redir_write(char_u *str, int maxlen)
|
||||
char_u *s = str;
|
||||
static int cur_col = 0;
|
||||
|
||||
if (maxlen == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Append output to capture().
|
||||
if (capture_ga) {
|
||||
size_t len = 0;
|
||||
while (str[len] && (maxlen < 0 ? 1 : (len < (size_t)maxlen))) {
|
||||
len++;
|
||||
}
|
||||
ga_concat_len(capture_ga, (const char *)str, len);
|
||||
}
|
||||
|
||||
/* Don't do anything for displaying prompts and the like. */
|
||||
if (redir_off)
|
||||
return;
|
||||
|
Reference in New Issue
Block a user