vim-patch:7.4.653 #2527

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)

https://github.com/vim/vim/commit/v7-4-653
This commit is contained in:
Florian Walch 2015-04-28 13:11:57 +03:00 committed by Justin M. Keyes
parent b427dcdda2
commit 64a4ef679a
2 changed files with 36 additions and 27 deletions

View File

@ -83,8 +83,10 @@
#define CTRL_X_OMNI 13 #define CTRL_X_OMNI 13
#define CTRL_X_SPELL 14 #define CTRL_X_SPELL 14
#define CTRL_X_LOCAL_MSG 15 /* only used in "ctrl_x_msgs" */ #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)
static char *ctrl_x_msgs[] = static char *ctrl_x_msgs[] =
{ {
@ -104,6 +106,7 @@ static char *ctrl_x_msgs[] =
N_(" Omni completion (^O^N^P)"), N_(" Omni completion (^O^N^P)"),
N_(" Spelling suggestion (s^N^P)"), N_(" Spelling suggestion (s^N^P)"),
N_(" Keyword Local completion (^N^P)"), N_(" Keyword Local completion (^N^P)"),
NULL, // CTRL_X_EVAL doesn't use msg.
}; };
static char e_hitend[] = N_("Hit end of paragraph"); static char e_hitend[] = N_("Hit end of paragraph");
@ -635,7 +638,7 @@ edit (
* "compl_leader". Except when at the original match and * "compl_leader". Except when at the original match and
* there is nothing to add, CTRL-L works like CTRL-P then. */ * there is nothing to add, CTRL-L works like CTRL-P then. */
if (c == Ctrl_L if (c == Ctrl_L
&& (ctrl_x_mode != CTRL_X_WHOLE_LINE && (!CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode)
|| (int)STRLEN(compl_shown_match->cp_str) || (int)STRLEN(compl_shown_match->cp_str)
> curwin->w_cursor.col - compl_col)) { > curwin->w_cursor.col - compl_col)) {
ins_compl_addfrommatch(); ins_compl_addfrommatch();
@ -1811,6 +1814,8 @@ int vim_is_ctrl_x_key(int c)
return c == Ctrl_O || c == Ctrl_P || c == Ctrl_N; return c == Ctrl_O || c == Ctrl_P || c == Ctrl_N;
case CTRL_X_SPELL: case CTRL_X_SPELL:
return c == Ctrl_S || c == Ctrl_P || c == Ctrl_N; return c == Ctrl_S || c == Ctrl_P || c == Ctrl_N;
case CTRL_X_EVAL:
return (c == Ctrl_P || c == Ctrl_N);
} }
EMSG(_(e_internal)); EMSG(_(e_internal));
return FALSE; return FALSE;
@ -2231,8 +2236,7 @@ void set_completion(colnr_T startcol, list_T *list)
return; return;
} }
/* Handle like dictionary completion. */ ctrl_x_mode = CTRL_X_EVAL;
ctrl_x_mode = CTRL_X_WHOLE_LINE;
ins_compl_add_list(list); ins_compl_add_list(list);
compl_matches = ins_compl_make_cyclic(); compl_matches = ins_compl_make_cyclic();
@ -2483,7 +2487,7 @@ ins_compl_dictionaries (
/* When invoked to match whole lines for CTRL-X CTRL-L adjust the pattern /* When invoked to match whole lines for CTRL-X CTRL-L adjust the pattern
* to only match at the start of a line. Otherwise just match the * to only match at the start of a line. Otherwise just match the
* pattern. Also need to double backslashes. */ * pattern. Also need to double backslashes. */
if (ctrl_x_mode == CTRL_X_WHOLE_LINE) { if (CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode)) {
char_u *pat_esc = vim_strsave_escaped(pat, (char_u *)"\\"); char_u *pat_esc = vim_strsave_escaped(pat, (char_u *)"\\");
size_t len = STRLEN(pat_esc) + 10; size_t len = STRLEN(pat_esc) + 10;
@ -2569,10 +2573,11 @@ static void ins_compl_files(int count, char_u **files, int thesaurus, int flags,
ptr = buf; ptr = buf;
while (vim_regexec(regmatch, buf, (colnr_T)(ptr - buf))) { while (vim_regexec(regmatch, buf, (colnr_T)(ptr - buf))) {
ptr = regmatch->startp[0]; ptr = regmatch->startp[0];
if (ctrl_x_mode == CTRL_X_WHOLE_LINE) if (CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode)) {
ptr = find_line_end(ptr); ptr = find_line_end(ptr);
else } else {
ptr = find_word_end(ptr); ptr = find_word_end(ptr);
}
add_r = ins_compl_add_infercase(regmatch->startp[0], add_r = ins_compl_add_infercase(regmatch->startp[0],
(int)(ptr - regmatch->startp[0]), (int)(ptr - regmatch->startp[0]),
p_ic, files[i], *dir, 0); p_ic, files[i], *dir, 0);
@ -2758,8 +2763,9 @@ static int ins_compl_bs(void)
* allow the word to be deleted, we won't match everything. */ * allow the word to be deleted, we won't match everything. */
if ((int)(p - line) - (int)compl_col < 0 if ((int)(p - line) - (int)compl_col < 0
|| ((int)(p - line) - (int)compl_col == 0 || ((int)(p - line) - (int)compl_col == 0
&& (ctrl_x_mode & CTRL_X_OMNI) == 0)) && ctrl_x_mode != CTRL_X_OMNI) || ctrl_x_mode == CTRL_X_EVAL) {
return K_BS; return K_BS;
}
/* Deleted more than what was used to find matches or didn't finish /* Deleted more than what was used to find matches or didn't finish
* finding all matches: need to look for matches all over again. */ * finding all matches: need to look for matches all over again. */
@ -3457,7 +3463,7 @@ static int 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 ((l_ctrl_x_mode == 0 || l_ctrl_x_mode == CTRL_X_WHOLE_LINE) if ((l_ctrl_x_mode == 0 || CTRL_X_MODE_LINE_OR_EVAL(l_ctrl_x_mode))
&& (!compl_started || found_all)) { && (!compl_started || found_all)) {
found_all = FALSE; found_all = FALSE;
while (*e_cpt == ',' || *e_cpt == ' ') while (*e_cpt == ',' || *e_cpt == ' ')
@ -3502,9 +3508,9 @@ static int ins_compl_get_exp(pos_T *ini)
} else if (*e_cpt == NUL) } else if (*e_cpt == NUL)
break; break;
else { else {
if (l_ctrl_x_mode == CTRL_X_WHOLE_LINE) if (CTRL_X_MODE_LINE_OR_EVAL(l_ctrl_x_mode)) {
type = -1; type = -1;
else if (*e_cpt == 'k' || *e_cpt == 's') { } else if (*e_cpt == 'k' || *e_cpt == 's') {
if (*e_cpt == 'k') if (*e_cpt == 'k')
type = CTRL_X_DICTIONARY; type = CTRL_X_DICTIONARY;
else else
@ -3632,13 +3638,13 @@ static int ins_compl_get_exp(pos_T *ini)
++msg_silent; /* Don't want messages for wrapscan. */ ++msg_silent; /* Don't want messages for wrapscan. */
/* l_ctrl_x_mode == CTRL_X_WHOLE_LINE || word-wise search that // CTRL_X_MODE_LINE_OR_EVAL(l_ctrl_x_mode) || word-wise search that
* has added a word that was at the beginning of the line */ // has added a word that was at the beginning of the line.
if ( l_ctrl_x_mode == CTRL_X_WHOLE_LINE if (CTRL_X_MODE_LINE_OR_EVAL(l_ctrl_x_mode)
|| (compl_cont_status & CONT_SOL)) || (compl_cont_status & CONT_SOL)) {
found_new_match = search_for_exact_line(ins_buf, pos, found_new_match = search_for_exact_line(ins_buf, pos,
compl_direction, compl_pattern); compl_direction, compl_pattern);
else } else
found_new_match = searchit(NULL, ins_buf, pos, found_new_match = searchit(NULL, ins_buf, pos,
compl_direction, compl_direction,
compl_pattern, 1L, SEARCH_KEEP + SEARCH_NFMSG, compl_pattern, 1L, SEARCH_KEEP + SEARCH_NFMSG,
@ -3665,7 +3671,7 @@ static int ins_compl_get_exp(pos_T *ini)
&& ini->col == pos->col) && ini->col == pos->col)
continue; continue;
ptr = ml_get_buf(ins_buf, pos->lnum, FALSE) + pos->col; ptr = ml_get_buf(ins_buf, pos->lnum, FALSE) + pos->col;
if (l_ctrl_x_mode == CTRL_X_WHOLE_LINE) { if (CTRL_X_MODE_LINE_OR_EVAL(l_ctrl_x_mode)) {
if (compl_cont_status & CONT_ADDING) { if (compl_cont_status & CONT_ADDING) {
if (pos->lnum >= ins_buf->b_ml.ml_line_count) if (pos->lnum >= ins_buf->b_ml.ml_line_count)
continue; continue;
@ -3749,7 +3755,7 @@ static int ins_compl_get_exp(pos_T *ini)
/* break the loop for specialized modes (use 'complete' just for the /* break the loop for specialized modes (use 'complete' just for the
* generic l_ctrl_x_mode == 0) or when we've found a new match */ * generic l_ctrl_x_mode == 0) or when we've found a new match */
if ((l_ctrl_x_mode != 0 && l_ctrl_x_mode != CTRL_X_WHOLE_LINE) if ((l_ctrl_x_mode != 0 && !CTRL_X_MODE_LINE_OR_EVAL(l_ctrl_x_mode))
|| found_new_match != FAIL) { || found_new_match != FAIL) {
if (got_int) if (got_int)
break; break;
@ -3757,9 +3763,10 @@ static int ins_compl_get_exp(pos_T *ini)
if (type != -1) if (type != -1)
ins_compl_check_keys(0); ins_compl_check_keys(0);
if ((l_ctrl_x_mode != 0 && l_ctrl_x_mode != CTRL_X_WHOLE_LINE) if ((l_ctrl_x_mode != 0 && !CTRL_X_MODE_LINE_OR_EVAL(l_ctrl_x_mode))
|| compl_interrupted) || compl_interrupted) {
break; break;
}
compl_started = TRUE; compl_started = TRUE;
} else { } else {
/* Mark a buffer scanned when it has been scanned completely */ /* Mark a buffer scanned when it has been scanned completely */
@ -3773,14 +3780,16 @@ static int ins_compl_get_exp(pos_T *ini)
} }
compl_started = TRUE; compl_started = TRUE;
if ((l_ctrl_x_mode == 0 || l_ctrl_x_mode == CTRL_X_WHOLE_LINE) if ((l_ctrl_x_mode == 0 || CTRL_X_MODE_LINE_OR_EVAL(l_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
|| (l_ctrl_x_mode != 0 && l_ctrl_x_mode != CTRL_X_WHOLE_LINE)) || (l_ctrl_x_mode != 0 && !CTRL_X_MODE_LINE_OR_EVAL(l_ctrl_x_mode))) {
i = ins_compl_make_cyclic(); i = ins_compl_make_cyclic();
}
/* If several matches were added (FORWARD) or the search failed and has /* If several matches were added (FORWARD) or the search failed and has
* just been made cyclic then we have to move compl_curr_match to the next * just been made cyclic then we have to move compl_curr_match to the next
@ -4201,9 +4210,9 @@ static int ins_complete(int c)
compl_cont_status |= CONT_ADDING | CONT_N_ADDS; compl_cont_status |= CONT_ADDING | CONT_N_ADDS;
if (compl_length < 1) if (compl_length < 1)
compl_cont_status &= CONT_LOCAL; compl_cont_status &= CONT_LOCAL;
} else if (ctrl_x_mode == CTRL_X_WHOLE_LINE) } else if (CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode)) {
compl_cont_status = CONT_ADDING | CONT_N_ADDS; compl_cont_status = CONT_ADDING | CONT_N_ADDS;
else } else
compl_cont_status = 0; compl_cont_status = 0;
} else } else
compl_cont_status &= CONT_LOCAL; compl_cont_status &= CONT_LOCAL;
@ -4292,7 +4301,7 @@ static int ins_complete(int c)
compl_length); compl_length);
} }
} }
} else if (ctrl_x_mode == CTRL_X_WHOLE_LINE) { } else if (CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode)) {
compl_col = (colnr_T)(skipwhite(line) - line); compl_col = (colnr_T)(skipwhite(line) - line);
compl_length = (int)curs_col - (int)compl_col; compl_length = (int)curs_col - (int)compl_col;
if (compl_length < 0) /* cursor in indent: empty pattern */ if (compl_length < 0) /* cursor in indent: empty pattern */
@ -4425,7 +4434,7 @@ static int ins_complete(int c)
if (compl_cont_status & CONT_ADDING) { if (compl_cont_status & CONT_ADDING) {
edit_submode_pre = (char_u *)_(" Adding"); edit_submode_pre = (char_u *)_(" Adding");
if (ctrl_x_mode == CTRL_X_WHOLE_LINE) { if (CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode)) {
/* Insert a new line, keep indentation but ignore 'comments' */ /* Insert a new line, keep indentation but ignore 'comments' */
char_u *old = curbuf->b_p_com; char_u *old = curbuf->b_p_com;

View File

@ -130,7 +130,7 @@ static int included_patches[] = {
//656, //656,
//655, //655,
//654, //654,
//653, 653,
//652, //652,
//651, //651,
//650, //650,