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 *arg = *argp;
int group = AUGROUP_ALL;
for (p = arg; *p && !ascii_iswhite(*p) && *p != '|'; p++) {}
if (p > arg) {
if (p <= arg) {
return AUGROUP_ALL;
}
char *group_name = xstrnsave(arg, (size_t)(p - arg));
group = augroup_find(group_name);
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;
}

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);
// if (retval != OK) {
if (retval == FAIL) {
return FAIL;
return retval;
}
// The autocommands may have changed the current buffer. Apply the
@@ -2473,7 +2474,11 @@ static char *fname_match(regmatch_T *rmp, char *name, bool ignore_case)
char *match = NULL;
char *p;
if (name != NULL) {
// extra check for valid arguments
if (name == NULL || rmp->regprog == NULL) {
return NULL;
}
// Ignore case when 'fileignorecase' or the argument is set.
rmp->rm_ic = p_fic || ignore_case;
if (vim_regexec(rmp, name, (colnr_T)0)) {
@@ -2486,7 +2491,6 @@ static char *fname_match(regmatch_T *rmp, char *name, bool ignore_case)
}
xfree(p);
}
}
return match;
}
@@ -2592,7 +2596,10 @@ 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)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
if (wip->wi_opt.wo_diff) {
if (!wip->wi_opt.wo_diff) {
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
@@ -2601,8 +2608,6 @@ static bool wininfo_other_tab_diff(wininfo_T *wip)
}
}
return true;
}
return false;
}
/// Find info for the current window in buffer "buf".
@@ -2625,12 +2630,15 @@ 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
// 'diff' set and is in another tab page).
// 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
// itself.
if (wip == NULL) {
if (skip_diff_buffer) {
for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next) {
if (!wininfo_other_tab_diff(wip)
@@ -2644,7 +2652,6 @@ static wininfo_T *find_wininfo(buf_T *buf, bool need_options, bool skip_diff_buf
} else {
wip = buf->b_wininfo;
}
}
return wip;
}

View File

@@ -1585,7 +1585,11 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, cons
case CMD_dsplit:
// Skip count.
arg = (const char *)skipwhite(skipdigits(arg));
if (*arg == '/') { // Match regexp, not just whole words.
if (*arg != '/') {
return NULL;
}
// Match regexp, not just whole words.
for (++arg; *arg && *arg != '/'; arg++) {
if (*arg == '\\' && arg[1] != NUL) {
arg++;
@@ -1601,7 +1605,6 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, cons
return arg;
}
}
}
break;
case CMD_autocmd:
return (const char *)set_context_in_autocmd(xp, (char *)arg, false);

View File

@@ -317,14 +317,16 @@ static int get_maxbacktrace_level(char *sname)
{
int maxbacktrace = 0;
if (sname != NULL) {
if (sname == NULL) {
return 0;
}
char *p = sname;
char *q;
while ((q = strstr(p, "..")) != NULL) {
p = q + 2;
maxbacktrace++;
}
}
return maxbacktrace;
}
@@ -458,7 +460,10 @@ void dbg_check_breakpoint(exarg_T *eap)
/// @return true when the debug mode is entered this time.
bool dbg_check_skipped(exarg_T *eap)
{
if (debug_skipped) {
if (!debug_skipped) {
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;
@@ -470,8 +475,6 @@ bool dbg_check_skipped(exarg_T *eap)
eap->skip = true;
got_int |= prev_got_int;
return true;
}
return false;
}
static garray_T dbg_breakp = { 0, 0, sizeof(struct debuggy), 4, NULL };

View File

@@ -1528,8 +1528,10 @@ int get_digraph(bool cmdline)
no_mapping--;
allow_keys--;
if (c != ESC) {
// ESC cancels CTRL-K
if (c == ESC) { // ESC cancels CTRL-K
return NUL;
}
if (IS_SPECIAL(c)) {
// insert special key code
return c;
@@ -1552,7 +1554,6 @@ int get_digraph(bool cmdline)
// ESC cancels CTRL-K
return digraph_get(c, cc, true);
}
}
return NUL;
}

View File

@@ -859,15 +859,15 @@ static void f_cindent(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
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 = find_win_by_nr_or_id(&argvars[idx]);
win_T *win = find_win_by_nr_or_id(&argvars[idx]);
if (win == NULL) {
emsg(_(e_invalwindow));
return NULL;
}
}
return win;
}
@@ -6109,7 +6109,10 @@ static int get_search_arg(typval_T *varp, int *flagsp)
{
int dir = FORWARD;
if (varp->v_type != VAR_UNKNOWN) {
if (varp->v_type == VAR_UNKNOWN) {
return FORWARD;
}
char nbuf[NUMBUFLEN];
const char *flags = tv_get_string_buf_chk(varp, nbuf);
if (flags == NULL) {
@@ -6158,7 +6161,6 @@ static int get_search_arg(typval_T *varp, int *flagsp)
}
flags++;
}
}
return dir;
}

