Hi,
I think that we would check `compl_started` except `ctrl_x_mode ==
CTRL_X_NOT_DEFINED_YET`.
Then we can return "" when not in complementary mode.
Patch attached.
--
Best regards,
Hirohito Higashi (h_east)
--
--
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/d/optout.
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index c41fdcee1..414a18e5d 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -2267,6 +2267,7 @@ col({expr}) Number column nr of cursor or mark
complete({startcol}, {matches}) none set Insert mode completion
complete_add({expr}) Number add completion match
complete_check() Number check for key typed during completion
+complete_mode() String get current completion mode
confirm({msg} [, {choices} [, {default} [, {type}]]])
Number number of choice picked by user
copy({expr}) any make a shallow copy of {expr}
@@ -3533,6 +3534,28 @@ complete_check() *complete_check()*
Only to be used by the function specified with the
'completefunc' option.
+ *complete_mode()*
+complete_mode()
+ Return a string that indicates the current completion mode.
+ Note: It does not check whether popup menu is visible.
+
+ "" Not in completion mode
+ "keyword" Keyword completion |i_CTRL-X_CTRL-N|
+ "ctrl_x" Just press |i_CTRL-X|
+ "whole_line" Whole lines |i_CTRL-X_CTRL-L|
+ "files" File names |i_CTRL-X_CTRL-F|
+ "tags" Tags |i_CTRL-X_CTRL-]|
+ "path_defines" Definition completion |i_CTRL-X_CTRL-D|
+ "path_patterns" Include completion |i_CTRL-X_CTRL-I|
+ "dictionary" Dictionary |i_CTRL-X_CTRL-K|
+ "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
+ "cmdline" Vim Command line completion |i_CTRL-X_CTRL-V|
+ "function" User defined completion |i_CTRL-X_CTRL-U|
+ "omni" Omni completion |i_CTRL-X_CTRL-O|
+ "spell" Spelling suggestions |i_CTRL-X_s|
+ "eval" |complete()| completion
+ "unknown" Other internal modes
+
*confirm()*
confirm({msg} [, {choices} [, {default} [, {type}]]])
Confirm() offers the user a dialog, from which a choice can be
diff --git a/runtime/doc/insert.txt b/runtime/doc/insert.txt
index 0431043c2..2bb357ef4 100644
--- a/runtime/doc/insert.txt
+++ b/runtime/doc/insert.txt
@@ -642,6 +642,7 @@ and one of the CTRL-X commands. You exit CTRL-X mode by typing a key that is
not a valid CTRL-X mode command. Valid keys are the CTRL-X command itself,
CTRL-N (next), and CTRL-P (previous).
+To get the current completion mode, |complete_mode()| can be used.
Also see the 'infercase' option if you want to adjust the case of the match.
*complete_CTRL-E*
diff --git a/runtime/doc/usr_41.txt b/runtime/doc/usr_41.txt
index dd0583b60..8225ab47b 100644
--- a/runtime/doc/usr_41.txt
+++ b/runtime/doc/usr_41.txt
@@ -834,6 +834,7 @@ Insert mode completion: *completion-functions*
complete() set found matches
complete_add() add to found matches
complete_check() check if completion should be aborted
+ complete_mode() get current completion mode
pumvisible() check if the popup menu is displayed
Folding: *folding-functions*
diff --git a/src/edit.c b/src/edit.c
index de5adcb19..2e556a391 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -16,6 +16,8 @@
#ifdef FEAT_INS_EXPAND
/*
* definitions used for CTRL-X submode
+ * Note: If add CTRL-X submode, you also need to maintain ctrl_x_msgs[], and
+ * mode_names[] in ins_compl_mode().
*/
# define CTRL_X_WANT_IDENT 0x100
@@ -3541,6 +3543,39 @@ ins_compl_active(void)
return compl_started;
}
+/*
+ * Return Insert completion mode name string
+ */
+ char_u *
+ins_compl_mode(void)
+{
+ static char *mode_names[] = {
+ "keyword",
+ "ctrl_x",
+ "unknown", // CTRL_X_SCROLL
+ "whole_line",
+ "files",
+ "tags",
+ "path_patterns",
+ "path_defines",
+ "unknown", // CTRL_X_FINISHED
+ "dictionary",
+ "thesaurus",
+ "cmdline",
+ "function",
+ "omni",
+ "spell",
+ NULL, // CTRL_X_LOCAL_MSG only used in "ctrl_x_msgs"
+ "eval"
+ };
+ char *mode = "";
+
+ if (ctrl_x_mode == CTRL_X_NOT_DEFINED_YET || compl_started)
+ mode = mode_names[ctrl_x_mode & ~CTRL_X_WANT_IDENT];
+
+ return (char_u *)mode;
+}
+
/*
* Delete one character before the cursor and show the subset of the matches
* that match the word that is now before the cursor.
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 874e3a66d..280853b49 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -113,6 +113,7 @@ static void f_col(typval_T *argvars, typval_T *rettv);
static void f_complete(typval_T *argvars, typval_T *rettv);
static void f_complete_add(typval_T *argvars, typval_T *rettv);
static void f_complete_check(typval_T *argvars, typval_T *rettv);
+static void f_complete_mode(typval_T *argvars, typval_T *rettv);
#endif
static void f_confirm(typval_T *argvars, typval_T *rettv);
static void f_copy(typval_T *argvars, typval_T *rettv);
@@ -589,6 +590,7 @@ static struct fst
{"complete", 2, 2, f_complete},
{"complete_add", 1, 1, f_complete_add},
{"complete_check", 0, 0, f_complete_check},
+ {"complete_mode", 0, 0, f_complete_mode},
#endif
{"confirm", 1, 4, f_confirm},
{"copy", 1, 1, f_copy},
@@ -2592,6 +2594,16 @@ f_complete_check(typval_T *argvars UNUSED, typval_T *rettv)
rettv->vval.v_number = compl_interrupted;
RedrawingDisabled = saved;
}
+
+/*
+ * "complete_mode()" function
+ */
+ static void
+f_complete_mode(typval_T *argvars UNUSED, typval_T *rettv)
+{
+ rettv->vval.v_string = vim_strsave(ins_compl_mode());
+ rettv->v_type = VAR_STRING;
+}
#endif
/*
diff --git a/src/proto/edit.pro b/src/proto/edit.pro
index 768af3a48..f92356f13 100644
--- a/src/proto/edit.pro
+++ b/src/proto/edit.pro
@@ -18,6 +18,7 @@ void ins_compl_show_pum(void);
char_u *find_word_start(char_u *ptr);
char_u *find_word_end(char_u *ptr);
int ins_compl_active(void);
+char_u *ins_compl_mode(void);
int ins_compl_add_tv(typval_T *tv, int dir);
void ins_compl_check_keys(int frequency, int in_compl_func);
int get_literal(void);
diff --git a/src/testdir/test_popup.vim b/src/testdir/test_popup.vim
index 663a6a8e0..227536d54 100644
--- a/src/testdir/test_popup.vim
+++ b/src/testdir/test_popup.vim
@@ -896,4 +896,50 @@ func Test_menu_only_exists_in_terminal()
endtry
endfunc
+func Test_popup_complete_mode()
+ new
+ inoremap <buffer><f5> <c-r>=complete_mode()<cr>
+ call writefile([
+ \ 'dummy dummy.txt 1',
+ \], 'Xdummy.txt')
+ setlocal tags=Xdummy.txt
+ setlocal dictionary=Xdummy.txt
+ setlocal thesaurus=Xdummy.txt
+ setlocal omnifunc=syntaxcomplete#Complete
+ setlocal completefunc=syntaxcomplete#Complete
+ setlocal spell
+ for [key, expected] in [
+ \ ["", ''],
+ \ ["\<C-X>", 'ctrl_x'],
+ \ ["\<C-X>\<C-N>", 'keyword'],
+ \ ["\<C-X>\<C-P>", 'keyword'],
+ \ ["\<C-X>\<C-L>", 'whole_line'],
+ \ ["\<C-X>\<C-F>", 'files'],
+ \ ["\<C-X>\<C-]>", 'tags'],
+ \ ["\<C-X>\<C-D>", 'path_defines'],
+ \ ["\<C-X>\<C-I>", 'path_patterns'],
+ \ ["\<C-X>\<C-K>", 'dictionary'],
+ \ ["\<C-X>\<C-T>", 'thesaurus'],
+ \ ["\<C-X>\<C-V>", 'cmdline'],
+ \ ["\<C-X>\<C-U>", 'function'],
+ \ ["\<C-X>\<C-O>", 'omni'],
+ \ ["\<C-X>s", 'spell'],
+ \]
+ call feedkeys("i" . key . "\<f5>\<ESC>", 'tx')
+ call assert_equal(expected, getline('.'))
+ %d
+ endfor
+ call delete('Xdummy.txt')
+
+ func s:complTestEval() abort
+ call complete(1, ['source', 'soundfold'])
+ return ''
+ endfunc
+ inoremap <buffer><f6> <c-r>=s:complTestEval()<CR>
+ call feedkeys("i\<f6>\<f5>\<ESC>", 'tx')
+ call assert_equal('eval', getline('.'))
+
+ bwipe!
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab