0
0
mirror of https://github.com/vim/vim.git synced 2025-09-27 04:14:06 -04:00

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.
This commit is contained in:
Bram Moolenaar
2018-02-09 12:13:34 +01:00
parent dff72ba445
commit bc0e9adae9
6 changed files with 89 additions and 56 deletions

View File

@@ -17,39 +17,41 @@
/* /*
* definitions used for CTRL-X submode * definitions used for CTRL-X submode
*/ */
#define CTRL_X_WANT_IDENT 0x100 # define CTRL_X_WANT_IDENT 0x100
#define CTRL_X_NOT_DEFINED_YET 1 # define CTRL_X_NORMAL 0 /* CTRL-N CTRL-P completion, default */
#define CTRL_X_SCROLL 2 # define CTRL_X_NOT_DEFINED_YET 1
#define CTRL_X_WHOLE_LINE 3 # define CTRL_X_SCROLL 2
#define CTRL_X_FILES 4 # define CTRL_X_WHOLE_LINE 3
#define CTRL_X_TAGS (5 + CTRL_X_WANT_IDENT) # define CTRL_X_FILES 4
#define CTRL_X_PATH_PATTERNS (6 + CTRL_X_WANT_IDENT) # define CTRL_X_TAGS (5 + CTRL_X_WANT_IDENT)
#define CTRL_X_PATH_DEFINES (7 + CTRL_X_WANT_IDENT) # define CTRL_X_PATH_PATTERNS (6 + CTRL_X_WANT_IDENT)
#define CTRL_X_FINISHED 8 # define CTRL_X_PATH_DEFINES (7 + CTRL_X_WANT_IDENT)
#define CTRL_X_DICTIONARY (9 + CTRL_X_WANT_IDENT) # define CTRL_X_FINISHED 8
#define CTRL_X_THESAURUS (10 + CTRL_X_WANT_IDENT) # define CTRL_X_DICTIONARY (9 + CTRL_X_WANT_IDENT)
#define CTRL_X_CMDLINE 11 # define CTRL_X_THESAURUS (10 + CTRL_X_WANT_IDENT)
#define CTRL_X_FUNCTION 12 # define CTRL_X_CMDLINE 11
#define CTRL_X_OMNI 13 # define CTRL_X_FUNCTION 12
#define CTRL_X_SPELL 14 # define CTRL_X_OMNI 13
#define CTRL_X_LOCAL_MSG 15 /* only used in "ctrl_x_msgs" */ # define CTRL_X_SPELL 14
#define CTRL_X_EVAL 16 /* for builtin function complete() */ # define CTRL_X_LOCAL_MSG 15 /* only used in "ctrl_x_msgs" */
# define CTRL_X_EVAL 16 /* for builtin function complete() */
#define CTRL_X_MSG(i) ctrl_x_msgs[(i) & ~CTRL_X_WANT_IDENT] # define CTRL_X_MSG(i) ctrl_x_msgs[(i) & ~CTRL_X_WANT_IDENT]
#define CTRL_X_MODE_LINE_OR_EVAL(m) (m == CTRL_X_WHOLE_LINE || m == CTRL_X_EVAL) # define CTRL_X_MODE_LINE_OR_EVAL(m) ((m) == CTRL_X_WHOLE_LINE || (m) == CTRL_X_EVAL)
/* Message for CTRL-X mode, index is ctrl_x_mode. */
static char *ctrl_x_msgs[] = static char *ctrl_x_msgs[] =
{ {
N_(" Keyword completion (^N^P)"), /* ctrl_x_mode == 0, ^P/^N compl. */ N_(" Keyword completion (^N^P)"), /* CTRL_X_NORMAL, ^P/^N compl. */
N_(" ^X mode (^]^D^E^F^I^K^L^N^O^Ps^U^V^Y)"), N_(" ^X mode (^]^D^E^F^I^K^L^N^O^Ps^U^V^Y)"),
NULL, NULL, /* CTRL_X_SCROLL: depends on state */
N_(" Whole line completion (^L^N^P)"), N_(" Whole line completion (^L^N^P)"),
N_(" File name completion (^F^N^P)"), N_(" File name completion (^F^N^P)"),
N_(" Tag completion (^]^N^P)"), N_(" Tag completion (^]^N^P)"),
N_(" Path pattern completion (^N^P)"), N_(" Path pattern completion (^N^P)"),
N_(" Definition completion (^D^N^P)"), N_(" Definition completion (^D^N^P)"),
NULL, NULL, /* CTRL_X_FINISHED */
N_(" Dictionary completion (^K^N^P)"), N_(" Dictionary completion (^K^N^P)"),
N_(" Thesaurus completion (^T^N^P)"), N_(" Thesaurus completion (^T^N^P)"),
N_(" Command-line completion (^V^N^P)"), N_(" Command-line completion (^V^N^P)"),
@@ -61,10 +63,10 @@ static char *ctrl_x_msgs[] =
}; };
static char e_hitend[] = N_("Hit end of paragraph"); static char e_hitend[] = N_("Hit end of paragraph");
#ifdef FEAT_COMPL_FUNC # ifdef FEAT_COMPL_FUNC
static char e_complwin[] = N_("E839: Completion function changed window"); static char e_complwin[] = N_("E839: Completion function changed window");
static char e_compldel[] = N_("E840: Completion function deleted text"); static char e_compldel[] = N_("E840: Completion function deleted text");
#endif # endif
/* /*
* Structure used to store one match for insert completion. * Structure used to store one match for insert completion.
@@ -83,8 +85,8 @@ struct compl_S
int cp_number; /* sequence number */ int cp_number; /* sequence number */
}; };
#define ORIGINAL_TEXT (1) /* the original text when the expansion begun */ # define ORIGINAL_TEXT (1) /* the original text when the expansion begun */
#define FREE_FNAME (2) # define FREE_FNAME (2)
/* /*
* All the current matches are stored in a list. * All the current matches are stored in a list.
@@ -127,6 +129,9 @@ static int compl_restarting = FALSE; /* don't insert match */
* FALSE the word to be completed must be located. */ * FALSE the word to be completed must be located. */
static int compl_started = FALSE; static int compl_started = FALSE;
/* Which Ctrl-X mode are we in? */
static int ctrl_x_mode = CTRL_X_NORMAL;
/* Set when doing something for completion that may call edit() recursively, /* Set when doing something for completion that may call edit() recursively,
* which is not allowed. */ * which is not allowed. */
static int compl_busy = FALSE; static int compl_busy = FALSE;
@@ -174,10 +179,10 @@ static void ins_compl_addfrommatch(void);
static int ins_compl_prep(int c); static int ins_compl_prep(int c);
static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg); static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg);
static buf_T *ins_compl_next_buf(buf_T *buf, int flag); static buf_T *ins_compl_next_buf(buf_T *buf, int flag);
#if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL) # if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL)
static void ins_compl_add_list(list_T *list); static void ins_compl_add_list(list_T *list);
static void ins_compl_add_dict(dict_T *dict); static void ins_compl_add_dict(dict_T *dict);
#endif # endif
static int ins_compl_get_exp(pos_T *ini); static int ins_compl_get_exp(pos_T *ini);
static void ins_compl_delete(void); static void ins_compl_delete(void);
static void ins_compl_insert(int in_compl_func); static void ins_compl_insert(int in_compl_func);
@@ -2241,6 +2246,24 @@ ins_ctrl_x(void)
} }
} }
/*
* Whether other than default completion has been selected.
*/
int
ctrl_x_mode_not_default(void)
{
return ctrl_x_mode != CTRL_X_NORMAL;
}
/*
* Whether CTRL-X was typed without a following character.
*/
int
ctrl_x_mode_not_defined_yet(void)
{
return ctrl_x_mode == CTRL_X_NOT_DEFINED_YET;
}
/* /*
* Return TRUE if the 'dict' or 'tsr' option can be used. * Return TRUE if the 'dict' or 'tsr' option can be used.
*/ */
@@ -2254,7 +2277,7 @@ has_compl_option(int dict_opt)
) )
: (*curbuf->b_p_tsr == NUL && *p_tsr == NUL)) : (*curbuf->b_p_tsr == NUL && *p_tsr == NUL))
{ {
ctrl_x_mode = 0; ctrl_x_mode = CTRL_X_NORMAL;
edit_submode = NULL; edit_submode = NULL;
msg_attr(dict_opt ? (char_u *)_("'dictionary' option is empty") msg_attr(dict_opt ? (char_u *)_("'dictionary' option is empty")
: (char_u *)_("'thesaurus' option is empty"), : (char_u *)_("'thesaurus' option is empty"),
@@ -2830,7 +2853,7 @@ set_completion(colnr_T startcol, list_T *list)
int save_w_leftcol = curwin->w_leftcol; int save_w_leftcol = curwin->w_leftcol;
/* If already doing completions stop it. */ /* If already doing completions stop it. */
if (ctrl_x_mode != 0) if (ctrl_x_mode != CTRL_X_NORMAL)
ins_compl_prep(' '); ins_compl_prep(' ');
ins_compl_clear(); ins_compl_clear();
ins_compl_free(); ins_compl_free();
@@ -3736,7 +3759,7 @@ ins_compl_prep(int c)
/* Set "compl_get_longest" when finding the first matches. */ /* Set "compl_get_longest" when finding the first matches. */
if (ctrl_x_mode == CTRL_X_NOT_DEFINED_YET if (ctrl_x_mode == CTRL_X_NOT_DEFINED_YET
|| (ctrl_x_mode == 0 && !compl_started)) || (ctrl_x_mode == CTRL_X_NORMAL && !compl_started))
{ {
compl_get_longest = (strstr((char *)p_cot, "longest") != NULL); compl_get_longest = (strstr((char *)p_cot, "longest") != NULL);
compl_used_match = TRUE; compl_used_match = TRUE;
@@ -3841,19 +3864,19 @@ ins_compl_prep(int c)
else else
compl_cont_mode = CTRL_X_NOT_DEFINED_YET; compl_cont_mode = CTRL_X_NOT_DEFINED_YET;
} }
ctrl_x_mode = 0; ctrl_x_mode = CTRL_X_NORMAL;
edit_submode = NULL; edit_submode = NULL;
showmode(); showmode();
break; break;
} }
} }
else if (ctrl_x_mode != 0) else if (ctrl_x_mode != CTRL_X_NORMAL)
{ {
/* We're already in CTRL-X mode, do we stay in it? */ /* We're already in CTRL-X mode, do we stay in it? */
if (!vim_is_ctrl_x_key(c)) if (!vim_is_ctrl_x_key(c))
{ {
if (ctrl_x_mode == CTRL_X_SCROLL) if (ctrl_x_mode == CTRL_X_SCROLL)
ctrl_x_mode = 0; ctrl_x_mode = CTRL_X_NORMAL;
else else
ctrl_x_mode = CTRL_X_FINISHED; ctrl_x_mode = CTRL_X_FINISHED;
edit_submode = NULL; edit_submode = NULL;
@@ -3867,8 +3890,8 @@ ins_compl_prep(int c)
* 'Pattern not found') until another key is hit, then go back to * 'Pattern not found') until another key is hit, then go back to
* showing what mode we are in. */ * showing what mode we are in. */
showmode(); showmode();
if ((ctrl_x_mode == 0 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_R if ((ctrl_x_mode == CTRL_X_NORMAL && c != Ctrl_N && c != Ctrl_P
&& !ins_compl_pum_key(c)) && c != Ctrl_R && !ins_compl_pum_key(c))
|| ctrl_x_mode == CTRL_X_FINISHED) || ctrl_x_mode == CTRL_X_FINISHED)
{ {
/* Get here when we have finished typing a sequence of ^N and /* Get here when we have finished typing a sequence of ^N and
@@ -3951,7 +3974,7 @@ ins_compl_prep(int c)
compl_matches = 0; compl_matches = 0;
if (!shortmess(SHM_COMPLETIONMENU)) if (!shortmess(SHM_COMPLETIONMENU))
msg_clr_cmdline(); /* necessary for "noshowmode" */ msg_clr_cmdline(); /* necessary for "noshowmode" */
ctrl_x_mode = 0; ctrl_x_mode = CTRL_X_NORMAL;
compl_enter_selects = FALSE; compl_enter_selects = FALSE;
if (edit_submode != NULL) if (edit_submode != NULL)
{ {
@@ -4292,7 +4315,8 @@ ins_compl_get_exp(pos_T *ini)
/* For ^N/^P pick a new entry from e_cpt if compl_started is off, /* For ^N/^P pick a new entry from e_cpt if compl_started is off,
* or if found_all says this entry is done. For ^X^L only use the * or if found_all says this entry is done. For ^X^L only use the
* entries from 'complete' that look in loaded buffers. */ * entries from 'complete' that look in loaded buffers. */
if ((ctrl_x_mode == 0 || CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode)) if ((ctrl_x_mode == CTRL_X_NORMAL
|| CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
&& (!compl_started || found_all)) && (!compl_started || found_all))
{ {
found_all = FALSE; found_all = FALSE;
@@ -4304,7 +4328,7 @@ ins_compl_get_exp(pos_T *ini)
first_match_pos = *ini; first_match_pos = *ini;
/* Move the cursor back one character so that ^N can match the /* Move the cursor back one character so that ^N can match the
* word immediately after the cursor. */ * word immediately after the cursor. */
if (ctrl_x_mode == 0 && dec(&first_match_pos) < 0) if (ctrl_x_mode == CTRL_X_NORMAL && dec(&first_match_pos) < 0)
{ {
/* Move the cursor to after the last character in the /* Move the cursor to after the last character in the
* buffer, so that word at start of buffer is found * buffer, so that word at start of buffer is found
@@ -4437,8 +4461,8 @@ ins_compl_get_exp(pos_T *ini)
/* Find up to TAG_MANY matches. Avoids that an enormous number /* Find up to TAG_MANY matches. Avoids that an enormous number
* of matches is found when compl_pattern is empty */ * of matches is found when compl_pattern is empty */
if (find_tags(compl_pattern, &num_matches, &matches, if (find_tags(compl_pattern, &num_matches, &matches,
TAG_REGEXP | TAG_NAMES | TAG_NOIC | TAG_REGEXP | TAG_NAMES | TAG_NOIC | TAG_INS_COMP
TAG_INS_COMP | (ctrl_x_mode ? TAG_VERBOSE : 0), | (ctrl_x_mode != CTRL_X_NORMAL ? TAG_VERBOSE : 0),
TAG_MANY, curbuf->b_ffname) == OK && num_matches > 0) TAG_MANY, curbuf->b_ffname) == OK && num_matches > 0)
{ {
ins_compl_add_matches(num_matches, matches, p_ic); ins_compl_add_matches(num_matches, matches, p_ic);
@@ -4633,8 +4657,10 @@ ins_compl_get_exp(pos_T *ini)
found_new_match = OK; found_new_match = OK;
/* break the loop for specialized modes (use 'complete' just for the /* break the loop for specialized modes (use 'complete' just for the
* generic ctrl_x_mode == 0) or when we've found a new match */ * generic ctrl_x_mode == CTRL_X_NORMAL) or when we've found a new
if ((ctrl_x_mode != 0 && !CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode)) * match */
if ((ctrl_x_mode != CTRL_X_NORMAL
&& !CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
|| found_new_match != FAIL) || found_new_match != FAIL)
{ {
if (got_int) if (got_int)
@@ -4643,7 +4669,8 @@ ins_compl_get_exp(pos_T *ini)
if (type != -1) if (type != -1)
ins_compl_check_keys(0, FALSE); ins_compl_check_keys(0, FALSE);
if ((ctrl_x_mode != 0 && !CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode)) if ((ctrl_x_mode != CTRL_X_NORMAL
&& !CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
|| compl_interrupted) || compl_interrupted)
break; break;
compl_started = TRUE; compl_started = TRUE;
@@ -4659,13 +4686,13 @@ ins_compl_get_exp(pos_T *ini)
} }
compl_started = TRUE; compl_started = TRUE;
if ((ctrl_x_mode == 0 || CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode)) if ((ctrl_x_mode == CTRL_X_NORMAL || CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
&& *e_cpt == NUL) /* Got to end of 'complete' */ && *e_cpt == NUL) /* Got to end of 'complete' */
found_new_match = FAIL; found_new_match = FAIL;
i = -1; /* total of matches, unknown */ i = -1; /* total of matches, unknown */
if (found_new_match == FAIL if (found_new_match == FAIL || (ctrl_x_mode != CTRL_X_NORMAL
|| (ctrl_x_mode != 0 && !CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))) && !CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode)))
i = ins_compl_make_cyclic(); i = ins_compl_make_cyclic();
if (compl_old_match != NULL) if (compl_old_match != NULL)
@@ -5166,7 +5193,8 @@ ins_complete(int c, int enable_pum)
* it is a continued search * it is a continued search
*/ */
compl_cont_status &= ~CONT_INTRPT; /* remove INTRPT */ compl_cont_status &= ~CONT_INTRPT; /* remove INTRPT */
if (ctrl_x_mode == 0 || ctrl_x_mode == CTRL_X_PATH_PATTERNS if (ctrl_x_mode == CTRL_X_NORMAL
|| ctrl_x_mode == CTRL_X_PATH_PATTERNS
|| ctrl_x_mode == CTRL_X_PATH_DEFINES) || ctrl_x_mode == CTRL_X_PATH_DEFINES)
{ {
if (compl_startpos.lnum != curwin->w_cursor.lnum) if (compl_startpos.lnum != curwin->w_cursor.lnum)
@@ -5219,7 +5247,8 @@ ins_complete(int c, int enable_pum)
if (!(compl_cont_status & CONT_ADDING)) /* normal expansion */ if (!(compl_cont_status & CONT_ADDING)) /* normal expansion */
{ {
compl_cont_mode = ctrl_x_mode; compl_cont_mode = ctrl_x_mode;
if (ctrl_x_mode != 0) /* Remove LOCAL if ctrl_x_mode != 0 */ if (ctrl_x_mode != CTRL_X_NORMAL)
/* Remove LOCAL if ctrl_x_mode != CTRL_X_NORMAL */
compl_cont_status = 0; compl_cont_status = 0;
compl_cont_status |= CONT_N_ADDS; compl_cont_status |= CONT_N_ADDS;
compl_startpos = curwin->w_cursor; compl_startpos = curwin->w_cursor;
@@ -5228,7 +5257,7 @@ ins_complete(int c, int enable_pum)
} }
/* Work out completion pattern and original text -- webb */ /* Work out completion pattern and original text -- webb */
if (ctrl_x_mode == 0 || (ctrl_x_mode & CTRL_X_WANT_IDENT)) if (ctrl_x_mode == CTRL_X_NORMAL || (ctrl_x_mode & CTRL_X_WANT_IDENT))
{ {
if ((compl_cont_status & CONT_SOL) if ((compl_cont_status & CONT_SOL)
|| ctrl_x_mode == CTRL_X_PATH_DEFINES) || ctrl_x_mode == CTRL_X_PATH_DEFINES)
@@ -5445,7 +5474,7 @@ ins_complete(int c, int enable_pum)
return FAIL; return FAIL;
if (col == -3) if (col == -3)
{ {
ctrl_x_mode = 0; ctrl_x_mode = CTRL_X_NORMAL;
edit_submode = NULL; edit_submode = NULL;
if (!shortmess(SHM_COMPLETIONMENU)) if (!shortmess(SHM_COMPLETIONMENU))
msg_clr_cmdline(); msg_clr_cmdline();
@@ -5604,7 +5633,7 @@ ins_complete(int c, int enable_pum)
* (such as M in M'exico) if not tried already. -- Acevedo */ * (such as M in M'exico) if not tried already. -- Acevedo */
if ( compl_length > 1 if ( compl_length > 1
|| (compl_cont_status & CONT_ADDING) || (compl_cont_status & CONT_ADDING)
|| (ctrl_x_mode != 0 || (ctrl_x_mode != CTRL_X_NORMAL
&& ctrl_x_mode != CTRL_X_PATH_PATTERNS && ctrl_x_mode != CTRL_X_PATH_PATTERNS
&& ctrl_x_mode != CTRL_X_PATH_DEFINES)) && ctrl_x_mode != CTRL_X_PATH_DEFINES))
compl_cont_status &= ~CONT_N_ADDS; compl_cont_status &= ~CONT_N_ADDS;

View File

@@ -2115,7 +2115,8 @@ vgetorpeek(int advance)
&& State != ASKMORE && State != ASKMORE
&& State != CONFIRM && State != CONFIRM
#ifdef FEAT_INS_EXPAND #ifdef FEAT_INS_EXPAND
&& !((ctrl_x_mode != 0 && vim_is_ctrl_x_key(c1)) && !((ctrl_x_mode_not_default()
&& vim_is_ctrl_x_key(c1))
|| ((compl_cont_status & CONT_LOCAL) || ((compl_cont_status & CONT_LOCAL)
&& (c1 == Ctrl_N || c1 == Ctrl_P))) && (c1 == Ctrl_N || c1 == Ctrl_P)))
#endif #endif

View File

@@ -964,7 +964,6 @@ EXTERN char_u *edit_submode INIT(= NULL); /* msg for CTRL-X submode */
EXTERN char_u *edit_submode_pre INIT(= NULL); /* prepended to edit_submode */ EXTERN char_u *edit_submode_pre INIT(= NULL); /* prepended to edit_submode */
EXTERN char_u *edit_submode_extra INIT(= NULL);/* appended to edit_submode */ EXTERN char_u *edit_submode_extra INIT(= NULL);/* appended to edit_submode */
EXTERN hlf_T edit_submode_highl; /* highl. method for extra info */ EXTERN hlf_T edit_submode_highl; /* highl. method for extra info */
EXTERN int ctrl_x_mode INIT(= 0); /* Which Ctrl-X mode are we in? */
#endif #endif
EXTERN int no_abbr INIT(= TRUE); /* TRUE when no abbreviations loaded */ EXTERN int no_abbr INIT(= TRUE); /* TRUE when no abbreviations loaded */

View File

@@ -6,6 +6,8 @@ void display_dollar(colnr_T col);
void change_indent(int type, int amount, int round, int replaced, int call_changed_bytes); void change_indent(int type, int amount, int round, int replaced, int call_changed_bytes);
void truncate_spaces(char_u *line); void truncate_spaces(char_u *line);
void backspace_until_column(int col); void backspace_until_column(int col);
int ctrl_x_mode_not_default(void);
int ctrl_x_mode_not_defined_yet(void);
int vim_is_ctrl_x_key(int c); int vim_is_ctrl_x_key(int c);
int ins_compl_add_infercase(char_u *str, int len, int icase, char_u *fname, int dir, int flags); int ins_compl_add_infercase(char_u *str, int len, int icase, char_u *fname, int dir, int flags);
void completeopt_was_set(void); void completeopt_was_set(void);

View File

@@ -421,7 +421,7 @@ ignorecase_opt(char_u *pat, int ic_in, int scs)
if (ic && !no_smartcase && scs if (ic && !no_smartcase && scs
#ifdef FEAT_INS_EXPAND #ifdef FEAT_INS_EXPAND
&& !(ctrl_x_mode && curbuf->b_p_inf) && !(ctrl_x_mode_not_default() && curbuf->b_p_inf)
#endif #endif
) )
ic = !pat_has_uppercase(pat); ic = !pat_has_uppercase(pat);

View File

@@ -771,6 +771,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1479,
/**/ /**/
1478, 1478,
/**/ /**/