]> granicus.if.org Git - vim/commitdiff
patch 7.4.774 v7.4.774
authorBram Moolenaar <Bram@vim.org>
Fri, 10 Jul 2015 15:56:23 +0000 (17:56 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 10 Jul 2015 15:56:23 +0000 (17:56 +0200)
Problem:    When using the CompleteDone autocommand event it's difficult to
            get to the completed items.
Solution:   Add the v:completed_items variable. (Shougo Matsu)

runtime/doc/autocmd.txt
runtime/doc/eval.txt
src/edit.c
src/eval.c
src/macros.h
src/proto/eval.pro
src/version.c
src/vim.h

index ff05fe5e687e674d6602825a93c605806e33fd70..2b7b987ede631fae5ee9201cddc82e1673108ff5 100644 (file)
@@ -505,6 +505,8 @@ ColorScheme                 After loading a color scheme. |:colorscheme|
 CompleteDone                   After Insert mode completion is done.  Either
                                when something was completed or abandoning
                                completion. |ins-completion|
+                               The |v:completed_item| variable contains
+                               information about the completed item.
 
                                                        *CursorHold*
 CursorHold                     When the user doesn't press a key for the time
index c416d773c6b91af75a78079bc193c7eca7248060..d139b12e0a1b432770808e5665c88e1e63d7c549 100644 (file)
@@ -1330,6 +1330,12 @@ v:cmdbang        Set like v:cmdarg for a file read/write command.  When a "!"
                can only be used in autocommands.  For user commands |<bang>|
                can be used.
 
+                               *v:completed_item* *completed_item-variable*
+v:completed_item
+               |Dictionary| containing the |complete-items| for the most
+               recently completed word after |CompleteDone|.  The
+               |Dictionary| is empty if the completion failed.
+
                                        *v:count* *count-variable*
 v:count                The count given for the last Normal mode command.  Can be used
                to get the count before a mapping.  Read-only.  Example: >
index 76bfcfb9741ff0b57a670530d2e3fe2e82b0be52..3e129cb62ba431ccf4eb9892d18115baf339a603 100644 (file)
@@ -3372,6 +3372,8 @@ ins_compl_clear()
     vim_free(compl_orig_text);
     compl_orig_text = NULL;
     compl_enter_selects = FALSE;
+    /* clear v:completed_item */
+    set_vim_var_dict(VV_COMPLETED_ITEM, dict_alloc());
 }
 
 /*
@@ -4606,17 +4608,39 @@ ins_compl_delete()
     /* TODO: is this sufficient for redrawing?  Redrawing everything causes
      * flicker, thus we can't do that. */
     changed_cline_bef_curs();
+    /* clear v:completed_item */
+    set_vim_var_dict(VV_COMPLETED_ITEM, dict_alloc());
 }
 
 /* Insert the new text being completed. */
     static void
 ins_compl_insert()
 {
+    dict_T     *dict;
+
     ins_bytes(compl_shown_match->cp_str + ins_compl_len());
     if (compl_shown_match->cp_flags & ORIGINAL_TEXT)
        compl_used_match = FALSE;
     else
        compl_used_match = TRUE;
+
+    /* Set completed item. */
+    /* { word, abbr, menu, kind, info } */
+    dict = dict_alloc();
+    if (dict != NULL)
+    {
+       dict_add_nr_str(dict, "word", 0L,
+                   EMPTY_IF_NULL(compl_shown_match->cp_str));
+       dict_add_nr_str(dict, "abbr", 0L,
+                   EMPTY_IF_NULL(compl_shown_match->cp_text[CPT_ABBR]));
+       dict_add_nr_str(dict, "menu", 0L,
+                   EMPTY_IF_NULL(compl_shown_match->cp_text[CPT_MENU]));
+       dict_add_nr_str(dict, "kind", 0L,
+                   EMPTY_IF_NULL(compl_shown_match->cp_text[CPT_KIND]));
+       dict_add_nr_str(dict, "info", 0L,
+                   EMPTY_IF_NULL(compl_shown_match->cp_text[CPT_INFO]));
+    }
+    set_vim_var_dict(VV_COMPLETED_ITEM, dict);
 }
 
 /*
index 5869370f3cc2a74c50b286c9675124b9ac7c83aa..5804efa6e1c88f396f0981749da2415f63de393f 100644 (file)
@@ -364,6 +364,7 @@ static struct vimvar
     {VV_NAME("oldfiles",        VAR_LIST), 0},
     {VV_NAME("windowid",        VAR_NUMBER), VV_RO},
     {VV_NAME("progpath",        VAR_STRING), VV_RO},
+    {VV_NAME("completed_item",  VAR_DICT), VV_RO},
 };
 
 /* shorthand */
