vim-patch:9.0.1132: code is indented more than needed (#21626)

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

dc4daa3a39

Omit expand_autoload_callback(): only applies to Vim9 script.

Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
zeertzjq
2023-01-03 14:55:00 +08:00
committed by GitHub
parent 3a519d86bf
commit 4dd793a256
9 changed files with 323 additions and 274 deletions

View File

@@ -631,7 +631,10 @@ void do_argfile(exarg_T *eap, int argn)
} else { } else {
emsg(_("E165: Cannot go beyond last file")); emsg(_("E165: Cannot go beyond last file"));
} }
} else {
return;
}
setpcmark(); setpcmark();
// split window or create new tab page first // split window or create new tab page first
@@ -676,7 +679,6 @@ void do_argfile(exarg_T *eap, int argn)
setmark('\''); setmark('\'');
} }
} }
}
/// ":next", and commands that behave like it. /// ":next", and commands that behave like it.
void ex_next(exarg_T *eap) void ex_next(exarg_T *eap)

View File

@@ -178,7 +178,10 @@ static int read_buffer(int read_stdin, exarg_T *eap, int flags)
/// Ensure buffer "buf" is loaded. Does not trigger the swap-exists action. /// Ensure buffer "buf" is loaded. Does not trigger the swap-exists action.
void buffer_ensure_loaded(buf_T *buf) void buffer_ensure_loaded(buf_T *buf)
{ {
if (buf->b_ml.ml_mfp == NULL) { if (buf->b_ml.ml_mfp != NULL) {
return;
}
aco_save_T aco; aco_save_T aco;
// Make sure the buffer is in a window. // Make sure the buffer is in a window.
@@ -187,7 +190,6 @@ void buffer_ensure_loaded(buf_T *buf)
open_buffer(false, NULL, 0); open_buffer(false, NULL, 0);
aucmd_restbuf(&aco); aucmd_restbuf(&aco);
} }
}
/// Open current buffer, that is: open the memfile and read the file into /// Open current buffer, that is: open the memfile and read the file into
/// memory. /// memory.
@@ -2903,7 +2905,10 @@ int setfname(buf_T *buf, char *ffname_arg, char *sfname_arg, bool message)
void buf_set_name(int fnum, char *name) void buf_set_name(int fnum, char *name)
{ {
buf_T *buf = buflist_findnr(fnum); buf_T *buf = buflist_findnr(fnum);
if (buf != NULL) { if (buf == NULL) {
return;
}
if (buf->b_sfname != buf->b_ffname) { if (buf->b_sfname != buf->b_ffname) {
xfree(buf->b_sfname); xfree(buf->b_sfname);
} }
@@ -2915,7 +2920,6 @@ void buf_set_name(int fnum, char *name)
fname_expand(buf, &buf->b_ffname, &buf->b_sfname); fname_expand(buf, &buf->b_ffname, &buf->b_sfname);
buf->b_fname = buf->b_sfname; buf->b_fname = buf->b_sfname;
} }
}
/// Take care of what needs to be done when the name of buffer "buf" has changed. /// Take care of what needs to be done when the name of buffer "buf" has changed.
void buf_name_changed(buf_T *buf) void buf_name_changed(buf_T *buf)
@@ -4138,7 +4142,10 @@ char *buf_get_fname(const buf_T *buf)
/// Set 'buflisted' for curbuf to "on" and trigger autocommands if it changed. /// Set 'buflisted' for curbuf to "on" and trigger autocommands if it changed.
void set_buflisted(int on) void set_buflisted(int on)
{ {
if (on != curbuf->b_p_bl) { if (on == curbuf->b_p_bl) {
return;
}
curbuf->b_p_bl = on; curbuf->b_p_bl = on;
if (on) { if (on) {
apply_autocmds(EVENT_BUFADD, NULL, NULL, false, curbuf); apply_autocmds(EVENT_BUFADD, NULL, NULL, false, curbuf);
@@ -4146,7 +4153,6 @@ void set_buflisted(int on)
apply_autocmds(EVENT_BUFDELETE, NULL, NULL, false, curbuf); apply_autocmds(EVENT_BUFDELETE, NULL, NULL, false, curbuf);
} }
} }
}
/// Read the file for "buf" again and check if the contents changed. /// Read the file for "buf" again and check if the contents changed.
/// Return true if it changed or this could not be checked. /// Return true if it changed or this could not be checked.

View File

