Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ef5bf58

Browse files
girishjichrisbra
authored andcommitted
patch 9.1.1876: pre-inserted text not exposed in cmdcomplete_info()
Problem: pre-inserted text not exposed in complete_info() Solution: Add the pre-inserted text to the complete_info() Vim script function (Girish Palya) closes: #18571 Signed-off-by: Girish Palya <girishji@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org> Feat: expose preinserted text in complete_info() Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent f17f78c commit ef5bf58

File tree

6 files changed

+61
-21
lines changed

6 files changed

+61
-21
lines changed

‎runtime/doc/builtin.txt‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,10 +2001,8 @@ complete_info([{what}]) *complete_info()*
20012001
Returns a |Dictionary| with information about Insert mode
20022002
completion. See |ins-completion|.
20032003
The items are:
2004-
mode Current completion mode name string.
2005-
See |complete_info_mode| for the values.
2006-
pum_visible |TRUE| if popup menu is visible.
2007-
See |pumvisible()|.
2004+
completed Return a dictionary containing the entries of
2005+
the currently selected index item.
20082006
items List of all completion candidates. Each item
20092007
is a dictionary containing the entries "word",
20102008
"abbr", "menu", "kind", "info" and
@@ -2015,13 +2013,18 @@ complete_info([{what}]) *complete_info()*
20152013
and "items" are in "what", the returned list
20162014
will still be named "items", but each item
20172015
will have an additional "match" field.
2016+
mode Current completion mode name string.
2017+
See |complete_info_mode| for the values.
2018+
preinserted_text
2019+
The actual text that is pre-inserted, see
2020+
|preinserted()|.
2021+
pum_visible |TRUE| if popup menu is visible.
2022+
See |pumvisible()|.
20182023
selected Selected item index. First index is zero.
20192024
Index is -1 if no item is selected (showing
20202025
typed text only, or the last completion after
20212026
no item is selected when using the <Up> or
20222027
<Down> keys)
2023-
completed Return a dictionary containing the entries of
2024-
the currently selected index item.
20252028

20262029
*complete_info_mode*
20272030
mode values are:

‎src/insexpand.c‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4186,13 +4186,14 @@ get_complete_info(list_T *what_list, dict_T *retdict)
41864186
{
41874187
int ret = OK;
41884188
listitem_T *item;
4189-
#define CI_WHAT_MODE 0x01
4190-
#define CI_WHAT_PUM_VISIBLE 0x02
4191-
#define CI_WHAT_ITEMS 0x04
4192-
#define CI_WHAT_SELECTED 0x08
4193-
#define CI_WHAT_COMPLETED 0x10
4194-
#define CI_WHAT_MATCHES 0x20
4195-
#define CI_WHAT_ALL 0xff
4189+
#define CI_WHAT_MODE 0x01
4190+
#define CI_WHAT_PUM_VISIBLE 0x02
4191+
#define CI_WHAT_ITEMS 0x04
4192+
#define CI_WHAT_SELECTED 0x08
4193+
#define CI_WHAT_COMPLETED 0x10
4194+
#define CI_WHAT_MATCHES 0x20
4195+
#define CI_WHAT_PREINSERTED_TEXT 0x40
4196+
#define CI_WHAT_ALL 0xff
41964197
int what_flag;
41974198

41984199
if (what_list == NULL)
@@ -4215,6 +4216,8 @@ get_complete_info(list_T *what_list, dict_T *retdict)
42154216
what_flag |= CI_WHAT_SELECTED;
42164217
else if (STRCMP(what, "completed") == 0)
42174218
what_flag |= CI_WHAT_COMPLETED;
4219+
else if (STRCMP(what, "preinserted_text") == 0)
4220+
what_flag |= CI_WHAT_PREINSERTED_TEXT;
42184221
else if (STRCMP(what, "matches") == 0)
42194222
what_flag |= CI_WHAT_MATCHES;
42204223
}
@@ -4226,6 +4229,15 @@ get_complete_info(list_T *what_list, dict_T *retdict)
42264229
if (ret == OK && (what_flag & CI_WHAT_PUM_VISIBLE))
42274230
ret = dict_add_number(retdict, "pum_visible", pum_visible());
42284231

