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,50 +631,52 @@ void do_argfile(exarg_T *eap, int argn)
} else { } else {
emsg(_("E165: Cannot go beyond last file")); emsg(_("E165: Cannot go beyond last file"));
} }
return;
}
setpcmark();
// 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
// the same buffer
// split window or create new tab page first other = true;
if (*eap->cmd == 's' || cmdmod.cmod_tab != 0) { if (buf_hide(curbuf)) {
if (win_split(0, 0) == FAIL) { p = fix_fname(alist_name(&ARGLIST[argn]));
return; other = otherfile(p);
} xfree(p);
RESET_BINDING(curwin);
} else {
// 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);
xfree(p);
}
if ((!buf_hide(curbuf) || !other)
&& check_changed(curbuf, CCGD_AW
| (other ? 0 : CCGD_MULTWIN)
| (eap->forceit ? CCGD_FORCEIT : 0)
| CCGD_EXCMD)) {
return;
}
} }
if ((!buf_hide(curbuf) || !other)
curwin->w_arg_idx = argn; && check_changed(curbuf, CCGD_AW
if (argn == ARGCOUNT - 1 && curwin->w_alist == &global_alist) { | (other ? 0 : CCGD_MULTWIN)
arg_had_last = true; | (eap->forceit ? CCGD_FORCEIT : 0)
| CCGD_EXCMD)) {
return;
} }
}
// Edit the file; always use the last known line number. curwin->w_arg_idx = argn;
// When it fails (e.g. Abort for already edited file) restore the if (argn == ARGCOUNT - 1 && curwin->w_alist == &global_alist) {
// argument index. arg_had_last = true;
if (do_ecmd(0, alist_name(&ARGLIST[curwin->w_arg_idx]), NULL, }
eap, ECMD_LAST,
(buf_hide(curwin->w_buffer) ? ECMD_HIDE : 0) // Edit the file; always use the last known line number.
+ (eap->forceit ? ECMD_FORCEIT : 0), curwin) == FAIL) { // When it fails (e.g. Abort for already edited file) restore the
curwin->w_arg_idx = old_arg_idx; // argument index.
} else if (eap->cmdidx != CMD_argdo) { if (do_ecmd(0, alist_name(&ARGLIST[curwin->w_arg_idx]), NULL,
// like Vi: set the mark where the cursor is in the file. eap, ECMD_LAST,
setmark('\''); (buf_hide(curwin->w_buffer) ? ECMD_HIDE : 0)
} + (eap->forceit ? ECMD_FORCEIT : 0), curwin) == FAIL) {
curwin->w_arg_idx = old_arg_idx;
} else if (eap->cmdidx != CMD_argdo) {
// like Vi: set the mark where the cursor is in the file.
setmark('\'');
} }
} }

View File

@@ -178,15 +178,17 @@ 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) {
aco_save_T aco; return;
// Make sure the buffer is in a window.
aucmd_prepbuf(&aco, buf);
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.
aucmd_prepbuf(&aco, buf);
swap_exists_action = SEA_NONE;
open_buffer(false, NULL, 0);
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
@@ -2903,18 +2905,20 @@ 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) {
if (buf->b_sfname != buf->b_ffname) { return;
xfree(buf->b_sfname);
}
xfree(buf->b_ffname);
buf->b_ffname = xstrdup(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->b_sfname != buf->b_ffname) {
xfree(buf->b_sfname);
}
xfree(buf->b_ffname);
buf->b_ffname = xstrdup(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;
} }
/// 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.
@@ -4138,13 +4142,15 @@ 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) {
curbuf->b_p_bl = on; return;
if (on) { }
apply_autocmds(EVENT_BUFADD, NULL, NULL, false, curbuf);
} else { curbuf->b_p_bl = on;
apply_autocmds(EVENT_BUFDELETE, NULL, NULL, false, curbuf); if (on) {
} apply_autocmds(EVENT_BUFADD, NULL, NULL, false, curbuf);
} else {
apply_autocmds(EVENT_BUFDELETE, NULL, NULL, false, curbuf);
} }
} }

