vim-patch:partial:9.0.1166: code is indented more than necessary (#21716)

Problem:    Code is indented more than necessary.
Solution:   Use an early return where it makes sense. (Yegappan Lakshmanan,
            closes vim/vim#11792)

1cfb14aa97

Partial port as some highlight.c changes depend on previous patches.
Cherry-pick fname_match() change from patch 8.2.4959.
Omit internal_func_check_arg_types(): only used for Vim9 script.

N/A patches for version.c:

vim-patch:9.0.1167: EditorConfig files do not have their own filetype

Problem:    EditorConfig files do not have their own filetype.
Solution:   Add the "editorconfig" filetype. (Gregory Anders, closes vim/vim#11779)

d41262ed06

Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
zeertzjq
2023-01-10 08:46:42 +08:00
committed by GitHub
parent 364b131f42
commit dc7edce650
12 changed files with 300 additions and 267 deletions

View File

@@ -2676,19 +2676,20 @@ static int arg_augroup_get(char **argp)
{ {
char *p; char *p;
char *arg = *argp; char *arg = *argp;
int group = AUGROUP_ALL;
for (p = arg; *p && !ascii_iswhite(*p) && *p != '|'; p++) {} for (p = arg; *p && !ascii_iswhite(*p) && *p != '|'; p++) {}
if (p > arg) { if (p <= arg) {
char *group_name = xstrnsave(arg, (size_t)(p - arg)); return AUGROUP_ALL;
group = augroup_find(group_name);
if (group == AUGROUP_ERROR) {
group = AUGROUP_ALL; // no match, use all groups
} else {
*argp = skipwhite(p); // match, skip over group name
}
xfree(group_name);
} }
char *group_name = xstrnsave(arg, (size_t)(p - arg));
int group = augroup_find(group_name);
if (group == AUGROUP_ERROR) {
group = AUGROUP_ALL; // no match, use all groups
} else {
*argp = skipwhite(p); // match, skip over group name
}
xfree(group_name);
return group; return group;
} }

View File

@@ -359,8 +359,9 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags_arg)
} }
apply_autocmds_retval(EVENT_BUFENTER, NULL, NULL, false, curbuf, &retval); apply_autocmds_retval(EVENT_BUFENTER, NULL, NULL, false, curbuf, &retval);
// if (retval != OK) {
if (retval == FAIL) { if (retval == FAIL) {
return FAIL; return retval;
} }
// The autocommands may have changed the current buffer. Apply the // The autocommands may have changed the current buffer. Apply the
@@ -2473,19 +2474,22 @@ static char *fname_match(regmatch_T *rmp, char *name, bool ignore_case)
char *match = NULL; char *match = NULL;
char *p; char *p;
if (name != NULL) { // extra check for valid arguments
// Ignore case when 'fileignorecase' or the argument is set. if (name == NULL || rmp->regprog == NULL) {
rmp->rm_ic = p_fic || ignore_case; return NULL;
if (vim_regexec(rmp, name, (colnr_T)0)) { }
// Ignore case when 'fileignorecase' or the argument is set.
rmp->rm_ic = p_fic || ignore_case;
if (vim_regexec(rmp, name, (colnr_T)0)) {
match = name;
} else if (rmp->regprog != NULL) {
// Replace $(HOME) with '~' and try matching again.
p = home_replace_save(NULL, name);
if (vim_regexec(rmp, p, (colnr_T)0)) {
match = name; match = name;
} else if (rmp->regprog != NULL) {
// Replace $(HOME) with '~' and try matching again.
p = home_replace_save(NULL, name);
if (vim_regexec(rmp, p, (colnr_T)0)) {
match = name;
}
xfree(p);
} }
xfree(p);
} }
return match; return match;
@@ -2592,17 +2596,18 @@ void buflist_setfpos(buf_T *const buf, win_T *const win, linenr_T lnum, colnr_T
static bool wininfo_other_tab_diff(wininfo_T *wip) static bool wininfo_other_tab_diff(wininfo_T *wip)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{ {
if (wip->wi_opt.wo_diff) { if (!wip->wi_opt.wo_diff) {
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { return false;
// return false when it's a window in the current tab page, thus
// the buffer was in diff mode here
if (wip->wi_win == wp) {
return false;
}
}
return true;
} }
return false;
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
// return false when it's a window in the current tab page, thus
// the buffer was in diff mode here
if (wip->wi_win == wp) {
return false;
}
}
return true;
} }
/// Find info for the current window in buffer "buf". /// Find info for the current window in buffer "buf".
@@ -2625,25 +2630,27 @@ static wininfo_T *find_wininfo(buf_T *buf, bool need_options, bool skip_diff_buf
} }
} }
if (wip != NULL) {
return wip;
}
// If no wininfo for curwin, use the first in the list (that doesn't have // If no wininfo for curwin, use the first in the list (that doesn't have
// 'diff' set and is in another tab page). // 'diff' set and is in another tab page).
// If "need_options" is true skip entries that don't have options set, // If "need_options" is true skip entries that don't have options set,
// unless the window is editing "buf", so we can copy from the window // unless the window is editing "buf", so we can copy from the window
// itself. // itself.
if (wip == NULL) { if (skip_diff_buffer) {
if (skip_diff_buffer) { for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next) {
for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next) { if (!wininfo_other_tab_diff(wip)
if (!wininfo_other_tab_diff(wip) && (!need_options
&& (!need_options || wip->wi_optset
|| wip->wi_optset || (wip->wi_win != NULL
|| (wip->wi_win != NULL && wip->wi_win->w_buffer == buf))) {
&& wip->wi_win->w_buffer == buf))) { break;
break;
}
} }
} else {
wip = buf->b_wininfo;
} }
} else {
wip = buf->b_wininfo;
} }
return wip; return wip;
} }

