mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
vim-patch:8.2.3689: ex_let_one() is too long (#23830)
Problem: ex_let_one() is too long.
Solution: Split into multiple functions.
3ccb579516
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
@@ -701,30 +701,18 @@ static const char *list_arg_vars(exarg_T *eap, const char *arg, int *first)
|
|||||||
return arg;
|
return arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set one item of `:let var = expr` or `:let [v1, v2] = list` to its value
|
/// Set an environment variable, part of ex_let_one().
|
||||||
///
|
static char *ex_let_env(char *arg, typval_T *const tv, const bool is_const,
|
||||||
/// @param[in] arg Start of the variable name.
|
|
||||||
/// @param[in] tv Value to assign to the variable.
|
|
||||||
/// @param[in] copy If true, copy value from `tv`.
|
|
||||||
/// @param[in] endchars Valid characters after variable name or NULL.
|
|
||||||
/// @param[in] op Operation performed: *op is `+`, `-`, `.` for `+=`, etc.
|
|
||||||
/// NULL for `=`.
|
|
||||||
///
|
|
||||||
/// @return a pointer to the char just after the var name or NULL in case of
|
|
||||||
/// error.
|
|
||||||
static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bool is_const,
|
|
||||||
const char *const endchars, const char *const op)
|
const char *const endchars, const char *const op)
|
||||||
FUNC_ATTR_NONNULL_ARG(1, 2) FUNC_ATTR_WARN_UNUSED_RESULT
|
FUNC_ATTR_NONNULL_ARG(1, 2) FUNC_ATTR_WARN_UNUSED_RESULT
|
||||||
{
|
{
|
||||||
char *arg_end = NULL;
|
|
||||||
|
|
||||||
// ":let $VAR = expr": Set environment variable.
|
|
||||||
if (*arg == '$') {
|
|
||||||
if (is_const) {
|
if (is_const) {
|
||||||
emsg(_("E996: Cannot lock an environment variable"));
|
emsg(_("E996: Cannot lock an environment variable"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the end of the name.
|
// Find the end of the name.
|
||||||
|
char *arg_end = NULL;
|
||||||
arg++;
|
arg++;
|
||||||
char *name = arg;
|
char *name = arg;
|
||||||
int len = get_env_len((const char **)&arg);
|
int len = get_env_len((const char **)&arg);
|
||||||
@@ -757,15 +745,21 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo
|
|||||||
xfree(tofree);
|
xfree(tofree);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ":let &option = expr": Set option value.
|
return arg_end;
|
||||||
// ":let &l:option = expr": Set local option value.
|
}
|
||||||
// ":let &g:option = expr": Set global option value.
|
|
||||||
} else if (*arg == '&') {
|
/// Set an option, part of ex_let_one().
|
||||||
|
static char *ex_let_option(char *arg, typval_T *const tv, const bool is_const,
|
||||||
|
const char *const endchars, const char *const op)
|
||||||
|
FUNC_ATTR_NONNULL_ARG(1, 2) FUNC_ATTR_WARN_UNUSED_RESULT
|
||||||
|
{
|
||||||
if (is_const) {
|
if (is_const) {
|
||||||
emsg(_("E996: Cannot lock an option"));
|
emsg(_("E996: Cannot lock an option"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the end of the name.
|
// Find the end of the name.
|
||||||
|
char *arg_end = NULL;
|
||||||
int scope;
|
int scope;
|
||||||
char *const p = (char *)find_option_end((const char **)&arg, &scope);
|
char *const p = (char *)find_option_end((const char **)&arg, &scope);
|
||||||
if (p == NULL
|
if (p == NULL
|
||||||
@@ -850,12 +844,20 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo
|
|||||||
xfree(stringval);
|
xfree(stringval);
|
||||||
xfree(tofree);
|
xfree(tofree);
|
||||||
}
|
}
|
||||||
// ":let @r = expr": Set register contents.
|
return arg_end;
|
||||||
} else if (*arg == '@') {
|
}
|
||||||
|
|
||||||
|
/// Set a register, part of ex_let_one().
|
||||||
|
static char *ex_let_register(char *arg, typval_T *const tv, const bool is_const,
|
||||||
|
const char *const endchars, const char *const op)
|
||||||
|
FUNC_ATTR_NONNULL_ARG(1, 2) FUNC_ATTR_WARN_UNUSED_RESULT
|
||||||
|
{
|
||||||
if (is_const) {
|
if (is_const) {
|
||||||
emsg(_("E996: Cannot lock a register"));
|
emsg(_("E996: Cannot lock a register"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *arg_end = NULL;
|
||||||
arg++;
|
arg++;
|
||||||
if (op != NULL && vim_strchr("+-*/%", (uint8_t)(*op)) != NULL) {
|
if (op != NULL && vim_strchr("+-*/%", (uint8_t)(*op)) != NULL) {
|
||||||
semsg(_(e_letwrong), op);
|
semsg(_(e_letwrong), op);
|
||||||
@@ -879,11 +881,41 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo
|
|||||||
}
|
}
|
||||||
xfree(ptofree);
|
xfree(ptofree);
|
||||||
}
|
}
|
||||||
|
return arg_end;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set one item of `:let var = expr` or `:let [v1, v2] = list` to its value
|
||||||
|
///
|
||||||
|
/// @param[in] arg Start of the variable name.
|
||||||
|
/// @param[in] tv Value to assign to the variable.
|
||||||
|
/// @param[in] copy If true, copy value from `tv`.
|
||||||
|
/// @param[in] endchars Valid characters after variable name or NULL.
|
||||||
|
/// @param[in] op Operation performed: *op is `+`, `-`, `.` for `+=`, etc.
|
||||||
|
/// NULL for `=`.
|
||||||
|
///
|
||||||
|
/// @return a pointer to the char just after the var name or NULL in case of
|
||||||
|
/// error.
|
||||||
|
static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bool is_const,
|
||||||
|
const char *const endchars, const char *const op)
|
||||||
|
FUNC_ATTR_NONNULL_ARG(1, 2) FUNC_ATTR_WARN_UNUSED_RESULT
|
||||||
|
{
|
||||||
|
char *arg_end = NULL;
|
||||||
|
|
||||||
|
if (*arg == '$') {
|
||||||
|
// ":let $VAR = expr": Set environment variable.
|
||||||
|
return ex_let_env(arg, tv, is_const, endchars, op);
|
||||||
|
} else if (*arg == '&') {
|
||||||
|
// ":let &option = expr": Set option value.
|
||||||
|
// ":let &l:option = expr": Set local option value.
|
||||||
|
// ":let &g:option = expr": Set global option value.
|
||||||
|
return ex_let_option(arg, tv, is_const, endchars, op);
|
||||||
|
} else if (*arg == '@') {
|
||||||
|
// ":let @r = expr": Set register contents.
|
||||||
|
return ex_let_register(arg, tv, is_const, endchars, op);
|
||||||
|
} else if (eval_isnamec1(*arg) || *arg == '{') {
|
||||||
// ":let var = expr": Set internal variable.
|
// ":let var = expr": Set internal variable.
|
||||||
// ":let {expr} = expr": Idem, name made with curly braces
|
// ":let {expr} = expr": Idem, name made with curly braces
|
||||||
} else if (eval_isnamec1(*arg) || *arg == '{') {
|
|
||||||
lval_T lv;
|
lval_T lv;
|
||||||
|
|
||||||
char *const p = get_lval(arg, tv, &lv, false, false, 0, FNE_CHECK_START);
|
char *const p = get_lval(arg, tv, &lv, false, false, 0, FNE_CHECK_START);
|
||||||
if (p != NULL && lv.ll_name != NULL) {
|
if (p != NULL && lv.ll_name != NULL) {
|
||||||
if (endchars != NULL && vim_strchr(endchars, (uint8_t)(*skipwhite(p))) == NULL) {
|
if (endchars != NULL && vim_strchr(endchars, (uint8_t)(*skipwhite(p))) == NULL) {
|
||||||
|
Reference in New Issue
Block a user