View File

@@ -1018,13 +1018,15 @@ 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) {
hashitem_T *hi = hash_find(&vimvarht, (char *)vimvars[idx].vv_di.di_key); return;
if (HASHITEM_EMPTY(hi)) { }
internal_error("restore_vimvar()");
} else { hashitem_T *hi = hash_find(&vimvarht, (char *)vimvars[idx].vv_di.di_key);
hash_remove(&vimvarht, hi); if (HASHITEM_EMPTY(hi)) {
} internal_error("restore_vimvar()");
} else {
hash_remove(&vimvarht, hi);
} }
} }
@@ -6685,12 +6687,13 @@ 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) {
if (val != NULL) { return;
val->dv_refcount++;
// Set readonly
tv_dict_set_keys_readonly(val);
} }
val->dv_refcount++;
// Set readonly
tv_dict_set_keys_readonly(val);
} }
/// Set the v:argv list. /// Set the v:argv list.

View File

@@ -1216,19 +1216,21 @@ 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
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
if (hProcess != NULL) {
DebugBreakProcess(hProcess);
CloseHandle(hProcess);
rettv->vval.v_number = OK;
}
#else
uv_kill(pid, SIGINT);
#endif
} }
#ifdef MSWIN
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
if (hProcess == NULL) {
return;
}
DebugBreakProcess(hProcess);
CloseHandle(hProcess);
rettv->vval.v_number = OK;
#else
uv_kill(pid, SIGINT);
#endif
} }
/// "deepcopy()" function /// "deepcopy()" function
@@ -2099,14 +2101,16 @@ 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)) {
if (f <= (float_T) - VARNUMBER_MAX + DBL_EPSILON) { return;
rettv->vval.v_number = -VARNUMBER_MAX; }
} else if (f >= (float_T)VARNUMBER_MAX - DBL_EPSILON) {
rettv->vval.v_number = VARNUMBER_MAX; if (f <= (float_T) - VARNUMBER_MAX + DBL_EPSILON) {
} else { rettv->vval.v_number = -VARNUMBER_MAX;
rettv->vval.v_number = (varnumber_T)f; } else if (f >= (float_T)VARNUMBER_MAX - DBL_EPSILON) {
} rettv->vval.v_number = VARNUMBER_MAX;
} else {
rettv->vval.v_number = (varnumber_T)f;
} }
} }
@@ -3435,33 +3439,36 @@ 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;
if (l != NULL) {
listitem_T *item = tv_list_first(l);
if (argvars[2].v_type != VAR_UNKNOWN) {
bool error = false;
// Start at specified item. list_T *const l = argvars[0].vval.v_list;
idx = tv_list_uidx(l, (int)tv_get_number_chk(&argvars[2], &error)); if (l == NULL) {
if (error || idx == -1) { return;
}
listitem_T *item = tv_list_first(l);
if (argvars[2].v_type != VAR_UNKNOWN) {
bool error = false;
// Start at specified item.
idx = tv_list_uidx(l, (int)tv_get_number_chk(&argvars[2], &error));
if (error || idx == -1) {
item = NULL;
} else {
item = tv_list_find(l, (int)idx);
assert(item != NULL);
}
if (argvars[3].v_type != VAR_UNKNOWN) {
ic = !!tv_get_number_chk(&argvars[3], &error);
if (error) {
item = NULL; item = NULL;
} else {
item = tv_list_find(l, (int)idx);
assert(item != NULL);
}
if (argvars[3].v_type != VAR_UNKNOWN) {
ic = !!tv_get_number_chk(&argvars[3], &error);
if (error) {
item = NULL;
}
} }
} }
}
for (; item != NULL; item = TV_LIST_ITEM_NEXT(l, item), idx++) { for (; item != NULL; item = TV_LIST_ITEM_NEXT(l, item), idx++) {
if (tv_equal(TV_LIST_ITEM_TV(item), &argvars[1], ic, false)) { if (tv_equal(TV_LIST_ITEM_TV(item), &argvars[1], ic, false)) {
rettv->vval.v_number = idx; rettv->vval.v_number = idx;
break; break;
}
} }
} }
} }
@@ -5311,13 +5318,16 @@ 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); }
for (varnumber_T i = start; stride > 0 ? i <= end : i >= end; i += stride) {
tv_list_append_number(rettv->vval.v_list, i); tv_list_alloc_ret(rettv, (end - start) / stride);
} for (varnumber_T i = start; stride > 0 ? i <= end : i >= end; i += stride) {
tv_list_append_number(rettv->vval.v_list, i);
} }
} }
@@ -7009,31 +7019,35 @@ 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) {
pos_T pos; return;
int fnum; }
if (list2fpos(&argvars[1], &pos, &fnum, &curswant, charpos) == OK) {
if (pos.col != MAXCOL && --pos.col < 0) { pos_T pos;
pos.col = 0; int fnum;
} if (list2fpos(&argvars[1], &pos, &fnum, &curswant, charpos) != OK) {
if (name[0] == '.' && name[1] == NUL) { return;
// 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) {
check_cursor(); // set cursor; "fnum" is ignored
rettv->vval.v_number = 0; curwin->w_cursor = pos;
} else if (name[0] == '\'' && name[1] != NUL && name[2] == NUL) { if (curswant >= 0) {
// set mark curwin->w_curswant = curswant - 1;
if (setmark_pos((uint8_t)name[1], &pos, fnum, NULL) == OK) { curwin->w_set_curswant = false;
rettv->vval.v_number = 0;
}
} else {
emsg(_(e_invarg));
}
} }
check_cursor();
rettv->vval.v_number = 0;
} else if (name[0] == '\'' && name[1] != NUL && name[2] == NUL) {
// set mark
if (setmark_pos((uint8_t)name[1], &pos, fnum, NULL) == OK) {
rettv->vval.v_number = 0;
}
} else {
emsg(_(e_invarg));
} }
} }
@@ -7051,23 +7065,25 @@ 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) {
char_u *const csearch = (char_u *)tv_dict_get_string(d, "char", false); return;
if (csearch != NULL) { }
int pcc[MAX_MCO];
const int c = utfc_ptr2char((char *)csearch, pcc);
set_last_csearch(c, csearch, utfc_ptr2len((char *)csearch));
}
dictitem_T *di = tv_dict_find(d, S_LEN("forward")); char_u *const csearch = (char_u *)tv_dict_get_string(d, "char", false);
if (di != NULL) { if (csearch != NULL) {
set_csearch_direction(tv_get_number(&di->di_tv) ? FORWARD : BACKWARD); int pcc[MAX_MCO];
} const int c = utfc_ptr2char((char *)csearch, pcc);
set_last_csearch(c, csearch, utfc_ptr2len((char *)csearch));
}
di = tv_dict_find(d, S_LEN("until")); dictitem_T *di = tv_dict_find(d, S_LEN("forward"));
if (di != NULL) { if (di != NULL) {
set_csearch_until(!!tv_get_number(&di->di_tv)); set_csearch_direction(tv_get_number(&di->di_tv) ? FORWARD : BACKWARD);
} }
di = tv_dict_find(d, S_LEN("until"));
if (di != NULL) {
set_csearch_until(!!tv_get_number(&di->di_tv));
} }
} }