@@ -1018,7 +1018,10 @@ void prepare_vimvar(int idx, typval_T *save_tv)
void restore_vimvar(int idx, typval_T *save_tv) void restore_vimvar(int idx, typval_T *save_tv)
{ {
vimvars[idx].vv_tv = *save_tv; vimvars[idx].vv_tv = *save_tv;
if (vimvars[idx].vv_type == VAR_UNKNOWN) { if (vimvars[idx].vv_type != VAR_UNKNOWN) {
return;
}
hashitem_T *hi = hash_find(&vimvarht, (char *)vimvars[idx].vv_di.di_key); hashitem_T *hi = hash_find(&vimvarht, (char *)vimvars[idx].vv_di.di_key);
if (HASHITEM_EMPTY(hi)) { if (HASHITEM_EMPTY(hi)) {
internal_error("restore_vimvar()"); internal_error("restore_vimvar()");
@@ -1026,7 +1029,6 @@ void restore_vimvar(int idx, typval_T *save_tv)
hash_remove(&vimvarht, hi); hash_remove(&vimvarht, hi);
} }
} }
}
/// Evaluate an expression to a list with suggestions. /// Evaluate an expression to a list with suggestions.
/// For the "expr:" part of 'spellsuggest'. /// For the "expr:" part of 'spellsuggest'.
@@ -6685,13 +6687,14 @@ void set_vim_var_dict(const VimVarIndex idx, dict_T *const val)
tv_clear(&vimvars[idx].vv_di.di_tv); tv_clear(&vimvars[idx].vv_di.di_tv);
vimvars[idx].vv_type = VAR_DICT; vimvars[idx].vv_type = VAR_DICT;
vimvars[idx].vv_dict = val; vimvars[idx].vv_dict = val;
if (val == NULL) {
return;
}
if (val != NULL) {
val->dv_refcount++; val->dv_refcount++;
// Set readonly // Set readonly
tv_dict_set_keys_readonly(val); tv_dict_set_keys_readonly(val);
} }
}
/// Set the v:argv list. /// Set the v:argv list.
void set_argv_var(char **argv, int argc) void set_argv_var(char **argv, int argc)

View File

