vim-patch:8.1.1823: command line history code is spread out (#19688)

Problem:    Command line history code is spread out.
Solution:   Put the code in a new file. (Yegappan Lakshmanan, closes vim/vim#4779)
            Also graduate the +cmdline_hist feature.
d7663c22c6
This commit is contained in:
zeertzjq
2022-08-09 17:13:44 +08:00
committed by GitHub
parent a5e846b996
commit cd14efd281
12 changed files with 835 additions and 792 deletions

View File

@@ -13,6 +13,7 @@
#include "nvim/change.h"
#include "nvim/channel.h"
#include "nvim/charset.h"
#include "nvim/cmdhist.h"
#include "nvim/context.h"
#include "nvim/cursor.h"
#include "nvim/diff.h"
@@ -4303,87 +4304,6 @@ static void f_haslocaldir(typval_T *argvars, typval_T *rettv, FunPtr fptr)
}
}
/// "histadd()" function
static void f_histadd(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
HistoryType histype;
rettv->vval.v_number = false;
if (check_secure()) {
return;
}
const char *str = tv_get_string_chk(&argvars[0]); // NULL on type error
histype = str != NULL ? get_histtype(str, strlen(str), false) : HIST_INVALID;
if (histype != HIST_INVALID) {
char buf[NUMBUFLEN];
str = tv_get_string_buf(&argvars[1], buf);
if (*str != NUL) {
init_history();
add_to_history(histype, (char_u *)str, false, NUL);
rettv->vval.v_number = true;
return;
}
}
}
/// "histdel()" function
static void f_histdel(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int n;
const char *const str = tv_get_string_chk(&argvars[0]); // NULL on type error
if (str == NULL) {
n = 0;
} else if (argvars[1].v_type == VAR_UNKNOWN) {
// only one argument: clear entire history
n = clr_history(get_histtype(str, strlen(str), false));
} else if (argvars[1].v_type == VAR_NUMBER) {
// index given: remove that entry
n = del_history_idx(get_histtype(str, strlen(str), false),
(int)tv_get_number(&argvars[1]));
} else {
// string given: remove all matching entries
char buf[NUMBUFLEN];
n = del_history_entry(get_histtype(str, strlen(str), false),
(char_u *)tv_get_string_buf(&argvars[1], buf));
}
rettv->vval.v_number = n;
}
/// "histget()" function
static void f_histget(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
HistoryType type;
int idx;
const char *const str = tv_get_string_chk(&argvars[0]); // NULL on type error
if (str == NULL) {
rettv->vval.v_string = NULL;
} else {
type = get_histtype(str, strlen(str), false);
if (argvars[1].v_type == VAR_UNKNOWN) {
idx = get_history_idx(type);
} else {
idx = (int)tv_get_number_chk(&argvars[1], NULL);
}
// -1 on type error
rettv->vval.v_string = (char *)vim_strsave(get_history_entry(type, idx));
}
rettv->v_type = VAR_STRING;
}
/// "histnr()" function
static void f_histnr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
const char *const history = tv_get_string_chk(&argvars[0]);
HistoryType i = history == NULL
? HIST_INVALID
: get_histtype(history, strlen(history), false);
if (i != HIST_INVALID) {
i = get_history_idx(i);
}
rettv->vval.v_number = i;
}
/// "highlightID(name)" function
static void f_hlID(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{