Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cd2c1cd

Browse files
committed
updated for version 7.4.653
Problem: Insert mode completion with complete() may have CTRL-L work like CTRL-P. Solution: Handle completion with complete() differently. (Yasuhiro Matsumoto, Christian Brabandt, Hirohito Higashi)
1 parent 74c825f commit cd2c1cd

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

src/edit.c

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434
#define CTRL_X_OMNI 13
3535
#define CTRL_X_SPELL 14
3636
#define CTRL_X_LOCAL_MSG 15 /* only used in "ctrl_x_msgs" */
37+
#define CTRL_X_EVAL 16 /* for builtin function complete() */
3738

3839
#define CTRL_X_MSG(i) ctrl_x_msgs[(i) & ~CTRL_X_WANT_IDENT]
40+
#define CTRL_X_MODE_LINE_OR_EVAL(m) (m == CTRL_X_WHOLE_LINE || m == CTRL_X_EVAL)
3941

4042
static char *ctrl_x_msgs[] =
4143
{
@@ -55,6 +57,7 @@ static char *ctrl_x_msgs[] =
5557
N_(" Omni completion (^O^N^P)"),
5658
N_(" Spelling suggestion (s^N^P)"),
5759
N_(" Keyword Local completion (^N^P)"),
60+
NULL, /* CTRL_X_EVAL doesn't use msg. */
5861
};
5962

6063
static char e_hitend[] = N_("Hit end of paragraph");
@@ -802,7 +805,7 @@ edit(cmdchar, startln, count)
802805
* "compl_leader". Except when at the original match and
803806
* there is nothing to add, CTRL-L works like CTRL-P then. */
804807
if (c == Ctrl_L
805-
&& (ctrl_x_mode != CTRL_X_WHOLE_LINE
808+
&& (!CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode)
806809
|| (int)STRLEN(compl_shown_match->cp_str)
807810
> curwin->w_cursor.col - compl_col))
808811
{
@@ -2267,6 +2270,8 @@ vim_is_ctrl_x_key(c)
22672270
#endif
22682271
case CTRL_X_SPELL:
22692272
return (c == Ctrl_S || c == Ctrl_P || c == Ctrl_N);
2273+
case CTRL_X_EVAL:
2274+
return (c == Ctrl_P || c == Ctrl_N);
22702275
}
22712276
EMSG(_(e_internal));
22722277
return FALSE;
@@ -2773,8 +2778,7 @@ set_completion(startcol, list)
27732778
-1, p_ic, NULL, NULL, 0, ORIGINAL_TEXT, FALSE) != OK)
27742779
return;
27752780

2776-
/* Handle like dictionary completion. */
2777-
ctrl_x_mode = CTRL_X_WHOLE_LINE;
2781+
ctrl_x_mode = CTRL_X_EVAL;
27782782

27792783
ins_compl_add_list(list);
27802784
compl_matches = ins_compl_make_cyclic();
@@ -3060,7 +3064,7 @@ ins_compl_dictionaries(dict_start, pat, flags, thesaurus)
30603064
/* When invoked to match whole lines for CTRL-X CTRL-L adjust the pattern
30613065
* to only match at the start of a line. Otherwise just match the
30623066
* pattern. Also need to double backslashes. */
3063-
if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
3067+
if (CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
30643068
{
30653069
char_u *pat_esc = vim_strsave_escaped(pat, (char_u *)"\\");
30663070
size_t len;
@@ -3181,7 +3185,7 @@ ins_compl_files(count, files, thesaurus, flags, regmatch, buf, dir)
31813185
while (vim_regexec(regmatch, buf, (colnr_T)(ptr - buf)))
31823186
{
31833187
ptr = regmatch->startp[0];
3184-
if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
3188+
if (CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
31853189
ptr = find_line_end(ptr);
31863190
else
31873191
ptr = find_word_end(ptr);
@@ -3394,7 +3398,7 @@ ins_compl_bs()
33943398
* allow the word to be deleted, we won't match everything. */
33953399
if ((int)(p - line) - (int)compl_col < 0
33963400
|| ((int)(p - line) - (int)compl_col == 0
3397-
&& ctrl_x_mode != CTRL_X_OMNI))
3401+
&& ctrl_x_mode != CTRL_X_OMNI) || ctrl_x_mode == CTRL_X_EVAL)
33983402
return K_BS;
33993403

34003404
/* Deleted more than what was used to find matches or didn't finish
@@ -4208,7 +4212,7 @@ ins_compl_get_exp(ini)
42084212
/* For ^N/^P pick a new entry from e_cpt if compl_started is off,
42094213
* or if found_all says this entry is done. For ^X^L only use the
42104214
* entries from 'complete' that look in loaded buffers. */
4211-
if ((ctrl_x_mode == 0 || ctrl_x_mode == CTRL_X_WHOLE_LINE)
4215+
if ((ctrl_x_mode == 0 || CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
42124216
&& (!compl_started || found_all))
42134217
{
42144218
found_all = FALSE;
@@ -4261,7 +4265,7 @@ ins_compl_get_exp(ini)
42614265
break;
42624266
else
42634267
{
4264-
if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
4268+
if (CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
42654269
type = -1;
42664270
else if (*e_cpt == 'k' || *e_cpt == 's')
42674271
{
@@ -4406,9 +4410,10 @@ ins_compl_get_exp(ini)
44064410

44074411
++msg_silent; /* Don't want messages for wrapscan. */
44084412

4409-
/* ctrl_x_mode == CTRL_X_WHOLE_LINE || word-wise search that
4413+
/* CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode)
4414+
* || word-wise search that
44104415
* has added a word that was at the beginning of the line */
4411-
if ( ctrl_x_mode == CTRL_X_WHOLE_LINE
4416+
if (CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode)
44124417
|| (compl_cont_status & CONT_SOL))
44134418
found_new_match = search_for_exact_line(ins_buf, pos,
44144419
compl_direction, compl_pattern);
@@ -4442,7 +4447,7 @@ ins_compl_get_exp(ini)
44424447
&& ini->col == pos->col)
44434448
continue;
44444449
ptr = ml_get_buf(ins_buf, pos->lnum, FALSE) + pos->col;
4445-
if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
4450+
if (CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
44464451
{
44474452
if (compl_cont_status & CONT_ADDING)
44484453
{
@@ -4536,7 +4541,7 @@ ins_compl_get_exp(ini)
45364541

45374542
/* break the loop for specialized modes (use 'complete' just for the
45384543
* generic ctrl_x_mode == 0) or when we've found a new match */
4539-
if ((ctrl_x_mode != 0 && ctrl_x_mode != CTRL_X_WHOLE_LINE)
4544+
if ((ctrl_x_mode != 0 && !CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
45404545
|| found_new_match != FAIL)
45414546
{
45424547
if (got_int)
@@ -4545,7 +4550,7 @@ ins_compl_get_exp(ini)
45454550
if (type != -1)
45464551
ins_compl_check_keys(0);
45474552

4548-
if ((ctrl_x_mode != 0 && ctrl_x_mode != CTRL_X_WHOLE_LINE)
4553+
if ((ctrl_x_mode != 0 && !CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
45494554
|| compl_interrupted)
45504555
break;
45514556
compl_started = TRUE;
@@ -4561,13 +4566,13 @@ ins_compl_get_exp(ini)
45614566
}
45624567
compl_started = TRUE;
45634568

4564-
if ((ctrl_x_mode == 0 || ctrl_x_mode == CTRL_X_WHOLE_LINE)
4569+
if ((ctrl_x_mode == 0 || CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
45654570
&& *e_cpt == NUL) /* Got to end of 'complete' */
45664571
found_new_match = FAIL;
45674572

45684573
i = -1; /* total of matches, unknown */
45694574
if (found_new_match == FAIL
4570-
|| (ctrl_x_mode != 0 && ctrl_x_mode != CTRL_X_WHOLE_LINE))
4575+
|| (ctrl_x_mode != 0 && !CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode)))
45714576
i = ins_compl_make_cyclic();
45724577

45734578
/* If several matches were added (FORWARD) or the search failed and has
@@ -5052,7 +5057,7 @@ ins_complete(c)
50525057
if (compl_length < 1)
50535058
compl_cont_status &= CONT_LOCAL;
50545059
}
5055-
else if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
5060+
else if (CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
50565061
compl_cont_status = CONT_ADDING | CONT_N_ADDS;
50575062
else
50585063
compl_cont_status = 0;
@@ -5183,7 +5188,7 @@ ins_complete(c)
51835188
}
51845189
}
51855190
}
5186-
else if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
5191+
else if (CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
51875192
{
51885193
compl_col = (colnr_T)(skipwhite(line) - line);
51895194
compl_length = (int)curs_col - (int)compl_col;
@@ -5348,7 +5353,7 @@ ins_complete(c)
53485353
if (compl_cont_status & CONT_ADDING)
53495354
{
53505355
edit_submode_pre = (char_u *)_(" Adding");
5351-
if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
5356+
if (CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
53525357
{
53535358
/* Insert a new line, keep indentation but ignore 'comments' */
53545359
#ifdef FEAT_COMMENTS

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,8 @@ static char *(features[]) =
741741

742742
static int included_patches[] =
743743
{ /* Add new patch number below this line */
744+
/**/
745+
653,
744746
/**/
745747
652,
746748
/**/

0 commit comments

Comments
 (0)