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. */
4244static 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
6365static char e_hitend [] = N_ ("Hit end of paragraph" );
64- #ifdef FEAT_COMPL_FUNC
66+ # ifdef FEAT_COMPL_FUNC
6567static char e_complwin [] = N_ ("E839: Completion function changed window" );
6668static 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. */
128130static 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. */
132137static int compl_busy = FALSE;
@@ -174,10 +179,10 @@ static void ins_compl_addfrommatch(void);
174179static int ins_compl_prep (int c );
175180static void ins_compl_fixRedoBufForLeader (char_u * ptr_arg );
176181static 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 )
178183static void ins_compl_add_list (list_T * list );
179184static void ins_compl_add_dict (dict_T * dict );
180- #endif
185+ # endif
181186static int ins_compl_get_exp (pos_T * ini );
182187static void ins_compl_delete (void );
183188static 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 ;
0 commit comments