Hi, Bram.
I added v:completed_item feature for CompleteDone event.

https://groups.google.com/d/msg/vim_dev/XDFDQ8rkBII/xfOjjDzpa00J

This feature is useful for printing selected item information.
You can get the selected dictionary which has "word", "abbr", "menu", "kind" 
dictionary key.
It is implemented by jedi-vim, and more plugins.

http://stackoverflow.com/questions/14053720/get-selected-item-from-the-completion-popup-menu

The patch is below. It is reviewed by Yasuhiro Matsumoto.

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
diff -r 7f08152faea8 runtime/doc/autocmd.txt
--- a/runtime/doc/autocmd.txt	Thu Nov 28 12:45:24 2013 +0900
+++ b/runtime/doc/autocmd.txt	Fri Nov 29 14:24:59 2013 +0900
@@ -485,6 +485,8 @@
 CompleteDone			After Insert mode completion is done.  Either
 				when something was completed or abandoning
 				completion. |ins-completion|
+				The |v:completed_item| variable indicates the
+				completed item.
 
 							*CursorHold*
 CursorHold			When the user doesn't press a key for the time
diff -r 7f08152faea8 runtime/doc/eval.txt
--- a/runtime/doc/eval.txt	Thu Nov 28 12:45:24 2013 +0900
+++ b/runtime/doc/eval.txt	Fri Nov 29 14:24:59 2013 +0900
@@ -1329,6 +1329,14 @@
 		can only be used in autocommands.  For user commands |<bang>|
 		can be used.
 
+				*v:completed_item* *completed_item-variable*
+v:completed_item
+		The selected item in the last candidate. This dictionary
+		contains following items: "word", "abbr", "menu", "kind",
+		"info" (See |complete-items|).  If previous completion is
+		failed or isn't matched, it becomes an empty dictionary.
+		Note: This is for |CompleteDone| event.
+
 					*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: >
diff -r 7f08152faea8 src/edit.c
--- a/src/edit.c	Thu Nov 28 12:45:24 2013 +0900
+++ b/src/edit.c	Fri Nov 29 14:24:59 2013 +0900
@@ -3369,6 +3369,8 @@
     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());
 }
 
 /*
@@ -4607,17 +4609,40 @@
     i = compl_col + (compl_cont_status & CONT_ADDING ? compl_length : 0);
     backspace_until_column(i);
     changed_cline_bef_curs();
-}
+    /* clear v:completed_item */
+    set_vim_var_dict(VV_COMPLETED_ITEM, dict_alloc());
+}
+
+#define SHOULD_BE_STR(x) ((x) ? (x) : (u_char *)"")
 
 /* 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,
+		    SHOULD_BE_STR(compl_shown_match->cp_str));
+	dict_add_nr_str(dict, "abbr", 0L,
+		    SHOULD_BE_STR(compl_shown_match->cp_text[CPT_ABBR]));
+	dict_add_nr_str(dict, "menu", 0L,
+		    SHOULD_BE_STR(compl_shown_match->cp_text[CPT_MENU]));
+	dict_add_nr_str(dict, "kind", 0L,
+		    SHOULD_BE_STR(compl_shown_match->cp_text[CPT_KIND]));
+	dict_add_nr_str(dict, "info", 0L,
+		    SHOULD_BE_STR(compl_shown_match->cp_text[CPT_INFO]));
+    }
+    set_vim_var_dict(VV_COMPLETED_ITEM, dict);
 }
 
 /*
diff -r 7f08152faea8 src/eval.c
--- a/src/eval.c	Thu Nov 28 12:45:24 2013 +0900
+++ b/src/eval.c	Fri Nov 29 14:24:59 2013 +0900
@@ -359,6 +359,7 @@
     {VV_NAME("hlsearch",	 VAR_NUMBER), 0},
     {VV_NAME("oldfiles",	 VAR_LIST), 0},
     {VV_NAME("windowid",	 VAR_NUMBER), VV_RO},
+    {VV_NAME("completed_item",	 VAR_DICT), VV_RO},
 };
 
 /* shorthand */
@@ -367,6 +368,7 @@
 #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: */
@@ -19569,6 +19571,17 @@
 }
 
 /*
+ * Get Dictionary v: variable value.  Caller must take care of reference count when
+ * needed.
+ */
+    dict_T *
+get_vim_var_dict(idx)
+    int		idx;
+{
+    return vimvars[idx].vv_dict;
+}
+
+/*
  * Set v:char to character "c".
  */
     void
@@ -19642,6 +19655,20 @@
 }
 
 /*
+ * Set Dictionary v: variable to "val".
+ */
+    void
+set_vim_var_dict(idx, val)
+    int		idx;
+    dict_T	*val;
+{
+    dict_unref(vimvars[idx].vv_dict);
+    vimvars[idx].vv_dict = val;
+    if (val != NULL)
+	++val->dv_refcount;
+}
+
+/*
  * Set v:register if needed.
  */
     void
diff -r 7f08152faea8 src/main.c
--- a/src/main.c	Thu Nov 28 12:45:24 2013 +0900
+++ b/src/main.c	Fri Nov 29 14:24:59 2013 +0900
@@ -1606,6 +1606,7 @@
 
 #ifdef FEAT_EVAL
     set_vim_var_string(VV_PROGNAME, initstr, -1);
+    set_vim_var_dict(VV_COMPLETED_ITEM, dict_alloc());
 #endif
 
     if (TOLOWER_ASC(initstr[0]) == 'r')
diff -r 7f08152faea8 src/vim.h
--- a/src/vim.h	Thu Nov 28 12:45:24 2013 +0900
+++ b/src/vim.h	Fri Nov 29 14:24:59 2013 +0900
@@ -1876,7 +1876,8 @@
 #define VV_HLSEARCH	54
 #define VV_OLDFILES	55
 #define VV_WINDOWID	56
-#define VV_LEN		57	/* number of v: vars */
+#define VV_COMPLETED_ITEM 57
+#define VV_LEN		58	/* number of v: vars */
 
 #ifdef FEAT_CLIPBOARD
 

Raspunde prin e-mail lui