Skip to content

Commit e90858d

Browse files
committed
patch 8.0.0283: mode() does not indicate Insert mode completion
Problem: The return value of mode() does not indicate that completion is active in Replace and Insert mode. (Zhen-Huan (Kenny) Hu) Solution: Add "c" or "x" for two kinds of completion. (Yegappan Lakshmanan, closes #1397) Test some more modes.
1 parent 0b5c93a commit e90858d

5 files changed

Lines changed: 111 additions & 13 deletions

File tree

runtime/doc/eval.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5848,9 +5848,13 @@ mode([expr]) Return a string that indicates the current mode.
58485848
S Select by line
58495849
CTRL-S Select blockwise
58505850
i Insert
5851+
ic Insert mode completion |compl-generic|
5852+
ix Insert mode |i_CTRL-X| completion
58515853
R Replace |R|
5854+
Rc Replace mode completion |compl-generic|
58525855
Rv Virtual Replace |gR|
5853-
c Command-line
5856+
Rx Replace mode |i_CTRL-X| completion
5857+
c Command-line editing
58545858
cv Vim Ex mode |gQ|
58555859
ce Normal Ex mode |Q|
58565860
r Hit-enter prompt

src/evalfunc.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7783,21 +7783,26 @@ f_mode(typval_T *argvars, typval_T *rettv)
77837783
}
77847784
else
77857785
#endif
7786-
if (State & REPLACE_FLAG)
7787-
buf[0] = 'R';
7788-
else
7789-
buf[0] = 'i';
7786+
{
7787+
if (State & REPLACE_FLAG)
7788+
buf[0] = 'R';
7789+
else
7790+
buf[0] = 'i';
7791+
#ifdef FEAT_INS_EXPAND
7792+
if (ins_compl_active())
7793+
buf[1] = 'c';
7794+
else if (ctrl_x_mode == 1)
7795+
buf[1] = 'x';
7796+
#endif
7797+
}
77907798
}
7791-
else if (State & CMDLINE)
7799+
else if ((State & CMDLINE) || exmode_active)
77927800
{
77937801
buf[0] = 'c';
7794-
if (exmode_active)
7802+
if (exmode_active == EXMODE_VIM)
77957803
buf[1] = 'v';
7796-
}
7797-
else if (exmode_active)
7798-
{
7799-
buf[0] = 'c';
7800-
buf[1] = 'e';
7804+
else if (exmode_active == EXMODE_NORMAL)
7805+
buf[1] = 'e';
78017806
}
78027807
else
78037808
{

src/testdir/test_functions.vim

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,4 +304,89 @@ func Test_toupper()
304304
call assert_equal("Ⱥ Ⱦ", toupper("ⱥ ⱦ"))
305305
endfunc
306306

307+
" Tests for the mode() function
308+
let current_modes = ''
309+
func! Save_mode()
310+
let g:current_modes = mode(0) . '-' . mode(1)
311+
return ''
312+
endfunc
307313

314+
func! Test_mode()
315+
new
316+
call append(0, ["Blue Ball Black", "Brown Band Bowl", ""])
317+
318+
inoremap <F2> <C-R>=Save_mode()<CR>
319+
320+
normal! 3G
321+
exe "normal i\<F2>\<Esc>"
322+
call assert_equal('i-i', g:current_modes)
323+
exe "normal i\<C-G>uBa\<C-P>\<F2>\<Esc>u"
324+
call assert_equal('i-ic', g:current_modes)
325+
exe "normal iBro\<C-P>\<F2>\<Esc>u"
326+
call assert_equal('i-ic', g:current_modes)
327+
exe "normal iBa\<C-X>\<F2>\<Esc>u"
328+
call assert_equal('i-ix', g:current_modes)
329+
exe "normal iBa\<C-X>\<C-P>\<F2>\<Esc>u"
330+
call assert_equal('i-ic', g:current_modes)
331+
exe "normal iBro\<C-X>\<C-P>\<F2>\<Esc>u"
332+
call assert_equal('i-ic', g:current_modes)
333+
exe "normal iBro\<C-X>\<C-P>\<C-P>\<F2>\<Esc>u"
334+
call assert_equal('i-ic', g:current_modes)
335+
exe "normal iCom\<C-P>\<F2>\<Esc>u"
336+
call assert_equal('i-ic', g:current_modes)
337+
exe "normal iCom\<C-X>\<C-P>\<F2>\<Esc>u"
338+
call assert_equal('i-ic', g:current_modes)
339+
340+
exe "normal RBa\<C-P>\<F2>\<Esc>u"
341+
call assert_equal('R-Rc', g:current_modes)
342+
exe "normal RBro\<C-P>\<F2>\<Esc>u"
343+
call assert_equal('R-Rc', g:current_modes)
344+
exe "normal RBa\<C-X>\<F2>\<Esc>u"
345+
call assert_equal('R-Rx', g:current_modes)
346+
exe "normal RBa\<C-X>\<C-P>\<F2>\<Esc>u"
347+
call assert_equal('R-Rc', g:current_modes)
348+
exe "normal RBro\<C-X>\<C-P>\<F2>\<Esc>u"
349+
call assert_equal('R-Rc', g:current_modes)
350+
exe "normal RBro\<C-X>\<C-P>\<C-P>\<F2>\<Esc>u"
351+
call assert_equal('R-Rc', g:current_modes)
352+
exe "normal RCom\<C-P>\<F2>\<Esc>u"
353+
call assert_equal('R-Rc', g:current_modes)
354+
exe "normal RCom\<C-X>\<C-P>\<F2>\<Esc>u"
355+
call assert_equal('R-Rc', g:current_modes)
356+
357+
call assert_equal('n', mode(0))
358+
call assert_equal('n', mode(1))
359+
360+
" How to test operator-pending mode?
361+
362+
call feedkeys("v", 'xt')
363+
call assert_equal('v', mode())
364+
call assert_equal('v', mode(1))
365+
call feedkeys("\<Esc>V", 'xt')
366+
call assert_equal('V', mode())
367+
call assert_equal('V', mode(1))
368+
call feedkeys("\<Esc>\<C-V>", 'xt')
369+
call assert_equal("\<C-V>", mode())
370+
call assert_equal("\<C-V>", mode(1))
371+
call feedkeys("\<Esc>", 'xt')
372+
373+
call feedkeys("gh", 'xt')
374+
call assert_equal('s', mode())
375+
call assert_equal('s', mode(1))
376+
call feedkeys("\<Esc>gH", 'xt')
377+
call assert_equal('S', mode())
378+
call assert_equal('S', mode(1))
379+
call feedkeys("\<Esc>g\<C-H>", 'xt')
380+
call assert_equal("\<C-S>", mode())
381+
call assert_equal("\<C-S>", mode(1))
382+
call feedkeys("\<Esc>", 'xt')
383+
384+
call feedkeys(":echo \<C-R>=Save_mode()\<C-U>\<CR>", 'xt')
385+
call assert_equal('c-c', g:current_modes)
386+
call feedkeys("gQecho \<C-R>=Save_mode()\<CR>\<CR>vi\<CR>", 'xt')
387+
call assert_equal('c-cv', g:current_modes)
388+
" How to test Ex mode?
389+
390+
bwipe!
391+
iunmap <F2>
392+
endfunc

src/testdir/test_mapping.vim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ func Test_map_langmap()
110110
call feedkeys(":call append(line('$'), '+')\<CR>", "xt")
111111
call assert_equal('+', getline('$'))
112112

113+
iunmap a
114+
iunmap c
113115
set nomodified
114116
endfunc
115117

@@ -120,7 +122,7 @@ func Test_map_feedkeys()
120122
$-1
121123
call feedkeys("0qqdw.ifoo\<Esc>qj0@q\<Esc>", "xt")
122124
call assert_equal(['fooc d', 'fooc d'], getline(line('$') - 1, line('$')))
123-
unmap .
125+
nunmap .
124126
set nomodified
125127
endfunc
126128

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
283,
767769
/**/
768770
282,
769771
/**/

0 commit comments

Comments
 (0)