Merge pull request #20088 from zeertzjq/vim-9.0.0386

vim-patch:9.0.0386: some code blocks are nested too deep

N/A patches for version.c:

vim-patch:9.0.0385: GUI: when CTRL-D is mapped in Insert mode it gets inserted
This commit is contained in:
zeertzjq
2022-09-05 23:02:01 +08:00
committed by GitHub
4 changed files with 122 additions and 110 deletions

View File

@@ -79,11 +79,12 @@ void alist_expand(int *fnum_list, int fnum_len)
{ {
char *save_p_su = p_su; char *save_p_su = p_su;
char **old_arg_files = xmalloc(sizeof(*old_arg_files) * GARGCOUNT);
// Don't use 'suffixes' here. This should work like the shell did the // Don't use 'suffixes' here. This should work like the shell did the
// expansion. Also, the vimrc file isn't read yet, thus the user // expansion. Also, the vimrc file isn't read yet, thus the user
// can't set the options. // can't set the options.
p_su = empty_option; p_su = empty_option;
char **old_arg_files = xmalloc(sizeof(*old_arg_files) * GARGCOUNT);
for (int i = 0; i < GARGCOUNT; i++) { for (int i = 0; i < GARGCOUNT; i++) {
old_arg_files[i] = vim_strsave(GARGLIST[i].ae_fname); old_arg_files[i] = vim_strsave(GARGLIST[i].ae_fname);
} }
@@ -308,47 +309,16 @@ static void alist_add_list(int count, char **files, int after, bool will_edit)
} }
} }
/// @param str /// Delete the file names in "alist_ga" from the argument list.
/// @param what static void arglist_del_files(garray_T *alist_ga)
/// AL_SET: Redefine the argument list to 'str'.
/// AL_ADD: add files in 'str' to the argument list after "after".
/// AL_DEL: remove files in 'str' from the argument list.
/// @param after
/// 0 means before first one
/// @param will_edit will edit added argument
///
/// @return FAIL for failure, OK otherwise.
static int do_arglist(char *str, int what, int after, bool will_edit)
FUNC_ATTR_NONNULL_ALL
{ {
garray_T new_ga;
int exp_count;
char **exp_files;
char *p;
int match;
int arg_escaped = true;
// Set default argument for ":argadd" command.
if (what == AL_ADD && *str == NUL) {
if (curbuf->b_ffname == NULL) {
return FAIL;
}
str = curbuf->b_fname;
arg_escaped = false;
}
// Collect all file name arguments in "new_ga".
get_arglist(&new_ga, str, arg_escaped);
if (what == AL_DEL) {
regmatch_T regmatch; regmatch_T regmatch;
bool didone;
// Delete the items: use each item as a regexp and find a match in the // Delete the items: use each item as a regexp and find a match in the
// argument list. // argument list.
regmatch.rm_ic = p_fic; // ignore case when 'fileignorecase' is set regmatch.rm_ic = p_fic; // ignore case when 'fileignorecase' is set
for (int i = 0; i < new_ga.ga_len && !got_int; i++) { for (int i = 0; i < alist_ga->ga_len && !got_int; i++) {
p = ((char **)new_ga.ga_data)[i]; char *p = ((char **)alist_ga->ga_data)[i];
p = file_pat_to_reg_pat(p, NULL, NULL, false); p = file_pat_to_reg_pat(p, NULL, NULL, false);
if (p == NULL) { if (p == NULL) {
break; break;
@@ -359,8 +329,8 @@ static int do_arglist(char *str, int what, int after, bool will_edit)
break; break;
} }
didone = false; bool didone = false;
for (match = 0; match < ARGCOUNT; match++) { for (int match = 0; match < ARGCOUNT; match++) {
if (vim_regexec(&regmatch, alist_name(&ARGLIST[match]), (colnr_T)0)) { if (vim_regexec(&regmatch, alist_name(&ARGLIST[match]), (colnr_T)0)) {
didone = true; didone = true;
xfree(ARGLIST[match].ae_fname); xfree(ARGLIST[match].ae_fname);
@@ -377,10 +347,44 @@ static int do_arglist(char *str, int what, int after, bool will_edit)
vim_regfree(regmatch.regprog); vim_regfree(regmatch.regprog);
xfree(p); xfree(p);
if (!didone) { if (!didone) {
semsg(_(e_nomatch2), ((char **)new_ga.ga_data)[i]); semsg(_(e_nomatch2), ((char **)alist_ga->ga_data)[i]);
} }
} }
ga_clear(&new_ga); ga_clear(alist_ga);
}
/// @param str
/// @param what
/// AL_SET: Redefine the argument list to 'str'.
/// AL_ADD: add files in 'str' to the argument list after "after".
/// AL_DEL: remove files in 'str' from the argument list.
/// @param after
/// 0 means before first one
/// @param will_edit will edit added argument
///
/// @return FAIL for failure, OK otherwise.
static int do_arglist(char *str, int what, int after, bool will_edit)
FUNC_ATTR_NONNULL_ALL
{
garray_T new_ga;
int exp_count;
char **exp_files;
int arg_escaped = true;
// Set default argument for ":argadd" command.
if (what == AL_ADD && *str == NUL) {
if (curbuf->b_ffname == NULL) {
return FAIL;
}
str = curbuf->b_fname;
arg_escaped = false;
}
// Collect all file name arguments in "new_ga".
get_arglist(&new_ga, str, arg_escaped);
if (what == AL_DEL) {
arglist_del_files(&new_ga);
} else { } else {
int i = expand_wildcards(new_ga.ga_len, new_ga.ga_data, int i = expand_wildcards(new_ga.ga_len, new_ga.ga_data,
&exp_count, &exp_files, &exp_count, &exp_files,
@@ -471,22 +475,27 @@ void ex_args(exarg_T *eap)
ex_next(eap); ex_next(eap);
} else if (eap->cmdidx == CMD_args) { } else if (eap->cmdidx == CMD_args) {
// ":args": list arguments. // ":args": list arguments.
if (ARGCOUNT > 0) { if (ARGCOUNT <= 0) {
return;
}
char **items = xmalloc(sizeof(char *) * (size_t)ARGCOUNT); char **items = xmalloc(sizeof(char *) * (size_t)ARGCOUNT);
// Overwrite the command, for a short list there is no scrolling // Overwrite the command, for a short list there is no scrolling
// required and no wait_return(). // required and no wait_return().
gotocmdline(true); gotocmdline(true);
for (int i = 0; i < ARGCOUNT; i++) { for (int i = 0; i < ARGCOUNT; i++) {
items[i] = alist_name(&ARGLIST[i]); items[i] = alist_name(&ARGLIST[i]);
} }
list_in_columns(items, ARGCOUNT, curwin->w_arg_idx); list_in_columns(items, ARGCOUNT, curwin->w_arg_idx);
xfree(items); xfree(items);
}
} else if (eap->cmdidx == CMD_arglocal) { } else if (eap->cmdidx == CMD_arglocal) {
garray_T *gap = &curwin->w_alist->al_ga; garray_T *gap = &curwin->w_alist->al_ga;
// ":argslocal": make a local copy of the global argument list. // ":argslocal": make a local copy of the global argument list.
ga_grow(gap, GARGCOUNT); ga_grow(gap, GARGCOUNT);
for (int i = 0; i < GARGCOUNT; i++) { for (int i = 0; i < GARGCOUNT; i++) {
if (GARGLIST[i].ae_fname != NULL) { if (GARGLIST[i].ae_fname != NULL) {
AARGLIST(curwin->w_alist)[gap->ga_len].ae_fname = xstrdup(GARGLIST[i].ae_fname); AARGLIST(curwin->w_alist)[gap->ga_len].ae_fname = xstrdup(GARGLIST[i].ae_fname);
@@ -1126,7 +1135,11 @@ void f_argv(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
aentry_T *arglist = NULL; aentry_T *arglist = NULL;
int argcount = -1; int argcount = -1;
if (argvars[0].v_type != VAR_UNKNOWN) { if (argvars[0].v_type == VAR_UNKNOWN) {
get_arglist_as_rettv(ARGLIST, ARGCOUNT, rettv);
return;
}
if (argvars[1].v_type == VAR_UNKNOWN) { if (argvars[1].v_type == VAR_UNKNOWN) {
arglist = ARGLIST; arglist = ARGLIST;
argcount = ARGCOUNT; argcount = ARGCOUNT;
@@ -1142,6 +1155,7 @@ void f_argv(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
argcount = WARGCOUNT(wp); argcount = WARGCOUNT(wp);
} }
} }
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL; rettv->vval.v_string = NULL;
int idx = (int)tv_get_number_chk(&argvars[0], NULL); int idx = (int)tv_get_number_chk(&argvars[0], NULL);
@@ -1150,7 +1164,4 @@ void f_argv(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
} else if (idx == -1) { } else if (idx == -1) {
get_arglist_as_rettv(arglist, argcount, rettv); get_arglist_as_rettv(arglist, argcount, rettv);
} }
} else {
get_arglist_as_rettv(ARGLIST, ARGCOUNT, rettv);
}
} }

View File

@@ -5544,9 +5544,9 @@ void ex_cd(exarg_T *eap)
// for non-UNIX ":cd" means: print current directory unless 'cdhome' is set // for non-UNIX ":cd" means: print current directory unless 'cdhome' is set
if (*new_dir == NUL && !p_cdh) { if (*new_dir == NUL && !p_cdh) {
ex_pwd(NULL); ex_pwd(NULL);
} else return;
}
#endif #endif
{
CdScope scope = kCdScopeGlobal; CdScope scope = kCdScopeGlobal;
switch (eap->cmdidx) { switch (eap->cmdidx) {
case CMD_tcd: case CMD_tcd:
@@ -5567,7 +5567,6 @@ void ex_cd(exarg_T *eap)
} }
} }
} }
}
/// ":pwd". /// ":pwd".
static void ex_pwd(exarg_T *eap) static void ex_pwd(exarg_T *eap)

View File

@@ -506,17 +506,19 @@ bool striequal(const char *a, const char *b)
// Did_outofmem_msg is reset when a character is read. // Did_outofmem_msg is reset when a character is read.
void do_outofmem_msg(size_t size) void do_outofmem_msg(size_t size)
{ {
if (!did_outofmem_msg) { if (did_outofmem_msg) {
return;
}
// Don't hide this message // Don't hide this message
emsg_silent = 0; emsg_silent = 0;
/* Must come first to avoid coming back here when printing the error // Must come first to avoid coming back here when printing the error
* message fails, e.g. when setting v:errmsg. */ // message fails, e.g. when setting v:errmsg.
did_outofmem_msg = true; did_outofmem_msg = true;
semsg(_("E342: Out of memory! (allocating %" PRIu64 " bytes)"), (uint64_t)size); semsg(_("E342: Out of memory! (allocating %" PRIu64 " bytes)"), (uint64_t)size);
} }
}
/// Writes time_t to "buf[8]". /// Writes time_t to "buf[8]".
void time_to_bytes(time_t time_, uint8_t buf[8]) void time_to_bytes(time_t time_, uint8_t buf[8])

View File

@@ -1042,14 +1042,14 @@ void pum_show_popupmenu(vimmenu_T *menu)
pum_scrollbar = 0; pum_scrollbar = 0;
pum_height = pum_size; pum_height = pum_size;
pum_position_at_mouse(20); pum_position_at_mouse(20);
pum_selected = -1;
pum_first = 0;
if (!p_mousemev) { if (!p_mousemev) {
// Pretend 'mousemoveevent' is set. // Pretend 'mousemoveevent' is set.
ui_call_option_set(STATIC_CSTR_AS_STRING("mousemoveevent"), BOOLEAN_OBJ(true)); ui_call_option_set(STATIC_CSTR_AS_STRING("mousemoveevent"), BOOLEAN_OBJ(true));
} }
pum_selected = -1;
pum_first = 0;
for (;;) { for (;;) {
pum_is_visible = true; pum_is_visible = true;
pum_is_drawn = true; pum_is_drawn = true;