4232+
if (ret == OK && (what_flag & CI_WHAT_PREINSERTED_TEXT))
4233+
{
4234+
char_u *line = ml_get_curline();
4235+
int len = compl_ins_end_col - curwin->w_cursor.col;
4236+
4237+
ret = dict_add_string_len(retdict, "preinserted_text",
4238+
(len > 0) ? line + curwin->w_cursor.col : (char_u *)"", len);
4239+
}
4240+
42294241
if (ret == OK && (what_flag & (CI_WHAT_ITEMS | CI_WHAT_SELECTED
42304242
| CI_WHAT_MATCHES | CI_WHAT_COMPLETED)))
42314243
{

‎src/testdir/test_ins_complete.vim‎

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -572,15 +572,15 @@ func Test_completefunc_info()
572572
set completeopt=menuone
573573
set completefunc=CompleteTest
574574
call feedkeys("i\<C-X>\<C-U>\<C-R>\<C-R>=string(complete_info())\<CR>\<ESC>", "tx")
575-
call assert_equal("matched{'pum_visible': 1, 'mode': 'function', 'selected': 0, 'items': [{'word': 'matched', 'menu': '', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}]}", getline(1))
575+
call assert_equal("matched{'preinserted_text': '', 'pum_visible': 1, 'mode': 'function', 'selected': 0, 'items': [{'word': 'matched', 'menu': '', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}]}", getline(1))
576576
%d
577577
set complete=.,FCompleteTest
578578
call feedkeys("i\<C-N>\<C-R>\<C-R>=string(complete_info())\<CR>\<ESC>", "tx")
579-
call assert_equal("matched{'pum_visible': 1, 'mode': 'keyword', 'selected': 0, 'items': [{'word': 'matched', 'menu': '', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}]}", getline(1))
579+
call assert_equal("matched{'preinserted_text': '', 'pum_visible': 1, 'mode': 'keyword', 'selected': 0, 'items': [{'word': 'matched', 'menu': '', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}]}", getline(1))
580580
%d
581581
set complete=.,F
582582
call feedkeys("i\<C-N>\<C-R>\<C-R>=string(complete_info())\<CR>\<ESC>", "tx")
583-
call assert_equal("matched{'pum_visible': 1, 'mode': 'keyword', 'selected': 0, 'items': [{'word': 'matched', 'menu': '', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}]}", getline(1))
583+
call assert_equal("matched{'preinserted_text': '', 'pum_visible': 1, 'mode': 'keyword', 'selected': 0, 'items': [{'word': 'matched', 'menu': '', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}]}", getline(1))
584584
set completeopt&
585585
set complete&
586586
set completefunc&
@@ -698,17 +698,17 @@ func CompleteInfoTestUserDefinedFn(mvmt, idx, noselect)
698698
set completefunc=CompleteInfoUserDefinedFn
699699
call feedkeys("i\<C-X>\<C-U>" . a:mvmt . "\<C-R>\<C-R>=string(complete_info())\<CR>\<ESC>", "tx")
700700
let completed = a:idx != -1 ? ['foo', 'bar', 'baz', 'qux']->get(a:idx) : ''
701-
call assert_equal(completed. "{'pum_visible': 1, 'mode': 'function', 'selected': " . a:idx . ", 'items': " . items . "}", getline(1))
701+
call assert_equal(completed. "{'preinserted_text': '', 'pum_visible': 1, 'mode': 'function', 'selected': " . a:idx . ", 'items': " . items . "}", getline(1))
702702
%d
703703
set complete=.,FCompleteInfoUserDefinedFn
704704
call feedkeys("i\<C-N>" . a:mvmt . "\<C-R>\<C-R>=string(complete_info())\<CR>\<ESC>", "tx")
705705
let completed = a:idx != -1 ? ['foo', 'bar', 'baz', 'qux']->get(a:idx) : ''
706-
call assert_equal(completed. "{'pum_visible': 1, 'mode': 'keyword', 'selected': " . a:idx . ", 'items': " . items . "}", getline(1))
706+
call assert_equal(completed. "{'preinserted_text': '', 'pum_visible': 1, 'mode': 'keyword', 'selected': " . a:idx . ", 'items': " . items . "}", getline(1))
707707
%d
708708
set complete=.,F
709709
call feedkeys("i\<C-N>" . a:mvmt . "\<C-R>\<C-R>=string(complete_info())\<CR>\<ESC>", "tx")
710710
let completed = a:idx != -1 ? ['foo', 'bar', 'baz', 'qux']->get(a:idx) : ''
711-
call assert_equal(completed. "{'pum_visible': 1, 'mode': 'keyword', 'selected': " . a:idx . ", 'items': " . items . "}", getline(1))
711+
call assert_equal(completed. "{'preinserted_text': '', 'pum_visible': 1, 'mode': 'keyword', 'selected': " . a:idx . ", 'items': " . items . "}", getline(1))
712712
bwipe!
713713
set completeopt& completefunc& complete&
714714
endfunc
@@ -5904,6 +5904,26 @@ func Test_autocomplete_longest()
59045904
call DoTest("f", 'foobar', 2)
59055905
call assert_equal(1, g:preinserted)
59065906

5907+
" complete_info()
5908+
%delete
5909+
func GetPreinsert()
5910+
let g:cinfo = complete_info(['preinserted_text'])
5911+
return ""
5912+
endfunc
5913+
inoremap <buffer><F6> <C-R>=GetPreinsert()<CR>
5914+
call setline(1, ["foo_bar_xyz", "foo__xyz"])
5915+
5916+
set completeopt& completeopt+=preinsert
5917+
call feedkeys("G4li\<F6>\<C-Y>", 'tx')
5918+
call assert_equal("bar_xyz", g:cinfo.preinserted_text)
5919+
5920+
set completeopt& completeopt+=longest
5921+
call feedkeys("Gof\<F6>\<ESC>", 'tx')
5922+
call assert_equal("oo_bar_xyz", g:cinfo.preinserted_text)
5923+
unlet g:cinfo
5924+
delfunc GetPreinsert
5925+
set completeopt&
5926+
59075927
" Undo
59085928
%delete _
59095929
let &l:undolevels = &l:undolevels

‎src/testdir/test_popup.vim‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,21 +1163,23 @@ func Test_popup_complete_info_02()
11631163
\ {'word': 'Apr', 'menu': 'April', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''},
11641164
\ {'word': 'May', 'menu': 'May', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}
11651165
\ ],
1166+
\ 'preinserted_text': '',
11661167
\ 'selected': 0,
11671168
\ }
11681169

