vim-patch:9.0.1115: code is indented more than needed (#21598)

Problem:    Code is indented more than needed.
Solution:   Use an early return to reduce indenting. (Yegappan Lakshmanan,
            closes vim/vim#11758)

ed0c1d5d4b

Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
zeertzjq
2022-12-31 06:41:23 +08:00
committed by GitHub
parent 6a45360de9
commit 99cf111289
4 changed files with 291 additions and 263 deletions

View File

@@ -4743,45 +4743,46 @@ void ex_oldfiles(exarg_T *eap)
if (l == NULL) { if (l == NULL) {
msg(_("No old files")); msg(_("No old files"));
} else { return;
msg_start(); }
msg_scroll = true;
TV_LIST_ITER(l, li, {
if (got_int) {
break;
}
nr++;
const char *fname = tv_get_string(TV_LIST_ITEM_TV(li));
if (!message_filtered((char *)fname)) {
msg_outnum(nr);
msg_puts(": ");
msg_outtrans((char *)tv_get_string(TV_LIST_ITEM_TV(li)));
msg_clr_eos();
msg_putchar('\n');
os_breakcheck();
}
});
// Assume "got_int" was set to truncate the listing. msg_start();
got_int = false; msg_scroll = true;
TV_LIST_ITER(l, li, {
if (got_int) {
break;
}
nr++;
const char *fname = tv_get_string(TV_LIST_ITEM_TV(li));
if (!message_filtered((char *)fname)) {
msg_outnum(nr);
msg_puts(": ");
msg_outtrans((char *)tv_get_string(TV_LIST_ITEM_TV(li)));
msg_clr_eos();
msg_putchar('\n');
os_breakcheck();
}
});
// File selection prompt on ":browse oldfiles" // Assume "got_int" was set to truncate the listing.
if (cmdmod.cmod_flags & CMOD_BROWSE) { got_int = false;
quit_more = false;
nr = prompt_for_number(false); // File selection prompt on ":browse oldfiles"
msg_starthere(); if (cmdmod.cmod_flags & CMOD_BROWSE) {
if (nr > 0 && nr <= tv_list_len(l)) { quit_more = false;
const char *const p = tv_list_find_str(l, (int)nr - 1); nr = prompt_for_number(false);
if (p == NULL) { msg_starthere();
return; if (nr > 0 && nr <= tv_list_len(l)) {
} const char *const p = tv_list_find_str(l, (int)nr - 1);
char *const s = expand_env_save((char *)p); if (p == NULL) {
eap->arg = s; return;
eap->cmdidx = CMD_edit;
cmdmod.cmod_flags &= ~CMOD_BROWSE;
do_exedit(eap, NULL);
xfree(s);
} }
char *const s = expand_env_save((char *)p);
eap->arg = s;
eap->cmdidx = CMD_edit;
cmdmod.cmod_flags &= ~CMOD_BROWSE;
do_exedit(eap, NULL);
xfree(s);
} }
} }
} }

View File