View File

@@ -1585,21 +1585,24 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, cons
case CMD_dsplit: case CMD_dsplit:
// Skip count. // Skip count.
arg = (const char *)skipwhite(skipdigits(arg)); arg = (const char *)skipwhite(skipdigits(arg));
if (*arg == '/') { // Match regexp, not just whole words. if (*arg != '/') {
for (++arg; *arg && *arg != '/'; arg++) { return NULL;
if (*arg == '\\' && arg[1] != NUL) { }
arg++;
}
}
if (*arg) {
arg = (const char *)skipwhite(arg + 1);
// Check for trailing illegal characters. // Match regexp, not just whole words.
if (*arg == NUL || strchr("|\"\n", *arg) == NULL) { for (++arg; *arg && *arg != '/'; arg++) {
xp->xp_context = EXPAND_NOTHING; if (*arg == '\\' && arg[1] != NUL) {
} else { arg++;
return arg; }
} }
if (*arg) {
arg = (const char *)skipwhite(arg + 1);
// Check for trailing illegal characters.
if (*arg == NUL || strchr("|\"\n", *arg) == NULL) {
xp->xp_context = EXPAND_NOTHING;
} else {
return arg;
} }
} }
break; break;

View File

@@ -317,13 +317,15 @@ static int get_maxbacktrace_level(char *sname)
{ {
int maxbacktrace = 0; int maxbacktrace = 0;
if (sname != NULL) { if (sname == NULL) {
char *p = sname; return 0;
char *q; }
while ((q = strstr(p, "..")) != NULL) {
p = q + 2; char *p = sname;
maxbacktrace++; char *q;
} while ((q = strstr(p, "..")) != NULL) {
p = q + 2;
maxbacktrace++;
} }
return maxbacktrace; return maxbacktrace;
} }
@@ -458,20 +460,21 @@ void dbg_check_breakpoint(exarg_T *eap)
/// @return true when the debug mode is entered this time. /// @return true when the debug mode is entered this time.
bool dbg_check_skipped(exarg_T *eap) bool dbg_check_skipped(exarg_T *eap)
{ {
if (debug_skipped) { if (!debug_skipped) {
// Save the value of got_int and reset it. We don't want a previous return false;
// interruption cause flushing the input buffer.
int prev_got_int = got_int;
got_int = false;
debug_breakpoint_name = debug_skipped_name;
// eap->skip is true
eap->skip = false;
dbg_check_breakpoint(eap);
eap->skip = true;
got_int |= prev_got_int;
return true;
} }
return false;
// Save the value of got_int and reset it. We don't want a previous
// interruption cause flushing the input buffer.
int prev_got_int = got_int;
got_int = false;
debug_breakpoint_name = debug_skipped_name;
// eap->skip is true
eap->skip = false;
dbg_check_breakpoint(eap);
eap->skip = true;
got_int |= prev_got_int;
return true;
} }
static garray_T dbg_breakp = { 0, 0, sizeof(struct debuggy), 4, NULL }; static garray_T dbg_breakp = { 0, 0, sizeof(struct debuggy), 4, NULL };