11691170
let g:compl_what = []
11701171
call feedkeys("i\<C-X>\<C-U>\<F5>", 'tx')
11711172
call assert_equal(d, g:compl_info)
11721173

1173-
let g:compl_what = ['mode', 'pum_visible', 'selected']
1174+
let g:compl_what = ['mode', 'pum_visible', 'preinserted_text', 'selected']
11741175
call remove(d, 'items')
11751176
call feedkeys("i\<C-X>\<C-U>\<F5>", 'tx')
11761177
call assert_equal(d, g:compl_info)
11771178

11781179
let g:compl_what = ['mode']
11791180
call remove(d, 'selected')
11801181
call remove(d, 'pum_visible')
1182+
call remove(d, 'preinserted_text')
11811183
call feedkeys("i\<C-X>\<C-U>\<F5>", 'tx')
11821184
call assert_equal(d, g:compl_info)
11831185
bwipe!
@@ -1191,6 +1193,7 @@ func Test_popup_complete_info_no_pum()
11911193
\ 'mode': '',
11921194
\ 'pum_visible': 0,
11931195
\ 'items': [],
1196+
\ 'preinserted_text': '',
11941197
\ 'selected': -1,
11951198
\ }
11961199
call assert_equal( d, complete_info() )

‎src/testdir/test_vim9_builtin.vim‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ enddef
819819
def Test_complete_info()
820820
v9.CheckSourceDefAndScriptFailure(['complete_info("")'], ['E1013: Argument 1: type mismatch, expected list<string> but got string', 'E1211: List required for argument 1'])
821821
v9.CheckSourceDefAndScriptFailure(['complete_info({})'], ['E1013: Argument 1: type mismatch, expected list<string> but got dict<any>', 'E1211: List required for argument 1'])
822-
assert_equal({'pum_visible': 0, 'mode': '', 'selected': -1, 'items': []}, complete_info())
822+
assert_equal({'pum_visible': 0, 'mode': '', 'preinserted_text': '', 'selected': -1, 'items': []}, complete_info())
823823
assert_equal({'mode': '', 'items': []}, complete_info(['mode', 'items']))
824824
enddef
825825

‎src/version.c‎

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

730730
static int included_patches[] =
731731
{ /* Add new patch number below this line */
732+
/**/
733+
1876,
732734
/**/
733735
1875,
734736
/**/

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /