test40 test41 test42 test43 test44 test45 test48 test49 \
test50 test51 test52 test53 test54 test55 test56 test57 test58 test59 \
test60 test64 test65 test66 test67 test68 test69 \
- test70 test72 test73 test74 test75 test76 test77 test78 test79 \
+ test70 test72 test73 test74 test75 test77 test78 test79 \
test80 test82 test83 test84 test85 test86 test87 test88 test89 \
test90 test91 test92 test93 test94 test95 test97 test98 test99 \
test100 test101 test103 test104 test107 test108:
#endif
static int ins_compl_get_exp(pos_T *ini);
static void ins_compl_delete(void);
-static void ins_compl_insert(void);
-static int ins_compl_next(int allow_get_expansion, int count, int insert_match);
+static void ins_compl_insert(int in_compl_func);
+static int ins_compl_next(int allow_get_expansion, int count, int insert_match, int in_compl_func);
static int ins_compl_key2dir(int c);
static int ins_compl_pum_key(int c);
static int ins_compl_key2count(int c);
&& (c == CAR || c == K_KENTER || c == NL)))
{
ins_compl_delete();
- ins_compl_insert();
+ ins_compl_insert(FALSE);
}
}
}
break;
}
line_breakcheck();
- ins_compl_check_keys(50);
+ ins_compl_check_keys(50, FALSE);
}
fclose(fp);
}
}
#ifdef FEAT_COMPL_FUNC
-static void expand_by_function(int type, char_u *base);
-
/*
* Execute user defined complete function 'completefunc' or 'omnifunc', and
* get matches in "matches".
break;
/* Fill the popup menu as soon as possible. */
if (type != -1)
- ins_compl_check_keys(0);
+ ins_compl_check_keys(0, FALSE);
if ((ctrl_x_mode != 0 && !CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
|| compl_interrupted)
set_vim_var_dict(VV_COMPLETED_ITEM, dict_alloc());
}
-/* Insert the new text being completed. */
+/*
+ * Insert the new text being completed.
+ * "in_compl_func" is TRUE when called from complete_check().
+ */
static void
-ins_compl_insert(void)
+ins_compl_insert(int in_compl_func)
{
dict_T *dict;
EMPTY_IF_NULL(compl_shown_match->cp_text[CPT_INFO]));
}
set_vim_var_dict(VV_COMPLETED_ITEM, dict);
- compl_curr_match = compl_shown_match;
+ if (!in_compl_func)
+ compl_curr_match = compl_shown_match;
}
/*
int allow_get_expansion,
int count, /* repeat completion this many times; should
be at least 1 */
- int insert_match) /* Insert the newly selected match */
+ int insert_match, /* Insert the newly selected match */
+ int in_compl_func) /* called from complete_check() */
{
int num_matches = -1;
int i;
else if (insert_match)
{
if (!compl_get_longest || compl_used_match)
- ins_compl_insert();
+ ins_compl_insert(in_compl_func);
else
ins_bytes(compl_leader + ins_compl_len());
}
* mode. Also, when compl_pending is not zero, show a completion as soon as
* possible. -- webb
* "frequency" specifies out of how many calls we actually check.
+ * "in_compl_func" is TRUE when called from complete_check(), don't set
+ * compl_curr_match.
*/
void
-ins_compl_check_keys(int frequency)
+ins_compl_check_keys(int frequency, int in_compl_func)
{
static int count = 0;
c = safe_vgetc(); /* Eat the character */
compl_shows_dir = ins_compl_key2dir(c);
(void)ins_compl_next(FALSE, ins_compl_key2count(c),
- c != K_UP && c != K_DOWN);
+ c != K_UP && c != K_DOWN, in_compl_func);
}
else
{
int todo = compl_pending > 0 ? compl_pending : -compl_pending;
compl_pending = 0;
- (void)ins_compl_next(FALSE, todo, TRUE);
+ (void)ins_compl_next(FALSE, todo, TRUE, in_compl_func);
}
}
* Find next match (and following matches).
*/
save_w_wrow = curwin->w_wrow;
- n = ins_compl_next(TRUE, ins_compl_key2count(c), ins_compl_use_match(c));
+ n = ins_compl_next(TRUE, ins_compl_key2count(c),
+ ins_compl_use_match(c), FALSE);
/* may undisplay the popup menu */
ins_compl_upd_pum();
int saved = RedrawingDisabled;
RedrawingDisabled = 0;
- ins_compl_check_keys(0);
+ ins_compl_check_keys(0, TRUE);
rettv->vval.v_number = compl_interrupted;
RedrawingDisabled = saved;
}
char_u *find_word_end(char_u *ptr);
int ins_compl_active(void);
int ins_compl_add_tv(typval_T *tv, int dir);
-void ins_compl_check_keys(int frequency);
+void ins_compl_check_keys(int frequency, int in_compl_func);
int get_literal(void);
void insertchar(int c, int flags, int second_indent);
void auto_format(int trailblank, int prev_line);
line_breakcheck();
#ifdef FEAT_INS_EXPAND
if (action == ACTION_EXPAND)
- ins_compl_check_keys(30);
+ ins_compl_check_keys(30, FALSE);
if (got_int || compl_interrupted)
#else
if (got_int)
/* Done all bytes at this node, go up one level. */
--depth;
line_breakcheck();
- ins_compl_check_keys(50);
+ ins_compl_check_keys(50, FALSE);
}
else
{
fast_breakcheck();
#ifdef FEAT_INS_EXPAND
if ((flags & TAG_INS_COMP)) /* Double brackets for gcc */
- ins_compl_check_keys(30);
+ ins_compl_check_keys(30, FALSE);
if (got_int || compl_interrupted)
#else
if (got_int)
test70.out \
test73.out \
test75.out \
- test76.out \
test77.out \
test79.out \
test80.out \
+++ /dev/null
-Tests for completefunc/omnifunc. vim: set ft=vim :
-
-STARTTEST
-:"Test that nothing happens if the 'completefunc' opens
-:"a new window (no completion, no crash)
-:so small.vim
-:function! DummyCompleteOne(findstart, base)
-: if a:findstart
-: return 0
-: else
-: wincmd n
-: return ['onedef', 'oneDEF']
-: endif
-:endfunction
-:setlocal completefunc=DummyCompleteOne
-/^one
-A\18\15\ e\e:q!
-:function! DummyCompleteTwo(findstart, base)
-: if a:findstart
-: wincmd n
-: return 0
-: else
-: return ['twodef', 'twoDEF']
-: endif
-:endfunction
-:setlocal completefunc=DummyCompleteTwo
-/^two
-A\18\15\ e\e:q!
-:"Test that 'completefunc' works when it's OK.
-:function! DummyCompleteThree(findstart, base)
-: if a:findstart
-: return 0
-: else
-: return ['threedef', 'threeDEF']
-: endif
-:endfunction
-:setlocal completefunc=DummyCompleteThree
-/^three
-A\18\15\ e\e:/^+++/,/^three/w! test.out
-:qa!
-ENDTEST
-
-+++
-one
-two
-three
+++ /dev/null
-+++
-
-two
-threeDEF
bwipe!
endfunc
+func DummyCompleteOne(findstart, base)
+ if a:findstart
+ return 0
+ else
+ wincmd n
+ return ['onedef', 'oneDEF']
+ endif
+endfunc
+
+" Test that nothing happens if the 'completefunc' opens
+" a new window (no completion, no crash)
+func Test_completefunc_opens_new_window_one()
+ new
+ let winid = win_getid()
+ setlocal completefunc=DummyCompleteOne
+ call setline(1, 'one')
+ /^one
+ call assert_fails('call feedkeys("A\<C-X>\<C-U>\<C-N>\<Esc>", "x")', 'E839:')
+ call assert_notequal(winid, win_getid())
+ q!
+ call assert_equal(winid, win_getid())
+ call assert_equal('', getline(1))
+ q!
+endfunc
+
+" Test that nothing happens if the 'completefunc' opens
+" a new window (no completion, no crash)
+func DummyCompleteTwo(findstart, base)
+ if a:findstart
+ wincmd n
+ return 0
+ else
+ return ['twodef', 'twoDEF']
+ endif
+endfunction
+
+" Test that nothing happens if the 'completefunc' opens
+" a new window (no completion, no crash)
+func Test_completefunc_opens_new_window_two()
+ new
+ let winid = win_getid()
+ setlocal completefunc=DummyCompleteTwo
+ call setline(1, 'two')
+ /^two
+ call assert_fails('call feedkeys("A\<C-X>\<C-U>\<C-N>\<Esc>", "x")', 'E764:')
+ call assert_notequal(winid, win_getid())
+ q!
+ call assert_equal(winid, win_getid())
+ call assert_equal('two', getline(1))
+ q!
+endfunc
+
+func DummyCompleteThree(findstart, base)
+ if a:findstart
+ return 0
+ else
+ return ['threedef', 'threeDEF']
+ endif
+endfunc
+
+:"Test that 'completefunc' works when it's OK.
+func Test_completefunc_works()
+ new
+ let winid = win_getid()
+ setlocal completefunc=DummyCompleteThree
+ call setline(1, 'three')
+ /^three
+ call feedkeys("A\<C-X>\<C-U>\<C-N>\<Esc>", "x")
+ call assert_equal(winid, win_getid())
+ call assert_equal('threeDEF', getline(1))
+ q!
+endfunc
+
+func DummyCompleteFour(findstart, base)
+ if a:findstart
+ return 0
+ else
+ call complete_add('four1')
+ call complete_add('four2')
+ call complete_check()
+ call complete_add('four3')
+ call complete_add('four4')
+ call complete_check()
+ call complete_add('four5')
+ call complete_add('four6')
+ return []
+ endif
+endfunc
+
+:"Test that 'completefunc' works when it's OK.
+func Test_omnifunc_with_check()
+ new
+ setlocal omnifunc=DummyCompleteFour
+ call setline(1, 'four')
+ /^four
+ call feedkeys("A\<C-X>\<C-O>\<C-N>\<Esc>", "x")
+ call assert_equal('four2', getline(1))
+
+ call setline(1, 'four')
+ /^four
+ call feedkeys("A\<C-X>\<C-O>\<C-N>\<C-N>\<Esc>", "x")
+ call assert_equal('four3', getline(1))
+
+ call setline(1, 'four')
+ /^four
+ call feedkeys("A\<C-X>\<C-O>\<C-N>\<C-N>\<C-N>\<C-N>\<Esc>", "x")
+ call assert_equal('four5', getline(1))
+
+ q!
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 35,
/**/
34,
/**/