@@ -705,54 +705,56 @@ void ex_compiler(exarg_T *eap)
// List all compiler scripts. // List all compiler scripts.
do_cmdline_cmd("echo globpath(&rtp, 'compiler/*.vim')"); // NOLINT do_cmdline_cmd("echo globpath(&rtp, 'compiler/*.vim')"); // NOLINT
do_cmdline_cmd("echo globpath(&rtp, 'compiler/*.lua')"); // NOLINT do_cmdline_cmd("echo globpath(&rtp, 'compiler/*.lua')"); // NOLINT
return;
}
size_t bufsize = strlen(eap->arg) + 14;
buf = xmalloc(bufsize);
if (eap->forceit) {
// ":compiler! {name}" sets global options
do_cmdline_cmd("command -nargs=* CompilerSet set <args>");
} else { } else {
size_t bufsize = strlen(eap->arg) + 14; // ":compiler! {name}" sets local options.
buf = xmalloc(bufsize); // To remain backwards compatible "current_compiler" is always
if (eap->forceit) { // used. A user's compiler plugin may set it, the distributed
// ":compiler! {name}" sets global options // plugin will then skip the settings. Afterwards set
do_cmdline_cmd("command -nargs=* CompilerSet set <args>"); // "b:current_compiler" and restore "current_compiler".
} else { // Explicitly prepend "g:" to make it work in a function.
// ":compiler! {name}" sets local options. old_cur_comp = (char *)get_var_value("g:current_compiler");
// To remain backwards compatible "current_compiler" is always if (old_cur_comp != NULL) {
// used. A user's compiler plugin may set it, the distributed old_cur_comp = xstrdup(old_cur_comp);
// plugin will then skip the settings. Afterwards set
// "b:current_compiler" and restore "current_compiler".
// Explicitly prepend "g:" to make it work in a function.
old_cur_comp = (char *)get_var_value("g:current_compiler");
if (old_cur_comp != NULL) {
old_cur_comp = xstrdup(old_cur_comp);
}
do_cmdline_cmd("command -nargs=* -keepscript CompilerSet setlocal <args>");
} }
do_unlet(S_LEN("g:current_compiler"), true); do_cmdline_cmd("command -nargs=* -keepscript CompilerSet setlocal <args>");
do_unlet(S_LEN("b:current_compiler"), true); }
do_unlet(S_LEN("g:current_compiler"), true);
do_unlet(S_LEN("b:current_compiler"), true);
snprintf(buf, bufsize, "compiler/%s.vim", eap->arg); snprintf(buf, bufsize, "compiler/%s.vim", eap->arg);
if (source_runtime(buf, DIP_ALL) == FAIL) {
// Try lua compiler
snprintf(buf, bufsize, "compiler/%s.lua", eap->arg);
if (source_runtime(buf, DIP_ALL) == FAIL) { if (source_runtime(buf, DIP_ALL) == FAIL) {
// Try lua compiler semsg(_("E666: compiler not supported: %s"), eap->arg);
snprintf(buf, bufsize, "compiler/%s.lua", eap->arg);
if (source_runtime(buf, DIP_ALL) == FAIL) {
semsg(_("E666: compiler not supported: %s"), eap->arg);
}
} }
xfree(buf); }
xfree(buf);
do_cmdline_cmd(":delcommand CompilerSet"); do_cmdline_cmd(":delcommand CompilerSet");
// Set "b:current_compiler" from "current_compiler". // Set "b:current_compiler" from "current_compiler".
p = (char *)get_var_value("g:current_compiler"); p = (char *)get_var_value("g:current_compiler");
if (p != NULL) { if (p != NULL) {
set_internal_string_var("b:current_compiler", p); set_internal_string_var("b:current_compiler", p);
} }
// Restore "current_compiler" for ":compiler {name}". // Restore "current_compiler" for ":compiler {name}".
if (!eap->forceit) { if (!eap->forceit) {
if (old_cur_comp != NULL) { if (old_cur_comp != NULL) {
set_internal_string_var("g:current_compiler", old_cur_comp); set_internal_string_var("g:current_compiler", old_cur_comp);
xfree(old_cur_comp); xfree(old_cur_comp);
} else { } else {
do_unlet(S_LEN("g:current_compiler"), true); do_unlet(S_LEN("g:current_compiler"), true);
}
} }
} }
} }
@@ -847,45 +849,46 @@ void ex_drop(exarg_T *eap)
// edited in a window yet. It's like ":tab all" but without closing // edited in a window yet. It's like ":tab all" but without closing
// windows or tabs. // windows or tabs.
ex_all(eap); ex_all(eap);
} else { return;
// ":drop file ...": Edit the first argument. Jump to an existing
// window if possible, edit in current window if the current buffer
// can be abandoned, otherwise open a new window.
buf = buflist_findnr(ARGLIST[0].ae_fnum);
FOR_ALL_TAB_WINDOWS(tp, wp) {
if (wp->w_buffer == buf) {
goto_tabpage_win(tp, wp);
curwin->w_arg_idx = 0;
if (!bufIsChanged(curbuf)) {
const int save_ar = curbuf->b_p_ar;
// reload the file if it is newer
curbuf->b_p_ar = 1;
buf_check_timestamp(curbuf);
curbuf->b_p_ar = save_ar;
}
return;
}
}
// Check whether the current buffer is changed. If so, we will need
// to split the current window or data could be lost.
// Skip the check if the 'hidden' option is set, as in this case the
// buffer won't be lost.
if (!buf_hide(curbuf)) {
emsg_off++;
split = check_changed(curbuf, CCGD_AW | CCGD_EXCMD);
emsg_off--;
}
// Fake a ":sfirst" or ":first" command edit the first argument.
if (split) {
eap->cmdidx = CMD_sfirst;
eap->cmd[0] = 's';
} else {
eap->cmdidx = CMD_first;
}
ex_rewind(eap);
} }
// ":drop file ...": Edit the first argument. Jump to an existing
// window if possible, edit in current window if the current buffer
// can be abandoned, otherwise open a new window.
buf = buflist_findnr(ARGLIST[0].ae_fnum);
FOR_ALL_TAB_WINDOWS(tp, wp) {
if (wp->w_buffer == buf) {
goto_tabpage_win(tp, wp);
curwin->w_arg_idx = 0;
if (!bufIsChanged(curbuf)) {
const int save_ar = curbuf->b_p_ar;
// reload the file if it is newer
curbuf->b_p_ar = 1;
buf_check_timestamp(curbuf);
curbuf->b_p_ar = save_ar;
}
return;
}
}
// Check whether the current buffer is changed. If so, we will need
// to split the current window or data could be lost.
// Skip the check if the 'hidden' option is set, as in this case the
// buffer won't be lost.
if (!buf_hide(curbuf)) {
emsg_off++;
split = check_changed(curbuf, CCGD_AW | CCGD_EXCMD);
emsg_off--;
}
// Fake a ":sfirst" or ":first" command edit the first argument.
if (split) {
eap->cmdidx = CMD_sfirst;
eap->cmd[0] = 's';
} else {
eap->cmdidx = CMD_first;
}
ex_rewind(eap);
} }

