vim-patch:8.1.1966: some code in options.c fits better elsewhere (#19840)

Problem:    Some code in options.c fits better elsewhere.
Solution:   Move functions from options.c to other files. (Yegappan
            Lakshmanan, closes vim/vim#4889)
e677df8d93
This commit is contained in:
zeertzjq
2022-08-19 19:20:39 +08:00
committed by GitHub
parent 5dc43265b1
commit 2af9be3db5
13 changed files with 951 additions and 941 deletions

View File

@@ -3097,13 +3097,6 @@ static void f_getline(typval_T *argvars, typval_T *rettv, FunPtr fptr)
get_buffer_lines(curbuf, lnum, end, retlist, rettv);
}
/// "getloclist()" function
static void f_getloclist(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
win_T *wp = find_win_by_nr_or_id(&argvars[0]);
get_qf_loc_list(false, wp, &argvars[1], rettv);
}
/// "getmarklist()" function
static void f_getmarklist(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
@@ -3186,12 +3179,6 @@ static void f_getpos(typval_T *argvars, typval_T *rettv, FunPtr fptr)
getpos_both(argvars, rettv, false, false);
}
/// "getqflist()" functions
static void f_getqflist(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
get_qf_loc_list(true, NULL, &argvars[0], rettv);
}
/// Common between getreg(), getreginfo() and getregtype(): get the register
/// name from the first argument.
/// Returns zero on error.
@@ -7761,110 +7748,12 @@ static void f_setline(typval_T *argvars, typval_T *rettv, FunPtr fptr)
set_buffer_lines(curbuf, lnum, false, &argvars[1], rettv);
}
/// Create quickfix/location list from VimL values
///
/// Used by `setqflist()` and `setloclist()` functions. Accepts invalid
/// args argument in which case errors out, including VAR_UNKNOWN parameters.
///
/// @param[in,out] wp Window to create location list for. May be NULL in
/// which case quickfix list will be created.
/// @param[in] args [list, action, what]
/// @param[in] args[0] Quickfix list contents.
/// @param[in] args[1] Optional. Action to perform:
/// append to an existing list, replace its content,
/// or create a new one.
/// @param[in] args[2] Optional. Quickfix list properties or title.
/// Defaults to caller function name.
/// @param[out] rettv Return value: 0 in case of success, -1 otherwise.
static void set_qf_ll_list(win_T *wp, typval_T *args, typval_T *rettv)
FUNC_ATTR_NONNULL_ARG(2, 3)
{
static char *e_invact = N_("E927: Invalid action: '%s'");
const char *title = NULL;
char action = ' ';
static int recursive = 0;
rettv->vval.v_number = -1;
dict_T *what = NULL;
typval_T *list_arg = &args[0];
if (list_arg->v_type != VAR_LIST) {
emsg(_(e_listreq));
return;
} else if (recursive != 0) {
emsg(_(e_au_recursive));
return;
}
typval_T *action_arg = &args[1];
if (action_arg->v_type == VAR_UNKNOWN) {
// Option argument was not given.
goto skip_args;
} else if (action_arg->v_type != VAR_STRING) {
emsg(_(e_stringreq));
return;
}
const char *const act = tv_get_string_chk(action_arg);
if ((*act == 'a' || *act == 'r' || *act == ' ' || *act == 'f')
&& act[1] == NUL) {
action = *act;
} else {
semsg(_(e_invact), act);
return;
}
typval_T *const what_arg = &args[2];
if (what_arg->v_type == VAR_UNKNOWN) {
// Option argument was not given.
goto skip_args;
} else if (what_arg->v_type == VAR_STRING) {
title = tv_get_string_chk(what_arg);
if (!title) {
// Type error. Error already printed by tv_get_string_chk().
return;
}
} else if (what_arg->v_type == VAR_DICT && what_arg->vval.v_dict != NULL) {
what = what_arg->vval.v_dict;
} else {
emsg(_(e_dictreq));
return;
}
skip_args:
if (!title) {
title = (wp ? ":setloclist()" : ":setqflist()");
}
recursive++;
list_T *const l = list_arg->vval.v_list;
if (set_errorlist(wp, l, action, (char *)title, what) == OK) {
rettv->vval.v_number = 0;
}
recursive--;
}
/// "setloclist()" function
static void f_setloclist(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = -1;
win_T *win = find_win_by_nr_or_id(&argvars[0]);
if (win != NULL) {
set_qf_ll_list(win, &argvars[1], rettv);
}
}
/// "setpos()" function
static void f_setpos(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
set_position(argvars, rettv, false);
}
/// "setqflist()" function
static void f_setqflist(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
set_qf_ll_list(NULL, argvars, rettv);
}
/// Translate a register type string to the yank type and block length
static int get_yank_type(char **const pp, MotionType *const yank_type, long *const block_len)
FUNC_ATTR_NONNULL_ALL