aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/edit.c61
-rw-r--r--src/nvim/version.c2
2 files changed, 36 insertions, 27 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index 413df3c036..674d4aa512 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -83,8 +83,10 @@
#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)
static char *ctrl_x_msgs[] =
{
@@ -104,6 +106,7 @@ static char *ctrl_x_msgs[] =
N_(" Omni completion (^O^N^P)"),
N_(" Spelling suggestion (s^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");
@@ -635,7 +638,7 @@ edit (
* "compl_leader". Except when at the original match and
* there is nothing to add, CTRL-L works like CTRL-P then. */
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)
> curwin->w_cursor.col - compl_col)) {
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;
case CTRL_X_SPELL:
return c == Ctrl_S || c == Ctrl_P || c == Ctrl_N;
+ case CTRL_X_EVAL:
+ return (c == Ctrl_P || c == Ctrl_N);
}
EMSG(_(e_internal));
return FALSE;
@@ -2231,8 +2236,7 @@ void set_completion(colnr_T startcol, list_T *list)
return;
}
- /* Handle like dictionary completion. */
- ctrl_x_mode = CTRL_X_WHOLE_LINE;
+ ctrl_x_mode = CTRL_X_EVAL;
ins_compl_add_list(list);
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
* to only match at the start of a line. Otherwise just match the
* 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 *)"\\");
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;
while (vim_regexec(regmatch, buf, (colnr_T)(ptr - buf))) {
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);
- else
+ } else {
ptr = find_word_end(ptr);
+ }
add_r = ins_compl_add_infercase(regmatch->startp[0],
(int)(ptr - regmatch->startp[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. */
if ((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;
+ }
/* Deleted more than what was used to find matches or didn't finish
* 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,
* or if found_all says this entry is done. For ^X^L only use the
* 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)) {
found_all = FALSE;
while (*e_cpt == ',' || *e_cpt == ' ')
@@ -3502,9 +3508,9 @@ static int ins_compl_get_exp(pos_T *ini)
} else if (*e_cpt == NUL)
break;
else {
- if (l_ctrl_x_mode == CTRL_X_WHOLE_LINE)
+ if (CTRL_X_MODE_LINE_OR_EVAL(l_ctrl_x_mode)) {
type = -1;
- else if (*e_cpt == 'k' || *e_cpt == 's') {
+ } else if (*e_cpt == 'k' || *e_cpt == 's') {
if (*e_cpt == 'k')
type = CTRL_X_DICTIONARY;
else
@@ -3632,13 +3638,13 @@ static int ins_compl_get_exp(pos_T *ini)
++msg_silent; /* Don't want messages for wrapscan. */
- /* l_ctrl_x_mode == CTRL_X_WHOLE_LINE || word-wise search that
- * has added a word that was at the beginning of the line */
- if ( l_ctrl_x_mode == CTRL_X_WHOLE_LINE
- || (compl_cont_status & CONT_SOL))
+ // 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.
+ if (CTRL_X_MODE_LINE_OR_EVAL(l_ctrl_x_mode)
+ || (compl_cont_status & CONT_SOL)) {
found_new_match = search_for_exact_line(ins_buf, pos,
compl_direction, compl_pattern);
- else
+ } else
found_new_match = searchit(NULL, ins_buf, pos,
compl_direction,
compl_pattern, 1L, SEARCH_KEEP + SEARCH_NFMSG,
@@ -3665,7 +3671,7 @@ static int ins_compl_get_exp(pos_T *ini)
&& ini->col == pos->col)
continue;
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 (pos->lnum >= ins_buf->b_ml.ml_line_count)
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
* 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) {
if (got_int)
break;
@@ -3757,9 +3763,10 @@ static int ins_compl_get_exp(pos_T *ini)
if (type != -1)
ins_compl_check_keys(0);
- if ((l_ctrl_x_mode != 0 && l_ctrl_x_mode != CTRL_X_WHOLE_LINE)
- || compl_interrupted)
+ if ((l_ctrl_x_mode != 0 && !CTRL_X_MODE_LINE_OR_EVAL(l_ctrl_x_mode))
+ || compl_interrupted) {
break;
+ }
compl_started = TRUE;
} else {
/* 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;
- if ((l_ctrl_x_mode == 0 || l_ctrl_x_mode == CTRL_X_WHOLE_LINE)
- && *e_cpt == NUL) /* Got to end of 'complete' */
+ if ((l_ctrl_x_mode == 0 || CTRL_X_MODE_LINE_OR_EVAL(l_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
- || (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();
+ }
/* 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
@@ -4201,9 +4210,9 @@ static int ins_complete(int c)
compl_cont_status |= CONT_ADDING | CONT_N_ADDS;
if (compl_length < 1)
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;
- else
+ } else
compl_cont_status = 0;
} else
compl_cont_status &= CONT_LOCAL;
@@ -4292,7 +4301,7 @@ static int ins_complete(int c)
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_length = (int)curs_col - (int)compl_col;
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) {
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' */
char_u *old = curbuf->b_p_com;
diff --git a/src/nvim/version.c b/src/nvim/version.c
index 4b4d28dcc2..544c9e754f 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -130,7 +130,7 @@ static int included_patches[] = {
//656,
//655,
//654,
- //653,
+ 653,
//652,
//651,
//650,