mirror of
https://github.com/neovim/neovim.git
synced 2025-10-09 11:26:37 +00:00
Merge #10823 from janlazo/vim-8.1.1124
This commit is contained in:
299
src/nvim/edit.c
299
src/nvim/edit.c
@@ -141,19 +141,13 @@ struct compl_S {
|
||||
compl_T *cp_next;
|
||||
compl_T *cp_prev;
|
||||
char_u *cp_str; // matched text
|
||||
char cp_icase; // TRUE or FALSE: ignore case
|
||||
char cp_equal; // TRUE or FALSE: ins_compl_equal always ok
|
||||
char_u *(cp_text[CPT_COUNT]); // text for the menu
|
||||
char_u *cp_fname; // file containing the match, allocated when
|
||||
// cp_flags has FREE_FNAME
|
||||
int cp_flags; // ORIGINAL_TEXT, CONT_S_IPOS or FREE_FNAME
|
||||
// cp_flags has CP_FREE_FNAME
|
||||
int cp_flags; // CP_ values
|
||||
int cp_number; // sequence number
|
||||
};
|
||||
|
||||
// flags for ins_compl_add()
|
||||
#define ORIGINAL_TEXT (1) // the original text when the expansion begun
|
||||
#define FREE_FNAME (2)
|
||||
|
||||
/*
|
||||
* All the current matches are stored in a list.
|
||||
* "compl_first_match" points to the start of the list.
|
||||
@@ -182,18 +176,18 @@ static int compl_no_insert = FALSE; /* FALSE: select & insert
|
||||
static int compl_no_select = FALSE; /* FALSE: select & insert
|
||||
TRUE: noselect */
|
||||
|
||||
static int compl_used_match; // Selected one of the matches. When
|
||||
// FALSE the match was edited or using
|
||||
// the longest common string.
|
||||
static bool compl_used_match; // Selected one of the matches.
|
||||
// When false the match was edited or using
|
||||
// the longest common string.
|
||||
|
||||
static int compl_was_interrupted = FALSE; /* didn't finish finding
|
||||
completions. */
|
||||
|
||||
static int compl_restarting = FALSE; /* don't insert match */
|
||||
|
||||
/* When the first completion is done "compl_started" is set. When it's
|
||||
* FALSE the word to be completed must be located. */
|
||||
static int compl_started = FALSE;
|
||||
// When the first completion is done "compl_started" is set. When it's
|
||||
// false the word to be completed must be located.
|
||||
static bool compl_started = false;
|
||||
|
||||
// Which Ctrl-X mode are we in?
|
||||
static int ctrl_x_mode = CTRL_X_NORMAL;
|
||||
@@ -2062,21 +2056,24 @@ static bool ins_compl_accept_char(int c)
|
||||
return vim_iswordc(c);
|
||||
}
|
||||
|
||||
// This is like ins_compl_add(), but if 'ic' and 'inf' are set, then the
|
||||
// case of the originally typed text is used, and the case of the completed
|
||||
// text is inferred, ie this tries to work out what case you probably wanted
|
||||
// the rest of the word to be in -- webb
|
||||
int ins_compl_add_infercase(char_u *str_arg, int len, int icase, char_u *fname,
|
||||
int dir, int flags)
|
||||
/// This is like ins_compl_add(), but if 'ic' and 'inf' are set, then the
|
||||
/// case of the originally typed text is used, and the case of the completed
|
||||
/// text is inferred, ie this tries to work out what case you probably wanted
|
||||
/// the rest of the word to be in -- webb
|
||||
///
|
||||
/// @param[in] cont_s_ipos next ^X<> will set initial_pos
|
||||
int ins_compl_add_infercase(char_u *str_arg, int len, bool icase, char_u *fname,
|
||||
int dir, bool cont_s_ipos)
|
||||
FUNC_ATTR_NONNULL_ARG(1)
|
||||
{
|
||||
char_u *str = str_arg;
|
||||
int i, c;
|
||||
int actual_len; /* Take multi-byte characters */
|
||||
int actual_compl_length; /* into account. */
|
||||
int min_len;
|
||||
int *wca; /* Wide character array. */
|
||||
int has_lower = FALSE;
|
||||
int was_letter = FALSE;
|
||||
bool has_lower = false;
|
||||
bool was_letter = false;
|
||||
int flags = 0;
|
||||
|
||||
if (p_ic && curbuf->b_p_inf && len > 0) {
|
||||
// Infer case of completed part.
|
||||
@@ -2108,8 +2105,8 @@ int ins_compl_add_infercase(char_u *str_arg, int len, int icase, char_u *fname,
|
||||
min_len = actual_len < actual_compl_length
|
||||
? actual_len : actual_compl_length;
|
||||
|
||||
/* Allocate wide character array for the completion and fill it. */
|
||||
wca = xmalloc(actual_len * sizeof(*wca));
|
||||
// Allocate wide character array for the completion and fill it.
|
||||
int *const wca = xmalloc(actual_len * sizeof(*wca));
|
||||
{
|
||||
const char_u *p = str;
|
||||
for (i = 0; i < actual_len; i++) {
|
||||
@@ -2200,15 +2197,20 @@ int ins_compl_add_infercase(char_u *str_arg, int len, int icase, char_u *fname,
|
||||
|
||||
str = IObuff;
|
||||
}
|
||||
return ins_compl_add(str, len, icase, fname, NULL, false, dir, flags,
|
||||
false, false);
|
||||
if (cont_s_ipos) {
|
||||
flags |= CP_CONT_S_IPOS;
|
||||
}
|
||||
if (icase) {
|
||||
flags |= CP_ICASE;
|
||||
}
|
||||
|
||||
return ins_compl_add(str, len, fname, NULL, false, dir, flags, false);
|
||||
}
|
||||
|
||||
/// Add a match to the list of matches
|
||||
///
|
||||
/// @param[in] str Match to add.
|
||||
/// @param[in] len Match length, -1 to use #STRLEN.
|
||||
/// @param[in] icase Whether case is to be ignored.
|
||||
/// @param[in] fname File name match comes from. May be NULL.
|
||||
/// @param[in] cptext Extra text for popup menu. May be NULL. If not NULL,
|
||||
/// must have exactly #CPT_COUNT items.
|
||||
@@ -2218,21 +2220,20 @@ int ins_compl_add_infercase(char_u *str_arg, int len, int icase, char_u *fname,
|
||||
/// cptext itself will not be freed.
|
||||
/// @param[in] cdir Completion direction.
|
||||
/// @param[in] adup True if duplicate matches are to be accepted.
|
||||
/// @param[in] equal Match is always accepted by ins_compl_equal.
|
||||
///
|
||||
/// @return NOTDONE if the given string is already in the list of completions,
|
||||
/// otherwise it is added to the list and OK is returned. FAIL will be
|
||||
/// returned in case of error.
|
||||
static int ins_compl_add(char_u *const str, int len,
|
||||
const bool icase, char_u *const fname,
|
||||
char_u *const fname,
|
||||
char_u *const *const cptext,
|
||||
const bool cptext_allocated,
|
||||
const Direction cdir, int flags, const bool adup,
|
||||
int equal)
|
||||
const Direction cdir, int flags_arg, const bool adup)
|
||||
FUNC_ATTR_NONNULL_ARG(1)
|
||||
{
|
||||
compl_T *match;
|
||||
int dir = (cdir == kDirectionNotSet ? compl_direction : cdir);
|
||||
int flags = flags_arg;
|
||||
|
||||
os_breakcheck();
|
||||
#define FREE_CPTEXT(cptext, cptext_allocated) \
|
||||
@@ -2257,7 +2258,7 @@ static int ins_compl_add(char_u *const str, int len,
|
||||
if (compl_first_match != NULL && !adup) {
|
||||
match = compl_first_match;
|
||||
do {
|
||||
if (!(match->cp_flags & ORIGINAL_TEXT)
|
||||
if (!(match->cp_flags & CP_ORIGINAL_TEXT)
|
||||
&& STRNCMP(match->cp_str, str, len) == 0
|
||||
&& match->cp_str[len] == NUL) {
|
||||
FREE_CPTEXT(cptext, cptext_allocated);
|
||||
@@ -2276,24 +2277,23 @@ static int ins_compl_add(char_u *const str, int len,
|
||||
*/
|
||||
match = xcalloc(1, sizeof(compl_T));
|
||||
match->cp_number = -1;
|
||||
if (flags & ORIGINAL_TEXT)
|
||||
if (flags & CP_ORIGINAL_TEXT) {
|
||||
match->cp_number = 0;
|
||||
}
|
||||
match->cp_str = vim_strnsave(str, len);
|
||||
match->cp_icase = icase;
|
||||
match->cp_equal = equal;
|
||||
|
||||
/* match-fname is:
|
||||
* - compl_curr_match->cp_fname if it is a string equal to fname.
|
||||
* - a copy of fname, FREE_FNAME is set to free later THE allocated mem.
|
||||
* - NULL otherwise. --Acevedo */
|
||||
// match-fname is:
|
||||
// - compl_curr_match->cp_fname if it is a string equal to fname.
|
||||
// - a copy of fname, CP_FREE_FNAME is set to free later THE allocated mem.
|
||||
// - NULL otherwise. --Acevedo
|
||||
if (fname != NULL
|
||||
&& compl_curr_match != NULL
|
||||
&& compl_curr_match->cp_fname != NULL
|
||||
&& STRCMP(fname, compl_curr_match->cp_fname) == 0)
|
||||
&& STRCMP(fname, compl_curr_match->cp_fname) == 0) {
|
||||
match->cp_fname = compl_curr_match->cp_fname;
|
||||
else if (fname != NULL) {
|
||||
} else if (fname != NULL) {
|
||||
match->cp_fname = vim_strsave(fname);
|
||||
flags |= FREE_FNAME;
|
||||
flags |= CP_FREE_FNAME;
|
||||
} else {
|
||||
match->cp_fname = NULL;
|
||||
}
|
||||
@@ -2339,14 +2339,15 @@ static int ins_compl_add(char_u *const str, int len,
|
||||
/*
|
||||
* Find the longest common string if still doing that.
|
||||
*/
|
||||
if (compl_get_longest && (flags & ORIGINAL_TEXT) == 0)
|
||||
if (compl_get_longest && (flags & CP_ORIGINAL_TEXT) == 0) {
|
||||
ins_compl_longest_match(match);
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/// Check that "str[len]" matches with "match->cp_str", considering
|
||||
/// "match->cp_icase".
|
||||
/// "match->cp_flags".
|
||||
///
|
||||
/// @param match completion match
|
||||
/// @param str character string to check
|
||||
@@ -2354,10 +2355,10 @@ static int ins_compl_add(char_u *const str, int len,
|
||||
static bool ins_compl_equal(compl_T *match, char_u *str, size_t len)
|
||||
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
if (match->cp_equal) {
|
||||
if (match->cp_flags & CP_EQUAL) {
|
||||
return true;
|
||||
}
|
||||
if (match->cp_icase) {
|
||||
if (match->cp_flags & CP_ICASE) {
|
||||
return STRNICMP(match->cp_str, str, len) == 0;
|
||||
}
|
||||
return STRNCMP(match->cp_str, str, len) == 0;
|
||||
@@ -2384,7 +2385,7 @@ static void ins_compl_longest_match(compl_T *match)
|
||||
* again after redrawing. */
|
||||
if (!had_match)
|
||||
ins_compl_delete();
|
||||
compl_used_match = FALSE;
|
||||
compl_used_match = false;
|
||||
} else {
|
||||
/* Reduce the text if this match differs from compl_leader. */
|
||||
p = compl_leader;
|
||||
@@ -2393,7 +2394,9 @@ static void ins_compl_longest_match(compl_T *match)
|
||||
c1 = utf_ptr2char(p);
|
||||
c2 = utf_ptr2char(s);
|
||||
|
||||
if (match->cp_icase ? (mb_tolower(c1) != mb_tolower(c2)) : (c1 != c2)) {
|
||||
if ((match->cp_flags & CP_ICASE)
|
||||
? (mb_tolower(c1) != mb_tolower(c2))
|
||||
: (c1 != c2)) {
|
||||
break;
|
||||
}
|
||||
MB_PTR_ADV(p);
|
||||
@@ -2414,7 +2417,7 @@ static void ins_compl_longest_match(compl_T *match)
|
||||
ins_compl_delete();
|
||||
}
|
||||
|
||||
compl_used_match = FALSE;
|
||||
compl_used_match = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2423,18 +2426,18 @@ static void ins_compl_longest_match(compl_T *match)
|
||||
* Frees matches[].
|
||||
*/
|
||||
static void ins_compl_add_matches(int num_matches, char_u **matches, int icase)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
int i;
|
||||
int add_r = OK;
|
||||
int dir = compl_direction;
|
||||
|
||||
for (i = 0; i < num_matches && add_r != FAIL; i++)
|
||||
if ((add_r = ins_compl_add(matches[i], -1, icase,
|
||||
NULL, NULL, false, dir, 0, false,
|
||||
false)) == OK) {
|
||||
for (int i = 0; i < num_matches && add_r != FAIL; i++) {
|
||||
if ((add_r = ins_compl_add(matches[i], -1, NULL, NULL, false, dir,
|
||||
icase ? CP_ICASE : 0, false)) == OK) {
|
||||
// If dir was BACKWARD then honor it just once.
|
||||
dir = FORWARD;
|
||||
}
|
||||
}
|
||||
FreeWild(num_matches, matches);
|
||||
}
|
||||
|
||||
@@ -2484,6 +2487,8 @@ void completeopt_was_set(void)
|
||||
*/
|
||||
void set_completion(colnr_T startcol, list_T *list)
|
||||
{
|
||||
int flags = CP_ORIGINAL_TEXT;
|
||||
|
||||
// If already doing completions stop it.
|
||||
if (ctrl_x_mode != CTRL_X_NORMAL) {
|
||||
ins_compl_prep(' ');
|
||||
@@ -2499,8 +2504,11 @@ void set_completion(colnr_T startcol, list_T *list)
|
||||
/* compl_pattern doesn't need to be set */
|
||||
compl_orig_text = vim_strnsave(get_cursor_line_ptr() + compl_col,
|
||||
compl_length);
|
||||
if (ins_compl_add(compl_orig_text, -1, p_ic, NULL, NULL, false, 0,
|
||||
ORIGINAL_TEXT, false, false) != OK) {
|
||||
if (p_ic) {
|
||||
flags |= CP_ICASE;
|
||||
}
|
||||
if (ins_compl_add(compl_orig_text, -1, NULL, NULL, false, 0,
|
||||
flags, false) != OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2508,8 +2516,8 @@ void set_completion(colnr_T startcol, list_T *list)
|
||||
|
||||
ins_compl_add_list(list);
|
||||
compl_matches = ins_compl_make_cyclic();
|
||||
compl_started = TRUE;
|
||||
compl_used_match = TRUE;
|
||||
compl_started = true;
|
||||
compl_used_match = true;
|
||||
compl_cont_status = 0;
|
||||
int save_w_wrow = curwin->w_wrow;
|
||||
int save_w_leftcol = curwin->w_leftcol;
|
||||
@@ -2569,7 +2577,8 @@ static bool pum_enough_matches(void)
|
||||
compl_T *comp = compl_first_match;
|
||||
int i = 0;
|
||||
do {
|
||||
if (comp == NULL || ((comp->cp_flags & ORIGINAL_TEXT) == 0 && ++i == 2)) {
|
||||
if (comp == NULL
|
||||
|| ((comp->cp_flags & CP_ORIGINAL_TEXT) == 0 && ++i == 2)) {
|
||||
break;
|
||||
}
|
||||
comp = comp->cp_next;
|
||||
@@ -2614,8 +2623,8 @@ void ins_compl_show_pum(void)
|
||||
{
|
||||
compl_T *compl;
|
||||
compl_T *shown_compl = NULL;
|
||||
int did_find_shown_match = FALSE;
|
||||
int shown_match_ok = FALSE;
|
||||
bool did_find_shown_match = false;
|
||||
bool shown_match_ok = false;
|
||||
int i;
|
||||
int cur = -1;
|
||||
colnr_T col;
|
||||
@@ -2647,7 +2656,7 @@ void ins_compl_show_pum(void)
|
||||
lead_len = (int)STRLEN(compl_leader);
|
||||
}
|
||||
do {
|
||||
if ((compl->cp_flags & ORIGINAL_TEXT) == 0
|
||||
if ((compl->cp_flags & CP_ORIGINAL_TEXT) == 0
|
||||
&& (compl_leader == NULL
|
||||
|| ins_compl_equal(compl, compl_leader, lead_len))) {
|
||||
compl_match_arraysize++;
|
||||
@@ -2661,13 +2670,14 @@ void ins_compl_show_pum(void)
|
||||
compl_match_array = xcalloc(compl_match_arraysize, sizeof(pumitem_T));
|
||||
/* If the current match is the original text don't find the first
|
||||
* match after it, don't highlight anything. */
|
||||
if (compl_shown_match->cp_flags & ORIGINAL_TEXT)
|
||||
shown_match_ok = TRUE;
|
||||
if (compl_shown_match->cp_flags & CP_ORIGINAL_TEXT) {
|
||||
shown_match_ok = true;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
compl = compl_first_match;
|
||||
do {
|
||||
if ((compl->cp_flags & ORIGINAL_TEXT) == 0
|
||||
if ((compl->cp_flags & CP_ORIGINAL_TEXT) == 0
|
||||
&& (compl_leader == NULL
|
||||
|| ins_compl_equal(compl, compl_leader, lead_len))) {
|
||||
if (!shown_match_ok) {
|
||||
@@ -2675,12 +2685,13 @@ void ins_compl_show_pum(void)
|
||||
/* This item is the shown match or this is the
|
||||
* first displayed item after the shown match. */
|
||||
compl_shown_match = compl;
|
||||
did_find_shown_match = TRUE;
|
||||
shown_match_ok = TRUE;
|
||||
} else
|
||||
/* Remember this displayed match for when the
|
||||
* shown match is just below it. */
|
||||
did_find_shown_match = true;
|
||||
shown_match_ok = true;
|
||||
} else {
|
||||
// Remember this displayed match for when the
|
||||
// shown match is just below it.
|
||||
shown_compl = compl;
|
||||
}
|
||||
cur = i;
|
||||
}
|
||||
|
||||
@@ -2699,18 +2710,19 @@ void ins_compl_show_pum(void)
|
||||
}
|
||||
|
||||
if (compl == compl_shown_match) {
|
||||
did_find_shown_match = TRUE;
|
||||
did_find_shown_match = true;
|
||||
|
||||
/* When the original text is the shown match don't set
|
||||
* compl_shown_match. */
|
||||
if (compl->cp_flags & ORIGINAL_TEXT)
|
||||
shown_match_ok = TRUE;
|
||||
if (compl->cp_flags & CP_ORIGINAL_TEXT) {
|
||||
shown_match_ok = true;
|
||||
}
|
||||
|
||||
if (!shown_match_ok && shown_compl != NULL) {
|
||||
/* The shown match isn't displayed, set it to the
|
||||
* previously displayed match. */
|
||||
compl_shown_match = shown_compl;
|
||||
shown_match_ok = TRUE;
|
||||
shown_match_ok = true;
|
||||
}
|
||||
}
|
||||
compl = compl->cp_next;
|
||||
@@ -2882,8 +2894,8 @@ static void ins_compl_files(int count, char_u **files, int thesaurus, int flags,
|
||||
ptr = find_word_end(ptr);
|
||||
}
|
||||
add_r = ins_compl_add_infercase(regmatch->startp[0],
|
||||
(int)(ptr - regmatch->startp[0]),
|
||||
p_ic, files[i], *dir, 0);
|
||||
(int)(ptr - regmatch->startp[0]),
|
||||
p_ic, files[i], *dir, false);
|
||||
if (thesaurus) {
|
||||
char_u *wstart;
|
||||
|
||||
@@ -2914,11 +2926,11 @@ static void ins_compl_files(int count, char_u **files, int thesaurus, int flags,
|
||||
else
|
||||
ptr = find_word_end(ptr);
|
||||
|
||||
/* Add the word. Skip the regexp match. */
|
||||
if (wstart != regmatch->startp[0])
|
||||
add_r = ins_compl_add_infercase(wstart,
|
||||
(int)(ptr - wstart),
|
||||
p_ic, files[i], *dir, 0);
|
||||
// Add the word. Skip the regexp match.
|
||||
if (wstart != regmatch->startp[0]) {
|
||||
add_r = ins_compl_add_infercase(wstart, (int)(ptr - wstart),
|
||||
p_ic, files[i], *dir, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (add_r == OK)
|
||||
@@ -2995,7 +3007,6 @@ static char_u *find_line_end(char_u *ptr)
|
||||
static void ins_compl_free(void)
|
||||
{
|
||||
compl_T *match;
|
||||
int i;
|
||||
|
||||
XFREE_CLEAR(compl_pattern);
|
||||
XFREE_CLEAR(compl_leader);
|
||||
@@ -3011,11 +3022,13 @@ static void ins_compl_free(void)
|
||||
match = compl_curr_match;
|
||||
compl_curr_match = compl_curr_match->cp_next;
|
||||
xfree(match->cp_str);
|
||||
/* several entries may use the same fname, free it just once. */
|
||||
if (match->cp_flags & FREE_FNAME)
|
||||
// several entries may use the same fname, free it just once.
|
||||
if (match->cp_flags & CP_FREE_FNAME) {
|
||||
xfree(match->cp_fname);
|
||||
for (i = 0; i < CPT_COUNT; ++i)
|
||||
}
|
||||
for (int i = 0; i < CPT_COUNT; i++) {
|
||||
xfree(match->cp_text[i]);
|
||||
}
|
||||
xfree(match);
|
||||
} while (compl_curr_match != NULL && compl_curr_match != compl_first_match);
|
||||
compl_first_match = compl_curr_match = NULL;
|
||||
@@ -3026,7 +3039,7 @@ static void ins_compl_free(void)
|
||||
static void ins_compl_clear(void)
|
||||
{
|
||||
compl_cont_status = 0;
|
||||
compl_started = FALSE;
|
||||
compl_started = false;
|
||||
compl_matches = 0;
|
||||
XFREE_CLEAR(compl_pattern);
|
||||
XFREE_CLEAR(compl_leader);
|
||||
@@ -3095,7 +3108,7 @@ void get_complete_info(list_T *what_list, dict_T *retdict)
|
||||
if (ret == OK && compl_first_match != NULL) {
|
||||
compl_T *match = compl_first_match;
|
||||
do {
|
||||
if (!(match->cp_flags & ORIGINAL_TEXT)) {
|
||||
if (!(match->cp_flags & CP_ORIGINAL_TEXT)) {
|
||||
dict_T *di = tv_dict_alloc();
|
||||
|
||||
tv_list_append_dict(li, di);
|
||||
@@ -3202,7 +3215,7 @@ static void ins_compl_new_leader(void)
|
||||
ins_compl_del_pum();
|
||||
ins_compl_delete();
|
||||
ins_bytes(compl_leader + ins_compl_len());
|
||||
compl_used_match = FALSE;
|
||||
compl_used_match = false;
|
||||
|
||||
if (compl_started) {
|
||||
ins_compl_set_original_text(compl_leader);
|
||||
@@ -3283,7 +3296,7 @@ static void ins_compl_restart(void)
|
||||
* will stay to the last popup menu and reduce flicker */
|
||||
update_screen(0);
|
||||
ins_compl_free();
|
||||
compl_started = FALSE;
|
||||
compl_started = false;
|
||||
compl_matches = 0;
|
||||
compl_cont_status = 0;
|
||||
compl_cont_mode = 0;
|
||||
@@ -3293,15 +3306,16 @@ static void ins_compl_restart(void)
|
||||
* Set the first match, the original text.
|
||||
*/
|
||||
static void ins_compl_set_original_text(char_u *str)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
// Replace the original text entry.
|
||||
// The ORIGINAL_TEXT flag is either at the first item or might possibly be
|
||||
// The CP_ORIGINAL_TEXT flag is either at the first item or might possibly be
|
||||
// at the last item for backward completion
|
||||
if (compl_first_match->cp_flags & ORIGINAL_TEXT) { // safety check
|
||||
if (compl_first_match->cp_flags & CP_ORIGINAL_TEXT) { // safety check
|
||||
xfree(compl_first_match->cp_str);
|
||||
compl_first_match->cp_str = vim_strsave(str);
|
||||
} else if (compl_first_match->cp_prev != NULL
|
||||
&& (compl_first_match->cp_prev->cp_flags & ORIGINAL_TEXT)) {
|
||||
&& (compl_first_match->cp_prev->cp_flags & CP_ORIGINAL_TEXT)) {
|
||||
xfree(compl_first_match->cp_prev->cp_str);
|
||||
compl_first_match->cp_prev->cp_str = vim_strsave(str);
|
||||
}
|
||||
@@ -3322,7 +3336,7 @@ static void ins_compl_addfrommatch(void)
|
||||
if ((int)STRLEN(p) <= len) { /* the match is too short */
|
||||
/* When still at the original match use the first entry that matches
|
||||
* the leader. */
|
||||
if (compl_shown_match->cp_flags & ORIGINAL_TEXT) {
|
||||
if (compl_shown_match->cp_flags & CP_ORIGINAL_TEXT) {
|
||||
p = NULL;
|
||||
for (cp = compl_shown_match->cp_next; cp != NULL
|
||||
&& cp != compl_first_match; cp = cp->cp_next) {
|
||||
@@ -3371,8 +3385,7 @@ static bool ins_compl_prep(int c)
|
||||
if (ctrl_x_mode == CTRL_X_NOT_DEFINED_YET
|
||||
|| (ctrl_x_mode == CTRL_X_NORMAL && !compl_started)) {
|
||||
compl_get_longest = (strstr((char *)p_cot, "longest") != NULL);
|
||||
compl_used_match = TRUE;
|
||||
|
||||
compl_used_match = true;
|
||||
}
|
||||
|
||||
if (ctrl_x_mode == CTRL_X_NOT_DEFINED_YET) {
|
||||
@@ -3563,7 +3576,7 @@ static bool ins_compl_prep(int c)
|
||||
auto_format(FALSE, TRUE);
|
||||
|
||||
ins_compl_free();
|
||||
compl_started = FALSE;
|
||||
compl_started = false;
|
||||
compl_matches = 0;
|
||||
if (!shortmess(SHM_COMPLETIONMENU)) {
|
||||
msg_clr_cmdline(); // necessary for "noshowmode"
|
||||
@@ -3807,10 +3820,9 @@ int ins_compl_add_tv(typval_T *const tv, const Direction dir)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
const char *word;
|
||||
bool icase = false;
|
||||
bool adup = false;
|
||||
bool aempty = false;
|
||||
bool aequal = false;
|
||||
bool dup = false;
|
||||
bool empty = false;
|
||||
int flags = 0;
|
||||
char *(cptext[CPT_COUNT]);
|
||||
|
||||
if (tv->v_type == VAR_DICT && tv->vval.v_dict != NULL) {
|
||||
@@ -3822,30 +3834,33 @@ int ins_compl_add_tv(typval_T *const tv, const Direction dir)
|
||||
cptext[CPT_USER_DATA] = tv_dict_get_string(tv->vval.v_dict,
|
||||
"user_data", true);
|
||||
|
||||
icase = (bool)tv_dict_get_number(tv->vval.v_dict, "icase");
|
||||
adup = (bool)tv_dict_get_number(tv->vval.v_dict, "dup");
|
||||
aempty = (bool)tv_dict_get_number(tv->vval.v_dict, "empty");
|
||||
if (tv_dict_get_string(tv->vval.v_dict, "equal", false) != NULL) {
|
||||
aequal = tv_dict_get_number(tv->vval.v_dict, "equal");
|
||||
if (tv_dict_get_number(tv->vval.v_dict, "icase")) {
|
||||
flags |= CP_ICASE;
|
||||
}
|
||||
dup = (bool)tv_dict_get_number(tv->vval.v_dict, "dup");
|
||||
empty = (bool)tv_dict_get_number(tv->vval.v_dict, "empty");
|
||||
if (tv_dict_get_string(tv->vval.v_dict, "equal", false) != NULL
|
||||
&& tv_dict_get_number(tv->vval.v_dict, "equal")) {
|
||||
flags |= CP_EQUAL;
|
||||
}
|
||||
} else {
|
||||
word = (const char *)tv_get_string_chk(tv);
|
||||
memset(cptext, 0, sizeof(cptext));
|
||||
}
|
||||
if (word == NULL || (!aempty && *word == NUL)) {
|
||||
if (word == NULL || (!empty && *word == NUL)) {
|
||||
for (size_t i = 0; i < CPT_COUNT; i++) {
|
||||
xfree(cptext[i]);
|
||||
}
|
||||
return FAIL;
|
||||
}
|
||||
return ins_compl_add((char_u *)word, -1, icase, NULL,
|
||||
(char_u **)cptext, true, dir, 0, adup, aequal);
|
||||
return ins_compl_add((char_u *)word, -1, NULL,
|
||||
(char_u **)cptext, true, dir, flags, dup);
|
||||
}
|
||||
|
||||
// Get the next expansion(s), using "compl_pattern".
|
||||
// The search starts at position "ini" in curbuf and in the direction
|
||||
// compl_direction.
|
||||
// When "compl_started" is FALSE start at that position, otherwise continue
|
||||
// When "compl_started" is false start at that position, otherwise continue
|
||||
// where we stopped searching before.
|
||||
// This may return before finding all the matches.
|
||||
// Return the total number of matches or -1 if still unknown -- Acevedo
|
||||
@@ -4085,7 +4100,7 @@ static int ins_compl_get_exp(pos_T *ini)
|
||||
else if (*e_cpt == '.')
|
||||
p_ws = true;
|
||||
for (;; ) {
|
||||
int flags = 0;
|
||||
bool cont_s_ipos = false;
|
||||
|
||||
msg_silent++; // Don't want messages for wrapscan.
|
||||
// CTRL_X_MODE_LINE_OR_EVAL(l_ctrl_x_mode) || word-wise search that
|
||||
@@ -4185,7 +4200,7 @@ static int ins_compl_get_exp(pos_T *ini)
|
||||
}
|
||||
STRLCPY(IObuff + len, ptr, IOSIZE - len);
|
||||
len += (int)(tmp_ptr - ptr);
|
||||
flags |= CONT_S_IPOS;
|
||||
cont_s_ipos = true;
|
||||
}
|
||||
IObuff[len] = NUL;
|
||||
ptr = IObuff;
|
||||
@@ -4194,9 +4209,9 @@ static int ins_compl_get_exp(pos_T *ini)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (ins_compl_add_infercase(ptr, len, p_ic,
|
||||
ins_buf == curbuf ? NULL : ins_buf->b_sfname,
|
||||
0, flags) != NOTDONE) {
|
||||
if (ins_compl_add_infercase(
|
||||
ptr, len, p_ic, ins_buf == curbuf ? NULL : ins_buf->b_sfname,
|
||||
0, cont_s_ipos) != NOTDONE) {
|
||||
found_new_match = OK;
|
||||
break;
|
||||
}
|
||||
@@ -4228,7 +4243,7 @@ static int ins_compl_get_exp(pos_T *ini)
|
||||
|| compl_interrupted) {
|
||||
break;
|
||||
}
|
||||
compl_started = TRUE;
|
||||
compl_started = true;
|
||||
} else {
|
||||
// Mark a buffer scanned when it has been scanned completely
|
||||
if (type == 0 || type == CTRL_X_PATH_PATTERNS) {
|
||||
@@ -4236,10 +4251,10 @@ static int ins_compl_get_exp(pos_T *ini)
|
||||
ins_buf->b_scanned = true;
|
||||
}
|
||||
|
||||
compl_started = FALSE;
|
||||
compl_started = false;
|
||||
}
|
||||
}
|
||||
compl_started = TRUE;
|
||||
compl_started = true;
|
||||
|
||||
if ((l_ctrl_x_mode == CTRL_X_NORMAL
|
||||
|| CTRL_X_MODE_LINE_OR_EVAL(l_ctrl_x_mode))
|
||||
@@ -4295,10 +4310,7 @@ static void ins_compl_delete(void)
|
||||
static void ins_compl_insert(int in_compl_func)
|
||||
{
|
||||
ins_bytes(compl_shown_match->cp_str + ins_compl_len());
|
||||
if (compl_shown_match->cp_flags & ORIGINAL_TEXT)
|
||||
compl_used_match = FALSE;
|
||||
else
|
||||
compl_used_match = TRUE;
|
||||
compl_used_match = !(compl_shown_match->cp_flags & CP_ORIGINAL_TEXT);
|
||||
|
||||
dict_T *dict = ins_compl_dict_alloc(compl_shown_match);
|
||||
set_vim_var_dict(VV_COMPLETED_ITEM, dict);
|
||||
@@ -4363,7 +4375,7 @@ ins_compl_next (
|
||||
compl_T *found_compl = NULL;
|
||||
int found_end = FALSE;
|
||||
int advance;
|
||||
int started = compl_started;
|
||||
const bool started = compl_started;
|
||||
|
||||
/* When user complete function return -1 for findstart which is next
|
||||
* time of 'always', compl_shown_match become NULL. */
|
||||
@@ -4371,14 +4383,15 @@ ins_compl_next (
|
||||
return -1;
|
||||
|
||||
if (compl_leader != NULL
|
||||
&& (compl_shown_match->cp_flags & ORIGINAL_TEXT) == 0) {
|
||||
/* Set "compl_shown_match" to the actually shown match, it may differ
|
||||
* when "compl_leader" is used to omit some of the matches. */
|
||||
&& (compl_shown_match->cp_flags & CP_ORIGINAL_TEXT) == 0) {
|
||||
// Set "compl_shown_match" to the actually shown match, it may differ
|
||||
// when "compl_leader" is used to omit some of the matches.
|
||||
while (!ins_compl_equal(compl_shown_match,
|
||||
compl_leader, (int)STRLEN(compl_leader))
|
||||
compl_leader, STRLEN(compl_leader))
|
||||
&& compl_shown_match->cp_next != NULL
|
||||
&& compl_shown_match->cp_next != compl_first_match)
|
||||
&& compl_shown_match->cp_next != compl_first_match) {
|
||||
compl_shown_match = compl_shown_match->cp_next;
|
||||
}
|
||||
|
||||
/* If we didn't find it searching forward, and compl_shows_dir is
|
||||
* backward, find the last match. */
|
||||
@@ -4459,14 +4472,15 @@ ins_compl_next (
|
||||
}
|
||||
found_end = FALSE;
|
||||
}
|
||||
if ((compl_shown_match->cp_flags & ORIGINAL_TEXT) == 0
|
||||
if ((compl_shown_match->cp_flags & CP_ORIGINAL_TEXT) == 0
|
||||
&& compl_leader != NULL
|
||||
&& !ins_compl_equal(compl_shown_match,
|
||||
compl_leader, (int)STRLEN(compl_leader)))
|
||||
++todo;
|
||||
else
|
||||
/* Remember a matching item. */
|
||||
compl_leader, STRLEN(compl_leader))) {
|
||||
todo++;
|
||||
} else {
|
||||
// Remember a matching item.
|
||||
found_compl = compl_shown_match;
|
||||
}
|
||||
|
||||
/* Stop at the end of the list when we found a usable match. */
|
||||
if (found_end) {
|
||||
@@ -4481,7 +4495,7 @@ ins_compl_next (
|
||||
/* Insert the text of the new completion, or the compl_leader. */
|
||||
if (compl_no_insert && !started) {
|
||||
ins_bytes(compl_orig_text + ins_compl_len());
|
||||
compl_used_match = FALSE;
|
||||
compl_used_match = false;
|
||||
} else if (insert_match) {
|
||||
if (!compl_get_longest || compl_used_match) {
|
||||
ins_compl_insert(in_compl_func);
|
||||
@@ -4489,7 +4503,7 @@ ins_compl_next (
|
||||
ins_bytes(compl_leader + ins_compl_len());
|
||||
}
|
||||
} else {
|
||||
compl_used_match = FALSE;
|
||||
compl_used_match = false;
|
||||
}
|
||||
|
||||
if (!allow_get_expansion) {
|
||||
@@ -4697,6 +4711,7 @@ static int ins_complete(int c, bool enable_pum)
|
||||
int save_w_leftcol;
|
||||
int insert_match;
|
||||
const bool save_did_ai = did_ai;
|
||||
int flags = CP_ORIGINAL_TEXT;
|
||||
|
||||
compl_direction = ins_compl_key2dir(c);
|
||||
insert_match = ins_compl_use_match(c);
|
||||
@@ -5024,8 +5039,11 @@ static int ins_complete(int c, bool enable_pum)
|
||||
/* Always add completion for the original text. */
|
||||
xfree(compl_orig_text);
|
||||
compl_orig_text = vim_strnsave(line + compl_col, compl_length);
|
||||
if (ins_compl_add(compl_orig_text, -1, p_ic, NULL, NULL, false, 0,
|
||||
ORIGINAL_TEXT, false, false) != OK) {
|
||||
if (p_ic) {
|
||||
flags |= CP_ICASE;
|
||||
}
|
||||
if (ins_compl_add(compl_orig_text, -1, NULL, NULL, false, 0,
|
||||
flags, false) != OK) {
|
||||
XFREE_CLEAR(compl_pattern);
|
||||
XFREE_CLEAR(compl_orig_text);
|
||||
return FAIL;
|
||||
@@ -5086,13 +5104,14 @@ static int ins_complete(int c, bool enable_pum)
|
||||
}
|
||||
}
|
||||
|
||||
if (compl_curr_match->cp_flags & CONT_S_IPOS)
|
||||
if (compl_curr_match->cp_flags & CP_CONT_S_IPOS) {
|
||||
compl_cont_status |= CONT_S_IPOS;
|
||||
else
|
||||
} else {
|
||||
compl_cont_status &= ~CONT_S_IPOS;
|
||||
}
|
||||
|
||||
if (edit_submode_extra == NULL) {
|
||||
if (compl_curr_match->cp_flags & ORIGINAL_TEXT) {
|
||||
if (compl_curr_match->cp_flags & CP_ORIGINAL_TEXT) {
|
||||
edit_submode_extra = (char_u *)_("Back at original");
|
||||
edit_submode_highl = HLF_W;
|
||||
} else if (compl_cont_status & CONT_S_IPOS) {
|
||||
|
Reference in New Issue
Block a user