aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-02-03 09:42:04 +0800
committerGitHub <noreply@github.com>2024-02-03 09:42:04 +0800
commit1f40b4e22232f22551a9ae89a9f8d59b5ba0c0b6 (patch)
treee4f0777cae588b2274a190b145db539b1b280a6e /src
parentbe1d09c4272212ea9b354c900603568d238b4ab3 (diff)
downloadrneovim-1f40b4e22232f22551a9ae89a9f8d59b5ba0c0b6.tar.gz
rneovim-1f40b4e22232f22551a9ae89a9f8d59b5ba0c0b6.tar.bz2
rneovim-1f40b4e22232f22551a9ae89a9f8d59b5ba0c0b6.zip
vim-patch:9.0.1105: code is indented too much (#27314)
Problem: Code is indented too much. Solution: Use an early return. (Yegappan Lakshmanan, closes vim/vim#11756) https://github.com/vim/vim/commit/87c1cbbe984e60582f2536e4d3c2ce88cd474bb7 Omit free_eval_tofree_later(): Vim9 script only. Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Diffstat (limited to 'src')
-rw-r--r--src/nvim/edit.c76
-rw-r--r--src/nvim/eval.c90
-rw-r--r--src/nvim/eval/funcs.c144
3 files changed, 169 insertions, 141 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index 4dcf4d266d..41df039b85 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -1439,45 +1439,47 @@ static int pc_col;
void edit_putchar(int c, bool highlight)
{
- if (curwin->w_grid_alloc.chars != NULL || default_grid.chars != NULL) {
- int attr;
- update_topline(curwin); // just in case w_topline isn't valid
- validate_cursor();
- if (highlight) {
- attr = HL_ATTR(HLF_8);
- } else {
- attr = 0;
- }
- pc_row = curwin->w_wrow;
- pc_status = PC_STATUS_UNSET;
- grid_line_start(&curwin->w_grid, pc_row);
- if (curwin->w_p_rl) {
- pc_col = curwin->w_grid.cols - 1 - curwin->w_wcol;
-
- if (grid_line_getchar(pc_col, NULL) == NUL) {
- grid_line_put_schar(pc_col - 1, schar_from_ascii(' '), attr);
- curwin->w_wcol--;
- pc_status = PC_STATUS_RIGHT;
- }
- } else {
- pc_col = curwin->w_wcol;
+ if (curwin->w_grid_alloc.chars == NULL && default_grid.chars == NULL) {
+ return;
+ }
- if (grid_line_getchar(pc_col + 1, NULL) == NUL) {
- // pc_col is the left half of a double-width char
- pc_status = PC_STATUS_LEFT;
- }
+ int attr;
+ update_topline(curwin); // just in case w_topline isn't valid
+ validate_cursor();
+ if (highlight) {
+ attr = HL_ATTR(HLF_8);
+ } else {
+ attr = 0;
+ }
+ pc_row = curwin->w_wrow;
+ pc_status = PC_STATUS_UNSET;
+ grid_line_start(&curwin->w_grid, pc_row);
+ if (curwin->w_p_rl) {
+ pc_col = curwin->w_grid.cols - 1 - curwin->w_wcol;
+
+ if (grid_line_getchar(pc_col, NULL) == NUL) {
+ grid_line_put_schar(pc_col - 1, schar_from_ascii(' '), attr);
+ curwin->w_wcol--;
+ pc_status = PC_STATUS_RIGHT;
}
+ } else {
+ pc_col = curwin->w_wcol;
- // save the character to be able to put it back
- if (pc_status == PC_STATUS_UNSET) {
- pc_schar = grid_line_getchar(pc_col, &pc_attr);
- pc_status = PC_STATUS_SET;
+ if (grid_line_getchar(pc_col + 1, NULL) == NUL) {
+ // pc_col is the left half of a double-width char
+ pc_status = PC_STATUS_LEFT;
}
+ }
- char buf[MB_MAXCHAR + 1];
- grid_line_puts(pc_col, buf, utf_char2bytes(c, buf), attr);
- grid_line_flush();
+ // save the character to be able to put it back
+ if (pc_status == PC_STATUS_UNSET) {
+ pc_schar = grid_line_getchar(pc_col, &pc_attr);
+ pc_status = PC_STATUS_SET;
}
+
+ char buf[MB_MAXCHAR + 1];
+ grid_line_puts(pc_col, buf, utf_char2bytes(c, buf), attr);
+ grid_line_flush();
}
/// @return the effective prompt for the specified buffer.
@@ -1591,10 +1593,12 @@ void display_dollar(colnr_T col_arg)
// in insert mode.
void undisplay_dollar(void)
{
- if (dollar_vcol >= 0) {
- dollar_vcol = -1;
- redrawWinline(curwin, curwin->w_cursor.lnum);
+ if (dollar_vcol < 0) {
+ return;
}
+
+ dollar_vcol = -1;
+ redrawWinline(curwin, curwin->w_cursor.lnum);
}
/// Insert an indent (for <Tab> or CTRL-T) or delete an indent (for CTRL-D).
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index faa652f80a..5053cc38de 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -758,11 +758,14 @@ void eval_patch(const char *const origfile, const char *const difffile, const ch
void fill_evalarg_from_eap(evalarg_T *evalarg, exarg_T *eap, bool skip)
{
*evalarg = (evalarg_T){ .eval_flags = skip ? 0 : EVAL_EVALUATE };
- if (eap != NULL) {
- if (getline_equal(eap->getline, eap->cookie, getsourceline)) {
- evalarg->eval_getline = eap->getline;
- evalarg->eval_cookie = eap->cookie;
- }
+
+ if (eap == NULL) {
+ return;
+ }
+
+ if (getline_equal(eap->getline, eap->cookie, getsourceline)) {
+ evalarg->eval_getline = eap->getline;
+ evalarg->eval_cookie = eap->cookie;
}
}
@@ -2326,20 +2329,22 @@ static int eval_func(char **const arg, evalarg_T *const evalarg, char *const nam
/// After using "evalarg" filled from "eap": free the memory.
void clear_evalarg(evalarg_T *evalarg, exarg_T *eap)
{
- if (evalarg != NULL) {
- if (evalarg->eval_tofree != NULL) {
- if (eap != NULL) {
- // We may need to keep the original command line, e.g. for
- // ":let" it has the variable names. But we may also need the
- // new one, "nextcmd" points into it. Keep both.
- xfree(eap->cmdline_tofree);
- eap->cmdline_tofree = *eap->cmdlinep;
- *eap->cmdlinep = evalarg->eval_tofree;
- } else {
- xfree(evalarg->eval_tofree);
- }
- evalarg->eval_tofree = NULL;
+ if (evalarg == NULL) {
+ return;
+ }
+
+ if (evalarg->eval_tofree != NULL) {
+ if (eap != NULL) {
+ // We may need to keep the original command line, e.g. for
+ // ":let" it has the variable names. But we may also need the
+ // new one, "nextcmd" points into it. Keep both.
+ xfree(eap->cmdline_tofree);
+ eap->cmdline_tofree = *eap->cmdlinep;
+ *eap->cmdlinep = evalarg->eval_tofree;
+ } else {
+ xfree(evalarg->eval_tofree);
}
+ evalarg->eval_tofree = NULL;
}
}
@@ -3626,12 +3631,14 @@ static int check_can_index(typval_T *rettv, bool evaluate, bool verbose)
/// slice() function
void f_slice(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
{
- if (check_can_index(argvars, true, false) == OK) {
- tv_copy(argvars, rettv);
- eval_index_inner(rettv, true, argvars + 1,
- argvars[2].v_type == VAR_UNKNOWN ? NULL : argvars + 2,
- true, NULL, 0, false);
+ if (check_can_index(argvars, true, false) != OK) {
+ return;
}
+
+ tv_copy(argvars, rettv);
+ eval_index_inner(rettv, true, argvars + 1,
+ argvars[2].v_type == VAR_UNKNOWN ? NULL : argvars + 2,
+ true, NULL, 0, false);
}
/// Apply index or range to "rettv".
@@ -4248,7 +4255,11 @@ static void partial_free(partial_T *pt)
/// becomes zero.
void partial_unref(partial_T *pt)
{
- if (pt != NULL && --pt->pt_refcount <= 0) {
+ if (pt == NULL) {
+ return;
+ }
+
+ if (--pt->pt_refcount <= 0) {
partial_free(pt);
}
}
@@ -8241,21 +8252,24 @@ void last_set_msg(sctx_T script_ctx)
/// Should only be invoked when 'verbose' is non-zero.
void option_last_set_msg(LastSet last_set)
{
- if (last_set.script_ctx.sc_sid != 0) {
- bool should_free;
- char *p = get_scriptname(last_set, &should_free);
- verbose_enter();
- msg_puts(_("\n\tLast set from "));
- msg_puts(p);
- if (last_set.script_ctx.sc_lnum > 0) {
- msg_puts(_(line_msg));
- msg_outnum(last_set.script_ctx.sc_lnum);
- }
- if (should_free) {
- xfree(p);
- }
- verbose_leave();
+ if (last_set.script_ctx.sc_sid == 0) {
+ return;
+ }
+
+ bool should_free;
+ char *p = get_scriptname(last_set, &should_free);
+
+ verbose_enter();
+ msg_puts(_("\n\tLast set from "));
+ msg_puts(p);
+ if (last_set.script_ctx.sc_lnum > 0) {
+ msg_puts(_(line_msg));
+ msg_outnum(last_set.script_ctx.sc_lnum);
+ }
+ if (should_free) {
+ xfree(p);
}
+ verbose_leave();
}
// reset v:option_new, v:option_old, v:option_oldlocal, v:option_oldglobal,
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index d5d16fb1ef..655d6c9ab3 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -1937,44 +1937,47 @@ static void extend_list(typval_T *argvars, const char *arg_errmsg, bool is_new,
list_T *l1 = argvars[0].vval.v_list;
list_T *const l2 = argvars[1].vval.v_list;
- if (is_new || !value_check_lock(tv_list_locked(l1), arg_errmsg, TV_TRANSLATE)) {
- if (is_new) {
- l1 = tv_list_copy(NULL, l1, false, get_copyID());
- if (l1 == NULL) {
- return;
- }
- }
- listitem_T *item;
- if (argvars[2].v_type != VAR_UNKNOWN) {
- int before = (int)tv_get_number_chk(&argvars[2], &error);
- if (error) {
- return; // Type error; errmsg already given.
- }
+ if (!is_new && value_check_lock(tv_list_locked(l1), arg_errmsg, TV_TRANSLATE)) {
+ return;
+ }
- if (before == tv_list_len(l1)) {
- item = NULL;
- } else {
- item = tv_list_find(l1, before);
- if (item == NULL) {
- semsg(_(e_list_index_out_of_range_nr), (int64_t)before);
- return;
- }
- }
- } else {
- item = NULL;
+ if (is_new) {
+ l1 = tv_list_copy(NULL, l1, false, get_copyID());
+ if (l1 == NULL) {
+ return;
}
- tv_list_extend(l1, l2, item);
+ }
- if (is_new) {
- *rettv = (typval_T){
- .v_type = VAR_LIST,
- .v_lock = VAR_UNLOCKED,
- .vval.v_list = l1,
- };
+ listitem_T *item;
+ if (argvars[2].v_type != VAR_UNKNOWN) {
+ int before = (int)tv_get_number_chk(&argvars[2], &error);
+ if (error) {
+ return; // Type error; errmsg already given.
+ }
+
+ if (before == tv_list_len(l1)) {
+ item = NULL;
} else {
- tv_copy(&argvars[0], rettv);
+ item = tv_list_find(l1, before);
+ if (item == NULL) {
+ semsg(_(e_list_index_out_of_range_nr), (int64_t)before);
+ return;
+ }
}
+ } else {
+ item = NULL;
+ }
+ tv_list_extend(l1, l2, item);
+
+ if (is_new) {
+ *rettv = (typval_T){
+ .v_type = VAR_LIST,
+ .v_lock = VAR_UNLOCKED,
+ .vval.v_list = l1,
+ };
+ } else {
+ tv_copy(&argvars[0], rettv);
}
}
@@ -1985,54 +1988,61 @@ static void extend_list(typval_T *argvars, const char *arg_errmsg, bool is_new,
static void extend_dict(typval_T *argvars, const char *arg_errmsg, bool is_new, typval_T *rettv)
{
dict_T *d1 = argvars[0].vval.v_dict;
- dict_T *const d2 = argvars[1].vval.v_dict;
if (d1 == NULL) {
const bool locked = value_check_lock(VAR_FIXED, arg_errmsg, TV_TRANSLATE);
(void)locked;
assert(locked == true);
- } else if (d2 == NULL) {
+ return;
+ }
+ dict_T *const d2 = argvars[1].vval.v_dict;
+ if (d2 == NULL) {
// Do nothing
tv_copy(&argvars[0], rettv);
- } else if (is_new || !value_check_lock(d1->dv_lock, arg_errmsg, TV_TRANSLATE)) {
- if (is_new) {
- d1 = tv_dict_copy(NULL, d1, false, get_copyID());
- if (d1 == NULL) {
- return;
- }
+ return;
+ }
+
+ if (!is_new && value_check_lock(d1->dv_lock, arg_errmsg, TV_TRANSLATE)) {
+ return;
+ }
+
+ if (is_new) {
+ d1 = tv_dict_copy(NULL, d1, false, get_copyID());
+ if (d1 == NULL) {
+ return;
}
+ }
- const char *action = "force";
- // Check the third argument.
- if (argvars[2].v_type != VAR_UNKNOWN) {
- const char *const av[] = { "keep", "force", "error" };
+ const char *action = "force";
+ // Check the third argument.
+ if (argvars[2].v_type != VAR_UNKNOWN) {
+ const char *const av[] = { "keep", "force", "error" };
- action = tv_get_string_chk(&argvars[2]);
- if (action == NULL) {
- return; // Type error; error message already given.
- }
- size_t i;
- for (i = 0; i < ARRAY_SIZE(av); i++) {
- if (strcmp(action, av[i]) == 0) {
- break;
- }
- }
- if (i == 3) {
- semsg(_(e_invarg2), action);
- return;
+ action = tv_get_string_chk(&argvars[2]);
+ if (action == NULL) {
+ return; // Type error; error message already given.
+ }
+ size_t i;
+ for (i = 0; i < ARRAY_SIZE(av); i++) {
+ if (strcmp(action, av[i]) == 0) {
+ break;
}
}
+ if (i == 3) {
+ semsg(_(e_invarg2), action);
+ return;
+ }
+ }
- tv_dict_extend(d1, d2, action);
+ tv_dict_extend(d1, d2, action);
- if (is_new) {
- *rettv = (typval_T){
- .v_type = VAR_DICT,
- .v_lock = VAR_UNLOCKED,
- .vval.v_dict = d1,
- };
- } else {
- tv_copy(&argvars[0], rettv);
- }
+ if (is_new) {
+ *rettv = (typval_T){
+ .v_type = VAR_DICT,
+ .v_lock = VAR_UNLOCKED,
+ .vval.v_dict = d1,
+ };
+ } else {
+ tv_copy(&argvars[0], rettv);
}
}