View File

@@ -1528,30 +1528,31 @@ int get_digraph(bool cmdline)
no_mapping--; no_mapping--;
allow_keys--; allow_keys--;
if (c != ESC) { if (c == ESC) { // ESC cancels CTRL-K
return NUL;
}
if (IS_SPECIAL(c)) {
// insert special key code
return c;
}
if (cmdline) {
if ((char2cells(c) == 1) && c < 128 && (cmdline_star == 0)) {
putcmdline((char)c, true);
}
} else {
add_to_showcmd(c);
}
no_mapping++;
allow_keys++;
int cc = plain_vgetc();
no_mapping--;
allow_keys--;
if (cc != ESC) {
// ESC cancels CTRL-K // ESC cancels CTRL-K
if (IS_SPECIAL(c)) { return digraph_get(c, cc, true);
// insert special key code
return c;
}
if (cmdline) {
if ((char2cells(c) == 1) && c < 128 && (cmdline_star == 0)) {
putcmdline((char)c, true);
}
} else {
add_to_showcmd(c);
}
no_mapping++;
allow_keys++;
int cc = plain_vgetc();
no_mapping--;
allow_keys--;
if (cc != ESC) {
// ESC cancels CTRL-K
return digraph_get(c, cc, true);
}
} }
return NUL; return NUL;
} }

View File

