Skip to content

Commit bc0e9ad

Browse files
committed
patch 8.0.1479: insert mode completion state is confusing
Problem: Insert mode completion state is confusing. Solution: Move ctrl_x_mode into edit.c. Add CTRL_X_NORMAL for zero.
1 parent dff72ba commit bc0e9ad

6 files changed

Lines changed: 92 additions & 59 deletions

File tree

src/edit.c

Lines changed: 85 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,41 @@
1717
/*
1818
* definitions used for CTRL-X submode
1919
*/
20-
#define CTRL_X_WANT_IDENT 0x100
21-
22-
#define CTRL_X_NOT_DEFINED_YET 1
23-
#define CTRL_X_SCROLL 2
24-
#define CTRL_X_WHOLE_LINE 3
25-
#define CTRL_X_FILES 4
26-
#define CTRL_X_TAGS (5 + CTRL_X_WANT_IDENT)
27-
#define CTRL_X_PATH_PATTERNS (6 + CTRL_X_WANT_IDENT)
28-
#define CTRL_X_PATH_DEFINES (7 + CTRL_X_WANT_IDENT)
29-
#define CTRL_X_FINISHED 8
30-
#define CTRL_X_DICTIONARY (9 + CTRL_X_WANT_IDENT)
31-
#define CTRL_X_THESAURUS (10 + CTRL_X_WANT_IDENT)
32-
#define CTRL_X_CMDLINE 11
33-
#define CTRL_X_FUNCTION 12
34-
#define CTRL_X_OMNI 13
35-
#define CTRL_X_SPELL 14
36-
#define CTRL_X_LOCAL_MSG 15 /* only used in "ctrl_x_msgs" */
37-
#define CTRL_X_EVAL 16 /* for builtin function complete() */
38-
39-
#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)
41-
20+
# define CTRL_X_WANT_IDENT 0x100
21+
22+
# define CTRL_X_NORMAL 0 /* CTRL-N CTRL-P completion, default */
23+
# define CTRL_X_NOT_DEFINED_YET 1
24+
# define CTRL_X_SCROLL 2
25+
# define CTRL_X_WHOLE_LINE 3
26+
# define CTRL_X_FILES 4
27+
# define CTRL_X_TAGS (5 + CTRL_X_WANT_IDENT)
28+
# define CTRL_X_PATH_PATTERNS (6 + CTRL_X_WANT_IDENT)
29+
# define CTRL_X_PATH_DEFINES (7 + CTRL_X_WANT_IDENT)
30+
# define CTRL_X_FINISHED 8
31+
# define CTRL_X_DICTIONARY (9 + CTRL_X_WANT_IDENT)
32+
# define CTRL_X_THESAURUS (10 + CTRL_X_WANT_IDENT)
33+
# define CTRL_X_CMDLINE 11
34+
# define CTRL_X_FUNCTION 12
35+
# define CTRL_X_OMNI 13
36+
# define CTRL_X_SPELL 14
37+
# define CTRL_X_LOCAL_MSG 15 /* only used in "ctrl_x_msgs" */
38+
# define CTRL_X_EVAL 16 /* for builtin function complete() */
39+
40+
# define CTRL_X_MSG(i) ctrl_x_msgs[(i) & ~CTRL_X_WANT_IDENT]
41+
# define CTRL_X_MODE_LINE_OR_EVAL(m) ((m) == CTRL_X_WHOLE_LINE || (m) == CTRL_X_EVAL)
42+
43+
/* Message for CTRL-X mode, index is ctrl_x_mode. */
4244
static char *ctrl_x_msgs[] =
4345
{
44-
N_(" Keyword completion (^N^P)"), /* ctrl_x_mode == 0, ^P/^N compl. */
46+
N_(" Keyword completion (^N^P)"), /* CTRL_X_NORMAL, ^P/^N compl. */
4547
N_(" ^X mode (^]^D^E^F^I^K^L^N^O^Ps^U^V^Y)"),
46-
NULL,
48+
NULL, /* CTRL_X_SCROLL: depends on state */
4749
N_(" Whole line completion (^L^N^P)"),
4850
N_(" File name completion (^F^N^P)"),
4951
N_(" Tag completion (^]^N^P)"),
5052
N_(" Path pattern completion (^N^P)"),
5153
N_(" Definition completion (^D^N^P)"),
52-
NULL,
54+
NULL, /* CTRL_X_FINISHED */
5355
N_(" Dictionary completion (^K^N^P)"),
5456
N_(" Thesaurus completion (^T^N^P)"),
5557
N_(" Command-line completion (^V^N^P)"),
@@ -61,10 +63,10 @@ static char *ctrl_x_msgs[] =
6163
};
6264

