0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

patch 9.0.1098: code uses too much indent

Problem:    Code uses too much indent.
Solution:   Use an early return. (Yegappan Lakshmanan, closes #11747)
This commit is contained in:
Yegappan Lakshmanan
2022-12-26 12:50:04 +00:00
committed by Bram Moolenaar
parent b3d614369f
commit 465de3a57b
6 changed files with 226 additions and 222 deletions

View File

@@ -460,44 +460,46 @@ del_history_entry(int histype, char_u *str)
int last;
int found = FALSE;
regmatch.regprog = NULL;
if (hislen == 0 || histype < 0 || histype >= HIST_COUNT || *str == NUL
|| hisidx[histype] < 0)
return FALSE;
idx = hisidx[histype];
regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING);
if (regmatch.regprog == NULL)
return FALSE;
regmatch.rm_ic = FALSE; // always match case
if (hislen != 0
&& histype >= 0
&& histype < HIST_COUNT
&& *str != NUL
&& (idx = hisidx[histype]) >= 0
&& (regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING))
!= NULL)
i = last = idx;
do
{
i = last = idx;
do
hisptr = &history[histype][i];
if (hisptr->hisstr == NULL)
break;
if (vim_regexec(&regmatch, hisptr->hisstr, (colnr_T)0))
{
hisptr = &history[histype][i];
if (hisptr->hisstr == NULL)
break;
if (vim_regexec(&regmatch, hisptr->hisstr, (colnr_T)0))
found = TRUE;
vim_free(hisptr->hisstr);
clear_hist_entry(hisptr);
}
else
{
if (i != last)
{
found = TRUE;
vim_free(hisptr->hisstr);
history[histype][last] = *hisptr;
clear_hist_entry(hisptr);
}
else
{
if (i != last)
{
history[histype][last] = *hisptr;
clear_hist_entry(hisptr);
}
if (--last < 0)
last += hislen;
}
if (--i < 0)
i += hislen;
} while (i != idx);
if (history[histype][idx].hisstr == NULL)
hisidx[histype] = -1;
}
if (--last < 0)
last += hislen;
}
if (--i < 0)
i += hislen;
} while (i != idx);
if (history[histype][idx].hisstr == NULL)
hisidx[histype] = -1;
vim_regfree(regmatch.regprog);
return found;
}

View File