@@ -1216,20 +1216,22 @@ static void f_debugbreak(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
int pid = (int)tv_get_number(&argvars[0]); int pid = (int)tv_get_number(&argvars[0]);
if (pid == 0) { if (pid == 0) {
emsg(_(e_invarg)); emsg(_(e_invarg));
} else { return;
}
#ifdef MSWIN #ifdef MSWIN
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, pid); HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
if (hProcess == NULL) {
return;
}
if (hProcess != NULL) {
DebugBreakProcess(hProcess); DebugBreakProcess(hProcess);
CloseHandle(hProcess); CloseHandle(hProcess);
rettv->vval.v_number = OK; rettv->vval.v_number = OK;
}
#else #else
uv_kill(pid, SIGINT); uv_kill(pid, SIGINT);
#endif #endif
} }
}
/// "deepcopy()" function /// "deepcopy()" function
static void f_deepcopy(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) static void f_deepcopy(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
@@ -2099,7 +2101,10 @@ static void f_float2nr(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
{ {
float_T f; float_T f;
if (tv_get_float_chk(argvars, &f)) { if (!tv_get_float_chk(argvars, &f)) {
return;
}
if (f <= (float_T) - VARNUMBER_MAX + DBL_EPSILON) { if (f <= (float_T) - VARNUMBER_MAX + DBL_EPSILON) {
rettv->vval.v_number = -VARNUMBER_MAX; rettv->vval.v_number = -VARNUMBER_MAX;
} else if (f >= (float_T)VARNUMBER_MAX - DBL_EPSILON) { } else if (f >= (float_T)VARNUMBER_MAX - DBL_EPSILON) {
@@ -2108,7 +2113,6 @@ static void f_float2nr(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
rettv->vval.v_number = (varnumber_T)f; rettv->vval.v_number = (varnumber_T)f;
} }
} }
}
/// "fmod()" function /// "fmod()" function
static void f_fmod(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) static void f_fmod(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
@@ -3435,8 +3439,12 @@ static void f_index(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
emsg(_(e_listblobreq)); emsg(_(e_listblobreq));
return; return;
} }
list_T *const l = argvars[0].vval.v_list; list_T *const l = argvars[0].vval.v_list;
if (l != NULL) { if (l == NULL) {
return;
}
listitem_T *item = tv_list_first(l); listitem_T *item = tv_list_first(l);
if (argvars[2].v_type != VAR_UNKNOWN) { if (argvars[2].v_type != VAR_UNKNOWN) {
bool error = false; bool error = false;
@@ -3464,7 +3472,6 @@ static void f_index(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
} }
} }
} }
}
static bool inputsecret_flag = false; static bool inputsecret_flag = false;
@@ -5311,15 +5318,18 @@ static void f_range(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
} }
if (stride == 0) { if (stride == 0) {
emsg(_("E726: Stride is zero")); emsg(_("E726: Stride is zero"));
} else if (stride > 0 ? end + 1 < start : end - 1 > start) { return;
}
if (stride > 0 ? end + 1 < start : end - 1 > start) {
emsg(_("E727: Start past end")); emsg(_("E727: Start past end"));
} else { return;
}
tv_list_alloc_ret(rettv, (end - start) / stride); tv_list_alloc_ret(rettv, (end - start) / stride);
for (varnumber_T i = start; stride > 0 ? i <= end : i >= end; i += stride) { for (varnumber_T i = start; stride > 0 ? i <= end : i >= end; i += stride) {
tv_list_append_number(rettv->vval.v_list, i); tv_list_append_number(rettv->vval.v_list, i);
} }
} }
}
/// Evaluate "expr" (= "context") for readdir(). /// Evaluate "expr" (= "context") for readdir().
static varnumber_T readdir_checkitem(void *context, const char *name) static varnumber_T readdir_checkitem(void *context, const char *name)
@@ -7009,10 +7019,16 @@ static void set_position(typval_T *argvars, typval_T *rettv, bool charpos)
rettv->vval.v_number = -1; rettv->vval.v_number = -1;
const char *const name = tv_get_string_chk(argvars); const char *const name = tv_get_string_chk(argvars);
if (name != NULL) { if (name == NULL) {
return;
}
pos_T pos; pos_T pos;
int fnum; int fnum;
if (list2fpos(&argvars[1], &pos, &fnum, &curswant, charpos) == OK) { if (list2fpos(&argvars[1], &pos, &fnum, &curswant, charpos) != OK) {
return;
}
if (pos.col != MAXCOL && --pos.col < 0) { if (pos.col != MAXCOL && --pos.col < 0) {
pos.col = 0; pos.col = 0;
} }
@@ -7034,8 +7050,6 @@ static void set_position(typval_T *argvars, typval_T *rettv, bool charpos)
emsg(_(e_invarg)); emsg(_(e_invarg));
} }
} }
}
}
/// "setcharpos()" function /// "setcharpos()" function
static void f_setcharpos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) static void f_setcharpos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
@@ -7051,7 +7065,10 @@ static void f_setcharsearch(typval_T *argvars, typval_T *rettv, EvalFuncData fpt
} }
dict_T *d = argvars[0].vval.v_dict; dict_T *d = argvars[0].vval.v_dict;
if (d != NULL) { if (d == NULL) {
return;
}
char_u *const csearch = (char_u *)tv_dict_get_string(d, "char", false); char_u *const csearch = (char_u *)tv_dict_get_string(d, "char", false);
if (csearch != NULL) { if (csearch != NULL) {
int pcc[MAX_MCO]; int pcc[MAX_MCO];
@@ -7069,7 +7086,6 @@ static void f_setcharsearch(typval_T *argvars, typval_T *rettv, EvalFuncData fpt
set_csearch_until(!!tv_get_number(&di->di_tv)); set_csearch_until(!!tv_get_number(&di->di_tv));
} }
} }
}
/// "setcursorcharpos" function /// "setcursorcharpos" function
static void f_setcursorcharpos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) static void f_setcursorcharpos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)

View File