@@ -859,14 +859,14 @@ static void f_cindent(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
win_T *get_optional_window(typval_T *argvars, int idx) win_T *get_optional_window(typval_T *argvars, int idx)
{ {
win_T *win = curwin; if (argvars[idx].v_type == VAR_UNKNOWN) {
return curwin;
}
if (argvars[idx].v_type != VAR_UNKNOWN) { win_T *win = find_win_by_nr_or_id(&argvars[idx]);
win = find_win_by_nr_or_id(&argvars[idx]); if (win == NULL) {
if (win == NULL) { emsg(_(e_invalwindow));
emsg(_(e_invalwindow)); return NULL;
return NULL;
}
} }
return win; return win;
} }
@@ -6109,55 +6109,57 @@ static int get_search_arg(typval_T *varp, int *flagsp)
{ {
int dir = FORWARD; int dir = FORWARD;
if (varp->v_type != VAR_UNKNOWN) { if (varp->v_type == VAR_UNKNOWN) {
char nbuf[NUMBUFLEN]; return FORWARD;
const char *flags = tv_get_string_buf_chk(varp, nbuf); }
if (flags == NULL) {
return 0; // Type error; errmsg already given. char nbuf[NUMBUFLEN];
} const char *flags = tv_get_string_buf_chk(varp, nbuf);
int mask; if (flags == NULL) {
while (*flags != NUL) { return 0; // Type error; errmsg already given.
switch (*flags) { }
case 'b': int mask;
dir = BACKWARD; break; while (*flags != NUL) {
case 'w': switch (*flags) {
p_ws = true; break; case 'b':
case 'W': dir = BACKWARD; break;
p_ws = false; break; case 'w':
default: p_ws = true; break;
mask = 0; case 'W':
if (flagsp != NULL) { p_ws = false; break;
switch (*flags) { default:
case 'c': mask = 0;
mask = SP_START; break; if (flagsp != NULL) {
case 'e': switch (*flags) {
mask = SP_END; break; case 'c':
case 'm': mask = SP_START; break;
mask = SP_RETCOUNT; break; case 'e':
case 'n': mask = SP_END; break;
mask = SP_NOMOVE; break; case 'm':
case 'p': mask = SP_RETCOUNT; break;
mask = SP_SUBPAT; break; case 'n':
case 'r': mask = SP_NOMOVE; break;
mask = SP_REPEAT; break; case 'p':
case 's': mask = SP_SUBPAT; break;
mask = SP_SETPCMARK; break; case 'r':
case 'z': mask = SP_REPEAT; break;
mask = SP_COLUMN; break; case 's':
} mask = SP_SETPCMARK; break;
} case 'z':
if (mask == 0) { mask = SP_COLUMN; break;
semsg(_(e_invarg2), flags);
dir = 0;
} else {
*flagsp |= mask;
} }
} }
if (dir == 0) { if (mask == 0) {
break; semsg(_(e_invarg2), flags);
dir = 0;
} else {
*flagsp |= mask;
} }
flags++;
} }
if (dir == 0) {
break;
}
flags++;
} }
return dir; return dir;
} }

View File

@@ -46,31 +46,33 @@ static int win_getid(typval_T *argvars)
} }
int winnr = (int)tv_get_number(&argvars[0]); int winnr = (int)tv_get_number(&argvars[0]);
win_T *wp; win_T *wp;
if (winnr > 0) { if (winnr <= 0) {
if (argvars[1].v_type == VAR_UNKNOWN) { return 0;
wp = firstwin; }
} else {
tabpage_T *tp = NULL; if (argvars[1].v_type == VAR_UNKNOWN) {
int tabnr = (int)tv_get_number(&argvars[1]); wp = firstwin;
FOR_ALL_TABS(tp2) { } else {
if (--tabnr == 0) { tabpage_T *tp = NULL;
tp = tp2; int tabnr = (int)tv_get_number(&argvars[1]);
break; FOR_ALL_TABS(tp2) {
} if (--tabnr == 0) {
} tp = tp2;
if (tp == NULL) { break;
return -1;
}
if (tp == curtab) {
wp = firstwin;
} else {
wp = tp->tp_firstwin;
} }
} }
for (; wp != NULL; wp = wp->w_next) { if (tp == NULL) {
if (--winnr == 0) { return -1;
return wp->handle; }
} if (tp == curtab) {
wp = firstwin;
} else {
wp = tp->tp_firstwin;
}
}
for (; wp != NULL; wp = wp->w_next) {
if (--winnr == 0) {
return wp->handle;
} }
} }
return 0; return 0;
@@ -288,16 +290,18 @@ static int get_winnr(tabpage_T *tp, typval_T *argvar)
} }
} }
if (nr > 0) { if (nr <= 0) {
for (win_T *wp = (tp == curtab) ? firstwin : tp->tp_firstwin; return 0;
wp != twin; wp = wp->w_next) { }
if (wp == NULL) {
// didn't find it in this tabpage for (win_T *wp = (tp == curtab) ? firstwin : tp->tp_firstwin;
nr = 0; wp != twin; wp = wp->w_next) {
break; if (wp == NULL) {
} // didn't find it in this tabpage
nr++; nr = 0;
break;
} }
nr++;
} }
return nr; return nr;
} }

View File

