Skip to content
Permalink
Browse files

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.
  • Loading branch information...
brammool committed Feb 9, 2018
1 parent dff72ba commit bc0e9adae9c253f36803665180e4b576d1e725ab
Showing with 92 additions and 59 deletions.
  1. +85 −56 src/edit.c
  2. +2 −1 src/getchar.c
  3. +0 −1 src/globals.h
  4. +2 −0 src/proto/edit.pro
  5. +1 −1 src/search.c
  6. +2 −0 src/version.c
@@ -17,39 +17,41 @@
/*
* definitions used for CTRL-X submode
*/
#define CTRL_X_WANT_IDENT 0x100

#define CTRL_X_NOT_DEFINED_YET 1
#define CTRL_X_SCROLL 2
#define CTRL_X_WHOLE_LINE 3
#define CTRL_X_FILES 4
#define CTRL_X_TAGS (5 + CTRL_X_WANT_IDENT)
#define CTRL_X_PATH_PATTERNS (6 + CTRL_X_WANT_IDENT)
#define CTRL_X_PATH_DEFINES (7 + CTRL_X_WANT_IDENT)
#define CTRL_X_FINISHED 8
#define CTRL_X_DICTIONARY (9 + CTRL_X_WANT_IDENT)
#define CTRL_X_THESAURUS (10 + CTRL_X_WANT_IDENT)
#define CTRL_X_CMDLINE 11
#define CTRL_X_FUNCTION 12
#define CTRL_X_OMNI 13
#define CTRL_X_SPELL 14
#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_MODE_LINE_OR_EVAL(m) (m == CTRL_X_WHOLE_LINE || m == CTRL_X_EVAL)

# define CTRL_X_WANT_IDENT 0x100

# define CTRL_X_NORMAL 0 /* CTRL-N CTRL-P completion, default */
# define CTRL_X_NOT_DEFINED_YET 1
# define CTRL_X_SCROLL 2
# define CTRL_X_WHOLE_LINE 3
# define CTRL_X_FILES 4
# define CTRL_X_TAGS (5 + CTRL_X_WANT_IDENT)
# define CTRL_X_PATH_PATTERNS (6 + CTRL_X_WANT_IDENT)
# define CTRL_X_PATH_DEFINES (7 + CTRL_X_WANT_IDENT)
# define CTRL_X_FINISHED 8
# define CTRL_X_DICTIONARY (9 + CTRL_X_WANT_IDENT)
# define CTRL_X_THESAURUS (10 + CTRL_X_WANT_IDENT)
# define CTRL_X_CMDLINE 11
# define CTRL_X_FUNCTION 12
# define CTRL_X_OMNI 13
# define CTRL_X_SPELL 14
# 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_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[] =
{
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)"),
NULL,
NULL, /* CTRL_X_SCROLL: depends on state */
N_(" Whole line completion (^L^N^P)"),
N_(" File name completion (^F^N^P)"),
N_(" Tag completion (^]^N^P)"),
N_(" Path pattern completion (^N^P)"),
N_(" Definition completion (^D^N^P)"),
NULL,
NULL, /* CTRL_X_FINISHED */
N_(" Dictionary completion (^K^N^P)"),
N_(" Thesaurus completion (^T^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");
#ifdef FEAT_COMPL_FUNC
# ifdef FEAT_COMPL_FUNC
static char e_complwin[] = N_("E839: Completion function changed window");
static char e_compldel[] = N_("E840: Completion function deleted text");
#endif
# endif

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

#define ORIGINAL_TEXT (1) /* the original text when the expansion begun */
#define FREE_FNAME (2)
# define ORIGINAL_TEXT (1) /* the original text when the expansion begun */
# define FREE_FNAME (2)