View File

@@ -1654,25 +1654,27 @@ 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) {
bool need_switch_win = !(tp == curtab && win == curwin); return;
switchwin_T switchwin; }
if (!need_switch_win || switch_win(&switchwin, win, tp, true) == OK) {
if (*varname == '&') { bool need_switch_win = !(tp == curtab && win == curwin);
set_option_from_tv(varname + 1, varp); switchwin_T switchwin;
} else { if (!need_switch_win || switch_win(&switchwin, win, tp, true) == OK) {
const size_t varname_len = strlen(varname); if (*varname == '&') {
char *const winvarname = xmalloc(varname_len + 3); set_option_from_tv(varname + 1, varp);
memcpy(winvarname, "w:", 2); } else {
memcpy(winvarname + 2, varname, varname_len + 1); const size_t varname_len = strlen(varname);
set_var(winvarname, varname_len + 2, varp, true); char *const winvarname = xmalloc(varname_len + 3);
xfree(winvarname); memcpy(winvarname, "w:", 2);
} memcpy(winvarname + 2, varname, varname_len + 1);
} set_var(winvarname, varname_len + 2, varp, true);
if (need_switch_win) { xfree(winvarname);
restore_win(&switchwin, true);
} }
} }
if (need_switch_win) {
restore_win(&switchwin, true);
}
} }
bool var_exists(const char *var) bool var_exists(const char *var)
@@ -1755,21 +1757,23 @@ 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) {
tabpage_T *const save_curtab = curtab; return;
goto_tabpage_tp(tp, false, false); }
const size_t varname_len = strlen(varname); tabpage_T *const save_curtab = curtab;
char *const tabvarname = xmalloc(varname_len + 3); goto_tabpage_tp(tp, false, false);
memcpy(tabvarname, "t:", 2);
memcpy(tabvarname + 2, varname, varname_len + 1);
set_var(tabvarname, varname_len + 2, varp, true);
xfree(tabvarname);
// Restore current tabpage. const size_t varname_len = strlen(varname);
if (valid_tabpage(save_curtab)) { char *const tabvarname = xmalloc(varname_len + 3);
goto_tabpage_tp(save_curtab, false, false); memcpy(tabvarname, "t:", 2);
} memcpy(tabvarname + 2, varname, varname_len + 1);
set_var(tabvarname, varname_len + 2, varp, true);
xfree(tabvarname);
// Restore current tabpage.
if (valid_tabpage(save_curtab)) {
goto_tabpage_tp(save_curtab, false, false);
} }
} }
@@ -1796,27 +1800,29 @@ 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) {
if (*varname == '&') { return;
aco_save_T aco; }
// Set curbuf to be our buf, temporarily. if (*varname == '&') {
aucmd_prepbuf(&aco, buf); aco_save_T aco;
set_option_from_tv(varname + 1, varp); // Set curbuf to be our buf, temporarily.
aucmd_prepbuf(&aco, buf);
// reset notion of buffer set_option_from_tv(varname + 1, varp);
aucmd_restbuf(&aco);
} else { // reset notion of buffer
const size_t varname_len = strlen(varname); aucmd_restbuf(&aco);
char *const bufvarname = xmalloc(varname_len + 3); } else {
buf_T *const save_curbuf = curbuf; const size_t varname_len = strlen(varname);
curbuf = buf; char *const bufvarname = xmalloc(varname_len + 3);
memcpy(bufvarname, "b:", 2); buf_T *const save_curbuf = curbuf;
memcpy(bufvarname + 2, varname, varname_len + 1); curbuf = buf;
set_var(bufvarname, varname_len + 2, varp, true); memcpy(bufvarname, "b:", 2);
xfree(bufvarname); memcpy(bufvarname + 2, varname, varname_len + 1);
curbuf = save_curbuf; set_var(bufvarname, varname_len + 2, varp, true);
} xfree(bufvarname);
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,11 +5171,13 @@ static void ex_find(exarg_T *eap)
} }
} }
if (fname != NULL) { if (fname == NULL) {
eap->arg = fname; return;
do_exedit(eap, NULL);
xfree(fname);
} }
eap->arg = fname;
do_exedit(eap, NULL);
xfree(fname);
} }
/// ":edit", ":badd", ":balt", ":visual". /// ":edit", ":badd", ":balt", ":visual".