@@ -4510,32 +4510,30 @@ void free_old_sub(void)
/// @return true when it was created. /// @return true when it was created.
bool prepare_tagpreview(bool undo_sync) bool prepare_tagpreview(bool undo_sync)
{ {
if (curwin->w_p_pvw) {
return false;
}
// If there is already a preview window open, use that one. // If there is already a preview window open, use that one.
if (!curwin->w_p_pvw) { FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
bool found_win = false; if (wp->w_p_pvw) {
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { win_enter(wp, undo_sync);
if (wp->w_p_pvw) { return false;
win_enter(wp, undo_sync);
found_win = true;
break;
}
}
if (!found_win) {
// There is no preview window open yet. Create one.
if (win_split(g_do_tagpreview > 0 ? g_do_tagpreview : 0, 0)
== FAIL) {
return false;
}
curwin->w_p_pvw = true;
curwin->w_p_wfh = true;
RESET_BINDING(curwin); // don't take over 'scrollbind' and 'cursorbind'
curwin->w_p_diff = false; // no 'diff'
set_string_option_direct("fdc", -1, // no 'foldcolumn'
"0", OPT_FREE, SID_NONE);
return true;
} }
} }
return false;
// There is no preview window open yet. Create one.
if (win_split(g_do_tagpreview > 0 ? g_do_tagpreview : 0, 0)
== FAIL) {
return false;
}
curwin->w_p_pvw = true;
curwin->w_p_wfh = true;
RESET_BINDING(curwin); // don't take over 'scrollbind' and 'cursorbind'
curwin->w_p_diff = false; // no 'diff'
set_string_option_direct("fdc", -1, // no 'foldcolumn'
"0", OPT_FREE, SID_NONE);
return true;
} }
/// Shows the effects of the :substitute command being typed ('inccommand'). /// Shows the effects of the :substitute command being typed ('inccommand').

View File

@@ -4083,12 +4083,14 @@ static char *get_cmdline_completion(void)
} }
CmdlineInfo *p = get_ccline_ptr(); CmdlineInfo *p = get_ccline_ptr();
if (p != NULL && p->xpc != NULL) { if (p == NULL || p->xpc == NULL) {
set_expand_context(p->xpc); return NULL;
char *cmd_compl = get_user_cmd_complete(p->xpc, p->xpc->xp_context); }
if (cmd_compl != NULL) {
return xstrdup(cmd_compl); set_expand_context(p->xpc);
} char *cmd_compl = get_user_cmd_complete(p->xpc, p->xpc->xp_context);
if (cmd_compl != NULL) {
return xstrdup(cmd_compl);
} }
return NULL; return NULL;

View File

