1
0
forked from aniani/vim

patch 9.0.1132: code is indented more than needed

Problem:    Code is indented more than needed.
Solution:   Use an early return to reduce indentation. (Yegappan Lakshmanan,
            closes #11769)
This commit is contained in:
Yegappan Lakshmanan
2023-01-02 16:54:53 +00:00
committed by Bram Moolenaar
parent a2942c7468
commit dc4daa3a39
13 changed files with 647 additions and 642 deletions

View File

@@ -693,9 +693,10 @@ do_argfile(exarg_T *eap, int argn)
emsg(_(e_cannot_go_before_first_file));
else
emsg(_(e_cannot_go_beyond_last_file));
return;
}
else
{
setpcmark();
#ifdef FEAT_GUI
need_mouse_correct = TRUE;
@@ -743,7 +744,6 @@ do_argfile(exarg_T *eap, int argn)
else if (eap->cmdidx != CMD_argdo)
setmark('\'');
}
}
/*
* ":next", and commands that behave like it.

View File

@@ -146,8 +146,9 @@ read_buffer(
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;
// Make sure the buffer is in a window. If not then skip it.
@@ -160,7 +161,6 @@ buffer_ensure_loaded(buf_T *buf)
aucmd_restbuf(&aco);
}
}
}
#endif
/*
@@ -3582,8 +3582,9 @@ buf_set_name(int fnum, char_u *name)
buf_T *buf;
buf = buflist_findnr(fnum);
if (buf != NULL)
{
if (buf == NULL)
return;
if (buf->b_sfname != buf->b_ffname)
vim_free(buf->b_sfname);
vim_free(buf->b_ffname);
@@ -3594,7 +3595,6 @@ buf_set_name(int fnum, char_u *name)
fname_expand(buf, &buf->b_ffname, &buf->b_sfname);
buf->b_fname = buf->b_sfname;
}
}
/*
* Take care of what needs to be done when the name of buffer "buf" has
@@ -5921,15 +5921,15 @@ buf_get_fname(buf_T *buf)
void
set_buflisted(int on)
{
if (on != curbuf->b_p_bl)
{
if (on == curbuf->b_p_bl)
return;
curbuf->b_p_bl = on;
if (on)
apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, curbuf);
else
apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf);
}
}
/*
* Read the file for "buf" again and check if the contents changed.

View File

@@ -191,8 +191,9 @@ static char_u *build_drop_cmd(int filec, char **filev, int tabs, int sendReply);
void
exec_on_server(mparm_T *parmp)
{
if (parmp->serverName_arg == NULL || *parmp->serverName_arg != NUL)
{
if (parmp->serverName_arg != NULL && *parmp->serverName_arg == NUL)
return;
# ifdef MSWIN
// Initialise the client/server messaging infrastructure.
serverInitMessaging();
@@ -223,7 +224,6 @@ exec_on_server(mparm_T *parmp)
}
# endif
}
}
/*
* Prepare for running as a Vim server.

View File

@@ -830,13 +830,16 @@ install_bat_choice(int idx)
char *vimarg = targets[choices[idx].arg].exearg;
FILE *fd;
if (*batpath != NUL)
{
if (*batpath == NUL)
return;
fd = fopen(batpath, "w");
if (fd == NULL)
printf("\nERROR: Cannot open \"%s\" for writing.\n", batpath);
else
{
printf("\nERROR: Cannot open \"%s\" for writing.\n", batpath);
return;
}
need_uninstall_entry = 1;
fprintf(fd, "@echo off\n");
@@ -910,8 +913,6 @@ install_bat_choice(int idx)
printf("%s has been %s\n", batpath,
oldname == NULL ? "created" : "overwritten");
}
}
}
/*
* Make the text string for choice "idx".

View File

@@ -3172,20 +3172,21 @@ f_and(typval_T *argvars, typval_T *rettv)
f_balloon_gettext(typval_T *argvars UNUSED, typval_T *rettv)
{
rettv->v_type = VAR_STRING;
if (balloonEval != NULL)
{
if (balloonEval == NULL)
return;
if (balloonEval->msg == NULL)
rettv->vval.v_string = NULL;
else
rettv->vval.v_string = vim_strsave(balloonEval->msg);
}
}
static void
f_balloon_show(typval_T *argvars, typval_T *rettv UNUSED)
{
if (balloonEval != NULL)
{
if (balloonEval == NULL)
return;
if (in_vim9script()
&& check_for_string_or_list_arg(argvars, 0) == FAIL)
return;
@@ -3215,14 +3216,14 @@ f_balloon_show(typval_T *argvars, typval_T *rettv UNUSED)
post_balloon(balloonEval, *mesg == NUL ? NULL : mesg, NULL);
}
}
}
# if defined(FEAT_BEVAL_TERM)
static void
f_balloon_split(typval_T *argvars, typval_T *rettv UNUSED)
{
if (rettv_list_alloc(rettv) == OK)
{
if (rettv_list_alloc(rettv) != OK)
return;
char_u *msg;
if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
@@ -3241,7 +3242,6 @@ f_balloon_split(typval_T *argvars, typval_T *rettv UNUSED)
vim_free(array);
}
}
}
# endif
#endif
@@ -3676,19 +3676,19 @@ f_debugbreak(typval_T *argvars, typval_T *rettv)
pid = (int)tv_get_number(&argvars[0]);
if (pid == 0)
{
emsg(_(e_invalid_argument));
else
{
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
return;
}
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
if (hProcess == NULL)
return;
if (hProcess != NULL)
{
DebugBreakProcess(hProcess);
CloseHandle(hProcess);
rettv->vval.v_number = OK;
}
}
}
#endif
/*
@@ -3932,13 +3932,13 @@ execute_redir_str(char_u *value, int value_len)
len = (int)STRLEN(value); // Append the entire string
else
len = value_len; // Append only "value_len" characters
if (ga_grow(&redir_execute_ga, len) == OK)
{
if (ga_grow(&redir_execute_ga, len) != OK)
return;
mch_memmove((char *)redir_execute_ga.ga_data
+ redir_execute_ga.ga_len, value, len);
redir_execute_ga.ga_len += len;
}
}
#if defined(FEAT_LUA) || defined(PROTO)
/*
@@ -5043,15 +5043,15 @@ f_getcharpos(typval_T *argvars UNUSED, typval_T *rettv)
static void
f_getcharsearch(typval_T *argvars UNUSED, typval_T *rettv)
{
if (rettv_dict_alloc(rettv) == OK)
{
if (rettv_dict_alloc(rettv) != OK)
return;
dict_T *dict = rettv->vval.v_dict;
dict_add_string(dict, "char", last_csearch());
dict_add_number(dict, "forward", last_csearch_forward());
dict_add_number(dict, "until", last_csearch_until());
}
}
/*
* "getenv()" function
@@ -6792,8 +6792,9 @@ f_index(typval_T *argvars, typval_T *rettv)
}
l = argvars[0].vval.v_list;
if (l != NULL)
{
if (l == NULL)
return;
CHECK_LIST_MATERIALIZE(l);
item = l->lv_first;
if (argvars[2].v_type != VAR_UNKNOWN)
@@ -6815,7 +6816,6 @@ f_index(typval_T *argvars, typval_T *rettv)
break;
}
}
}
/*
* Evaluate 'expr' with the v:key and v:val arguments and return the result.
@@ -8363,11 +8363,16 @@ f_range(typval_T *argvars, typval_T *rettv)
if (error)
return; // type error; errmsg already given
if (stride == 0)
emsg(_(e_stride_is_zero));
else if (stride > 0 ? end + 1 < start : end - 1 > start)
emsg(_(e_start_past_end));
else
{
emsg(_(e_stride_is_zero));
return;
}
if (stride > 0 ? end + 1 < start : end - 1 > start)
{
emsg(_(e_start_past_end));
return;
}
list_T *list = rettv->vval.v_list;
// Create a non-materialized list. This is much more efficient and
@@ -8379,7 +8384,6 @@ f_range(typval_T *argvars, typval_T *rettv)
list->lv_u.nonmat.lv_stride = stride;
list->lv_len = (end - start) / stride + 1;
}
}
/*
* Materialize "list".
@@ -9382,10 +9386,12 @@ set_position(typval_T *argvars, typval_T *rettv, int charpos)
return;
name = tv_get_string_chk(argvars);
if (name != NULL)
{
if (list2fpos(&argvars[1], &pos, &fnum, &curswant, charpos) == OK)
{
if (name == NULL)
return;
if (list2fpos(&argvars[1], &pos, &fnum, &curswant, charpos) != OK)
return;
if (pos.col != MAXCOL && --pos.col < 0)
pos.col = 0;
if ((name[0] == '.' && name[1] == NUL))
@@ -9409,8 +9415,6 @@ set_position(typval_T *argvars, typval_T *rettv, int charpos)
else
emsg(_(e_invalid_argument));
}
}
}
/*
* "setcharpos()" function
*/
@@ -9430,8 +9434,9 @@ f_setcharsearch(typval_T *argvars, typval_T *rettv UNUSED)
if (check_for_dict_arg(argvars, 0) == FAIL)
return;
if ((d = argvars[0].vval.v_dict) != NULL)
{
if ((d = argvars[0].vval.v_dict) == NULL)
return;
csearch = dict_get_string(d, "char", FALSE);
if (csearch != NULL)
{
@@ -9456,7 +9461,6 @@ f_setcharsearch(typval_T *argvars, typval_T *rettv UNUSED)
if (di != NULL)
set_csearch_until(!!tv_get_number(&di->di_tv));
}
}
/*
* "setcursorcharpos" function

View File

@@ -350,16 +350,16 @@ set_internal_string_var(char_u *name, char_u *value)
typval_T *tvp;
val = vim_strsave(value);
if (val != NULL)
{
if (val == NULL)
return;
tvp = alloc_string_tv(val);
if (tvp != NULL)
{
if (tvp == NULL)
return;
set_var(name, tvp, FALSE);
free_tv(tvp);
}
}
}
int
eval_charconvert(
@@ -576,15 +576,15 @@ restore_vimvar(int idx, typval_T *save_tv)
hashitem_T *hi;
vimvars[idx].vv_tv = *save_tv;
if (vimvars[idx].vv_tv_type == VAR_UNKNOWN)
{
if (vimvars[idx].vv_tv_type != VAR_UNKNOWN)
return;
hi = hash_find(&vimvarht, vimvars[idx].vv_di.di_key);
if (HASHITEM_EMPTY(hi))
internal_error("restore_vimvar()");
else
hash_remove(&vimvarht, hi, "restore vimvar");
}
}
/*
* List Vim variables.
@@ -2740,12 +2740,12 @@ set_vim_var_dict(int idx, dict_T *val)
clear_tv(&vimvars[idx].vv_di.di_tv);
vimvars[idx].vv_tv_type = VAR_DICT;
vimvars[idx].vv_dict = val;
if (val != NULL)
{
if (val == NULL)
return;
++val->dv_refcount;
dict_set_items_ro(val);
}
}
/*
* Set the v:argv list.
@@ -3562,12 +3562,12 @@ delete_var(hashtab_T *ht, hashitem_T *hi)
{
dictitem_T *di = HI2DI(hi);
if (hash_remove(ht, hi, "delete variable") == OK)
{
if (hash_remove(ht, hi, "delete variable") != OK)
return;
clear_tv(&di->di_tv);
vim_free(di);
}
}
/*
* List the value of one internal variable.
@@ -4317,8 +4317,9 @@ setwinvar(typval_T *argvars, int off)
varname = tv_get_string_chk(&argvars[off + 1]);
varp = &argvars[off + 2];
if (win != NULL && varname != NULL && varp != NULL)
{
if (win == NULL || varname == NULL || varp == NULL)
return;
need_switch_win = !(tp == curtab && win == curwin);
if (!need_switch_win
|| switch_win(&switchwin, win, tp, TRUE) == OK)
@@ -4340,7 +4341,6 @@ setwinvar(typval_T *argvars, int off)
if (need_switch_win)
restore_win(&switchwin, TRUE);
}
}
/*
* reset v:option_new, v:option_old, v:option_oldlocal, v:option_oldglobal,
@@ -4686,8 +4686,9 @@ f_settabvar(typval_T *argvars, typval_T *rettv UNUSED)
varname = tv_get_string_chk(&argvars[1]);
varp = &argvars[2];
if (varname != NULL && varp != NULL && tp != NULL)
{
if (varname == NULL || varp == NULL || tp == NULL)
return;
save_curtab = curtab;
goto_tabpage_tp(tp, FALSE, FALSE);
@@ -4704,7 +4705,6 @@ f_settabvar(typval_T *argvars, typval_T *rettv UNUSED)
if (valid_tabpage(save_curtab))
goto_tabpage_tp(save_curtab, FALSE, FALSE);
}
}
/*
* "settabwinvar()" function
@@ -4757,8 +4757,9 @@ f_setbufvar(typval_T *argvars, typval_T *rettv UNUSED)
buf = tv_get_buf_from_arg(&argvars[0]);
varp = &argvars[2];
if (buf != NULL && varname != NULL && varp != NULL)
{
if (buf == NULL || varname == NULL || varp == NULL)
return;
if (*varname == '&')
{
aco_save_T aco;
@@ -4790,7 +4791,6 @@ f_setbufvar(typval_T *argvars, typval_T *rettv UNUSED)
}
}
}
}
/*
* Get a callback from "arg". It can be a Funcref or a function name.
@@ -4930,17 +4930,19 @@ expand_autload_callback(callback_T *cb)
p = vim_strchr(name, '.');
if (p == NULL)
return;
import = find_imported(name, p - name, FALSE);
if (import != NULL && SCRIPT_ID_VALID(import->imp_sid))
{
if (import == NULL || !SCRIPT_ID_VALID(import->imp_sid))
return;
scriptitem_T *si = SCRIPT_ITEM(import->imp_sid);
if (si->sn_autoload_prefix == NULL)
return;
if (si->sn_autoload_prefix != NULL)
{
char_u *newname = concat_str(si->sn_autoload_prefix, p + 1);
if (newname == NULL)
return;
if (newname != NULL)
{
if (cb->cb_partial != NULL)
{
if (cb->cb_name == cb->cb_partial->pt_name)
@@ -4954,9 +4956,6 @@ expand_autload_callback(callback_T *cb)
cb->cb_name = newname;
}
}
}
}
}
/*
* Unref/free "callback" returned by get_callback() or set_callback().

View File

@@ -718,8 +718,9 @@ f_win_execute(typval_T *argvars, typval_T *rettv)
id = (int)tv_get_number(argvars);
wp = win_id2wp_tp(id, &tp);
if (wp != NULL && tp != NULL)
{
if (wp == NULL || tp == NULL)
return;
pos_T curpos = wp->w_cursor;
char_u cwd[MAXPATHL];
int cwd_status = FAIL;
@@ -778,7 +779,6 @@ f_win_execute(typval_T *argvars, typval_T *rettv)
if (VIsual_active)
check_pos(curbuf, &VIsual);
}
}
/*
* "win_findbuf()" function
@@ -1093,12 +1093,12 @@ f_getcmdwintype(typval_T *argvars UNUSED, typval_T *rettv)
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
rettv->vval.v_string = alloc(2);
if (rettv->vval.v_string != NULL)
{
if (rettv->vval.v_string == NULL)
return;
rettv->vval.v_string[0] = cmdwin_type;
rettv->vval.v_string[1] = NUL;
}
}
/*
* "winbufnr(nr)" function

View File

@@ -7049,13 +7049,13 @@ ex_find(exarg_T *eap)
}
}
if (fname != NULL)
{
if (fname == NULL)
return;
eap->arg = fname;
do_exedit(eap, NULL);
vim_free(fname);
}
}
/*
* ":open" simulation: for now just work like ":visual".

View File

@@ -4210,12 +4210,12 @@ f_getcmdtype(typval_T *argvars UNUSED, typval_T *rettv)
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = alloc(2);
if (rettv->vval.v_string != NULL)
{
if (rettv->vval.v_string == NULL)
return;
rettv->vval.v_string[0] = get_cmdline_type();
rettv->vval.v_string[1] = NUL;
}
}
// Set the command line str to "str".
// Returns 1 when failed, 0 when OK.

View File

@@ -2767,8 +2767,9 @@ set_file_options(int set_options, exarg_T *eap)
void
set_forced_fenc(exarg_T *eap)
{
if (eap->force_enc != 0)
{
if (eap->force_enc == 0)
return;
char_u *fenc = enc_canonize(eap->cmd + eap->force_enc);
if (fenc != NULL)
@@ -2776,7 +2777,6 @@ set_forced_fenc(exarg_T *eap)
fenc, OPT_FREE|OPT_LOCAL, 0);
vim_free(fenc);
}
}
/*
* Find next fileencoding to use from 'fileencodings'.
@@ -5070,13 +5070,12 @@ vim_opentempdir(void)
return;
dp = opendir((const char*)vim_tempdir);
if (dp == NULL)
return;
if (dp != NULL)
{
vim_tempdir_dp = dp;
flock(dirfd(vim_tempdir_dp), LOCK_SH);
}
}
/*
* Close temporary directory - it automatically release file lock.
@@ -5084,12 +5083,12 @@ vim_opentempdir(void)
static void
vim_closetempdir(void)
{
if (vim_tempdir_dp != NULL)
{
if (vim_tempdir_dp == NULL)
return;
closedir(vim_tempdir_dp);
vim_tempdir_dp = NULL;
}
}
# endif
/*
@@ -5098,8 +5097,9 @@ vim_closetempdir(void)
void
vim_deltempdir(void)
{
if (vim_tempdir != NULL)
{
if (vim_tempdir == NULL)
return;
# if defined(UNIX) && defined(HAVE_FLOCK) && defined(HAVE_DIRFD)
vim_closetempdir();
# endif
@@ -5108,7 +5108,6 @@ vim_deltempdir(void)
delete_recursive(vim_tempdir);
VIM_CLEAR(vim_tempdir);
}
}
/*
* Directory "tempdir" was created. Expand this name to a full path and put
@@ -5121,8 +5120,9 @@ vim_settempdir(char_u *tempdir)
char_u *buf;
buf = alloc(MAXPATHL + 2);
if (buf != NULL)
{
if (buf == NULL)
return;
if (vim_FullName(tempdir, buf, MAXPATHL, FALSE) == FAIL)
STRCPY(buf, tempdir);
add_pathsep(buf);
@@ -5132,7 +5132,6 @@ vim_settempdir(char_u *tempdir)
# endif
vim_free(buf);
}
}
#endif
/*

View File

@@ -288,8 +288,9 @@ f_float2nr(typval_T *argvars, typval_T *rettv)
if (in_vim9script() && check_for_float_or_nr_arg(argvars, 0) == FAIL)
return;
if (get_float_arg(argvars, &f) == OK)
{
if (get_float_arg(argvars, &f) != OK)
return;
if (f <= (float_T)-VARNUM_MAX + DBL_EPSILON)
rettv->vval.v_number = -VARNUM_MAX;
else if (f >= (float_T)VARNUM_MAX - DBL_EPSILON)
@@ -297,7 +298,6 @@ f_float2nr(typval_T *argvars, typval_T *rettv)
else
rettv->vval.v_number = (varnumber_T)f;
}
}
/*
* "floor({float})" function

View File

@@ -644,8 +644,9 @@ foldCreate(linenr_T start, linenr_T end)
i = (int)(fp - (fold_T *)gap->ga_data);
}
if (ga_grow(gap, 1) == OK)
{
if (ga_grow(gap, 1) != OK)
return;
fp = (fold_T *)gap->ga_data + i;
ga_init2(&fold_ga, sizeof(fold_T), 10);
@@ -697,7 +698,6 @@ foldCreate(linenr_T start, linenr_T end)
// redraw
changed_window_setting();
}
}
// deleteFold() {{{2
/*
@@ -1719,8 +1719,9 @@ checkSmall(
int count;
int n;
if (fp->fd_small == MAYBE)
{
if (fp->fd_small != MAYBE)
return;
// Mark any nested folds to maybe-small
setSmallMaybe(&fp->fd_nested);
@@ -1741,7 +1742,6 @@ checkSmall(
fp->fd_small = TRUE;
}
}
}
// setSmallMaybe() {{{2
/*
@@ -1799,8 +1799,9 @@ foldAddMarker(linenr_T lnum, char_u *marker, int markerlen)
line = ml_get(lnum);
line_len = (int)STRLEN(line);
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
(void)skip_comment(line, FALSE, FALSE, &line_is_comment);
newline = alloc(line_len + markerlen + STRLEN(cms) + 1);
@@ -1819,7 +1820,6 @@ foldAddMarker(linenr_T lnum, char_u *marker, int markerlen)
ml_replace(lnum, newline, FALSE);
}
}
// deleteFoldMarkers() {{{2
/*

View File

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