/*
* 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. */
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,
* which is not allowed. */
static int compl_busy = FALSE;
@@ -174,10 +179,10 @@ static void ins_compl_addfrommatch(void);
static int ins_compl_prep(int c);
static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg);
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_dict(dict_T *dict);
#endif
# endif
static int ins_compl_get_exp(pos_T *ini);
static void ins_compl_delete(void);
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.
*/
@@ -2254,7 +2277,7 @@ has_compl_option(int dict_opt)
)
: (*curbuf->b_p_tsr == NUL && *p_tsr == NUL))
{
ctrl_x_mode = 0;
ctrl_x_mode = CTRL_X_NORMAL;
edit_submode = NULL;
msg_attr(dict_opt ? (char_u *)_("'dictionary' 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;

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

/* Set "compl_get_longest" when finding the first matches. */
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_used_match = TRUE;
@@ -3841,19 +3864,19 @@ ins_compl_prep(int c)
else
compl_cont_mode = CTRL_X_NOT_DEFINED_YET;
}
ctrl_x_mode = 0;
ctrl_x_mode = CTRL_X_NORMAL;
edit_submode = NULL;
showmode();
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? */
if (!vim_is_ctrl_x_key(c))
{
if (ctrl_x_mode == CTRL_X_SCROLL)
ctrl_x_mode = 0;
ctrl_x_mode = CTRL_X_NORMAL;
else
ctrl_x_mode = CTRL_X_FINISHED;
edit_submode = NULL;
@@ -3867,8 +3890,8 @@ ins_compl_prep(int c)
* 'Pattern not found') until another key is hit, then go back to
* showing what mode we are in. */
showmode();
if ((ctrl_x_mode == 0 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_R
&& !ins_compl_pum_key(c))
if ((ctrl_x_mode == CTRL_X_NORMAL && c != Ctrl_N && c != Ctrl_P
&& c != Ctrl_R && !ins_compl_pum_key(c))
|| ctrl_x_mode == CTRL_X_FINISHED)
{
/* Get here when we have finished typing a sequence of ^N and
@@ -3951,7 +3974,7 @@ ins_compl_prep(int c)
compl_matches = 0;
if (!shortmess(SHM_COMPLETIONMENU))
msg_clr_cmdline(); /* necessary for "noshowmode" */
ctrl_x_mode = 0;
ctrl_x_mode = CTRL_X_NORMAL;
compl_enter_selects = FALSE;
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,
* or if found_all says this entry is done. For ^X^L only use the
* 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))
{
found_all = FALSE;
@@ -4304,7 +4328,7 @@ ins_compl_get_exp(pos_T *ini)
first_match_pos = *ini;
/* Move the cursor back one character so that ^N can match the
* 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
* 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
* of matches is found when compl_pattern is empty */
if (find_tags(compl_pattern, &num_matches, &matches,
TAG_REGEXP | TAG_NAMES | TAG_NOIC |
TAG_INS_COMP | (ctrl_x_mode ? TAG_VERBOSE : 0),
TAG_REGEXP | TAG_NAMES | TAG_NOIC | TAG_INS_COMP
| (ctrl_x_mode != CTRL_X_NORMAL ? TAG_VERBOSE : 0),
TAG_MANY, curbuf->b_ffname) == OK && num_matches > 0)
{
ins_compl_add_matches(num_matches, matches, p_ic);
@@ -4633,8 +4657,10 @@ ins_compl_get_exp(pos_T *ini)
found_new_match = OK;

/* break the loop for specialized modes (use 'complete' just for the
* generic ctrl_x_mode == 0) or when we've found a new match */
if ((ctrl_x_mode != 0 && !CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
* generic ctrl_x_mode == CTRL_X_NORMAL) or when we've found a new
* match */
if ((ctrl_x_mode != CTRL_X_NORMAL
&& !CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
|| found_new_match != FAIL)
{
if (got_int)
@@ -4643,7 +4669,8 @@ ins_compl_get_exp(pos_T *ini)
if (type != -1)
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)
break;
compl_started = TRUE;
@@ -4659,13 +4686,13 @@ ins_compl_get_exp(pos_T *ini)
}
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' */
found_new_match = FAIL;

i = -1; /* total of matches, unknown */
if (found_new_match == FAIL
|| (ctrl_x_mode != 0 && !CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode)))
if (found_new_match == FAIL || (ctrl_x_mode != CTRL_X_NORMAL
&& !CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode)))
i = ins_compl_make_cyclic();

if (compl_old_match != NULL)
@@ -5166,8 +5193,9 @@ ins_complete(int c, int enable_pum)
* it is a continued search
*/
compl_cont_status &= ~CONT_INTRPT; /* remove INTRPT */
if (ctrl_x_mode == 0 || ctrl_x_mode == CTRL_X_PATH_PATTERNS
|| ctrl_x_mode == CTRL_X_PATH_DEFINES)
if (ctrl_x_mode == CTRL_X_NORMAL
|| ctrl_x_mode == CTRL_X_PATH_PATTERNS
|| ctrl_x_mode == CTRL_X_PATH_DEFINES)
{
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 */
{
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 |= CONT_N_ADDS;
compl_startpos = curwin->w_cursor;
@@ -5228,7 +5257,7 @@ ins_complete(int c, int enable_pum)
}

/* 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)
|| ctrl_x_mode == CTRL_X_PATH_DEFINES)
@@ -5445,7 +5474,7 @@ ins_complete(int c, int enable_pum)
return FAIL;
if (col == -3)
{
ctrl_x_mode = 0;
ctrl_x_mode = CTRL_X_NORMAL;
edit_submode = NULL;
if (!shortmess(SHM_COMPLETIONMENU))
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 */
if ( compl_length > 1
|| (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_DEFINES))
compl_cont_status &= ~CONT_N_ADDS;
@@ -2115,7 +2115,8 @@ vgetorpeek(int advance)
&& State != ASKMORE
&& State != CONFIRM
#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)
&& (c1 == Ctrl_N || c1 == Ctrl_P)))
#endif
@@ -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_extra INIT(= NULL);/* appended to edit_submode */
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

EXTERN int no_abbr INIT(= TRUE); /* TRUE when no abbreviations loaded */
@@ -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 truncate_spaces(char_u *line);
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 ins_compl_add_infercase(char_u *str, int len, int icase, char_u *fname, int dir, int flags);
void completeopt_was_set(void);
@@ -421,7 +421,7 @@ ignorecase_opt(char_u *pat, int ic_in, int scs)

if (ic && !no_smartcase && scs
#ifdef FEAT_INS_EXPAND
&& !(ctrl_x_mode && curbuf->b_p_inf)
&& !(ctrl_x_mode_not_default() && curbuf->b_p_inf)
#endif
)
ic = !pat_has_uppercase(pat);
@@ -771,6 +771,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1479,
/**/
1478,
/**/

0 comments on commit bc0e9ad

Please sign in to comment.
You can’t perform that action at this time.