mirror of
https://github.com/neovim/neovim.git
synced 2025-09-19 09:48:19 +00:00
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:
@@ -631,50 +631,52 @@ void do_argfile(exarg_T *eap, int argn)
|
||||
} else {
|
||||
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 {
|
||||
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 {
|
||||
// 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 '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);
|
||||
}
|
||||
|
||||
curwin->w_arg_idx = argn;
|
||||
if (argn == ARGCOUNT - 1 && curwin->w_alist == &global_alist) {
|
||||
arg_had_last = true;
|
||||
if ((!buf_hide(curbuf) || !other)
|
||||
&& check_changed(curbuf, CCGD_AW
|
||||
| (other ? 0 : CCGD_MULTWIN)
|
||||
| (eap->forceit ? CCGD_FORCEIT : 0)
|
||||
| CCGD_EXCMD)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
} else if (eap->cmdidx != CMD_argdo) {
|
||||
// like Vi: set the mark where the cursor is in the file.
|
||||
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;
|
||||
} else if (eap->cmdidx != CMD_argdo) {
|
||||
// like Vi: set the mark where the cursor is in the file.
|
||||
setmark('\'');
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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.
|
||||
void buffer_ensure_loaded(buf_T *buf)
|
||||
{
|
||||
if (buf->b_ml.ml_mfp == NULL) {
|
||||
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);
|
||||
if (buf->b_ml.ml_mfp != NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
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
|
||||
@@ -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)
|
||||
{
|
||||
buf_T *buf = buflist_findnr(fnum);
|
||||
if (buf != NULL) {
|
||||
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;
|
||||
if (buf == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
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.
|
||||
@@ -4138,13 +4142,15 @@ char *buf_get_fname(const buf_T *buf)
|
||||
/// Set 'buflisted' for curbuf to "on" and trigger autocommands if it changed.
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1018,13 +1018,15 @@ void prepare_vimvar(int idx, typval_T *save_tv)
|
||||
void restore_vimvar(int idx, typval_T *save_tv)
|
||||
{
|
||||
vimvars[idx].vv_tv = *save_tv;
|
||||
if (vimvars[idx].vv_type == VAR_UNKNOWN) {
|
||||
hashitem_T *hi = hash_find(&vimvarht, (char *)vimvars[idx].vv_di.di_key);
|
||||
if (HASHITEM_EMPTY(hi)) {
|
||||
internal_error("restore_vimvar()");
|
||||
} else {
|
||||
hash_remove(&vimvarht, hi);
|
||||
}
|
||||
if (vimvars[idx].vv_type != VAR_UNKNOWN) {
|
||||
return;
|
||||
}
|
||||
|
||||
hashitem_T *hi = hash_find(&vimvarht, (char *)vimvars[idx].vv_di.di_key);
|
||||
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);
|
||||
vimvars[idx].vv_type = VAR_DICT;
|
||||
vimvars[idx].vv_dict = val;
|
||||
|
||||
if (val != NULL) {
|
||||
val->dv_refcount++;
|
||||
// Set readonly
|
||||
tv_dict_set_keys_readonly(val);
|
||||
if (val == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
val->dv_refcount++;
|
||||
// Set readonly
|
||||
tv_dict_set_keys_readonly(val);
|
||||
}
|
||||
|
||||
/// Set the v:argv list.
|
||||
|
@@ -1216,19 +1216,21 @@ static void f_debugbreak(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
int pid = (int)tv_get_number(&argvars[0]);
|
||||
if (pid == 0) {
|
||||
emsg(_(e_invarg));
|
||||
} else {
|
||||
#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
|
||||
return;
|
||||
}
|
||||
|
||||
#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
|
||||
@@ -2099,14 +2101,16 @@ static void f_float2nr(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
{
|
||||
float_T f;
|
||||
|
||||
if (tv_get_float_chk(argvars, &f)) {
|
||||
if (f <= (float_T) - VARNUMBER_MAX + DBL_EPSILON) {
|
||||
rettv->vval.v_number = -VARNUMBER_MAX;
|
||||
} else if (f >= (float_T)VARNUMBER_MAX - DBL_EPSILON) {
|
||||
rettv->vval.v_number = VARNUMBER_MAX;
|
||||
} else {
|
||||
rettv->vval.v_number = (varnumber_T)f;
|
||||
}
|
||||
if (!tv_get_float_chk(argvars, &f)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (f <= (float_T) - VARNUMBER_MAX + DBL_EPSILON) {
|
||||
rettv->vval.v_number = -VARNUMBER_MAX;
|
||||
} 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));
|
||||
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.
|
||||
idx = tv_list_uidx(l, (int)tv_get_number_chk(&argvars[2], &error));
|
||||
if (error || idx == -1) {
|
||||
list_T *const l = argvars[0].vval.v_list;
|
||||
if (l == NULL) {
|
||||
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;
|
||||
} 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++) {
|
||||
if (tv_equal(TV_LIST_ITEM_TV(item), &argvars[1], ic, false)) {
|
||||
rettv->vval.v_number = idx;
|
||||
break;
|
||||
}
|
||||
for (; item != NULL; item = TV_LIST_ITEM_NEXT(l, item), idx++) {
|
||||
if (tv_equal(TV_LIST_ITEM_TV(item), &argvars[1], ic, false)) {
|
||||
rettv->vval.v_number = idx;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5311,13 +5318,16 @@ static void f_range(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
}
|
||||
if (stride == 0) {
|
||||
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"));
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7009,31 +7019,35 @@ static void set_position(typval_T *argvars, typval_T *rettv, bool charpos)
|
||||
|
||||
rettv->vval.v_number = -1;
|
||||
const char *const name = tv_get_string_chk(argvars);
|
||||
if (name != NULL) {
|
||||
pos_T pos;
|
||||
int fnum;
|
||||
if (list2fpos(&argvars[1], &pos, &fnum, &curswant, charpos) == OK) {
|
||||
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((uint8_t)name[1], &pos, fnum, NULL) == OK) {
|
||||
rettv->vval.v_number = 0;
|
||||
}
|
||||
} else {
|
||||
emsg(_(e_invarg));
|
||||
}
|
||||
if (name == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
pos_T pos;
|
||||
int fnum;
|
||||
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) {
|
||||
// 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((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;
|
||||
if (d != NULL) {
|
||||
char_u *const csearch = (char_u *)tv_dict_get_string(d, "char", false);
|
||||
if (csearch != NULL) {
|
||||
int pcc[MAX_MCO];
|
||||
const int c = utfc_ptr2char((char *)csearch, pcc);
|
||||
set_last_csearch(c, csearch, utfc_ptr2len((char *)csearch));
|
||||
}
|
||||
if (d == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
dictitem_T *di = tv_dict_find(d, S_LEN("forward"));
|
||||
if (di != NULL) {
|
||||
set_csearch_direction(tv_get_number(&di->di_tv) ? FORWARD : BACKWARD);
|
||||
}
|
||||
char_u *const csearch = (char_u *)tv_dict_get_string(d, "char", false);
|
||||
if (csearch != NULL) {
|
||||
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"));
|
||||
if (di != NULL) {
|
||||
set_csearch_until(!!tv_get_number(&di->di_tv));
|
||||
}
|
||||
dictitem_T *di = tv_dict_find(d, S_LEN("forward"));
|
||||
if (di != NULL) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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]);
|
||||
typval_T *varp = &argvars[off + 2];
|
||||
|
||||
if (win != NULL && varname != NULL && varp != NULL) {
|
||||
bool need_switch_win = !(tp == curtab && win == curwin);
|
||||
switchwin_T switchwin;
|
||||
if (!need_switch_win || switch_win(&switchwin, win, tp, true) == OK) {
|
||||
if (*varname == '&') {
|
||||
set_option_from_tv(varname + 1, varp);
|
||||
} else {
|
||||
const size_t varname_len = strlen(varname);
|
||||
char *const winvarname = xmalloc(varname_len + 3);
|
||||
memcpy(winvarname, "w:", 2);
|
||||
memcpy(winvarname + 2, varname, varname_len + 1);
|
||||
set_var(winvarname, varname_len + 2, varp, true);
|
||||
xfree(winvarname);
|
||||
}
|
||||
}
|
||||
if (need_switch_win) {
|
||||
restore_win(&switchwin, true);
|
||||
if (win == NULL || varname == NULL || varp == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool need_switch_win = !(tp == curtab && win == curwin);
|
||||
switchwin_T switchwin;
|
||||
if (!need_switch_win || switch_win(&switchwin, win, tp, true) == OK) {
|
||||
if (*varname == '&') {
|
||||
set_option_from_tv(varname + 1, varp);
|
||||
} else {
|
||||
const size_t varname_len = strlen(varname);
|
||||
char *const winvarname = xmalloc(varname_len + 3);
|
||||
memcpy(winvarname, "w:", 2);
|
||||
memcpy(winvarname + 2, varname, varname_len + 1);
|
||||
set_var(winvarname, varname_len + 2, varp, true);
|
||||
xfree(winvarname);
|
||||
}
|
||||
}
|
||||
if (need_switch_win) {
|
||||
restore_win(&switchwin, true);
|
||||
}
|
||||
}
|
||||
|
||||
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]);
|
||||
typval_T *const varp = &argvars[2];
|
||||
|
||||
if (varname != NULL && tp != NULL) {
|
||||
tabpage_T *const save_curtab = curtab;
|
||||
goto_tabpage_tp(tp, false, false);
|
||||
if (varname == NULL || tp == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
const size_t varname_len = strlen(varname);
|
||||
char *const tabvarname = xmalloc(varname_len + 3);
|
||||
memcpy(tabvarname, "t:", 2);
|
||||
memcpy(tabvarname + 2, varname, varname_len + 1);
|
||||
set_var(tabvarname, varname_len + 2, varp, true);
|
||||
xfree(tabvarname);
|
||||
tabpage_T *const save_curtab = curtab;
|
||||
goto_tabpage_tp(tp, false, false);
|
||||
|
||||
// Restore current tabpage.
|
||||
if (valid_tabpage(save_curtab)) {
|
||||
goto_tabpage_tp(save_curtab, false, false);
|
||||
}
|
||||
const size_t varname_len = strlen(varname);
|
||||
char *const tabvarname = xmalloc(varname_len + 3);
|
||||
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);
|
||||
typval_T *varp = &argvars[2];
|
||||
|
||||
if (buf != NULL && varname != NULL) {
|
||||
if (*varname == '&') {
|
||||
aco_save_T aco;
|
||||
if (buf == NULL || varname == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Set curbuf to be our buf, temporarily.
|
||||
aucmd_prepbuf(&aco, buf);
|
||||
if (*varname == '&') {
|
||||
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
|
||||
aucmd_restbuf(&aco);
|
||||
} else {
|
||||
const size_t varname_len = strlen(varname);
|
||||
char *const bufvarname = xmalloc(varname_len + 3);
|
||||
buf_T *const save_curbuf = curbuf;
|
||||
curbuf = buf;
|
||||
memcpy(bufvarname, "b:", 2);
|
||||
memcpy(bufvarname + 2, varname, varname_len + 1);
|
||||
set_var(bufvarname, varname_len + 2, varp, true);
|
||||
xfree(bufvarname);
|
||||
curbuf = save_curbuf;
|
||||
}
|
||||
set_option_from_tv(varname + 1, varp);
|
||||
|
||||
// reset notion of buffer
|
||||
aucmd_restbuf(&aco);
|
||||
} else {
|
||||
const size_t varname_len = strlen(varname);
|
||||
char *const bufvarname = xmalloc(varname_len + 3);
|
||||
buf_T *const save_curbuf = curbuf;
|
||||
curbuf = buf;
|
||||
memcpy(bufvarname, "b:", 2);
|
||||
memcpy(bufvarname + 2, varname, varname_len + 1);
|
||||
set_var(bufvarname, varname_len + 2, varp, true);
|
||||
xfree(bufvarname);
|
||||
curbuf = save_curbuf;
|
||||
}
|
||||
}
|
||||
|
@@ -486,9 +486,11 @@ void f_win_execute(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
int id = (int)tv_get_number(argvars);
|
||||
tabpage_T *tp;
|
||||
win_T *wp = win_id2wp_tp(id, &tp);
|
||||
if (wp != NULL && tp != NULL) {
|
||||
WIN_EXECUTE(wp, tp, execute_common(argvars, rettv, 1));
|
||||
if (wp == NULL || tp == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
WIN_EXECUTE(wp, tp, execute_common(argvars, rettv, 1));
|
||||
}
|
||||
|
||||
/// "win_findbuf()" function
|
||||
|
@@ -5171,11 +5171,13 @@ static void ex_find(exarg_T *eap)
|
||||
}
|
||||
}
|
||||
|
||||
if (fname != NULL) {
|
||||
eap->arg = fname;
|
||||
do_exedit(eap, NULL);
|
||||
xfree(fname);
|
||||
if (fname == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
eap->arg = fname;
|
||||
do_exedit(eap, NULL);
|
||||
xfree(fname);
|
||||
}
|
||||
|
||||
/// ":edit", ":badd", ":balt", ":visual".
|
||||
|
@@ -2014,11 +2014,13 @@ void set_file_options(int set_options, exarg_T *eap)
|
||||
/// Set forced 'fileencoding'.
|
||||
void set_forced_fenc(exarg_T *eap)
|
||||
{
|
||||
if (eap->force_enc != 0) {
|
||||
char *fenc = enc_canonize(eap->cmd + eap->force_enc);
|
||||
set_string_option_direct("fenc", -1, fenc, OPT_FREE|OPT_LOCAL, 0);
|
||||
xfree(fenc);
|
||||
if (eap->force_enc == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
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'.
|
||||
@@ -5348,35 +5350,40 @@ static void vim_opentempdir(void)
|
||||
}
|
||||
|
||||
DIR *dp = opendir(vim_tempdir);
|
||||
|
||||
if (dp != NULL) {
|
||||
vim_tempdir_dp = dp;
|
||||
flock(dirfd(vim_tempdir_dp), LOCK_SH);
|
||||
if (dp == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
vim_tempdir_dp = dp;
|
||||
flock(dirfd(vim_tempdir_dp), LOCK_SH);
|
||||
}
|
||||
|
||||
/// Close temporary directory - it automatically release file lock.
|
||||
static void vim_closetempdir(void)
|
||||
{
|
||||
if (vim_tempdir_dp != NULL) {
|
||||
closedir(vim_tempdir_dp);
|
||||
vim_tempdir_dp = NULL;
|
||||
if (vim_tempdir_dp == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
closedir(vim_tempdir_dp);
|
||||
vim_tempdir_dp = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// Delete the temp directory and all files it contains.
|
||||
void vim_deltempdir(void)
|
||||
{
|
||||
if (vim_tempdir != NULL) {
|
||||
#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);
|
||||
if (vim_tempdir == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
#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).
|
||||
@@ -5401,9 +5408,10 @@ char *vim_gettempdir(void)
|
||||
static bool vim_settempdir(char *tempdir)
|
||||
{
|
||||
char *buf = verbose_try_malloc(MAXPATHL + 2);
|
||||
if (!buf) {
|
||||
if (buf == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
vim_FullName(tempdir, buf, MAXPATHL, false);
|
||||
add_pathsep(buf);
|
||||
vim_tempdir = xstrdup(buf);
|
||||
|
@@ -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
|
||||
static void checkSmall(win_T *const wp, fold_T *const fp, const linenr_T lnum_off)
|
||||
{
|
||||
if (fp->fd_small == kNone) {
|
||||
// Mark any nested folds to maybe-small
|
||||
setSmallMaybe(&fp->fd_nested);
|
||||
if (fp->fd_small != kNone) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (fp->fd_len > wp->w_p_fml) {
|
||||
fp->fd_small = kFalse;
|
||||
} else {
|
||||
int count = 0;
|
||||
for (int n = 0; n < fp->fd_len; n++) {
|
||||
count += plines_win_nofold(wp, fp->fd_top + lnum_off + n);
|
||||
if (count > wp->w_p_fml) {
|
||||
fp->fd_small = kFalse;
|
||||
return;
|
||||
}
|
||||
// Mark any nested folds to maybe-small
|
||||
setSmallMaybe(&fp->fd_nested);
|
||||
|
||||
if (fp->fd_len > wp->w_p_fml) {
|
||||
fp->fd_small = kFalse;
|
||||
} else {
|
||||
int count = 0;
|
||||
for (int n = 0; n < fp->fd_len; n++) {
|
||||
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 added = 0;
|
||||
|
||||
if (u_save(lnum - 1, lnum + 1) == OK) {
|
||||
// Check if the line ends with an unclosed comment
|
||||
skip_comment(line, false, false, &line_is_comment);
|
||||
newline = xmalloc(line_len + markerlen + strlen(cms) + 1);
|
||||
STRCPY(newline, line);
|
||||
// Append the marker to the end of the line
|
||||
if (p == NULL || line_is_comment) {
|
||||
STRLCPY(newline + line_len, marker, markerlen + 1);
|
||||
added = markerlen;
|
||||
} else {
|
||||
STRCPY(newline + line_len, cms);
|
||||
memcpy(newline + line_len + (p - cms), marker, markerlen);
|
||||
STRCPY(newline + line_len + (p - cms) + markerlen, p + 2);
|
||||
added = markerlen + strlen(cms) - 2;
|
||||
}
|
||||
ml_replace_buf(buf, lnum, newline, false);
|
||||
if (added) {
|
||||
extmark_splice_cols(buf, (int)lnum - 1, (int)line_len,
|
||||
0, (int)added, kExtmarkUndo);
|
||||
}
|
||||
if (u_save(lnum - 1, lnum + 1) != OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the line ends with an unclosed comment
|
||||
skip_comment(line, false, false, &line_is_comment);
|
||||
newline = xmalloc(line_len + markerlen + strlen(cms) + 1);
|
||||
STRCPY(newline, line);
|
||||
// Append the marker to the end of the line
|
||||
if (p == NULL || line_is_comment) {
|
||||
STRLCPY(newline + line_len, marker, markerlen + 1);
|
||||
added = markerlen;
|
||||
} else {
|
||||
STRCPY(newline + line_len, cms);
|
||||
memcpy(newline + line_len + (p - cms), marker, markerlen);
|
||||
STRCPY(newline + line_len + (p - cms) + markerlen, p + 2);
|
||||
added = markerlen + strlen(cms) - 2;
|
||||
}
|
||||
ml_replace_buf(buf, lnum, newline, false);
|
||||
if (added) {
|
||||
extmark_splice_cols(buf, (int)lnum - 1, (int)line_len,
|
||||
0, (int)added, kExtmarkUndo);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user