@@ -1654,7 +1654,10 @@ static void setwinvar(typval_T *argvars, typval_T *rettv, int off)
const char *varname = tv_get_string_chk(&argvars[off + 1]); const char *varname = tv_get_string_chk(&argvars[off + 1]);
typval_T *varp = &argvars[off + 2]; typval_T *varp = &argvars[off + 2];
if (win != NULL && varname != NULL && varp != NULL) { if (win == NULL || varname == NULL || varp == NULL) {
return;
}
bool need_switch_win = !(tp == curtab && win == curwin); bool need_switch_win = !(tp == curtab && win == curwin);
switchwin_T switchwin; switchwin_T switchwin;
if (!need_switch_win || switch_win(&switchwin, win, tp, true) == OK) { if (!need_switch_win || switch_win(&switchwin, win, tp, true) == OK) {
@@ -1673,7 +1676,6 @@ static void setwinvar(typval_T *argvars, typval_T *rettv, int off)
restore_win(&switchwin, true); restore_win(&switchwin, true);
} }
} }
}
bool var_exists(const char *var) bool var_exists(const char *var)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
@@ -1755,7 +1757,10 @@ void f_settabvar(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
const char *const varname = tv_get_string_chk(&argvars[1]); const char *const varname = tv_get_string_chk(&argvars[1]);
typval_T *const varp = &argvars[2]; typval_T *const varp = &argvars[2];
if (varname != NULL && tp != NULL) { if (varname == NULL || tp == NULL) {
return;
}
tabpage_T *const save_curtab = curtab; tabpage_T *const save_curtab = curtab;
goto_tabpage_tp(tp, false, false); goto_tabpage_tp(tp, false, false);
@@ -1771,7 +1776,6 @@ void f_settabvar(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
goto_tabpage_tp(save_curtab, false, false); goto_tabpage_tp(save_curtab, false, false);
} }
} }
}
/// "settabwinvar()" function /// "settabwinvar()" function
void f_settabwinvar(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) void f_settabwinvar(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
@@ -1796,7 +1800,10 @@ void f_setbufvar(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
buf_T *const buf = tv_get_buf(&argvars[0], false); buf_T *const buf = tv_get_buf(&argvars[0], false);
typval_T *varp = &argvars[2]; typval_T *varp = &argvars[2];
if (buf != NULL && varname != NULL) { if (buf == NULL || varname == NULL) {
return;
}
if (*varname == '&') { if (*varname == '&') {
aco_save_T aco; aco_save_T aco;
@@ -1819,4 +1826,3 @@ void f_setbufvar(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
curbuf = save_curbuf; curbuf = save_curbuf;
} }
} }
}

View File

@@ -486,9 +486,11 @@ void f_win_execute(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
int id = (int)tv_get_number(argvars); int id = (int)tv_get_number(argvars);
tabpage_T *tp; tabpage_T *tp;
win_T *wp = win_id2wp_tp(id, &tp); win_T *wp = win_id2wp_tp(id, &tp);
if (wp != NULL && tp != NULL) { if (wp == NULL || tp == NULL) {
WIN_EXECUTE(wp, tp, execute_common(argvars, rettv, 1)); return;
} }
WIN_EXECUTE(wp, tp, execute_common(argvars, rettv, 1));
} }
/// "win_findbuf()" function /// "win_findbuf()" function

View File

@@ -5171,12 +5171,14 @@ static void ex_find(exarg_T *eap)
} }
} }
if (fname != NULL) { if (fname == NULL) {
return;
}
eap->arg = fname; eap->arg = fname;
do_exedit(eap, NULL); do_exedit(eap, NULL);
xfree(fname); xfree(fname);
} }
}
/// ":edit", ":badd", ":balt", ":visual". /// ":edit", ":badd", ":balt", ":visual".
static void ex_edit(exarg_T *eap) static void ex_edit(exarg_T *eap)

View File