@@ -372,6 +373,7 @@ static struct vimvar
 #define vv_float       vv_di.di_tv.vval.v_float
 #define vv_str         vv_di.di_tv.vval.v_string
 #define vv_list                vv_di.di_tv.vval.v_list
+#define vv_dict                vv_di.di_tv.vval.v_dict
 #define vv_tv          vv_di.di_tv
 
 static dictitem_T      vimvars_var;            /* variable used for v: */
@@ -888,6 +890,7 @@ eval_init()
     }
     set_vim_var_nr(VV_SEARCHFORWARD, 1L);
     set_vim_var_nr(VV_HLSEARCH, 1L);
+    set_vim_var_dict(VV_COMPLETED_ITEM, dict_alloc());
     set_reg_var(0);  /* default for v:register is not 0 but '"' */
 
 #ifdef EBCDIC
@@ -20576,6 +20579,35 @@ set_vim_var_list(idx, val)
        ++val->lv_refcount;
 }
 
+/*
+ * Set Dictionary v: variable to "val".
+ */
+    void
+set_vim_var_dict(idx, val)
+    int                idx;
+    dict_T     *val;
+{
+    int                todo;
+    hashitem_T *hi;
+
+    dict_unref(vimvars[idx].vv_dict);
+    vimvars[idx].vv_dict = val;
+    if (val != NULL)
+    {
+       ++val->dv_refcount;
+
+       /* Set readonly */
+       todo = (int)val->dv_hashtab.ht_used;
+       for (hi = val->dv_hashtab.ht_array; todo > 0 ; ++hi)
+       {
+           if (HASHITEM_EMPTY(hi))
+               continue;
+           --todo;
+           HI2DI(hi)->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX;
+       }
+    }
+}
+
 /*
  * Set v:register if needed.
  */
index 01207d91b3f5ad2e13476317c4e79d3e7caaef39..773cffdf77bec8b8e495f8af1e60b53be150bc32 100644 (file)
 # define ASCII_ISALNUM(c) (ASCII_ISALPHA(c) || VIM_ISDIGIT(c))
 #endif
 
+/* Returns empty string if it is NULL. */
+#define EMPTY_IF_NULL(x) ((x) ? (x) : (u_char *)"")
+
 /* macro version of chartab().
  * Only works with values 0-255!
  * Doesn't work for UTF-8 mode with chars >= 0x80. */
index 30416fb8782a55265cfb77c31f95bf97b0cde38f..22b8b189d1cea49f8fb53e3b52001a011ef46f46 100644 (file)
@@ -91,6 +91,7 @@ void set_vim_var_char __ARGS((int c));
 void set_vcount __ARGS((long count, long count1, int set_prevcount));
 void set_vim_var_string __ARGS((int idx, char_u *val, int len));
 void set_vim_var_list __ARGS((int idx, list_T *val));
+void set_vim_var_dict __ARGS((int idx, dict_T *val));
 void set_reg_var __ARGS((int c));
 char_u *v_exception __ARGS((char_u *oldval));
 char_u *v_throwpoint __ARGS((char_u *oldval));
index 8ab862ac411b015e71bf5dc32352fc6920e92889..e194707844f28f93ad561f9aa72bad2d7eb690bb 100644 (file)
@@ -741,6 +741,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    774,
 /**/
     773,
 /**/
index fe8f5582886894f614ac2c07f8ce28d9cc59238d..4e36f3d726abfd447ce4b8c249b2b1ecb35501cb 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -1897,7 +1897,8 @@ typedef int proftime_T;       /* dummy for function prototypes */
 #define VV_OLDFILES    55
 #define VV_WINDOWID    56
 #define VV_PROGPATH    57
-#define VV_LEN         58      /* number of v: vars */
+#define VV_COMPLETED_ITEM 58
+#define VV_LEN         59      /* number of v: vars */
 
 #ifdef FEAT_CLIPBOARD