summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYegappan Lakshmanan <yegappan@yahoo.com>2023-01-02 16:54:53 +0000
committerBram Moolenaar <Bram@vim.org>2023-01-02 16:54:53 +0000
commitdc4daa3a3915fba11ac87d27977240d9a5e0d47d (patch)
tree7c28de30cdf3c6a351bd41795612be078f451c9f
parenta2942c74683be3f67c6044c2886dc6c237358b3d (diff)
patch 9.0.1132: code is indented more than neededv9.0.1132
Problem: Code is indented more than needed. Solution: Use an early return to reduce indentation. (Yegappan Lakshmanan, closes #11769)
-rw-r--r--src/arglist.c86
-rw-r--r--src/buffer.c64
-rw-r--r--src/clientserver.c52
-rw-r--r--src/dosinst.c155
-rw-r--r--src/evalfunc.c300
-rw-r--r--src/evalvars.c213
-rw-r--r--src/evalwindow.c102
-rw-r--r--src/ex_docmd.c12
-rw-r--r--src/ex_getln.c10
-rw-r--r--src/fileio.c69
-rw-r--r--src/float.c18
-rw-r--r--src/fold.c170
-rw-r--r--src/version.c2
13 files changed, 629 insertions, 624 deletions
diff --git a/src/arglist.c b/src/arglist.c
index 6183fafff6..bb31c45e93 100644
--- a/src/arglist.c
+++ b/src/arglist.c
@@ -693,56 +693,56 @@ 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();
+
+ setpcmark();
#ifdef FEAT_GUI
- need_mouse_correct = TRUE;
+ need_mouse_correct = TRUE;
#endif
- // split window or create new tab page first
- if (*eap->cmd == 's' || cmdmod.cmod_tab != 0)
- {
- if (win_split(0, 0) == FAIL)
- return;
- RESET_BINDING(curwin);
- }
- else
+ // split window or create new tab page first
+ if (*eap->cmd == 's' || cmdmod.cmod_tab != 0)
+ {
+ if (win_split(0, 0) == FAIL)
+ return;
+ RESET_BINDING(curwin);
+ }
+ else
+ {
+ // if 'hidden' set, only check for changed file when re-editing
+ // the same buffer
+ other = TRUE;
+ if (buf_hide(curbuf))
{
- // if 'hidden' set, only check for changed file when re-editing
- // the same buffer
- other = TRUE;
- if (buf_hide(curbuf))
- {
- p = fix_fname(alist_name(&ARGLIST[argn]));
- other = otherfile(p);
- vim_free(p);
- }
- if ((!buf_hide(curbuf) || !other)
- && check_changed(curbuf, CCGD_AW
- | (other ? 0 : CCGD_MULTWIN)
- | (eap->forceit ? CCGD_FORCEIT : 0)
- | CCGD_EXCMD))
- return;
+ p = fix_fname(alist_name(&ARGLIST[argn]));
+ other = otherfile(p);
+ vim_free(p);
}
-
- curwin->w_arg_idx = argn;
- if (argn == ARGCOUNT - 1 && curwin->w_alist == &global_alist)
- arg_had_last = TRUE;
-
- // Edit the file; always use the last known line number.
- // When it fails (e.g. Abort for already edited file) restore the
- // argument index.
- if (do_ecmd(0, alist_name(&ARGLIST[curwin->w_arg_idx]), NULL,
- eap, ECMD_LAST,
- (buf_hide(curwin->w_buffer) ? ECMD_HIDE : 0)
- + (eap->forceit ? ECMD_FORCEIT : 0), curwin) == FAIL)
- curwin->w_arg_idx = old_arg_idx;
- // like Vi: set the mark where the cursor is in the file.
- else if (eap->cmdidx != CMD_argdo)
- setmark('\'');
+ if ((!buf_hide(curbuf) || !other)
+ && check_changed(curbuf, CCGD_AW
+ | (other ? 0 : CCGD_MULTWIN)
+ | (eap->forceit ? CCGD_FORCEIT : 0)
+ | CCGD_EXCMD))
+ return;
}
+
+ curwin->w_arg_idx = argn;
+ if (argn == ARGCOUNT - 1 && curwin->w_alist == &global_alist)
+ arg_had_last = TRUE;
+
+ // Edit the file; always use the last known line number.
+ // When it fails (e.g. Abort for already edited file) restore the
+ // argument index.
+ if (do_ecmd(0, alist_name(&ARGLIST[curwin->w_arg_idx]), NULL,
+ eap, ECMD_LAST,
+ (buf_hide(curwin->w_buffer) ? ECMD_HIDE : 0)
+ + (eap->forceit ? ECMD_FORCEIT : 0), curwin) == FAIL)
+ curwin->w_arg_idx = old_arg_idx;
+ // like Vi: set the mark where the cursor is in the file.
+ else if (eap->cmdidx != CMD_argdo)
+ setmark('\'');
}
/*
diff --git a/src/buffer.c b/src/buffer.c
index 7e4772921a..9856898789 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -146,19 +146,19 @@ read_buffer(
void
buffer_ensure_loaded(buf_T *buf)
{
- if (buf->b_ml.ml_mfp == NULL)
- {
- aco_save_T aco;
+ if (buf->b_ml.ml_mfp != NULL)
+ return;
- // Make sure the buffer is in a window. If not then skip it.
- aucmd_prepbuf(&aco, buf);
- if (curbuf == buf)
- {
- if (swap_exists_action != SEA_READONLY)
- swap_exists_action = SEA_NONE;
- open_buffer(FALSE, NULL, 0);
- aucmd_restbuf(&aco);
- }
+ aco_save_T aco;
+
+ // Make sure the buffer is in a window. If not then skip it.
+ aucmd_prepbuf(&aco, buf);
+ if (curbuf == buf)
+ {
+ if (swap_exists_action != SEA_READONLY)
+ swap_exists_action = SEA_NONE;
+ open_buffer(FALSE, NULL, 0);
+ aucmd_restbuf(&aco);
}
}
#endif
@@ -3582,18 +3582,18 @@ buf_set_name(int fnum, char_u *name)
buf_T *buf;
buf = buflist_findnr(fnum);
- if (buf != NULL)
- {
- if (buf->b_sfname != buf->b_ffname)
- vim_free(buf->b_sfname);
- vim_free(buf->b_ffname);
- buf->b_ffname = vim_strsave(name);
- buf->b_sfname = NULL;
- // Allocate ffname and expand into full path. Also resolves .lnk
- // files on Win32.
- fname_expand(buf, &buf->b_ffname, &buf->b_sfname);
- buf->b_fname = buf->b_sfname;
- }
+ if (buf == NULL)
+ return;
+
+ if (buf->b_sfname != buf->b_ffname)
+ vim_free(buf->b_sfname);
+ vim_free(buf->b_ffname);
+ buf->b_ffname = vim_strsave(name);
+ buf->b_sfname = NULL;
+ // Allocate ffname and expand into full path. Also resolves .lnk
+ // files on Win32.
+ fname_expand(buf, &buf->b_ffname, &buf->b_sfname);
+ buf->b_fname = buf->b_sfname;
}
/*
@@ -5921,14 +5921,14 @@ buf_get_fname(buf_T *buf)
void
set_buflisted(int on)
{
- if (on != curbuf->b_p_bl)
- {
- curbuf->b_p_bl = on;
- if (on)
- apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, curbuf);
- else
- apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf);
- }
+ 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);
}
/*
diff --git a/src/clientserver.c b/src/clientserver.c
index ccb7238725..2a091a6e97 100644
--- a/src/clientserver.c
+++ b/src/clientserver.c
@@ -191,38 +191,38 @@ 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();
+ // Initialise the client/server messaging infrastructure.
+ serverInitMessaging();
# endif
- /*
- * When a command server argument was found, execute it. This may
- * exit Vim when it was successful. Otherwise it's executed further
- * on. Remember the encoding used here in "serverStrEnc".
- */
- if (parmp->serverArg)
- {
- cmdsrv_main(&parmp->argc, parmp->argv,
- parmp->serverName_arg, &parmp->serverStr);
- parmp->serverStrEnc = vim_strsave(p_enc);
- }
+ /*
+ * When a command server argument was found, execute it. This may
+ * exit Vim when it was successful. Otherwise it's executed further
+ * on. Remember the encoding used here in "serverStrEnc".
+ */
+ if (parmp->serverArg)
+ {
+ cmdsrv_main(&parmp->argc, parmp->argv,
+ parmp->serverName_arg, &parmp->serverStr);
+ parmp->serverStrEnc = vim_strsave(p_enc);
+ }
- // If we're still running, get the name to register ourselves.
- // On Win32 can register right now, for X11 need to setup the
- // clipboard first, it's further down.
- parmp->servername = serverMakeName(parmp->serverName_arg,
- parmp->argv[0]);
+ // If we're still running, get the name to register ourselves.
+ // On Win32 can register right now, for X11 need to setup the
+ // clipboard first, it's further down.
+ parmp->servername = serverMakeName(parmp->serverName_arg,
+ parmp->argv[0]);
# ifdef MSWIN
- if (parmp->servername != NULL)
- {
- serverSetName(parmp->servername);
- vim_free(parmp->servername);
- }
-# endif
+ if (parmp->servername != NULL)
+ {
+ serverSetName(parmp->servername);
+ vim_free(parmp->servername);
}
+# endif
}
/*
diff --git a/src/dosinst.c b/src/dosinst.c
index 60e3c649ac..4eae5aadc4 100644
--- a/src/dosinst.c
+++ b/src/dosinst.c
@@ -830,87 +830,88 @@ 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)
{
- fd = fopen(batpath, "w");
- if (fd == NULL)
- printf("\nERROR: Cannot open \"%s\" for writing.\n", batpath);
- else
- {
- need_uninstall_entry = 1;
-
- fprintf(fd, "@echo off\n");
- fprintf(fd, "rem -- Run Vim --\n");
- fprintf(fd, VIMBAT_UNINSTKEY "\n");
- fprintf(fd, "\n");
- fprintf(fd, "setlocal\n");
-
- /*
- * Don't use double quotes for the "set" argument, also when it
- * contains a space. The quotes would be included in the value.
- * The order of preference is:
- * 1. $VIMRUNTIME/vim.exe (user preference)
- * 2. $VIM/vim81/vim.exe (hard coded version)
- * 3. installdir/vim.exe (hard coded install directory)
- */
- fprintf(fd, "set VIM_EXE_DIR=%s\n", installdir);
- fprintf(fd, "if exist \"%%VIM%%\\%s\\%s\" set VIM_EXE_DIR=%%VIM%%\\%s\n",
- VIM_VERSION_NODOT, exename, VIM_VERSION_NODOT);
- fprintf(fd, "if exist \"%%VIMRUNTIME%%\\%s\" set VIM_EXE_DIR=%%VIMRUNTIME%%\n", exename);
- fprintf(fd, "\n");
-
- // Give an error message when the executable could not be found.
- fprintf(fd, "if not exist \"%%VIM_EXE_DIR%%\\%s\" (\n", exename);
- fprintf(fd, " echo \"%%VIM_EXE_DIR%%\\%s\" not found\n", exename);
- fprintf(fd, " goto :eof\n");
- fprintf(fd, ")\n");
- fprintf(fd, "\n");
-
- if (*exename == 'g')
- {
- fprintf(fd, "rem check --nofork argument\n");
- fprintf(fd, "set VIMNOFORK=\n");
- fprintf(fd, ":loopstart\n");
- fprintf(fd, "if .%%1==. goto loopend\n");
- fprintf(fd, "if .%%1==.--nofork (\n");
- fprintf(fd, " set VIMNOFORK=1\n");
- fprintf(fd, ") else if .%%1==.-f (\n");
- fprintf(fd, " set VIMNOFORK=1\n");
- fprintf(fd, ")\n");
- fprintf(fd, "shift\n");
- fprintf(fd, "goto loopstart\n");
- fprintf(fd, ":loopend\n");
- fprintf(fd, "\n");
- }
+ printf("\nERROR: Cannot open \"%s\" for writing.\n", batpath);
+ return;
+ }
- if (*exename == 'g')
- {
- // For gvim.exe use "start /b" to avoid that the console window
- // stays open.
- fprintf(fd, "if .%%VIMNOFORK%%==.1 (\n");
- fprintf(fd, " start \"dummy\" /b /wait ");
- // Always use quotes, $VIM or $VIMRUNTIME might have a space.
- fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%*\n",
- exename, vimarg);
- fprintf(fd, ") else (\n");
- fprintf(fd, " start \"dummy\" /b ");
- // Always use quotes, $VIM or $VIMRUNTIME might have a space.
- fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%*\n",
- exename, vimarg);
- fprintf(fd, ")\n");
- }
- else
- {
- // Always use quotes, $VIM or $VIMRUNTIME might have a space.
- fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%*\n",
- exename, vimarg);
- }
+ need_uninstall_entry = 1;
- fclose(fd);
- printf("%s has been %s\n", batpath,
- oldname == NULL ? "created" : "overwritten");
- }
+ fprintf(fd, "@echo off\n");
+ fprintf(fd, "rem -- Run Vim --\n");
+ fprintf(fd, VIMBAT_UNINSTKEY "\n");
+ fprintf(fd, "\n");
+ fprintf(fd, "setlocal\n");
+
+ /*
+ * Don't use double quotes for the "set" argument, also when it
+ * contains a space. The quotes would be included in the value.
+ * The order of preference is:
+ * 1. $VIMRUNTIME/vim.exe (user preference)
+ * 2. $VIM/vim81/vim.exe (hard coded version)
+ * 3. installdir/vim.exe (hard coded install directory)
+ */
+ fprintf(fd, "set VIM_EXE_DIR=%s\n", installdir);
+ fprintf(fd, "if exist \"%%VIM%%\\%s\\%s\" set VIM_EXE_DIR=%%VIM%%\\%s\n",
+ VIM_VERSION_NODOT, exename, VIM_VERSION_NODOT);
+ fprintf(fd, "if exist \"%%VIMRUNTIME%%\\%s\" set VIM_EXE_DIR=%%VIMRUNTIME%%\n", exename);
+ fprintf(fd, "\n");
+
+ // Give an error message when the executable could not be found.
+ fprintf(fd, "if not exist \"%%VIM_EXE_DIR%%\\%s\" (\n", exename);
+ fprintf(fd, " echo \"%%VIM_EXE_DIR%%\\%s\" not found\n", exename);
+ fprintf(fd, " goto :eof\n");
+ fprintf(fd, ")\n");
+ fprintf(fd, "\n");
+
+ if (*exename == 'g')
+ {
+ fprintf(fd, "rem check --nofork argument\n");
+ fprintf(fd, "set VIMNOFORK=\n");
+ fprintf(fd, ":loopstart\n");
+ fprintf(fd, "if .%%1==. goto loopend\n");
+ fprintf(fd, "if .%%1==.--nofork (\n");
+ fprintf(fd, " set VIMNOFORK=1\n");
+ fprintf(fd, ") else if .%%1==.-f (\n");
+ fprintf(fd, " set VIMNOFORK=1\n");
+ fprintf(fd, ")\n");
+ fprintf(fd, "shift\n");
+ fprintf(fd, "goto loopstart\n");
+ fprintf(fd, ":loopend\n");
+ fprintf(fd, "\n");
+ }
+
+ if (*exename == 'g')
+ {
+ // For gvim.exe use "start /b" to avoid that the console window
+ // stays open.
+ fprintf(fd, "if .%%VIMNOFORK%%==.1 (\n");
+ fprintf(fd, " start \"dummy\" /b /wait ");
+ // Always use quotes, $VIM or $VIMRUNTIME might have a space.
+ fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%*\n",
+ exename, vimarg);
+ fprintf(fd, ") else (\n");
+ fprintf(fd, " start \"dummy\" /b ");
+ // Always use quotes, $VIM or $VIMRUNTIME might have a space.
+ fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%*\n",
+ exename, vimarg);
+ fprintf(fd, ")\n");
}
+ else
+ {
+ // Always use quotes, $VIM or $VIMRUNTIME might have a space.
+ fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%*\n",
+ exename, vimarg);
+ }
+
+ fclose(fd);
+ printf("%s has been %s\n", batpath,
+ oldname == NULL ? "created" : "overwritten");
}
/*
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 314a3f863d..56dc7b8e6a 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -3172,48 +3172,48 @@ 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->msg == NULL)
- rettv->vval.v_string = NULL;
- else
- rettv->vval.v_string = vim_strsave(balloonEval->msg);
- }
+ 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 (in_vim9script()
- && check_for_string_or_list_arg(argvars, 0) == FAIL)
- return;
+ if (balloonEval == NULL)
+ return;
- if (argvars[0].v_type == VAR_LIST
+ if (in_vim9script()
+ && check_for_string_or_list_arg(argvars, 0) == FAIL)
+ return;
+
+ if (argvars[0].v_type == VAR_LIST
# ifdef FEAT_GUI
- && !gui.in_use
+ && !gui.in_use
# endif
- )
- {
- list_T *l = argvars[0].vval.v_list;
+ )
+ {
+ list_T *l = argvars[0].vval.v_list;
- // empty list removes the balloon
- post_balloon(balloonEval, NULL,
- l == NULL || l->lv_len == 0 ? NULL : l);
- }
- else
- {
- char_u *mesg;
+ // empty list removes the balloon
+ post_balloon(balloonEval, NULL,
+ l == NULL || l->lv_len == 0 ? NULL : l);
+ }
+ else
+ {
+ char_u *mesg;
- if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
- return;
+ if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
+ return;
- mesg = tv_get_string_chk(&argvars[0]);
- if (mesg != NULL)
- // empty string removes the balloon
- post_balloon(balloonEval, *mesg == NUL ? NULL : mesg, NULL);
- }
+ mesg = tv_get_string_chk(&argvars[0]);
+ if (mesg != NULL)
+ // empty string removes the balloon
+ post_balloon(balloonEval, *mesg == NUL ? NULL : mesg, NULL);
}
}
@@ -3221,25 +3221,25 @@ f_balloon_show(typval_T *argvars, typval_T *rettv UNUSED)
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)
+ return;
+ msg = tv_get_string_chk(&argvars[0]);
+ if (msg != NULL)
{
- char_u *msg;
+ pumitem_T *array;
+ int size = split_message(msg, &array);
- if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
- return;
- msg = tv_get_string_chk(&argvars[0]);
- if (msg != NULL)
- {
- pumitem_T *array;
- int size = split_message(msg, &array);
-
- // Skip the first and last item, they are always empty.
- for (int i = 1; i < size - 1; ++i)
- list_append_string(rettv->vval.v_list, array[i].pum_text, -1);
- while (size > 0)
- vim_free(array[--size].pum_text);
- vim_free(array);
- }
+ // Skip the first and last item, they are always empty.
+ for (int i = 1; i < size - 1; ++i)
+ list_append_string(rettv->vval.v_list, array[i].pum_text, -1);
+ while (size > 0)
+ vim_free(array[--size].pum_text);
+ vim_free(array);
}
}
# endif
@@ -3676,18 +3676,18 @@ 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);
-
- if (hProcess != NULL)
- {
- DebugBreakProcess(hProcess);
- CloseHandle(hProcess);
- rettv->vval.v_number = OK;
- }
+ emsg(_(e_invalid_argument));
+ return;
}
+
+ HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
+ if (hProcess == NULL)
+ return;
+
+ DebugBreakProcess(hProcess);
+ CloseHandle(hProcess);
+ rettv->vval.v_number = OK;
}
#endif
@@ -3932,12 +3932,12 @@ 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)
- {
- mch_memmove((char *)redir_execute_ga.ga_data
- + redir_execute_ga.ga_len, value, len);
- redir_execute_ga.ga_len += len;
- }
+ 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,14 +5043,14 @@ 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)
- {
- dict_T *dict = rettv->vval.v_dict;
+ if (rettv_dict_alloc(rettv) != OK)
+ return;
- dict_add_string(dict, "char", last_csearch());
- dict_add_number(dict, "forward", last_csearch_forward());
- dict_add_number(dict, "until", last_csearch_until());
- }
+ 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());
}
/*
@@ -6792,29 +6792,29 @@ 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)
{
- CHECK_LIST_MATERIALIZE(l);
- item = l->lv_first;
- if (argvars[2].v_type != VAR_UNKNOWN)
+ // Start at specified item. Use the cached index that list_find()
+ // sets, so that a negative number also works.
+ item = list_find(l, (long)tv_get_number_chk(&argvars[2], &error));
+ idx = l->lv_u.mat.lv_idx;
+ if (argvars[3].v_type != VAR_UNKNOWN)
+ ic = (int)tv_get_bool_chk(&argvars[3], &error);
+ if (error)
+ item = NULL;
+ }
+
+ for ( ; item != NULL; item = item->li_next, ++idx)
+ if (tv_equal(&item->li_tv, &argvars[1], ic, FALSE))
{
- // Start at specified item. Use the cached index that list_find()
- // sets, so that a negative number also works.
- item = list_find(l, (long)tv_get_number_chk(&argvars[2], &error));
- idx = l->lv_u.mat.lv_idx;
- if (argvars[3].v_type != VAR_UNKNOWN)
- ic = (int)tv_get_bool_chk(&argvars[3], &error);
- if (error)
- item = NULL;
+ rettv->vval.v_number = idx;
+ break;
}
-
- for ( ; item != NULL; item = item->li_next, ++idx)
- if (tv_equal(&item->li_tv, &argvars[1], ic, FALSE))
- {
- rettv->vval.v_number = idx;
- break;
- }
- }
}
/*
@@ -8363,22 +8363,26 @@ 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
+ return;
+ }
+ if (stride > 0 ? end + 1 < start : end - 1 > start)
{
- list_T *list = rettv->vval.v_list;
-
- // Create a non-materialized list. This is much more efficient and
- // works with ":for". If used otherwise CHECK_LIST_MATERIALIZE() must
- // be called.
- list->lv_first = &range_list_item;
- list->lv_u.nonmat.lv_start = start;
- list->lv_u.nonmat.lv_end = end;
- list->lv_u.nonmat.lv_stride = stride;
- list->lv_len = (end - start) / stride + 1;
+ emsg(_(e_start_past_end));
+ return;
}
+
+ list_T *list = rettv->vval.v_list;
+
+ // Create a non-materialized list. This is much more efficient and
+ // works with ":for". If used otherwise CHECK_LIST_MATERIALIZE() must
+ // be called.
+ list->lv_first = &range_list_item;
+ list->lv_u.nonmat.lv_start = start;
+ list->lv_u.nonmat.lv_end = end;
+ list->lv_u.nonmat.lv_stride = stride;
+ list->lv_len = (end - start) / stride + 1;
}
/*
@@ -9382,34 +9386,34 @@ set_position(typval_T *argvars, typval_T *rettv, int charpos)
return;
name = tv_get_string_chk(argvars);
- if (name != NULL)
+ 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))
{
- if (list2fpos(&argvars[1], &pos, &fnum, &curswant, charpos) == OK)
+ // set cursor; "fnum" is ignored
+ curwin->w_cursor = pos;
+ if (curswant >= 0)
{
- if (pos.col != MAXCOL && --pos.col < 0)
- pos.col = 0;
- if ((name[0] == '.' && name[1] == NUL))
- {
- // set cursor; "fnum" is ignored
- curwin->w_cursor = pos;
- if (curswant >= 0)
- {
- curwin->w_curswant = curswant - 1;
- curwin->w_set_curswant = FALSE;
- }
- check_cursor();
- rettv->vval.v_number = 0;
- }
- else if (name[0] == '\'' && name[1] != NUL && name[2] == NUL)
- {
- // set mark
- if (setmark_pos(name[1], &pos, fnum) == OK)
- rettv->vval.v_number = 0;
- }
- else
- emsg(_(e_invalid_argument));
+ curwin->w_curswant = curswant - 1;
+ curwin->w_set_curswant = FALSE;
}
+ check_cursor();
+ rettv->vval.v_number = 0;
}
+ else if (name[0] == '\'' && name[1] != NUL && name[2] == NUL)
+ {
+ // set mark
+ if (setmark_pos(name[1], &pos, fnum) == OK)
+ rettv->vval.v_number = 0;
+ }
+ else
+ emsg(_(e_invalid_argument));
}
/*
* "setcharpos()" function
@@ -9430,32 +9434,32 @@ 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)
{
- csearch = dict_get_string(d, "char", FALSE);
- if (csearch != NULL)
+ if (enc_utf8)
{
- if (enc_utf8)
- {
- int pcc[MAX_MCO];
- int c = utfc_ptr2char(csearch, pcc);
+ int pcc[MAX_MCO];
+ int c = utfc_ptr2char(csearch, pcc);
- set_last_csearch(c, csearch, utfc_ptr2len(csearch));
- }
- else
- set_last_csearch(PTR2CHAR(csearch),
- csearch, mb_ptr2len(csearch));
+ set_last_csearch(c, csearch, utfc_ptr2len(csearch));
}
+ else
+ set_last_csearch(PTR2CHAR(csearch),
+ csearch, mb_ptr2len(csearch));
+ }
- di = dict_find(d, (char_u *)"forward", -1);
- if (di != NULL)
- set_csearch_direction((int)tv_get_number(&di->di_tv)
- ? FORWARD : BACKWARD);
+ di = dict_find(d, (char_u *)"forward", -1);
+ if (di != NULL)
+ set_csearch_direction((int)tv_get_number(&di->di_tv)
+ ? FORWARD : BACKWARD);
- di = dict_find(d, (char_u *)"until", -1);
- if (di != NULL)
- set_csearch_until(!!tv_get_number(&di->di_tv));
- }
+ di = dict_find(d, (char_u *)"until", -1);
+ if (di != NULL)
+ set_csearch_until(!!tv_get_number(&di->di_tv));
}
/*
diff --git a/src/evalvars.c b/src/evalvars.c
index d9466691f4..389a9e4d18 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -350,15 +350,15 @@ set_internal_string_var(char_u *name, char_u *value)
typval_T *tvp;
val = vim_strsave(value);
- if (val != NULL)
- {
- tvp = alloc_string_tv(val);
- if (tvp != NULL)
- {
- set_var(name, tvp, FALSE);
- free_tv(tvp);
- }
- }
+ if (val == NULL)
+ return;
+
+ tvp = alloc_string_tv(val);
+ if (tvp == NULL)
+ return;
+
+ set_var(name, tvp, FALSE);
+ free_tv(tvp);
}
int
@@ -576,14 +576,14 @@ 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)
- {
- 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");
- }
+ 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");
}
/*
@@ -2740,11 +2740,11 @@ 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)
- {
- ++val->dv_refcount;
- dict_set_items_ro(val);
- }
+ if (val == NULL)
+ return;
+
+ ++val->dv_refcount;
+ dict_set_items_ro(val);
}
/*
@@ -3562,11 +3562,11 @@ delete_var(hashtab_T *ht, hashitem_T *hi)
{
dictitem_T *di = HI2DI(hi);
- if (hash_remove(ht, hi, "delete variable") == OK)
- {
- clear_tv(&di->di_tv);
- vim_free(di);
- }
+ if (hash_remove(ht, hi, "delete variable") != OK)
+ return;
+
+ clear_tv(&di->di_tv);
+ vim_free(di);
}
/*
@@ -4317,29 +4317,29 @@ 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)
{
- need_switch_win = !(tp == curtab && win == curwin);
- if (!need_switch_win
- || switch_win(&switchwin, win, tp, TRUE) == OK)
+ if (*varname == '&')
+ set_option_from_tv(varname + 1, varp);
+ else
{
- if (*varname == '&')
- set_option_from_tv(varname + 1, varp);
- else
+ winvarname = alloc(STRLEN(varname) + 3);
+ if (winvarname != NULL)
{
- winvarname = alloc(STRLEN(varname) + 3);
- if (winvarname != NULL)
- {
- STRCPY(winvarname, "w:");
- STRCPY(winvarname + 2, varname);
- set_var(winvarname, varp, TRUE);
- vim_free(winvarname);
- }
+ STRCPY(winvarname, "w:");
+ STRCPY(winvarname + 2, varname);
+ set_var(winvarname, varp, TRUE);
+ vim_free(winvarname);
}
}
- if (need_switch_win)
- restore_win(&switchwin, TRUE);
}
+ if (need_switch_win)
+ restore_win(&switchwin, TRUE);
}
/*
@@ -4686,24 +4686,24 @@ 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)
- {
- save_curtab = curtab;
- goto_tabpage_tp(tp, FALSE, FALSE);
+ if (varname == NULL || varp == NULL || tp == NULL)
+ return;
- tabvarname = alloc(STRLEN(varname) + 3);
- if (tabvarname != NULL)
- {
- STRCPY(tabvarname, "t:");
- STRCPY(tabvarname + 2, varname);
- set_var(tabvarname, varp, TRUE);
- vim_free(tabvarname);
- }
+ save_curtab = curtab;
+ goto_tabpage_tp(tp, FALSE, FALSE);
- // Restore current tabpage
- if (valid_tabpage(save_curtab))
- goto_tabpage_tp(save_curtab, FALSE, FALSE);
+ tabvarname = alloc(STRLEN(varname) + 3);
+ if (tabvarname != NULL)
+ {
+ STRCPY(tabvarname, "t:");
+ STRCPY(tabvarname + 2, varname);
+ set_var(tabvarname, varp, TRUE);
+ vim_free(tabvarname);
}
+
+ // Restore current tabpage
+ if (valid_tabpage(save_curtab))
+ goto_tabpage_tp(save_curtab, FALSE, FALSE);
}
/*
@@ -4757,37 +4757,37 @@ 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 == '&')
{
- if (*varname == '&')
- {
- aco_save_T aco;
+ aco_save_T aco;
- // Set curbuf to be our buf, temporarily.
- aucmd_prepbuf(&aco, buf);
- if (curbuf == buf)
- {
- // Only when it worked to set "curbuf".
- set_option_from_tv(varname + 1, varp);
+ // Set curbuf to be our buf, temporarily.
+ aucmd_prepbuf(&aco, buf);
+ if (curbuf == buf)
+ {
+ // Only when it worked to set "curbuf".
+ set_option_from_tv(varname + 1, varp);
- // reset notion of buffer
- aucmd_restbuf(&aco);
- }
+ // reset notion of buffer
+ aucmd_restbuf(&aco);
}
- else
+ }
+ else
+ {
+ bufvarname = alloc(STRLEN(varname) + 3);
+ if (bufvarname != NULL)
{
- bufvarname = alloc(STRLEN(varname) + 3);
- if (bufvarname != NULL)
- {
- buf_T *save_curbuf = curbuf;
-
- curbuf = buf;
- STRCPY(bufvarname, "b:");