View File

@@ -2014,11 +2014,13 @@ 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) {
char *fenc = enc_canonize(eap->cmd + eap->force_enc); return;
set_string_option_direct("fenc", -1, fenc, OPT_FREE|OPT_LOCAL, 0);
xfree(fenc);
} }
char *fenc = enc_canonize(eap->cmd + eap->force_enc);
set_string_option_direct("fenc", -1, fenc, OPT_FREE|OPT_LOCAL, 0);
xfree(fenc);
} }
/// Find next fileencoding to use from 'fileencodings'. /// Find next fileencoding to use from 'fileencodings'.
@@ -5348,35 +5350,40 @@ static void vim_opentempdir(void)
} }
DIR *dp = opendir(vim_tempdir); DIR *dp = opendir(vim_tempdir);
if (dp == NULL) {
if (dp != NULL) { return;
vim_tempdir_dp = dp;
flock(dirfd(vim_tempdir_dp), LOCK_SH);
} }
vim_tempdir_dp = dp;
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) {
closedir(vim_tempdir_dp); return;
vim_tempdir_dp = NULL;
} }
closedir(vim_tempdir_dp);
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) {
#if defined(HAVE_FLOCK) && defined(HAVE_DIRFD) return;
vim_closetempdir();
#endif
// remove the trailing path separator
path_tail(vim_tempdir)[-1] = NUL;
delete_recursive(vim_tempdir);
XFREE_CLEAR(vim_tempdir);
} }
#if defined(HAVE_FLOCK) && defined(HAVE_DIRFD)
vim_closetempdir();
#endif
// remove the trailing path separator
path_tail(vim_tempdir)[-1] = NUL;
delete_recursive(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,23 +1523,25 @@ 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) {
// Mark any nested folds to maybe-small return;
setSmallMaybe(&fp->fd_nested); }
if (fp->fd_len > wp->w_p_fml) { // Mark any nested folds to maybe-small
fp->fd_small = kFalse; setSmallMaybe(&fp->fd_nested);
} else {
int count = 0; if (fp->fd_len > wp->w_p_fml) {
for (int n = 0; n < fp->fd_len; n++) { fp->fd_small = kFalse;
count += plines_win_nofold(wp, fp->fd_top + lnum_off + n); } else {
if (count > wp->w_p_fml) { int count = 0;
fp->fd_small = kFalse; for (int n = 0; n < fp->fd_len; n++) {
return; count += plines_win_nofold(wp, fp->fd_top + lnum_off + n);
} if (count > wp->w_p_fml) {
fp->fd_small = kFalse;
return;
} }
fp->fd_small = kTrue;
} }
fp->fd_small = kTrue;
} }
} }
@@ -1595,26 +1597,28 @@ 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) {
// Check if the line ends with an unclosed comment return;
skip_comment(line, false, false, &line_is_comment); }
newline = xmalloc(line_len + markerlen + strlen(cms) + 1);
STRCPY(newline, line); // Check if the line ends with an unclosed comment
// Append the marker to the end of the line skip_comment(line, false, false, &line_is_comment);
if (p == NULL || line_is_comment) { newline = xmalloc(line_len + markerlen + strlen(cms) + 1);
STRLCPY(newline + line_len, marker, markerlen + 1); STRCPY(newline, line);
added = markerlen; // Append the marker to the end of the line
} else { if (p == NULL || line_is_comment) {
STRCPY(newline + line_len, cms); STRLCPY(newline + line_len, marker, markerlen + 1);
memcpy(newline + line_len + (p - cms), marker, markerlen); added = markerlen;
STRCPY(newline + line_len + (p - cms) + markerlen, p + 2); } else {
added = markerlen + strlen(cms) - 2; STRCPY(newline + line_len, cms);
} memcpy(newline + line_len + (p - cms), marker, markerlen);
ml_replace_buf(buf, lnum, newline, false); STRCPY(newline + line_len + (p - cms) + markerlen, p + 2);
if (added) { added = markerlen + strlen(cms) - 2;
extmark_splice_cols(buf, (int)lnum - 1, (int)line_len, }
0, (int)added, kExtmarkUndo); ml_replace_buf(buf, lnum, newline, false);
} if (added) {
extmark_splice_cols(buf, (int)lnum - 1, (int)line_len,
0, (int)added, kExtmarkUndo);
} }
} }