]> granicus.if.org Git - vim/commitdiff
patch 7.4.775 v7.4.775
authorBram Moolenaar <Bram@vim.org>
Fri, 10 Jul 2015 16:18:40 +0000 (18:18 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 10 Jul 2015 16:18:40 +0000 (18:18 +0200)
Problem:    It is not possible to avoid using the first item of completion.
Solution:   Add the "noinsert" and "noselect" values to 'completeopt'. (Shougo
            Matsu)

runtime/doc/options.txt
src/edit.c
src/option.c
src/version.c

index 320b1544c5b8d091384bdae46bd922ffb19919ec..e371a74ec7e51cd2901433c465e2828b0c32cefa 100644 (file)
@@ -1819,6 +1819,14 @@ A jump table for the options with a short description can be found at |Q_op|.
                    completion in the preview window.  Only works in
                    combination with "menu" or "menuone".
 
+          noinsert Do not insert any text for a match until the user selects
+                   a match from the menu. Only works in combination with
+                   "menu" or "menuone". No effect if "longest" is present.
+
+          noselect Do not select a match in the menu, force the user to
+                   select one from the menu. Only works in combination with
+                   "menu" or "menuone".
+
 
                                                *'concealcursor'* *'cocu'*
 'concealcursor' 'cocu' string (default: "")
index 3e129cb62ba431ccf4eb9892d18115baf339a603..086a5b99eeb6b6b71c2246c6b0198f0f370a3fd9 100644 (file)
@@ -108,6 +108,11 @@ static char_u        *compl_leader = NULL;
 static int       compl_get_longest = FALSE;    /* put longest common string
                                                   in compl_leader */
 
+static int       compl_no_insert = FALSE;      /* FALSE: select & insert
+                                                  TRUE: noinsert */
+static int       compl_no_select = FALSE;      /* FALSE: select & insert
+                                                  TRUE: noselect */
+
 static int       compl_used_match;     /* Selected one of the matches.  When
                                           FALSE the match was edited or using
                                           the longest common string. */
@@ -2788,7 +2793,17 @@ set_completion(startcol, list)
     compl_cont_status = 0;
 
     compl_curr_match = compl_first_match;
-    ins_complete(Ctrl_N);
+    if (compl_no_insert)
+    {
+       if (!compl_no_select)
+           ins_complete(K_DOWN);
+    }
+    else
+    {
+       ins_complete(Ctrl_N);
+       if (compl_no_select)
+           ins_complete(Ctrl_P);
+    }
     out_flush();
 }
 
@@ -3657,10 +3672,18 @@ ins_compl_prep(c)
     if (ctrl_x_mode == CTRL_X_NOT_DEFINED_YET
                                      || (ctrl_x_mode == 0 && !compl_started))
     {
-       compl_get_longest = (vim_strchr(p_cot, 'l') != NULL);
+       compl_get_longest = (strstr((char *)p_cot, "longest") != NULL);
        compl_used_match = TRUE;
+
     }
 
+    compl_no_insert = FALSE;
+    compl_no_select = FALSE;
+    if (strstr((char *)p_cot, "noselect") != NULL)
+       compl_no_select = TRUE;
+    if (strstr((char *)p_cot, "noinsert") != NULL)
+       compl_no_insert = TRUE;
+
     if (ctrl_x_mode == CTRL_X_NOT_DEFINED_YET)
     {
        /*
@@ -4672,6 +4695,7 @@ ins_compl_next(allow_get_expansion, count, insert_match)
     compl_T *found_compl = NULL;
     int            found_end = FALSE;
     int            advance;
+    int            started = compl_started;
 
     /* When user complete function return -1 for findstart which is next
      * time of 'always', compl_shown_match become NULL. */
@@ -4753,7 +4777,7 @@ ins_compl_next(allow_get_expansion, count, insert_match)
                return -1;
            }
 
-           if (advance)
+           if (!compl_no_select && advance)
            {
                if (compl_shows_dir == BACKWARD)
                    --compl_pending;
@@ -4805,7 +4829,12 @@ ins_compl_next(allow_get_expansion, count, insert_match)
     }
 
     /* Insert the text of the new completion, or the compl_leader. */
-    if (insert_match)
+    if (compl_no_insert && !started)
+    {
+       ins_bytes(compl_orig_text + ins_compl_len());
+       compl_used_match = FALSE;
+    }
+    else if (insert_match)
     {
        if (!compl_get_longest || compl_used_match)
            ins_compl_insert();
@@ -4842,7 +4871,10 @@ ins_compl_next(allow_get_expansion, count, insert_match)
 
     /* Enter will select a match when the match wasn't inserted and the popup
      * menu is visible. */
-    compl_enter_selects = !insert_match && compl_match_array != NULL;
+    if (compl_no_insert && !started)
+       compl_enter_selects = TRUE;
+    else
+       compl_enter_selects = !insert_match && compl_match_array != NULL;
 
     /*
      * Show the file name for the match (if any)
@@ -4917,7 +4949,7 @@ ins_compl_check_keys(frequency)
            }
        }
     }
-    if (compl_pending != 0 && !got_int)
+    if (compl_pending != 0 && !got_int && !compl_no_insert)
     {
        int todo = compl_pending > 0 ? compl_pending : -compl_pending;
 
index 69c6bf4028c07149a90bae3786b3cb4ce661dee6..046a63f3f528365c29367ad49e8d3a8be595f58d 100644 (file)
@@ -3054,7 +3054,7 @@ static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
 static char *(p_fcl_values[]) = {"all", NULL};
 #endif
 #ifdef FEAT_INS_EXPAND
-static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
+static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
 #endif
 
 static void set_option_default __ARGS((int, int opt_flags, int compatible));
index e194707844f28f93ad561f9aa72bad2d7eb690bb..9a7aa784eb03e2ec86ea777a9a4cd514f567fb82 100644 (file)
@@ -741,6 +741,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    775,
 /**/
     774,
 /**/