@@ -481,7 +481,7 @@ void foldCheckClose(void)
return; return;
} }
// can only be "all" right now // 'foldclose' can only be "all" right now
checkupdate(curwin); checkupdate(curwin);
if (checkCloseRec(&curwin->w_folds, curwin->w_cursor.lnum, if (checkCloseRec(&curwin->w_folds, curwin->w_cursor.lnum,
(int)curwin->w_p_fdl)) { (int)curwin->w_p_fdl)) {

View File

@@ -1549,35 +1549,38 @@ static bool highlight_list_arg(const int id, bool didh, const int type, int iarg
if (got_int) { if (got_int) {
return false; return false;
} }
if (type == LIST_STRING ? (sarg != NULL) : (iarg != 0)) {
const char *ts = buf;
if (type == LIST_INT) {
snprintf((char *)buf, sizeof(buf), "%d", iarg - 1);
} else if (type == LIST_STRING) {
ts = sarg;
} else { // type == LIST_ATTR
buf[0] = NUL;
for (int i = 0; hl_attr_table[i] != 0; i++) {
if (iarg & hl_attr_table[i]) {
if (buf[0] != NUL) {
xstrlcat(buf, ",", 100);
}
xstrlcat(buf, hl_name_table[i], 100);
iarg &= ~hl_attr_table[i]; // don't want "inverse"
}
}
}
(void)syn_list_header(didh, vim_strsize((char *)ts) + (int)strlen(name) + 1, id, false); if (type == LIST_STRING ? (sarg == NULL) : (iarg == 0)) {
didh = true; return didh;
if (!got_int) { }
if (*name != NUL) {
msg_puts_attr(name, HL_ATTR(HLF_D)); const char *ts = buf;
msg_puts_attr("=", HL_ATTR(HLF_D)); if (type == LIST_INT) {
snprintf((char *)buf, sizeof(buf), "%d", iarg - 1);
} else if (type == LIST_STRING) {
ts = sarg;
} else { // type == LIST_ATTR
buf[0] = NUL;
for (int i = 0; hl_attr_table[i] != 0; i++) {
if (iarg & hl_attr_table[i]) {
if (buf[0] != NUL) {
xstrlcat(buf, ",", 100);
}
xstrlcat(buf, hl_name_table[i], 100);
iarg &= ~hl_attr_table[i]; // don't want "inverse"
} }
msg_outtrans((char *)ts);
} }
} }
(void)syn_list_header(didh, vim_strsize((char *)ts) + (int)strlen(name) + 1, id, false);
didh = true;
if (!got_int) {
if (*name != NUL) {
msg_puts_attr(name, HL_ATTR(HLF_D));
msg_puts_attr("=", HL_ATTR(HLF_D));
}
msg_outtrans((char *)ts);
}
return didh; return didh;
} }
@@ -2125,36 +2128,44 @@ void set_context_in_highlight_cmd(expand_T *xp, const char *arg)
include_link = 2; include_link = 2;
include_default = 1; include_default = 1;
if (*arg == NUL) {
return;
}
// (part of) subcommand already typed // (part of) subcommand already typed
if (*arg != NUL) { const char *p = (const char *)skiptowhite(arg);
const char *p = (const char *)skiptowhite(arg); if (*p == NUL) {
if (*p != NUL) { // Past "default" or group name. return;
include_default = 0; }
if (strncmp("default", arg, (unsigned)(p - arg)) == 0) {
arg = (const char *)skipwhite(p); // past "default" or group name
xp->xp_pattern = (char *)arg; include_default = 0;
p = (const char *)skiptowhite(arg); if (strncmp("default", arg, (unsigned)(p - arg)) == 0) {
} arg = (const char *)skipwhite(p);
if (*p != NUL) { // past group name xp->xp_pattern = (char *)arg;
include_link = 0; p = (const char *)skiptowhite(arg);
if (arg[1] == 'i' && arg[0] == 'N') { }
highlight_list(); if (*p == NUL) {
} return;
if (strncmp("link", arg, (unsigned)(p - arg)) == 0 }
|| strncmp("clear", arg, (unsigned)(p - arg)) == 0) {
xp->xp_pattern = skipwhite(p); // past group name
p = (const char *)skiptowhite(xp->xp_pattern); include_link = 0;
if (*p != NUL) { // Past first group name. if (arg[1] == 'i' && arg[0] == 'N') {
xp->xp_pattern = skipwhite(p); highlight_list();
p = (const char *)skiptowhite(xp->xp_pattern); }
} if (strncmp("link", arg, (unsigned)(p - arg)) == 0
} || strncmp("clear", arg, (unsigned)(p - arg)) == 0) {
if (*p != NUL) { // Past group name(s). xp->xp_pattern = skipwhite(p);
xp->xp_context = EXPAND_NOTHING; p = (const char *)skiptowhite(xp->xp_pattern);
} if (*p != NUL) { // past first group name
} xp->xp_pattern = skipwhite(p);
p = (const char *)skiptowhite(xp->xp_pattern);
} }
} }
if (*p != NUL) { // past group name(s)
xp->xp_context = EXPAND_NOTHING;
}
} }
/// List highlighting matches in a nice way. /// List highlighting matches in a nice way.

View File

@@ -356,6 +356,7 @@ bool cin_islabel(void) // XXX
if (cin_isscopedecl((char_u *)s)) { if (cin_isscopedecl((char_u *)s)) {
return false; return false;
} }
if (!cin_islabel_skip(&s)) { if (!cin_islabel_skip(&s)) {
return false; return false;
} }