Hi,
On Mon, Jan 23, 2017 at 9:02 AM, Zhen-Huan (Kenny) Hu
<[email protected]> wrote:
> else if (ins_compl_active())
>
> buf[1] = pum_visible() ? 'C' : 'c';
>
> Does this 'C' vs. 'c' mean whether a completion was successful? I don't
> think pum_visible() alone is able to determine this accurately since it
> depends on whether the user have completeopt=menuone to have a menu if there
> is only one match. I'd rather not distinguish it in mode() and let it return
> 'ic' if ins_compl_active() no matther whether pum_visible().
>
I am attaching a patch to the mode() function that returns 'ic' or 'ix'
or 'Rc' or 'Rx' depending on the insert completion mode. I have also
added a test for the mode() function.
The idea from Hirohito to add a separate function to get more
information about the insert mode completion can be addressed in a
separate patch.
- Yegappan
--
--
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 58a61f2..40e8a79 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -5848,8 +5848,12 @@ mode([expr]) Return a string that indicates the
current mode.
S Select by line
CTRL-S Select blockwise
i Insert
+ ic Insert mode completion |compl-generic|
+ ix Insert mode |i_CTRL-X| completion
R Replace |R|
+ Rc Replace mode completion |compl-generic|
Rv Virtual Replace |gR|
+ Rx Replace mode |i_CTRL-X| completion
c Command-line
cv Vim Ex mode |gQ|
ce Normal Ex mode |Q|
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 7f433a5..8f90fc1 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -7783,10 +7783,18 @@ f_mode(typval_T *argvars, typval_T *rettv)
}
else
#endif
- if (State & REPLACE_FLAG)
- buf[0] = 'R';
- else
- buf[0] = 'i';
+ {
+ if (State & REPLACE_FLAG)
+ buf[0] = 'R';
+ else
+ buf[0] = 'i';
+#ifdef FEAT_INS_EXPAND
+ if (ins_compl_active())
+ buf[1] = 'c';
+ else if (ctrl_x_mode == 1)
+ buf[1] = 'x';
+#endif
+ }
}
else if (State & CMDLINE)
{
diff --git a/src/testdir/test_functions.vim b/src/testdir/test_functions.vim
index 38f7723..e12bc6c 100644
--- a/src/testdir/test_functions.vim
+++ b/src/testdir/test_functions.vim
@@ -304,4 +304,42 @@ func Test_toupper()
call assert_equal("Ⱥ Ⱦ", toupper("ⱥ ⱦ"))
endfunc
+" Tests for the mode() function
+let saved_modes = ''
+func! Save_mode()
+ let g:saved_modes .= mode(1) . " "
+ return ''
+endfunc
+func! Test_mode()
+ new
+ call append(0, ["Blue Ball Black", "Brown Band Bowl", ""])
+
+ inoremap <F2> <C-R>=Save_mode()<CR>
+
+ normal! 3G
+ exe "normal i\<F2>\<Esc>"
+ exe "normal i\<C-G>uBa\<C-P>\<F2>\<Esc>u"
+ exe "normal iBro\<C-P>\<F2>\<Esc>u"
+ exe "normal iBa\<C-X>\<F2>\<Esc>u"
+ exe "normal iBa\<C-X>\<C-P>\<F2>\<Esc>u"
+ exe "normal iBro\<C-X>\<C-P>\<F2>\<Esc>u"
+ exe "normal iBro\<C-X>\<C-P>\<C-P>\<F2>\<Esc>u"
+ exe "normal iCom\<C-P>\<F2>\<Esc>u"
+ exe "normal iCom\<C-X>\<C-P>\<F2>\<Esc>u"
+
+ exe "normal RBa\<C-P>\<F2>\<Esc>u"
+ exe "normal RBro\<C-P>\<F2>\<Esc>u"
+ exe "normal RBa\<C-X>\<F2>\<Esc>u"
+ exe "normal RBa\<C-X>\<C-P>\<F2>\<Esc>u"
+ exe "normal RBro\<C-X>\<C-P>\<F2>\<Esc>u"
+ exe "normal RBro\<C-X>\<C-P>\<C-P>\<F2>\<Esc>u"
+ exe "normal RCom\<C-P>\<F2>\<Esc>u"
+ exe "normal RCom\<C-X>\<C-P>\<F2>\<Esc>u"
+
+ call assert_equal("i ic ic ix ic ic ic ic ic Rc Rc Rx Rc Rc Rc Rc Rc ",
+ \ g:saved_modes)
+
+ enew! | close
+ iunmap <F2>
+endfunc