View File

@@ -4663,23 +4663,29 @@ static void ex_tabclose(exarg_T *eap)
{ {
if (cmdwin_type != 0) { if (cmdwin_type != 0) {
cmdwin_result = K_IGNORE; cmdwin_result = K_IGNORE;
} else if (first_tabpage->tp_next == NULL) { return;
}
if (first_tabpage->tp_next == NULL) {
emsg(_("E784: Cannot close last tab page")); emsg(_("E784: Cannot close last tab page"));
} else { return;
int tab_number = get_tabpage_arg(eap); }
if (eap->errmsg == NULL) {
tabpage_T *tp = find_tabpage(tab_number); int tab_number = get_tabpage_arg(eap);
if (tp == NULL) { if (eap->errmsg != NULL) {
beep_flush(); return;
return; }
}
if (tp != curtab) { tabpage_T *tp = find_tabpage(tab_number);
tabpage_close_other(tp, eap->forceit); if (tp == NULL) {
return; beep_flush();
} else if (!text_locked() && !curbuf_locked()) { return;
tabpage_close(eap->forceit); }
} if (tp != curtab) {
} tabpage_close_other(tp, eap->forceit);
return;
} else if (!text_locked() && !curbuf_locked()) {
tabpage_close(eap->forceit);
} }
} }
@@ -4688,32 +4694,38 @@ static void ex_tabonly(exarg_T *eap)
{ {
if (cmdwin_type != 0) { if (cmdwin_type != 0) {
cmdwin_result = K_IGNORE; cmdwin_result = K_IGNORE;
} else if (first_tabpage->tp_next == NULL) { return;
}
if (first_tabpage->tp_next == NULL) {
msg(_("Already only one tab page")); msg(_("Already only one tab page"));
} else { return;
int tab_number = get_tabpage_arg(eap); }
if (eap->errmsg == NULL) {
goto_tabpage(tab_number); int tab_number = get_tabpage_arg(eap);
// Repeat this up to a 1000 times, because autocommands may if (eap->errmsg != NULL) {
// mess up the lists. return;
for (int done = 0; done < 1000; done++) { }
FOR_ALL_TABS(tp) {
if (tp->tp_topframe != topframe) { goto_tabpage(tab_number);
tabpage_close_other(tp, eap->forceit); // Repeat this up to a 1000 times, because autocommands may
// if we failed to close it quit // mess up the lists.
if (valid_tabpage(tp)) { for (int done = 0; done < 1000; done++) {
done = 1000; FOR_ALL_TABS(tp) {
} if (tp->tp_topframe != topframe) {
// start over, "tp" is now invalid tabpage_close_other(tp, eap->forceit);
break; // if we failed to close it quit
} if (valid_tabpage(tp)) {
} done = 1000;
assert(first_tabpage);
if (first_tabpage->tp_next == NULL) {
break;
} }
// start over, "tp" is now invalid
break;
} }
} }
assert(first_tabpage);
if (first_tabpage->tp_next == NULL) {
break;
}
} }
} }
@@ -4782,25 +4794,27 @@ static void ex_only(exarg_T *eap)
static void ex_hide(exarg_T *eap) static void ex_hide(exarg_T *eap)
{ {
// ":hide" or ":hide | cmd": hide current window // ":hide" or ":hide | cmd": hide current window
if (!eap->skip) { if (eap->skip) {
if (eap->addr_count == 0) { return;
win_close(curwin, false, eap->forceit); // don't free buffer }
} else {
int winnr = 0;
win_T *win = NULL;
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { if (eap->addr_count == 0) {
winnr++; win_close(curwin, false, eap->forceit); // don't free buffer
if (winnr == eap->line2) { } else {
win = wp; int winnr = 0;
break; win_T *win = NULL;
}
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
winnr++;
if (winnr == eap->line2) {
win = wp;
break;
} }
if (win == NULL) {
win = lastwin;
}
win_close(win, false, eap->forceit);
} }
if (win == NULL) {
win = lastwin;
}
win_close(win, false, eap->forceit);
} }
} }
@@ -5384,50 +5398,51 @@ static void ex_read(exarg_T *eap)
if (eap->usefilter) { // :r!cmd if (eap->usefilter) { // :r!cmd
do_bang(1, eap, false, false, true); do_bang(1, eap, false, false, true);
} else { return;
if (u_save(eap->line2, (linenr_T)(eap->line2 + 1)) == FAIL) { }
if (u_save(eap->line2, (linenr_T)(eap->line2 + 1)) == FAIL) {
return;
}
int i;
if (*eap->arg == NUL) {
if (check_fname() == FAIL) { // check for no file name
return; return;
} }
int i; i = readfile(curbuf->b_ffname, curbuf->b_fname,
eap->line2, (linenr_T)0, (linenr_T)MAXLNUM, eap, 0, false);
if (*eap->arg == NUL) { } else {
if (check_fname() == FAIL) { // check for no file name if (vim_strchr(p_cpo, CPO_ALTREAD) != NULL) {
return; (void)setaltfname(eap->arg, eap->arg, (linenr_T)1);
}
i = readfile(curbuf->b_ffname, curbuf->b_fname,
eap->line2, (linenr_T)0, (linenr_T)MAXLNUM, eap, 0, false);
} else {
if (vim_strchr(p_cpo, CPO_ALTREAD) != NULL) {
(void)setaltfname(eap->arg, eap->arg, (linenr_T)1);
}
i = readfile(eap->arg, NULL,
eap->line2, (linenr_T)0, (linenr_T)MAXLNUM, eap, 0, false);
} }
if (i != OK) { i = readfile(eap->arg, NULL,
if (!aborting()) { eap->line2, (linenr_T)0, (linenr_T)MAXLNUM, eap, 0, false);
semsg(_(e_notopen), eap->arg); }
} if (i != OK) {
} else { if (!aborting()) {
if (empty && exmode_active) { semsg(_(e_notopen), eap->arg);
// Delete the empty line that remains. Historically ex does
// this but vi doesn't.
linenr_T lnum;
if (eap->line2 == 0) {
lnum = curbuf->b_ml.ml_line_count;
} else {
lnum = 1;
}
if (*ml_get(lnum) == NUL && u_savedel(lnum, 1L) == OK) {
ml_delete(lnum, false);
if (curwin->w_cursor.lnum > 1
&& curwin->w_cursor.lnum >= lnum) {
curwin->w_cursor.lnum--;
}
deleted_lines_mark(lnum, 1L);
}
}
redraw_curbuf_later(UPD_VALID);
} }
} else {
if (empty && exmode_active) {
// Delete the empty line that remains. Historically ex does
// this but vi doesn't.
linenr_T lnum;
if (eap->line2 == 0) {
lnum = curbuf->b_ml.ml_line_count;
} else {
lnum = 1;
}
if (*ml_get(lnum) == NUL && u_savedel(lnum, 1L) == OK) {
ml_delete(lnum, false);
if (curwin->w_cursor.lnum > 1
&& curwin->w_cursor.lnum >= lnum) {
curwin->w_cursor.lnum--;
}
deleted_lines_mark(lnum, 1L);
}
}
redraw_curbuf_later(UPD_VALID);
} }
} }
@@ -5584,6 +5599,7 @@ void ex_cd(exarg_T *eap)
return; return;
} }
#endif #endif
CdScope scope = kCdScopeGlobal; CdScope scope = kCdScopeGlobal;
switch (eap->cmdidx) { switch (eap->cmdidx) {
case CMD_tcd: case CMD_tcd:
@@ -5879,20 +5895,21 @@ static void ex_at(exarg_T *eap)
// Put the register in the typeahead buffer with the "silent" flag. // Put the register in the typeahead buffer with the "silent" flag.
if (do_execreg(c, true, vim_strchr(p_cpo, CPO_EXECBUF) != NULL, true) == FAIL) { if (do_execreg(c, true, vim_strchr(p_cpo, CPO_EXECBUF) != NULL, true) == FAIL) {
beep_flush(); beep_flush();
} else { return;
bool save_efr = exec_from_reg;
exec_from_reg = true;
// Execute from the typeahead buffer.
// Continue until the stuff buffer is empty and all added characters
// have been consumed.
while (!stuff_empty() || typebuf.tb_len > prev_len) {
(void)do_cmdline(NULL, getexline, NULL, DOCMD_NOWAIT|DOCMD_VERBOSE);
}
exec_from_reg = save_efr;
} }
const bool save_efr = exec_from_reg;
exec_from_reg = true;
// Execute from the typeahead buffer.
// Continue until the stuff buffer is empty and all added characters
// have been consumed.
while (!stuff_empty() || typebuf.tb_len > prev_len) {
(void)do_cmdline(NULL, getexline, NULL, DOCMD_NOWAIT|DOCMD_VERBOSE);
}
exec_from_reg = save_efr;
} }
/// ":!". /// ":!".
@@ -6222,17 +6239,21 @@ static void ex_mark(exarg_T *eap)
{ {
if (*eap->arg == NUL) { // No argument? if (*eap->arg == NUL) { // No argument?
emsg(_(e_argreq)); emsg(_(e_argreq));
} else if (eap->arg[1] != NUL) { // more than one character? return;
semsg(_(e_trailing_arg), eap->arg);
} else {
pos_T pos = curwin->w_cursor; // save curwin->w_cursor
curwin->w_cursor.lnum = eap->line2;
beginline(BL_WHITE | BL_FIX);
if (setmark(*eap->arg) == FAIL) { // set mark
emsg(_("E191: Argument must be a letter or forward/backward quote"));
}
curwin->w_cursor = pos; // restore curwin->w_cursor
} }
if (eap->arg[1] != NUL) { // more than one character?
semsg(_(e_trailing_arg), eap->arg);
return;
}
pos_T pos = curwin->w_cursor; // save curwin->w_cursor
curwin->w_cursor.lnum = eap->line2;
beginline(BL_WHITE | BL_FIX);
if (setmark(*eap->arg) == FAIL) { // set mark
emsg(_("E191: Argument must be a letter or forward/backward quote"));
}
curwin->w_cursor = pos; // restore curwin->w_cursor
} }
/// Update w_topline, w_leftcol and the cursor position. /// Update w_topline, w_leftcol and the cursor position.
@@ -7146,17 +7167,18 @@ void filetype_maybe_enable(void)
/// ":setfiletype [FALLBACK] {name}" /// ":setfiletype [FALLBACK] {name}"
static void ex_setfiletype(exarg_T *eap) static void ex_setfiletype(exarg_T *eap)
{ {
if (!did_filetype) { if (did_filetype) {
char *arg = eap->arg; return;
}
if (strncmp(arg, "FALLBACK ", 9) == 0) { char *arg = eap->arg;
arg += 9; if (strncmp(arg, "FALLBACK ", 9) == 0) {
} arg += 9;
}
set_option_value_give_err("filetype", 0L, arg, OPT_LOCAL); set_option_value_give_err("filetype", 0L, arg, OPT_LOCAL);
if (arg != eap->arg) { if (arg != eap->arg) {
did_filetype = false; did_filetype = false;
}
} }
} }

View File

@@ -575,32 +575,34 @@ static int may_add_char_to_search(int firstc, int *c, incsearch_state_T *s)
static void finish_incsearch_highlighting(int gotesc, incsearch_state_T *s, bool call_update_screen) static void finish_incsearch_highlighting(int gotesc, incsearch_state_T *s, bool call_update_screen)
{ {
if (s->did_incsearch) { if (!s->did_incsearch) {
s->did_incsearch = false; return;
if (gotesc) { }
s->did_incsearch = false;
if (gotesc) {
curwin->w_cursor = s->save_cursor;
} else {
if (!equalpos(s->save_cursor, s->search_start)) {
// put the '" mark at the original position
curwin->w_cursor = s->save_cursor; curwin->w_cursor = s->save_cursor;
} else { setpcmark();
if (!equalpos(s->save_cursor, s->search_start)) {
// put the '" mark at the original position
curwin->w_cursor = s->save_cursor;
setpcmark();
}
curwin->w_cursor = s->search_start; // -V519
} }
restore_viewstate(curwin, &s->old_viewstate); curwin->w_cursor = s->search_start; // -V519
highlight_match = false; }
restore_viewstate(curwin, &s->old_viewstate);
highlight_match = false;
// by default search all lines // by default search all lines
search_first_line = 0; search_first_line = 0;
search_last_line = MAXLNUM; search_last_line = MAXLNUM;
magic_overruled = s->magic_overruled_save; magic_overruled = s->magic_overruled_save;
validate_cursor(); // needed for TAB validate_cursor(); // needed for TAB
redraw_all_later(UPD_SOME_VALID); redraw_all_later(UPD_SOME_VALID);
if (call_update_screen) { if (call_update_screen) {
update_screen(); update_screen();
}
} }
} }