6365
static char e_hitend[] = N_("Hit end of paragraph");
64-
#ifdef FEAT_COMPL_FUNC
66+
# ifdef FEAT_COMPL_FUNC
6567
static char e_complwin[] = N_("E839: Completion function changed window");
6668
static char e_compldel[] = N_("E840: Completion function deleted text");
67-
#endif
69+
# endif
6870

6971
/*
7072
* Structure used to store one match for insert completion.
@@ -83,8 +85,8 @@ struct compl_S
8385
int cp_number; /* sequence number */
8486
};
8587

86-
#define ORIGINAL_TEXT (1) /* the original text when the expansion begun */
87-
#define FREE_FNAME (2)
88+
# define ORIGINAL_TEXT (1) /* the original text when the expansion begun */
89+
# define FREE_FNAME (2)
8890

8991
/*
9092
* All the current matches are stored in a list.
@@ -127,6 +129,9 @@ static int compl_restarting = FALSE; /* don't insert match */
127129
* FALSE the word to be completed must be located. */
128130
static int compl_started = FALSE;
129131

132+
/* Which Ctrl-X mode are we in? */
133+
static int ctrl_x_mode = CTRL_X_NORMAL;
134+
130135
/* Set when doing something for completion that may call edit() recursively,
131136
* which is not allowed. */
132137
static int compl_busy = FALSE;
@@ -174,10 +179,10 @@ static void ins_compl_addfrommatch(void);
174179
static int ins_compl_prep(int c);
175180
static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg);
176181
static buf_T *ins_compl_next_buf(buf_T *buf, int flag);
177-
#if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL)
182+
# if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL)
178183
static void ins_compl_add_list(list_T *list);
179184
static void ins_compl_add_dict(dict_T *dict);
180-
#endif
185+
# endif
181186
static int ins_compl_get_exp(pos_T *ini);
182187
static void ins_compl_delete(void);
183188
static void ins_compl_insert(int in_compl_func);
@@ -2241,6 +2246,24 @@ ins_ctrl_x(void)
22412246
}
22422247
}
22432248

