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,56 +693,56 @@ do_argfile(exarg_T *eap, int argn)
emsg(_(e_cannot_go_before_first_file)); emsg(_(e_cannot_go_before_first_file));
else else
emsg(_(e_cannot_go_beyond_last_file)); emsg(_(e_cannot_go_beyond_last_file));
return;
}
setpcmark();
#ifdef FEAT_GUI
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 else
{ {
setpcmark(); // if 'hidden' set, only check for changed file when re-editing
#ifdef FEAT_GUI // the same buffer
need_mouse_correct = TRUE; other = TRUE;
#endif if (buf_hide(curbuf))
// split window or create new tab page first
if (*eap->cmd == 's' || cmdmod.cmod_tab != 0)
{ {
if (win_split(0, 0) == FAIL) p = fix_fname(alist_name(&ARGLIST[argn]));
return; other = otherfile(p);
RESET_BINDING(curwin); vim_free(p);
} }
else if ((!buf_hide(curbuf) || !other)
{ && check_changed(curbuf, CCGD_AW
// if 'hidden' set, only check for changed file when re-editing | (other ? 0 : CCGD_MULTWIN)
// the same buffer | (eap->forceit ? CCGD_FORCEIT : 0)
other = TRUE; | CCGD_EXCMD))
if (buf_hide(curbuf)) return;
{
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;
}
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('\'');
} }
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('\'');
} }
/* /*

View File

@@ -146,19 +146,19 @@ read_buffer(
void void
buffer_ensure_loaded(buf_T *buf) 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. aco_save_T aco;
aucmd_prepbuf(&aco, buf);
if (curbuf == buf) // Make sure the buffer is in a window. If not then skip it.
{ aucmd_prepbuf(&aco, buf);
if (swap_exists_action != SEA_READONLY) if (curbuf == buf)
swap_exists_action = SEA_NONE; {
open_buffer(FALSE, NULL, 0); if (swap_exists_action != SEA_READONLY)
aucmd_restbuf(&aco); swap_exists_action = SEA_NONE;
} open_buffer(FALSE, NULL, 0);
aucmd_restbuf(&aco);
} }
} }
#endif #endif
@@ -3582,18 +3582,18 @@ buf_set_name(int fnum, char_u *name)
buf_T *buf; buf_T *buf;
buf = buflist_findnr(fnum); buf = buflist_findnr(fnum);
if (buf != NULL) if (buf == NULL)
{ return;
if (buf->b_sfname != buf->b_ffname)
vim_free(buf->b_sfname); if (buf->b_sfname != buf->b_ffname)
vim_free(buf->b_ffname); vim_free(buf->b_sfname);
buf->b_ffname = vim_strsave(name); vim_free(buf->b_ffname);
buf->b_sfname = NULL; buf->b_ffname = vim_strsave(name);
// Allocate ffname and expand into full path. Also resolves .lnk buf->b_sfname = NULL;
// files on Win32. // Allocate ffname and expand into full path. Also resolves .lnk
fname_expand(buf, &buf->b_ffname, &buf->b_sfname); // files on Win32.
buf->b_fname = buf->b_sfname; 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 void
set_buflisted(int on) set_buflisted(int on)
{ {
if (on != curbuf->b_p_bl) if (on == curbuf->b_p_bl)
{ return;
curbuf->b_p_bl = on;
if (on) curbuf->b_p_bl = on;
apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, curbuf); if (on)
else apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, curbuf);
apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf); else
} apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf);
} }
/* /*

View File

@@ -191,38 +191,38 @@ static char_u *build_drop_cmd(int filec, char **filev, int tabs, int sendReply);
void void
exec_on_server(mparm_T *parmp) 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();
# 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)
{ {
# ifdef MSWIN cmdsrv_main(&parmp->argc, parmp->argv,
// Initialise the client/server messaging infrastructure. parmp->serverName_arg, &parmp->serverStr);
serverInitMessaging(); parmp->serverStrEnc = vim_strsave(p_enc);
# 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);
}
// 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 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
} }
/* /*

View File

@@ -830,87 +830,88 @@ install_bat_choice(int idx)
char *vimarg = targets[choices[idx].arg].exearg; char *vimarg = targets[choices[idx].arg].exearg;
FILE *fd; FILE *fd;
if (*batpath != NUL) if (*batpath == NUL)
return;
fd = fopen(batpath, "w");
if (fd == NULL)
{ {
fd = fopen(batpath, "w"); printf("\nERROR: Cannot open \"%s\" for writing.\n", batpath);
if (fd == NULL) return;
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");
}
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");
}
} }
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");
}
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");
} }
/* /*

View File

@@ -3172,48 +3172,48 @@ f_and(typval_T *argvars, typval_T *rettv)
f_balloon_gettext(typval_T *argvars UNUSED, typval_T *rettv) f_balloon_gettext(typval_T *argvars UNUSED, typval_T *rettv)
{ {
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
if (balloonEval != NULL) if (balloonEval == NULL)
{ return;
if (balloonEval->msg == NULL)
rettv->vval.v_string = NULL; if (balloonEval->msg == NULL)
else rettv->vval.v_string = NULL;
rettv->vval.v_string = vim_strsave(balloonEval->msg); else
} rettv->vval.v_string = vim_strsave(balloonEval->msg);
} }
static void static void
f_balloon_show(typval_T *argvars, typval_T *rettv UNUSED) 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;
if (argvars[0].v_type == VAR_LIST
# ifdef FEAT_GUI
&& !gui.in_use
# endif
)
{ {
if (in_vim9script() list_T *l = argvars[0].vval.v_list;
&& check_for_string_or_list_arg(argvars, 0) == FAIL)
// 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; return;
if (argvars[0].v_type == VAR_LIST mesg = tv_get_string_chk(&argvars[0]);
# ifdef FEAT_GUI if (mesg != NULL)
&& !gui.in_use // empty string removes the balloon
# endif post_balloon(balloonEval, *mesg == NUL ? NULL : mesg, NULL);
)
{
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;
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);
}
} }
} }
@@ -3221,25 +3221,25 @@ f_balloon_show(typval_T *argvars, typval_T *rettv UNUSED)
static void static void
f_balloon_split(typval_T *argvars, typval_T *rettv UNUSED) 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) // Skip the first and last item, they are always empty.
return; for (int i = 1; i < size - 1; ++i)
msg = tv_get_string_chk(&argvars[0]); list_append_string(rettv->vval.v_list, array[i].pum_text, -1);
if (msg != NULL) while (size > 0)
{ vim_free(array[--size].pum_text);
pumitem_T *array; vim_free(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);
}
} }
} }
# endif # endif
@@ -3676,18 +3676,18 @@ f_debugbreak(typval_T *argvars, typval_T *rettv)
pid = (int)tv_get_number(&argvars[0]); pid = (int)tv_get_number(&argvars[0]);
if (pid == 0) if (pid == 0)
emsg(_(e_invalid_argument));
else
{ {
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, pid); emsg(_(e_invalid_argument));
return;
if (hProcess != NULL)
{
DebugBreakProcess(hProcess);
CloseHandle(hProcess);
rettv->vval.v_number = OK;
}
} }
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
if (hProcess == NULL)
return;
DebugBreakProcess(hProcess);
CloseHandle(hProcess);
rettv->vval.v_number = OK;
} }
#endif #endif
@@ -3932,12 +3932,12 @@ execute_redir_str(char_u *value, int value_len)
len = (int)STRLEN(value); // Append the entire string len = (int)STRLEN(value); // Append the entire string
else else
len = value_len; // Append only "value_len" characters 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); mch_memmove((char *)redir_execute_ga.ga_data
redir_execute_ga.ga_len += len; + redir_execute_ga.ga_len, value, len);
} redir_execute_ga.ga_len += len;
} }
#if defined(FEAT_LUA) || defined(PROTO) #if defined(FEAT_LUA) || defined(PROTO)
@@ -5043,14 +5043,14 @@ f_getcharpos(typval_T *argvars UNUSED, typval_T *rettv)
static void static void
f_getcharsearch(typval_T *argvars UNUSED, typval_T *rettv) 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_T *dict = rettv->vval.v_dict;
dict_add_number(dict, "forward", last_csearch_forward());
dict_add_number(dict, "until", last_csearch_until()); 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; 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)
{
// 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) CHECK_LIST_MATERIALIZE(l);
if (tv_equal(&item->li_tv, &argvars[1], ic, FALSE)) item = l->lv_first;
{ if (argvars[2].v_type != VAR_UNKNOWN)
rettv->vval.v_number = idx; {
break; // 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))
{
rettv->vval.v_number = idx;
break;
}
} }
/* /*
@@ -8363,22 +8363,26 @@ f_range(typval_T *argvars, typval_T *rettv)
if (error) if (error)
return; // type error; errmsg already given return; // type error; errmsg already given
if (stride == 0) if (stride == 0)
emsg(_(e_stride_is_zero));
else if (stride > 0 ? end + 1 < start : end - 1 > start)
emsg(_(e_start_past_end));
else
{ {
list_T *list = rettv->vval.v_list; emsg(_(e_stride_is_zero));
return;
// 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;
} }
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
// 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; return;
name = tv_get_string_chk(argvars); 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) curwin->w_curswant = curswant - 1;
pos.col = 0; curwin->w_set_curswant = FALSE;
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));
} }
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 * "setcharpos()" function
@@ -9430,32 +9434,32 @@ f_setcharsearch(typval_T *argvars, typval_T *rettv UNUSED)
if (check_for_dict_arg(argvars, 0) == FAIL) if (check_for_dict_arg(argvars, 0) == FAIL)
return; 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 (enc_utf8)
if (csearch != NULL)
{ {
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)); set_last_csearch(c, csearch, utfc_ptr2len(csearch));
}
else
set_last_csearch(PTR2CHAR(csearch),
csearch, mb_ptr2len(csearch));
} }
else
di = dict_find(d, (char_u *)"forward", -1); set_last_csearch(PTR2CHAR(csearch),
if (di != NULL) csearch, mb_ptr2len(csearch));
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 *)"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));
} }
/* /*

View File

@@ -350,15 +350,15 @@ set_internal_string_var(char_u *name, char_u *value)
typval_T *tvp; typval_T *tvp;
val = vim_strsave(value); val = vim_strsave(value);
if (val != NULL) if (val == NULL)
{ return;
tvp = alloc_string_tv(val);
if (tvp != NULL) tvp = alloc_string_tv(val);
{ if (tvp == NULL)
set_var(name, tvp, FALSE); return;
free_tv(tvp);
} set_var(name, tvp, FALSE);
} free_tv(tvp);
} }
int int
@@ -576,14 +576,14 @@ restore_vimvar(int idx, typval_T *save_tv)
hashitem_T *hi; hashitem_T *hi;
vimvars[idx].vv_tv = *save_tv; 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)) hi = hash_find(&vimvarht, vimvars[idx].vv_di.di_key);
internal_error("restore_vimvar()"); if (HASHITEM_EMPTY(hi))
else internal_error("restore_vimvar()");
hash_remove(&vimvarht, hi, "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); clear_tv(&vimvars[idx].vv_di.di_tv);
vimvars[idx].vv_tv_type = VAR_DICT; vimvars[idx].vv_tv_type = VAR_DICT;
vimvars[idx].vv_dict = val; vimvars[idx].vv_dict = val;
if (val != NULL) if (val == NULL)
{ return;
++val->dv_refcount;
dict_set_items_ro(val); ++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); 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); 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]); varname = tv_get_string_chk(&argvars[off + 1]);
varp = &argvars[off + 2]; 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 (*varname == '&')
if (!need_switch_win set_option_from_tv(varname + 1, varp);
|| switch_win(&switchwin, win, tp, TRUE) == OK) else
{ {
if (*varname == '&') winvarname = alloc(STRLEN(varname) + 3);
set_option_from_tv(varname + 1, varp); if (winvarname != NULL)
else
{ {
winvarname = alloc(STRLEN(varname) + 3); STRCPY(winvarname, "w:");
if (winvarname != NULL) STRCPY(winvarname + 2, varname);
{ set_var(winvarname, varp, TRUE);
STRCPY(winvarname, "w:"); vim_free(winvarname);
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]); varname = tv_get_string_chk(&argvars[1]);
varp = &argvars[2]; 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);
tabvarname = alloc(STRLEN(varname) + 3);
if (tabvarname != NULL)
{ {
save_curtab = curtab; STRCPY(tabvarname, "t:");
goto_tabpage_tp(tp, FALSE, FALSE); STRCPY(tabvarname + 2, varname);
set_var(tabvarname, varp, TRUE);
tabvarname = alloc(STRLEN(varname) + 3); vim_free(tabvarname);
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);
} }
// 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]); buf = tv_get_buf_from_arg(&argvars[0]);
varp = &argvars[2]; 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;
// Set curbuf to be our buf, temporarily.
aucmd_prepbuf(&aco, buf);
if (curbuf == buf)
{ {
aco_save_T aco; // Only when it worked to set "curbuf".
set_option_from_tv(varname + 1, varp);
// Set curbuf to be our buf, temporarily. // reset notion of buffer
aucmd_prepbuf(&aco, buf); aucmd_restbuf(&aco);
if (curbuf == buf)
{
// Only when it worked to set "curbuf".
set_option_from_tv(varname + 1, varp);
// reset notion of buffer
aucmd_restbuf(&aco);
}
} }
else }
else
{
bufvarname = alloc(STRLEN(varname) + 3);
if (bufvarname != NULL)
{ {
bufvarname = alloc(STRLEN(varname) + 3); buf_T *save_curbuf = curbuf;
if (bufvarname != NULL)
{
buf_T *save_curbuf = curbuf;
curbuf = buf; curbuf = buf;
STRCPY(bufvarname, "b:"); STRCPY(bufvarname, "b:");
STRCPY(bufvarname + 2, varname); STRCPY(bufvarname + 2, varname);
set_var(bufvarname, varp, TRUE); set_var(bufvarname, varp, TRUE);
vim_free(bufvarname); vim_free(bufvarname);
curbuf = save_curbuf; curbuf = save_curbuf;
}
} }
} }
} }
@@ -4930,31 +4930,30 @@ expand_autload_callback(callback_T *cb)
p = vim_strchr(name, '.'); p = vim_strchr(name, '.');
if (p == NULL) if (p == NULL)
return; return;
import = find_imported(name, p - name, FALSE); 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;
char_u *newname = concat_str(si->sn_autoload_prefix, p + 1);
if (newname == NULL)
return;
if (cb->cb_partial != NULL)
{ {
scriptitem_T *si = SCRIPT_ITEM(import->imp_sid); if (cb->cb_name == cb->cb_partial->pt_name)
cb->cb_name = newname;
if (si->sn_autoload_prefix != NULL) vim_free(cb->cb_partial->pt_name);
{ cb->cb_partial->pt_name = newname;
char_u *newname = concat_str(si->sn_autoload_prefix, p + 1); }
else
if (newname != NULL) {
{ vim_free(cb->cb_name);
if (cb->cb_partial != NULL) cb->cb_name = newname;
{
if (cb->cb_name == cb->cb_partial->pt_name)
cb->cb_name = newname;
vim_free(cb->cb_partial->pt_name);
cb->cb_partial->pt_name = newname;
}
else
{
vim_free(cb->cb_name);
cb->cb_name = newname;
}
}
}
} }
} }

View File

@@ -718,66 +718,66 @@ f_win_execute(typval_T *argvars, typval_T *rettv)
id = (int)tv_get_number(argvars); id = (int)tv_get_number(argvars);
wp = win_id2wp_tp(id, &tp); 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;
#ifdef FEAT_AUTOCHDIR
char_u autocwd[MAXPATHL];
int apply_acd = FALSE;
#endif
// Getting and setting directory can be slow on some systems, only do
// this when the current or target window/tab have a local directory or
// 'acd' is set.
if (curwin != wp
&& (curwin->w_localdir != NULL
|| wp->w_localdir != NULL
|| (curtab != tp
&& (curtab->tp_localdir != NULL
|| tp->tp_localdir != NULL))
#ifdef FEAT_AUTOCHDIR
|| p_acd
#endif
))
cwd_status = mch_dirname(cwd, MAXPATHL);
#ifdef FEAT_AUTOCHDIR
// If 'acd' is set, check we are using that directory. If yes, then
// apply 'acd' afterwards, otherwise restore the current directory.
if (cwd_status == OK && p_acd)
{ {
pos_T curpos = wp->w_cursor; do_autochdir();
char_u cwd[MAXPATHL]; apply_acd = mch_dirname(autocwd, MAXPATHL) == OK
int cwd_status = FAIL; && STRCMP(cwd, autocwd) == 0;
#ifdef FEAT_AUTOCHDIR }
char_u autocwd[MAXPATHL];
int apply_acd = FALSE;
#endif #endif
// Getting and setting directory can be slow on some systems, only do if (switch_win_noblock(&switchwin, wp, tp, TRUE) == OK)
// this when the current or target window/tab have a local directory or {
// 'acd' is set. check_cursor();
if (curwin != wp execute_common(argvars, rettv, 1);
&& (curwin->w_localdir != NULL }
|| wp->w_localdir != NULL restore_win_noblock(&switchwin, TRUE);
|| (curtab != tp
&& (curtab->tp_localdir != NULL
|| tp->tp_localdir != NULL))
#ifdef FEAT_AUTOCHDIR #ifdef FEAT_AUTOCHDIR
|| p_acd if (apply_acd)
do_autochdir();
else
#endif #endif
)) if (cwd_status == OK)
cwd_status = mch_dirname(cwd, MAXPATHL);
#ifdef FEAT_AUTOCHDIR
// If 'acd' is set, check we are using that directory. If yes, then
// apply 'acd' afterwards, otherwise restore the current directory.
if (cwd_status == OK && p_acd)
{
do_autochdir();
apply_acd = mch_dirname(autocwd, MAXPATHL) == OK
&& STRCMP(cwd, autocwd) == 0;
}
#endif
if (switch_win_noblock(&switchwin, wp, tp, TRUE) == OK)
{
check_cursor();
execute_common(argvars, rettv, 1);
}
restore_win_noblock(&switchwin, TRUE);
#ifdef FEAT_AUTOCHDIR
if (apply_acd)
do_autochdir();
else
#endif
if (cwd_status == OK)
mch_chdir((char *)cwd); mch_chdir((char *)cwd);
// Update the status line if the cursor moved. // Update the status line if the cursor moved.
if (win_valid(wp) && !EQUAL_POS(curpos, wp->w_cursor)) if (win_valid(wp) && !EQUAL_POS(curpos, wp->w_cursor))
wp->w_redr_status = TRUE; wp->w_redr_status = TRUE;
// In case the command moved the cursor or changed the Visual area, // In case the command moved the cursor or changed the Visual area,
// check it is valid. // check it is valid.
check_cursor(); check_cursor();
if (VIsual_active) if (VIsual_active)
check_pos(curbuf, &VIsual); check_pos(curbuf, &VIsual);
}
} }
/* /*
@@ -1093,11 +1093,11 @@ f_getcmdwintype(typval_T *argvars UNUSED, typval_T *rettv)
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL; rettv->vval.v_string = NULL;
rettv->vval.v_string = alloc(2); 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; rettv->vval.v_string[0] = cmdwin_type;
} rettv->vval.v_string[1] = NUL;
} }
/* /*

View File

@@ -7049,12 +7049,12 @@ ex_find(exarg_T *eap)
} }
} }
if (fname != NULL) if (fname == NULL)
{ return;
eap->arg = fname;
do_exedit(eap, NULL); eap->arg = fname;
vim_free(fname); do_exedit(eap, NULL);
} vim_free(fname);
} }
/* /*

View File

@@ -4210,11 +4210,11 @@ f_getcmdtype(typval_T *argvars UNUSED, typval_T *rettv)
{ {
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
rettv->vval.v_string = alloc(2); 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; rettv->vval.v_string[0] = get_cmdline_type();
} rettv->vval.v_string[1] = NUL;
} }
// Set the command line str to "str". // Set the command line str to "str".

View File

@@ -2767,15 +2767,15 @@ set_file_options(int set_options, exarg_T *eap)
void void
set_forced_fenc(exarg_T *eap) 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) char_u *fenc = enc_canonize(eap->cmd + eap->force_enc);
set_string_option_direct((char_u *)"fenc", -1,
fenc, OPT_FREE|OPT_LOCAL, 0); if (fenc != NULL)
vim_free(fenc); set_string_option_direct((char_u *)"fenc", -1,
} fenc, OPT_FREE|OPT_LOCAL, 0);
vim_free(fenc);
} }
/* /*
@@ -5070,12 +5070,11 @@ vim_opentempdir(void)
return; return;
dp = opendir((const char*)vim_tempdir); dp = opendir((const char*)vim_tempdir);
if (dp == NULL)
return;
if (dp != NULL) vim_tempdir_dp = dp;
{ flock(dirfd(vim_tempdir_dp), LOCK_SH);
vim_tempdir_dp = dp;
flock(dirfd(vim_tempdir_dp), LOCK_SH);
}
} }
/* /*
@@ -5084,11 +5083,11 @@ vim_opentempdir(void)
static void static void
vim_closetempdir(void) vim_closetempdir(void)
{ {
if (vim_tempdir_dp != NULL) if (vim_tempdir_dp == NULL)
{ return;
closedir(vim_tempdir_dp);
vim_tempdir_dp = NULL; closedir(vim_tempdir_dp);
} vim_tempdir_dp = NULL;
} }
# endif # endif
@@ -5098,16 +5097,16 @@ vim_closetempdir(void)
void void
vim_deltempdir(void) vim_deltempdir(void)
{ {
if (vim_tempdir != NULL) if (vim_tempdir == NULL)
{ return;
# if defined(UNIX) && defined(HAVE_FLOCK) && defined(HAVE_DIRFD) # if defined(UNIX) && defined(HAVE_FLOCK) && defined(HAVE_DIRFD)
vim_closetempdir(); vim_closetempdir();
# endif # endif
// remove the trailing path separator // remove the trailing path separator
gettail(vim_tempdir)[-1] = NUL; gettail(vim_tempdir)[-1] = NUL;
delete_recursive(vim_tempdir); delete_recursive(vim_tempdir);
VIM_CLEAR(vim_tempdir); VIM_CLEAR(vim_tempdir);
}
} }
/* /*
@@ -5121,17 +5120,17 @@ vim_settempdir(char_u *tempdir)
char_u *buf; char_u *buf;
buf = alloc(MAXPATHL + 2); buf = alloc(MAXPATHL + 2);
if (buf != NULL) if (buf == NULL)
{ return;
if (vim_FullName(tempdir, buf, MAXPATHL, FALSE) == FAIL)
STRCPY(buf, tempdir); if (vim_FullName(tempdir, buf, MAXPATHL, FALSE) == FAIL)
add_pathsep(buf); STRCPY(buf, tempdir);
vim_tempdir = vim_strsave(buf); add_pathsep(buf);
vim_tempdir = vim_strsave(buf);
# if defined(UNIX) && defined(HAVE_FLOCK) && defined(HAVE_DIRFD) # if defined(UNIX) && defined(HAVE_FLOCK) && defined(HAVE_DIRFD)
vim_opentempdir(); vim_opentempdir();
# endif # endif
vim_free(buf); vim_free(buf);
}
} }
#endif #endif

View File

@@ -288,15 +288,15 @@ f_float2nr(typval_T *argvars, typval_T *rettv)
if (in_vim9script() && check_for_float_or_nr_arg(argvars, 0) == FAIL) if (in_vim9script() && check_for_float_or_nr_arg(argvars, 0) == FAIL)
return; 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; if (f <= (float_T)-VARNUM_MAX + DBL_EPSILON)
else if (f >= (float_T)VARNUM_MAX - DBL_EPSILON) rettv->vval.v_number = -VARNUM_MAX;
rettv->vval.v_number = VARNUM_MAX; else if (f >= (float_T)VARNUM_MAX - DBL_EPSILON)
else rettv->vval.v_number = VARNUM_MAX;
rettv->vval.v_number = (varnumber_T)f; else
} rettv->vval.v_number = (varnumber_T)f;
} }
/* /*

View File

@@ -644,59 +644,59 @@ foldCreate(linenr_T start, linenr_T end)
i = (int)(fp - (fold_T *)gap->ga_data); 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);
// Count number of folds that will be contained in the new fold.
for (cont = 0; i + cont < gap->ga_len; ++cont)
if (fp[cont].fd_top > end_rel)
break;
if (cont > 0 && ga_grow(&fold_ga, cont) == OK)
{ {
fp = (fold_T *)gap->ga_data + i; // If the first fold starts before the new fold, let the new fold
ga_init2(&fold_ga, sizeof(fold_T), 10); // start there. Otherwise the existing fold would change.
if (start_rel > fp->fd_top)
start_rel = fp->fd_top;
// Count number of folds that will be contained in the new fold. // When last contained fold isn't completely contained, adjust end
for (cont = 0; i + cont < gap->ga_len; ++cont) // of new fold.
if (fp[cont].fd_top > end_rel) if (end_rel < fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1)
break; end_rel = fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1;
if (cont > 0 && ga_grow(&fold_ga, cont) == OK) // Move contained folds to inside new fold.
{ mch_memmove(fold_ga.ga_data, fp, sizeof(fold_T) * cont);
// If the first fold starts before the new fold, let the new fold fold_ga.ga_len += cont;
// start there. Otherwise the existing fold would change. i += cont;
if (start_rel > fp->fd_top)
start_rel = fp->fd_top;
// When last contained fold isn't completely contained, adjust end // Adjust line numbers in contained folds to be relative to the
// of new fold. // new fold.
if (end_rel < fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1) for (j = 0; j < cont; ++j)
end_rel = fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1; ((fold_T *)fold_ga.ga_data)[j].fd_top -= start_rel;
// Move contained folds to inside new fold.
mch_memmove(fold_ga.ga_data, fp, sizeof(fold_T) * cont);
fold_ga.ga_len += cont;
i += cont;
// Adjust line numbers in contained folds to be relative to the
// new fold.
for (j = 0; j < cont; ++j)
((fold_T *)fold_ga.ga_data)[j].fd_top -= start_rel;
}
// Move remaining entries to after the new fold.
if (i < gap->ga_len)
mch_memmove(fp + 1, (fold_T *)gap->ga_data + i,
sizeof(fold_T) * (gap->ga_len - i));
gap->ga_len = gap->ga_len + 1 - cont;
// insert new fold
fp->fd_nested = fold_ga;
fp->fd_top = start_rel;
fp->fd_len = end_rel - start_rel + 1;
// We want the new fold to be closed. If it would remain open because
// of using 'foldlevel', need to adjust fd_flags of containing folds.
if (use_level && !closed && level < curwin->w_p_fdl)
closeFold(start, 1L);
if (!use_level)
curwin->w_fold_manual = TRUE;
fp->fd_flags = FD_CLOSED;
fp->fd_small = MAYBE;
// redraw
changed_window_setting();
} }
// Move remaining entries to after the new fold.
if (i < gap->ga_len)
mch_memmove(fp + 1, (fold_T *)gap->ga_data + i,
sizeof(fold_T) * (gap->ga_len - i));
gap->ga_len = gap->ga_len + 1 - cont;
// insert new fold
fp->fd_nested = fold_ga;
fp->fd_top = start_rel;
fp->fd_len = end_rel - start_rel + 1;
// We want the new fold to be closed. If it would remain open because
// of using 'foldlevel', need to adjust fd_flags of containing folds.
if (use_level && !closed && level < curwin->w_p_fdl)
closeFold(start, 1L);
if (!use_level)
curwin->w_fold_manual = TRUE;
fp->fd_flags = FD_CLOSED;
fp->fd_small = MAYBE;
// redraw
changed_window_setting();
} }
// deleteFold() {{{2 // deleteFold() {{{2
@@ -1719,27 +1719,27 @@ checkSmall(
int count; int count;
int n; int n;
if (fp->fd_small == MAYBE) if (fp->fd_small != MAYBE)
{ return;
// Mark any nested folds to maybe-small
setSmallMaybe(&fp->fd_nested);
if (fp->fd_len > curwin->w_p_fml) // Mark any nested folds to maybe-small
fp->fd_small = FALSE; setSmallMaybe(&fp->fd_nested);
else
if (fp->fd_len > curwin->w_p_fml)
fp->fd_small = FALSE;
else
{
count = 0;
for (n = 0; n < fp->fd_len; ++n)
{ {
count = 0; count += plines_win_nofold(wp, fp->fd_top + lnum_off + n);
for (n = 0; n < fp->fd_len; ++n) if (count > curwin->w_p_fml)
{ {
count += plines_win_nofold(wp, fp->fd_top + lnum_off + n); fp->fd_small = FALSE;
if (count > curwin->w_p_fml) return;
{
fp->fd_small = FALSE;
return;
}
} }
fp->fd_small = TRUE;
} }
fp->fd_small = TRUE;
} }
} }
@@ -1799,26 +1799,26 @@ foldAddMarker(linenr_T lnum, char_u *marker, int markerlen)
line = ml_get(lnum); line = ml_get(lnum);
line_len = (int)STRLEN(line); 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);
if (newline == NULL)
return;
STRCPY(newline, line);
// Append the marker to the end of the line
if (p == NULL || line_is_comment)
vim_strncpy(newline + line_len, marker, markerlen);
else
{
STRCPY(newline + line_len, cms);
STRNCPY(newline + line_len + (p - cms), marker, markerlen);
STRCPY(newline + line_len + (p - cms) + markerlen, p + 2);
}
ml_replace(lnum, newline, FALSE); // 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);
if (newline == NULL)
return;
STRCPY(newline, line);
// Append the marker to the end of the line
if (p == NULL || line_is_comment)
vim_strncpy(newline + line_len, marker, markerlen);
else
{
STRCPY(newline + line_len, cms);
STRNCPY(newline + line_len + (p - cms), marker, markerlen);
STRCPY(newline + line_len + (p - cms) + markerlen, p + 2);
} }
ml_replace(lnum, newline, FALSE);
} }
// deleteFoldMarkers() {{{2 // deleteFoldMarkers() {{{2

View File

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