@@ -2014,12 +2014,14 @@ void set_file_options(int set_options, exarg_T *eap)
/// Set forced 'fileencoding'. /// Set forced 'fileencoding'.
void set_forced_fenc(exarg_T *eap) void set_forced_fenc(exarg_T *eap)
{ {
if (eap->force_enc != 0) { if (eap->force_enc == 0) {
return;
}
char *fenc = enc_canonize(eap->cmd + eap->force_enc); char *fenc = enc_canonize(eap->cmd + eap->force_enc);
set_string_option_direct("fenc", -1, fenc, OPT_FREE|OPT_LOCAL, 0); set_string_option_direct("fenc", -1, fenc, OPT_FREE|OPT_LOCAL, 0);
xfree(fenc); xfree(fenc);
} }
}
/// Find next fileencoding to use from 'fileencodings'. /// Find next fileencoding to use from 'fileencodings'.
/// "pp" points to fenc_next. It's advanced to the next item. /// "pp" points to fenc_next. It's advanced to the next item.
@@ -5348,27 +5350,33 @@ static void vim_opentempdir(void)
} }
DIR *dp = opendir(vim_tempdir); DIR *dp = opendir(vim_tempdir);
if (dp == NULL) {
return;
}
if (dp != NULL) {
vim_tempdir_dp = dp; vim_tempdir_dp = dp;
flock(dirfd(vim_tempdir_dp), LOCK_SH); flock(dirfd(vim_tempdir_dp), LOCK_SH);
} }
}
/// Close temporary directory - it automatically release file lock. /// Close temporary directory - it automatically release file lock.
static void vim_closetempdir(void) static void vim_closetempdir(void)
{ {
if (vim_tempdir_dp != NULL) { if (vim_tempdir_dp == NULL) {
return;
}
closedir(vim_tempdir_dp); closedir(vim_tempdir_dp);
vim_tempdir_dp = NULL; vim_tempdir_dp = NULL;
} }
}
#endif #endif
/// Delete the temp directory and all files it contains. /// Delete the temp directory and all files it contains.
void vim_deltempdir(void) void vim_deltempdir(void)
{ {
if (vim_tempdir != NULL) { if (vim_tempdir == NULL) {
return;
}
#if defined(HAVE_FLOCK) && defined(HAVE_DIRFD) #if defined(HAVE_FLOCK) && defined(HAVE_DIRFD)
vim_closetempdir(); vim_closetempdir();
#endif #endif
@@ -5377,7 +5385,6 @@ void vim_deltempdir(void)
delete_recursive(vim_tempdir); delete_recursive(vim_tempdir);
XFREE_CLEAR(vim_tempdir); XFREE_CLEAR(vim_tempdir);
} }
}
/// Gets path to Nvim's own temp dir (ending with slash). /// Gets path to Nvim's own temp dir (ending with slash).
/// ///
@@ -5401,9 +5408,10 @@ char *vim_gettempdir(void)
static bool vim_settempdir(char *tempdir) static bool vim_settempdir(char *tempdir)
{ {
char *buf = verbose_try_malloc(MAXPATHL + 2); char *buf = verbose_try_malloc(MAXPATHL + 2);
if (!buf) { if (buf == NULL) {
return false; return false;
} }
vim_FullName(tempdir, buf, MAXPATHL, false); vim_FullName(tempdir, buf, MAXPATHL, false);
add_pathsep(buf); add_pathsep(buf);
vim_tempdir = xstrdup(buf); vim_tempdir = xstrdup(buf);

View File

@@ -1523,7 +1523,10 @@ static bool check_closed(win_T *const wp, fold_T *const fp, bool *const use_leve
/// @param lnum_off offset for fp->fd_top /// @param lnum_off offset for fp->fd_top
static void checkSmall(win_T *const wp, fold_T *const fp, const linenr_T lnum_off) static void checkSmall(win_T *const wp, fold_T *const fp, const linenr_T lnum_off)
{ {
if (fp->fd_small == kNone) { if (fp->fd_small != kNone) {
return;
}
// Mark any nested folds to maybe-small // Mark any nested folds to maybe-small
setSmallMaybe(&fp->fd_nested); setSmallMaybe(&fp->fd_nested);
@@ -1541,7 +1544,6 @@ static void checkSmall(win_T *const wp, fold_T *const fp, const linenr_T lnum_of
fp->fd_small = kTrue; fp->fd_small = kTrue;
} }
} }
}
// setSmallMaybe() {{{2 // setSmallMaybe() {{{2
/// Set small flags in "gap" to kNone. /// Set small flags in "gap" to kNone.
@@ -1595,7 +1597,10 @@ static void foldAddMarker(buf_T *buf, pos_T pos, const char *marker, size_t mark
size_t line_len = strlen(line); size_t line_len = strlen(line);
size_t added = 0; size_t added = 0;
if (u_save(lnum - 1, lnum + 1) == OK) { if (u_save(lnum - 1, lnum + 1) != OK) {
return;
}
// Check if the line ends with an unclosed comment // Check if the line ends with an unclosed comment
skip_comment(line, false, false, &line_is_comment); skip_comment(line, false, false, &line_is_comment);
newline = xmalloc(line_len + markerlen + strlen(cms) + 1); newline = xmalloc(line_len + markerlen + strlen(cms) + 1);
@@ -1616,7 +1621,6 @@ static void foldAddMarker(buf_T *buf, pos_T pos, const char *marker, size_t mark
0, (int)added, kExtmarkUndo); 0, (int)added, kExtmarkUndo);
} }
} }
}
// deleteFoldMarkers() {{{2 // deleteFoldMarkers() {{{2
/// Delete the markers for a fold, causing it to be deleted. /// Delete the markers for a fold, causing it to be deleted.