2249+
/*
2250+
* Whether other than default completion has been selected.
2251+
*/
2252+
int
2253+
ctrl_x_mode_not_default(void)
2254+
{
2255+
return ctrl_x_mode != CTRL_X_NORMAL;
2256+
}
2257+
2258+
/*
2259+
* Whether CTRL-X was typed without a following character.
2260+
*/
2261+
int
2262+
ctrl_x_mode_not_defined_yet(void)
2263+
{
2264+
return ctrl_x_mode == CTRL_X_NOT_DEFINED_YET;
2265+
}
2266+
22442267
/*
22452268
* Return TRUE if the 'dict' or 'tsr' option can be used.
22462269
*/
@@ -2254,7 +2277,7 @@ has_compl_option(int dict_opt)
22542277
)
22552278
: (*curbuf->b_p_tsr == NUL && *p_tsr == NUL))
22562279
{
2257-
ctrl_x_mode = 0;
2280+
ctrl_x_mode = CTRL_X_NORMAL;
22582281
edit_submode = NULL;
22592282
msg_attr(dict_opt ? (char_u *)_("'dictionary' option is empty")
22602283
: (char_u *)_("'thesaurus' option is empty"),
@@ -2830,7 +2853,7 @@ set_completion(colnr_T startcol, list_T *list)
28302853
int save_w_leftcol = curwin->w_leftcol;
28312854

28322855
/* If already doing completions stop it. */
2833-
if (ctrl_x_mode != 0)
2856+
if (ctrl_x_mode != CTRL_X_NORMAL)
28342857
ins_compl_prep(' ');
28352858
ins_compl_clear();
28362859
ins_compl_free();
@@ -3736,7 +3759,7 @@ ins_compl_prep(int c)
37363759

37373760
/* Set "compl_get_longest" when finding the first matches. */
37383761
if (ctrl_x_mode == CTRL_X_NOT_DEFINED_YET
3739-
|| (ctrl_x_mode == 0 && !compl_started))
3762+
|| (ctrl_x_mode == CTRL_X_NORMAL && !compl_started))
37403763
{
37413764
compl_get_longest = (strstr((char *)p_cot, "longest") != NULL);
37423765
compl_used_match = TRUE;
@@ -3841,19 +3864,19 @@ ins_compl_prep(int c)
38413864
else
38423865
compl_cont_mode = CTRL_X_NOT_DEFINED_YET;
38433866
}
3844-
ctrl_x_mode = 0;
3867+
ctrl_x_mode = CTRL_X_NORMAL;
38453868
edit_submode = NULL;
38463869
showmode();
38473870
break;
38483871
}
38493872
}
3850-
else if (ctrl_x_mode != 0)
3873+
else if (ctrl_x_mode != CTRL_X_NORMAL)
38513874
{
38523875
/* We're already in CTRL-X mode, do we stay in it? */
38533876
if (!vim_is_ctrl_x_key(c))
38543877
{
38553878
if (ctrl_x_mode == CTRL_X_SCROLL)
3856-
ctrl_x_mode = 0;
3879+
ctrl_x_mode = CTRL_X_NORMAL;
38573880
else
38583881
ctrl_x_mode = CTRL_X_FINISHED;
38593882
edit_submode = NULL;
@@ -3867,8 +3890,8 @@ ins_compl_prep(int c)
38673890
* 'Pattern not found') until another key is hit, then go back to
38683891
* showing what mode we are in. */
38693892
showmode();
3870-
if ((ctrl_x_mode == 0 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_R
3871-
&& !ins_compl_pum_key(c))
3893+
if ((ctrl_x_mode == CTRL_X_NORMAL && c != Ctrl_N && c != Ctrl_P
3894+
&& c != Ctrl_R && !ins_compl_pum_key(c))
38723895
|| ctrl_x_mode == CTRL_X_FINISHED)
38733896
{
38743897
/* Get here when we have finished typing a sequence of ^N and
@@ -3951,7 +3974,7 @@ ins_compl_prep(int c)
39513974
compl_matches = 0;
39523975
if (!shortmess(SHM_COMPLETIONMENU))
39533976
msg_clr_cmdline(); /* necessary for "noshowmode" */
3954-
ctrl_x_mode = 0;
3977+
ctrl_x_mode = CTRL_X_NORMAL;
39553978
compl_enter_selects = FALSE;
39563979
if (edit_submode != NULL)
39573980
{
@@ -4292,7 +4315,8 @@ ins_compl_get_exp(pos_T *ini)
42924315
/* For ^N/^P pick a new entry from e_cpt if compl_started is off,
42934316
* or if found_all says this entry is done. For ^X^L only use the
42944317
* entries from 'complete' that look in loaded buffers. */
4295-
if ((ctrl_x_mode == 0 || CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
4318+
if ((ctrl_x_mode == CTRL_X_NORMAL
4319+
|| CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
42964320
&& (!compl_started || found_all))
42974321
{
42984322
found_all = FALSE;
@@ -4304,7 +4328,7 @@ ins_compl_get_exp(pos_T *ini)
43044328
first_match_pos = *ini;
43054329
/* Move the cursor back one character so that ^N can match the
43064330
* word immediately after the cursor. */
4307-
if (ctrl_x_mode == 0 && dec(&first_match_pos) < 0)
4331+
if (ctrl_x_mode == CTRL_X_NORMAL && dec(&first_match_pos) < 0)
43084332
{
43094333
/* Move the cursor to after the last character in the
43104334
* buffer, so that word at start of buffer is found
@@ -4437,8 +4461,8 @@ ins_compl_get_exp(pos_T *ini)
44374461
/* Find up to TAG_MANY matches. Avoids that an enormous number
44384462
* of matches is found when compl_pattern is empty */
44394463
if (find_tags(compl_pattern, &num_matches, &matches,
4440-
TAG_REGEXP | TAG_NAMES | TAG_NOIC |
4441-
TAG_INS_COMP | (ctrl_x_mode ? TAG_VERBOSE : 0),
4464+
TAG_REGEXP | TAG_NAMES | TAG_NOIC | TAG_INS_COMP
4465+
| (ctrl_x_mode != CTRL_X_NORMAL ? TAG_VERBOSE : 0),
44424466
TAG_MANY, curbuf->b_ffname) == OK && num_matches > 0)
44434467
{
44444468
ins_compl_add_matches(num_matches, matches, p_ic);
@@ -4633,8 +4657,10 @@ ins_compl_get_exp(pos_T *ini)
46334657
found_new_match = OK;
46344658

46354659
/* break the loop for specialized modes (use 'complete' just for the
4636-
* generic ctrl_x_mode == 0) or when we've found a new match */
4637-
if ((ctrl_x_mode != 0 && !CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
4660+
* generic ctrl_x_mode == CTRL_X_NORMAL) or when we've found a new
4661+
* match */
4662+
if ((ctrl_x_mode != CTRL_X_NORMAL
4663+
&& !CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
46384664
|| found_new_match != FAIL)
46394665
{
46404666
if (got_int)
@@ -4643,7 +4669,8 @@ ins_compl_get_exp(pos_T *ini)
46434669
if (type != -1)
46444670
ins_compl_check_keys(0, FALSE);
46454671

4646-
if ((ctrl_x_mode != 0 && !CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
4672+
if ((ctrl_x_mode != CTRL_X_NORMAL
4673+
&& !CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
46474674
|| compl_interrupted)
46484675
break;
46494676
compl_started = TRUE;
@@ -4659,13 +4686,13 @@ ins_compl_get_exp(pos_T *ini)
46594686
}
46604687
compl_started = TRUE;
46614688

4662-
if ((ctrl_x_mode == 0 || CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
4689+
if ((ctrl_x_mode == CTRL_X_NORMAL || CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
46634690
&& *e_cpt == NUL) /* Got to end of 'complete' */
46644691
found_new_match = FAIL;
46654692

46664693
i = -1; /* total of matches, unknown */
4667-
if (found_new_match == FAIL
4668-
|| (ctrl_x_mode != 0 && !CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode)))
4694+
if (found_new_match == FAIL || (ctrl_x_mode != CTRL_X_NORMAL
4695+
&& !CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode)))
46694696
i = ins_compl_make_cyclic();
46704697

46714698
if (compl_old_match != NULL)
@@ -5166,8 +5193,9 @@ ins_complete(int c, int enable_pum)
51665193
* it is a continued search
51675194
*/
51685195
compl_cont_status &= ~CONT_INTRPT; /* remove INTRPT */
5169-
if (ctrl_x_mode == 0 || ctrl_x_mode == CTRL_X_PATH_PATTERNS
5170-
|| ctrl_x_mode == CTRL_X_PATH_DEFINES)
5196+
if (ctrl_x_mode == CTRL_X_NORMAL
5197+
|| ctrl_x_mode == CTRL_X_PATH_PATTERNS
5198+
|| ctrl_x_mode == CTRL_X_PATH_DEFINES)
51715199
{
51725200
if (compl_startpos.lnum != curwin->w_cursor.lnum)
51735201
{
@@ -5219,7 +5247,8 @@ ins_complete(int c, int enable_pum)
52195247
if (!(compl_cont_status & CONT_ADDING)) /* normal expansion */
52205248
{
52215249
compl_cont_mode = ctrl_x_mode;
5222-
if (ctrl_x_mode != 0) /* Remove LOCAL if ctrl_x_mode != 0 */
5250+
if (ctrl_x_mode != CTRL_X_NORMAL)
5251+
/* Remove LOCAL if ctrl_x_mode != CTRL_X_NORMAL */
52235252
compl_cont_status = 0;
52245253
compl_cont_status |= CONT_N_ADDS;
52255254
compl_startpos = curwin->w_cursor;
@@ -5228,7 +5257,7 @@ ins_complete(int c, int enable_pum)
52285257
}
52295258

52305259
/* Work out completion pattern and original text -- webb */
5231-
if (ctrl_x_mode == 0 || (ctrl_x_mode & CTRL_X_WANT_IDENT))
5260+
if (ctrl_x_mode == CTRL_X_NORMAL || (ctrl_x_mode & CTRL_X_WANT_IDENT))
52325261
{
52335262
if ((compl_cont_status & CONT_SOL)
52345263
|| ctrl_x_mode == CTRL_X_PATH_DEFINES)
@@ -5445,7 +5474,7 @@ ins_complete(int c, int enable_pum)
54455474
return FAIL;
54465475
if (col == -3)
54475476
{
5448-
ctrl_x_mode = 0;
5477+
ctrl_x_mode = CTRL_X_NORMAL;
54495478
edit_submode = NULL;
54505479
if (!shortmess(SHM_COMPLETIONMENU))
54515480
msg_clr_cmdline();
@@ -5604,7 +5633,7 @@ ins_complete(int c, int enable_pum)
56045633
* (such as M in M'exico) if not tried already. -- Acevedo */
56055634
if ( compl_length > 1
56065635
|| (compl_cont_status & CONT_ADDING)
5607-
|| (ctrl_x_mode != 0
5636+
|| (ctrl_x_mode != CTRL_X_NORMAL
56085637
&& ctrl_x_mode != CTRL_X_PATH_PATTERNS
56095638
&& ctrl_x_mode != CTRL_X_PATH_DEFINES))
56105639
compl_cont_status &= ~CONT_N_ADDS;

src/getchar.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2115,7 +2115,8 @@ vgetorpeek(int advance)
21152115
&& State != ASKMORE
21162116
&& State != CONFIRM
21172117
#ifdef FEAT_INS_EXPAND
2118-
&& !((ctrl_x_mode != 0 && vim_is_ctrl_x_key(c1))
2118+
&& !((ctrl_x_mode_not_default()
2119+
&& vim_is_ctrl_x_key(c1))
21192120
|| ((compl_cont_status & CONT_LOCAL)
21202121
&& (c1 == Ctrl_N || c1 == Ctrl_P)))
21212122
#endif

src/globals.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,6 @@ EXTERN char_u *edit_submode INIT(= NULL); /* msg for CTRL-X submode */
964964
EXTERN char_u *edit_submode_pre INIT(= NULL); /* prepended to edit_submode */
965965
EXTERN char_u *edit_submode_extra INIT(= NULL);/* appended to edit_submode */
966966
EXTERN hlf_T edit_submode_highl; /* highl. method for extra info */
967-
EXTERN int ctrl_x_mode INIT(= 0); /* Which Ctrl-X mode are we in? */
968967
#endif
969968

970969
EXTERN int no_abbr INIT(= TRUE); /* TRUE when no abbreviations loaded */

src/proto/edit.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ void display_dollar(colnr_T col);
66
void change_indent(int type, int amount, int round, int replaced, int call_changed_bytes);
77
void truncate_spaces(char_u *line);
88
void backspace_until_column(int col);
9+
int ctrl_x_mode_not_default(void);
10+
int ctrl_x_mode_not_defined_yet(void);
911
int vim_is_ctrl_x_key(int c);
1012
int ins_compl_add_infercase(char_u *str, int len, int icase, char_u *fname, int dir, int flags);
1113
void completeopt_was_set(void);

src/search.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ ignorecase_opt(char_u *pat, int ic_in, int scs)
421421

422422
if (ic && !no_smartcase && scs
423423
#ifdef FEAT_INS_EXPAND
424-
&& !(ctrl_x_mode && curbuf->b_p_inf)
424+
&& !(ctrl_x_mode_not_default() && curbuf->b_p_inf)
425425
#endif
426426
)
427427
ic = !pat_has_uppercase(pat);

src/version.c

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

772772
static int included_patches[] =
773773
{ /* Add new patch number below this line */
774+
/**/
775+
1479,
774776
/**/
775777
1478,
776778
/**/

0 commit comments

Comments
 (0)