View File

@@ -46,7 +46,10 @@ static int win_getid(typval_T *argvars)
}
int winnr = (int)tv_get_number(&argvars[0]);
win_T *wp;
if (winnr > 0) {
if (winnr <= 0) {
return 0;
}
if (argvars[1].v_type == VAR_UNKNOWN) {
wp = firstwin;
} else {
@@ -72,7 +75,6 @@ static int win_getid(typval_T *argvars)
return wp->handle;
}
}
}
return 0;
}
@@ -288,7 +290,10 @@ static int get_winnr(tabpage_T *tp, typval_T *argvar)
}
}
if (nr > 0) {
if (nr <= 0) {
return 0;
}
for (win_T *wp = (tp == curtab) ? firstwin : tp->tp_firstwin;
wp != twin; wp = wp->w_next) {
if (wp == NULL) {
@@ -298,7 +303,6 @@ static int get_winnr(tabpage_T *tp, typval_T *argvar)
}
nr++;
}
}
return nr;
}

View File

@@ -4510,17 +4510,18 @@ void free_old_sub(void)
/// @return true when it was created.
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 (!curwin->w_p_pvw) {
bool found_win = false;
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (wp->w_p_pvw) {
win_enter(wp, undo_sync);
found_win = true;
break;
return false;
}
}
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) {
@@ -4533,9 +4534,6 @@ bool prepare_tagpreview(bool undo_sync)
set_string_option_direct("fdc", -1, // no 'foldcolumn'
"0", OPT_FREE, SID_NONE);
return true;
}
}
return false;
}
/// Shows the effects of the :substitute command being typed ('inccommand').

View File

@@ -4083,13 +4083,15 @@ static char *get_cmdline_completion(void)
}
CmdlineInfo *p = get_ccline_ptr();
if (p != NULL && p->xpc != NULL) {
if (p == NULL || p->xpc == NULL) {
return NULL;
}
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;
}

View File

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

View File

@@ -1549,7 +1549,11 @@ static bool highlight_list_arg(const int id, bool didh, const int type, int iarg
if (got_int) {
return false;
}
if (type == LIST_STRING ? (sarg != NULL) : (iarg != 0)) {
if (type == LIST_STRING ? (sarg == NULL) : (iarg == 0)) {
return didh;
}
const char *ts = buf;
if (type == LIST_INT) {
snprintf((char *)buf, sizeof(buf), "%d", iarg - 1);
@@ -1577,7 +1581,6 @@ static bool highlight_list_arg(const int id, bool didh, const int type, int iarg
}
msg_outtrans((char *)ts);
}
}
return didh;
}
@@ -2125,17 +2128,28 @@ void set_context_in_highlight_cmd(expand_T *xp, const char *arg)
include_link = 2;
include_default = 1;
if (*arg == NUL) {
return;
}
// (part of) subcommand already typed
if (*arg != NUL) {
const char *p = (const char *)skiptowhite(arg);
if (*p != NUL) { // Past "default" or group name.
if (*p == NUL) {
return;
}
// past "default" or group name
include_default = 0;
if (strncmp("default", arg, (unsigned)(p - arg)) == 0) {
arg = (const char *)skipwhite(p);
xp->xp_pattern = (char *)arg;
p = (const char *)skiptowhite(arg);
}
if (*p != NUL) { // past group name
if (*p == NUL) {
return;
}
// past group name
include_link = 0;
if (arg[1] == 'i' && arg[0] == 'N') {
highlight_list();
@@ -2144,17 +2158,14 @@ void set_context_in_highlight_cmd(expand_T *xp, const char *arg)
|| strncmp("clear", arg, (unsigned)(p - arg)) == 0) {
xp->xp_pattern = skipwhite(p);
p = (const char *)skiptowhite(xp->xp_pattern);
if (*p != NUL) { // Past first group name.
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).
if (*p != NUL) { // past group name(s)
xp->xp_context = EXPAND_NOTHING;
}
}
}
}
}
/// List highlighting matches in a nice way.

View File

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