@@ -682,44 +682,44 @@ ex_breakadd(exarg_T *eap)
gap = &prof_ga;
#endif
if (dbg_parsearg(eap->arg, gap) == OK)
{
bp = &DEBUGGY(gap, gap->ga_len);
bp->dbg_forceit = eap->forceit;
if (dbg_parsearg(eap->arg, gap) != OK)
return;
if (bp->dbg_type != DBG_EXPR)
bp = &DEBUGGY(gap, gap->ga_len);
bp->dbg_forceit = eap->forceit;
if (bp->dbg_type != DBG_EXPR)
{
pat = file_pat_to_reg_pat(bp->dbg_name, NULL, NULL, FALSE);
if (pat != NULL)
{
pat = file_pat_to_reg_pat(bp->dbg_name, NULL, NULL, FALSE);
if (pat != NULL)
{
bp->dbg_prog = vim_regcomp(pat, RE_MAGIC + RE_STRING);
vim_free(pat);
}
if (pat == NULL || bp->dbg_prog == NULL)
vim_free(bp->dbg_name);
else
{
if (bp->dbg_lnum == 0) // default line number is 1
bp->dbg_lnum = 1;
#ifdef FEAT_PROFILE
if (eap->cmdidx != CMD_profile)
#endif
{
DEBUGGY(gap, gap->ga_len).dbg_nr = ++last_breakp;
++debug_tick;
}
++gap->ga_len;
}
bp->dbg_prog = vim_regcomp(pat, RE_MAGIC + RE_STRING);
vim_free(pat);
}
if (pat == NULL || bp->dbg_prog == NULL)
vim_free(bp->dbg_name);
else
{
// DBG_EXPR
DEBUGGY(gap, gap->ga_len++).dbg_nr = ++last_breakp;
++debug_tick;
if (gap == &dbg_breakp)
has_expr_breakpoint = TRUE;
if (bp->dbg_lnum == 0) // default line number is 1
bp->dbg_lnum = 1;
#ifdef FEAT_PROFILE
if (eap->cmdidx != CMD_profile)
#endif
{
DEBUGGY(gap, gap->ga_len).dbg_nr = ++last_breakp;
++debug_tick;
}
++gap->ga_len;
}
}
else
{
// DBG_EXPR
DEBUGGY(gap, gap->ga_len++).dbg_nr = ++last_breakp;
++debug_tick;
if (gap == &dbg_breakp)
has_expr_breakpoint = TRUE;
}
}
/*
@@ -822,36 +822,37 @@ ex_breakdel(exarg_T *eap)
}
if (todel < 0)
semsg(_(e_breakpoint_not_found_str), eap->arg);
else
{
while (gap->ga_len > 0)
{
vim_free(DEBUGGY(gap, todel).dbg_name);
#ifdef FEAT_EVAL
if (DEBUGGY(gap, todel).dbg_type == DBG_EXPR
&& DEBUGGY(gap, todel).dbg_val != NULL)
free_tv(DEBUGGY(gap, todel).dbg_val);
#endif
vim_regfree(DEBUGGY(gap, todel).dbg_prog);
--gap->ga_len;
if (todel < gap->ga_len)
mch_memmove(&DEBUGGY(gap, todel), &DEBUGGY(gap, todel + 1),
(gap->ga_len - todel) * sizeof(struct debuggy));
#ifdef FEAT_PROFILE
if (eap->cmdidx == CMD_breakdel)
#endif
++debug_tick;
if (!del_all)
break;
}
// If all breakpoints were removed clear the array.
if (gap->ga_len == 0)
ga_clear(gap);
if (gap == &dbg_breakp)
update_has_expr_breakpoint();
semsg(_(e_breakpoint_not_found_str), eap->arg);
return;
}
while (gap->ga_len > 0)
{
vim_free(DEBUGGY(gap, todel).dbg_name);
#ifdef FEAT_EVAL
if (DEBUGGY(gap, todel).dbg_type == DBG_EXPR
&& DEBUGGY(gap, todel).dbg_val != NULL)
free_tv(DEBUGGY(gap, todel).dbg_val);
#endif
vim_regfree(DEBUGGY(gap, todel).dbg_prog);
--gap->ga_len;
if (todel < gap->ga_len)
mch_memmove(&DEBUGGY(gap, todel), &DEBUGGY(gap, todel + 1),
(gap->ga_len - todel) * sizeof(struct debuggy));
#ifdef FEAT_PROFILE
if (eap->cmdidx == CMD_breakdel)
#endif
++debug_tick;
if (!del_all)
break;
}
// If all breakpoints were removed clear the array.
if (gap->ga_len == 0)
ga_clear(gap);
if (gap == &dbg_breakp)
update_has_expr_breakpoint();
}
/*
@@ -864,23 +865,26 @@ ex_breaklist(exarg_T *eap UNUSED)
int i;
if (dbg_breakp.ga_len == 0)
{
msg(_("No breakpoints defined"));
else
for (i = 0; i < dbg_breakp.ga_len; ++i)
{
bp = &BREAKP(i);
if (bp->dbg_type == DBG_FILE)
home_replace(NULL, bp->dbg_name, NameBuff, MAXPATHL, TRUE);
if (bp->dbg_type != DBG_EXPR)
smsg(_("%3d %s %s line %ld"),
return;
}
for (i = 0; i < dbg_breakp.ga_len; ++i)
{
bp = &BREAKP(i);
if (bp->dbg_type == DBG_FILE)
home_replace(NULL, bp->dbg_name, NameBuff, MAXPATHL, TRUE);
if (bp->dbg_type != DBG_EXPR)
smsg(_("%3d %s %s line %ld"),
bp->dbg_nr,
bp->dbg_type == DBG_FUNC ? "func" : "file",
bp->dbg_type == DBG_FUNC ? bp->dbg_name : NameBuff,
(long)bp->dbg_lnum);
else
smsg(_("%3d expr %s"),
else
smsg(_("%3d expr %s"),
bp->dbg_nr, bp->dbg_name);
}
}
}
/*

View File

@@ -1180,44 +1180,40 @@ diff_file(diffio_T *dio)
#endif
// Use xdiff for generating the diff.
if (dio->dio_internal)
{
return diff_file_internal(dio);
}
else
{
len = STRLEN(tmp_orig) + STRLEN(tmp_new)
+ STRLEN(tmp_diff) + STRLEN(p_srr) + 27;
cmd = alloc(len);
if (cmd == NULL)
return FAIL;
// We don't want $DIFF_OPTIONS to get in the way.
if (getenv("DIFF_OPTIONS"))
vim_setenv((char_u *)"DIFF_OPTIONS", (char_u *)"");
len = STRLEN(tmp_orig) + STRLEN(tmp_new)
+ STRLEN(tmp_diff) + STRLEN(p_srr) + 27;
cmd = alloc(len);
if (cmd == NULL)
return FAIL;
// Build the diff command and execute it. Always use -a, binary
// differences are of no use. Ignore errors, diff returns
// non-zero when differences have been found.
vim_snprintf((char *)cmd, len, "diff %s%s%s%s%s%s%s%s %s",
diff_a_works == FALSE ? "" : "-a ",
// We don't want $DIFF_OPTIONS to get in the way.
if (getenv("DIFF_OPTIONS"))
vim_setenv((char_u *)"DIFF_OPTIONS", (char_u *)"");
// Build the diff command and execute it. Always use -a, binary
// differences are of no use. Ignore errors, diff returns
// non-zero when differences have been found.
vim_snprintf((char *)cmd, len, "diff %s%s%s%s%s%s%s%s %s",
diff_a_works == FALSE ? "" : "-a ",
#if defined(MSWIN)
diff_bin_works == TRUE ? "--binary " : "",
diff_bin_works == TRUE ? "--binary " : "",
#else
"",
"",
#endif
(diff_flags & DIFF_IWHITE) ? "-b " : "",
(diff_flags & DIFF_IWHITEALL) ? "-w " : "",
(diff_flags & DIFF_IWHITEEOL) ? "-Z " : "",
(diff_flags & DIFF_IBLANK) ? "-B " : "",
(diff_flags & DIFF_ICASE) ? "-i " : "",
tmp_orig, tmp_new);
append_redir(cmd, (int)len, p_srr, tmp_diff);
block_autocmds(); // avoid ShellCmdPost stuff
(void)call_shell(cmd, SHELL_FILTER|SHELL_SILENT|SHELL_DOOUT);
unblock_autocmds();
vim_free(cmd);
return OK;
}
(diff_flags & DIFF_IWHITE) ? "-b " : "",
(diff_flags & DIFF_IWHITEALL) ? "-w " : "",
(diff_flags & DIFF_IWHITEEOL) ? "-Z " : "",
(diff_flags & DIFF_IBLANK) ? "-B " : "",
(diff_flags & DIFF_ICASE) ? "-i " : "",
tmp_orig, tmp_new);
append_redir(cmd, (int)len, p_srr, tmp_diff);
block_autocmds(); // avoid ShellCmdPost stuff
(void)call_shell(cmd, SHELL_FILTER|SHELL_SILENT|SHELL_DOOUT);
unblock_autocmds();
vim_free(cmd);
return OK;
}
/*
@@ -1432,31 +1428,31 @@ ex_diffsplit(exarg_T *eap)
// don't use a new tab page, each tab page has its own diffs
cmdmod.cmod_tab = 0;
if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL)
if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) == FAIL)
return;
// Pretend it was a ":split fname" command
eap->cmdidx = CMD_split;
curwin->w_p_diff = TRUE;
do_exedit(eap, old_curwin);
if (curwin == old_curwin) // split didn't work
return;
// Set 'diff', 'scrollbind' on and 'wrap' off.
diff_win_options(curwin, TRUE);
if (win_valid(old_curwin))
{
// Pretend it was a ":split fname" command
eap->cmdidx = CMD_split;
curwin->w_p_diff = TRUE;
do_exedit(eap, old_curwin);
diff_win_options(old_curwin, TRUE);
if (curwin != old_curwin) // split must have worked
{
// Set 'diff', 'scrollbind' on and 'wrap' off.
diff_win_options(curwin, TRUE);
if (win_valid(old_curwin))
{
diff_win_options(old_curwin, TRUE);
if (bufref_valid(&old_curbuf))
// Move the cursor position to that of the old window.
curwin->w_cursor.lnum = diff_get_corresponding_line(
old_curbuf.br_buf, old_curwin->w_cursor.lnum);
}
// Now that lines are folded scroll to show the cursor at the same
// relative position.
scroll_to_fraction(curwin, curwin->w_height);
}
if (bufref_valid(&old_curbuf))
// Move the cursor position to that of the old window.
curwin->w_cursor.lnum = diff_get_corresponding_line(
old_curbuf.br_buf, old_curwin->w_cursor.lnum);
}
// Now that lines are folded scroll to show the cursor at the same
// relative position.
scroll_to_fraction(curwin, curwin->w_height);
}
/*

View File

@@ -1681,14 +1681,14 @@ registerdigraph(int char1, int char2, int n)
}
// Add a new digraph to the table.
if (ga_grow(&user_digraphs, 1) == OK)
{
dp = (digr_T *)user_digraphs.ga_data + user_digraphs.ga_len;
dp->char1 = char1;
dp->char2 = char2;
dp->result = n;
++user_digraphs.ga_len;
}
if (ga_grow(&user_digraphs, 1) != OK)
return;
dp = (digr_T *)user_digraphs.ga_data + user_digraphs.ga_len;
dp->char1 = char1;
dp->char2 = char2;
dp->result = n;
++user_digraphs.ga_len;
}
/*
@@ -1948,54 +1948,54 @@ printdigraph(digr_T *dp, result_T *previous)
else
list_width = 11;
if (dp->result != 0)
{
if (dp->result == 0)
return;
#if defined(USE_UNICODE_DIGRAPHS)
if (previous != NULL)
{
int i;
if (previous != NULL)
{
int i;
for (i = 0; header_table[i].dg_header != NULL; ++i)
if (*previous < header_table[i].dg_start
&& dp->result >= header_table[i].dg_start
&& dp->result < header_table[i + 1].dg_start)
{
digraph_header(_(header_table[i].dg_header));
break;
}
*previous = dp->result;
}
#endif
if (msg_col > Columns - list_width)
msg_putchar('\n');
if (msg_col)
while (msg_col % list_width != 0)
msg_putchar(' ');
p = buf;
*p++ = dp->char1;
*p++ = dp->char2;
*p++ = ' ';
*p = NUL;
msg_outtrans(buf);
p = buf;
if (has_mbyte)
{
// add a space to draw a composing char on
if (enc_utf8 && utf_iscomposing(dp->result))
*p++ = ' ';
p += (*mb_char2bytes)(dp->result, p);
}
else
*p++ = (char_u)dp->result;
*p = NUL;
msg_outtrans_attr(buf, HL_ATTR(HLF_8));
p = buf;
if (char2cells(dp->result) == 1)
*p++ = ' ';
vim_snprintf((char *)p, sizeof(buf) - (p - buf), " %3d", dp->result);
msg_outtrans(buf);
for (i = 0; header_table[i].dg_header != NULL; ++i)
if (*previous < header_table[i].dg_start
&& dp->result >= header_table[i].dg_start
&& dp->result < header_table[i + 1].dg_start)
{
digraph_header(_(header_table[i].dg_header));
break;
}
*previous = dp->result;
}
#endif
if (msg_col > Columns - list_width)
msg_putchar('\n');
if (msg_col)
while (msg_col % list_width != 0)
msg_putchar(' ');
p = buf;
*p++ = dp->char1;
*p++ = dp->char2;
*p++ = ' ';
*p = NUL;
msg_outtrans(buf);
p = buf;
if (has_mbyte)
{
// add a space to draw a composing char on
if (enc_utf8 && utf_iscomposing(dp->result))
*p++ = ' ';
p += (*mb_char2bytes)(dp->result, p);
}
else
*p++ = (char_u)dp->result;
*p = NUL;
msg_outtrans_attr(buf, HL_ATTR(HLF_8));
p = buf;
if (char2cells(dp->result) == 1)
*p++ = ' ';
vim_snprintf((char *)p, sizeof(buf) - (p - buf), " %3d", dp->result);
msg_outtrans(buf);
}
# ifdef FEAT_EVAL

View File

@@ -225,19 +225,19 @@ handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
// Allocate a buffer, "wlv->extra[]" may already be in use.
vim_free(wlv->p_extra_free);
wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
if (wlv->p_extra_free != NULL)
{
wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
wp, FALSE, wlv->lnum);
wlv->p_extra_free[wlv->n_extra] = NUL;
wlv->p_extra = wlv->p_extra_free;
wlv->c_extra = NUL;
wlv->c_final = NUL;
if (use_cursor_line_highlight(wp, wlv->lnum))
wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
else
wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
}
if (wlv->p_extra_free == NULL)
return;
wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
wp, FALSE, wlv->lnum);
wlv->p_extra_free[wlv->n_extra] = NUL;
wlv->p_extra = wlv->p_extra_free;
wlv->c_extra = NUL;
wlv->c_final = NUL;
if (use_cursor_line_highlight(wp, wlv->lnum))
wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
else
wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
}
#endif

View File

@@ -695,6 +695,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1098,
/**/
1097,
/**/