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

Appearance settings

Commit 9071793

Browse filesBrowse files
committed
Allow using internal popupmenu or ext_popupmenu for wildmenu
Deprecate ext_wildmenu. ext_popupmenu already contains more state (anchor position), and will allow further expansion (info about items).
1 parent 175398f commit 9071793
Copy full SHA for 9071793
Expand file treeCollapse file tree

19 files changed

+551
-68
lines changed

‎runtime/doc/options.txt

Copy file name to clipboardExpand all lines: runtime/doc/options.txt
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6605,6 +6605,8 @@ A jump table for the options with a short description can be found at |Q_op|.
66056605
is displayed per line. Often used tag kinds are:
66066606
d #define
66076607
f function
6608+
pum Display the completion matches using the popupmenu
6609+
in the same style as the |ins-completion-menu|.
66086610
Also see |cmdline-completion|.
66096611

66106612
*'winaltkeys'* *'wak'*

‎runtime/doc/ui.txt

Copy file name to clipboardExpand all lines: runtime/doc/ui.txt
+14-4Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ a dictionary with these (optional) keys:
3131
`ext_popupmenu` Externalize the popupmenu. |ui-popupmenu|
3232
`ext_tabline` Externalize the tabline. |ui-tabline|
3333
`ext_cmdline` Externalize the cmdline. |ui-cmdline|
34-
`ext_wildmenu` Externalize the wildmenu. |ui-wildmenu|
34+
`ext_wildmenu` Externalize the wildmenu (deprecated). |ui-wildmenu|
3535
`ext_messages` Externalize messages. |ui-messages|
3636
`ext_linegrid` Use new revision of the grid events. |ui-linegrid|
3737
`ext_multigrid` Use per-window grid based events. |ui-multigrid|
@@ -554,7 +554,7 @@ See |nvim_input_mouse| for sending mouse events to Nvim.
554554
==============================================================================
555555
Popupmenu Events *ui-popupmenu*
556556

557-
Only sent if `ext_popupmenu` option is set in |ui-options|
557+
Only sent if `ext_popupmenu` option is set in |ui-options|.
558558

559559
["popupmenu_show", items, selected, row, col, grid]
560560
Show |popupmenu-completion|. `items` is an array of completion items
@@ -564,7 +564,9 @@ Only sent if `ext_popupmenu` option is set in |ui-options|
564564
index into the array of items (-1 if no item is selected). `row` and
565565
`col` give the anchor position, where the first character of the
566566
completed word will be. When |ui-multigrid| is used, `grid` is the
567-
grid for the anchor position.
567+
grid for the anchor position. When `ext_cmdline` is active, `grid` is
568+
set to -1 to indicate the popupmenu should be anchored to the external
569+
cmdline. Then `col` will be a byte position in the cmdline text.
568570

569571
["popupmenu_select", selected]
570572
Select an item in the current popupmenu. `selected` is a zero-based
@@ -588,7 +590,10 @@ Only sent if `ext_tabline` option is set in |ui-options|
588590
==============================================================================
589591
Cmdline Events *ui-cmdline*
590592

591-
Only sent if `ext_cmdline` option is set in |ui-options|.
593+
Only sent if `ext_cmdline` option is set in |ui-options|. To handle
594+
command-line completion (wildmenu), use |ui-popupmenu| events activated by
595+
|ext_popupmenu| option. (The `ext_wildmenu` option only exists for backwards
596+
compatibility).
592597

593598
["cmdline_show", content, pos, firstc, prompt, indent, level]
594599
content: List of [attrs, string]
@@ -648,6 +653,11 @@ Wildmenu Events *ui-wildmenu*
648653

649654
Only sent if `ext_wildmenu` option is set in |ui-options|
650655

656+
Deprecated. When `ext_cmdline` and `ext_popupmenu` are both set,
657+
|ui-popupmenu| events will be used for command-line completion. But if
658+
`ext_wildmenu` is also set, these events are still used for backwards
659+
compatibility. New clients should use `ext_popupmenu` instead.
660+
651661
["wildmenu_show", items]
652662
Activate the wildmenu (command-line completion). `items` is an array
653663
with the completion items.

‎runtime/doc/vim_diff.txt

Copy file name to clipboardExpand all lines: runtime/doc/vim_diff.txt
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ Options:
195195
'scrollback'
196196
'statusline' supports unlimited alignment sections
197197
'tabline' %@Func@foo%X can call any function on mouse-click
198+
'wildoptions' `pum` flag to use popupmenu for wildmode completion
198199
'winhighlight' window-local highlights
199200

200201
Variables:

‎src/nvim/api/ui.c

Copy file name to clipboardExpand all lines: src/nvim/api/ui.c
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ typedef struct {
3434

3535
// Position of legacy cursor, used both for drawing and visible user cursor.
3636
Integer client_row, client_col;
37+
bool wildmenu_active;
3738
} UIData;
3839

3940
static PMap(uint64_t) *connected_uis = NULL;
@@ -146,6 +147,7 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height,
146147
data->buffer = (Array)ARRAY_DICT_INIT;
147148
data->hl_id = 0;
148149
data->client_col = -1;
150+
data->wildmenu_active = false;
149151
ui->data = data;
150152

151153
pmap_put(uint64_t)(connected_uis, channel_id, ui);
@@ -586,6 +588,7 @@ static Array translate_firstarg(UI *ui, Array args)
586588

587589
static void remote_ui_event(UI *ui, char *name, Array args, bool *args_consumed)
588590
{
591+
UIData *data = ui->data;
589592
if (!ui->ui_ext[kUILinegrid]) {
590593
// the representation of highlights in cmdline changed, translate back
591594
// never consumes args
@@ -611,6 +614,38 @@ static void remote_ui_event(UI *ui, char *name, Array args, bool *args_consumed)
611614
}
612615
}
613616

617+
if (ui->ui_ext[kUIWildmenu]) {
618+
if (strequal(name, "popupmenu_show")) {
619+
data->wildmenu_active = (args.items[4].data.integer == -1)
620+
|| !ui->ui_ext[kUIPopupmenu];
621+
if (data->wildmenu_active) {
622+
Array new_args = ARRAY_DICT_INIT;
623+
Array items = args.items[0].data.array;
624+
Array new_items = ARRAY_DICT_INIT;
625+
for (size_t i = 0; i < items.size; i++) {
626+
ADD(new_items, copy_object(items.items[i].data.array.items[0]));
627+
}
628+
ADD(new_args, ARRAY_OBJ(new_items));
629+
push_call(ui, "wildmenu_show", new_args);
630+
if (args.items[1].data.integer != -1) {
631+
Array new_args2 = ARRAY_DICT_INIT;
632+
ADD(new_args2, args.items[1]);
633+
push_call(ui, "wildmenu_select", new_args);
634+
}
635+
return;
636+
}
637+
} else if (strequal(name, "popupmenu_select")) {
638+
if (data->wildmenu_active) {
639+
name = "wildmenu_select";
640+
}
641+
} else if (strequal(name, "popupmenu_hide")) {
642+
if (data->wildmenu_active) {
643+
name = "wildmenu_hide";
644+
}
645+
}
646+
}
647+
648+
614649
Array my_args = ARRAY_DICT_INIT;
615650
// Objects are currently single-reference
616651
// make a copy, but only if necessary

‎src/nvim/api/ui_events.in.h

Copy file name to clipboardExpand all lines: src/nvim/api/ui_events.in.h
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ void cmdline_block_hide(void)
143143
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
144144

145145
void wildmenu_show(Array items)
146-
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
146+
FUNC_API_SINCE(3) FUNC_API_REMOTE_IMPL FUNC_API_BRIDGE_IMPL;
147147
void wildmenu_select(Integer selected)
148-
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
148+
FUNC_API_SINCE(3) FUNC_API_REMOTE_IMPL FUNC_API_BRIDGE_IMPL;
149149
void wildmenu_hide(void)
150-
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
150+
FUNC_API_SINCE(3) FUNC_API_REMOTE_IMPL FUNC_API_BRIDGE_IMPL;
151151

152152
void msg_show(String kind, Array content, Boolean replace_last)
153153
FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY;

‎src/nvim/edit.c

Copy file name to clipboardExpand all lines: src/nvim/edit.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2656,7 +2656,7 @@ void ins_compl_show_pum(void)
26562656
col = curwin->w_cursor.col;
26572657
curwin->w_cursor.col = compl_col;
26582658
pum_selected_item = cur;
2659-
pum_display(compl_match_array, compl_match_arraysize, cur, array_changed);
2659+
pum_display(compl_match_array, compl_match_arraysize, cur, array_changed, 0);
26602660
curwin->w_cursor.col = col;
26612661

26622662
if (!has_event(EVENT_MENUPOPUPCHANGED)) {

‎src/nvim/ex_docmd.c

Copy file name to clipboardExpand all lines: src/nvim/ex_docmd.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3235,7 +3235,7 @@ const char * set_one_cmd_context(
32353235
case CMD_tjump:
32363236
case CMD_stjump:
32373237
case CMD_ptjump:
3238-
if (*p_wop != NUL) {
3238+
if (wop_flags & WOP_TAGFILE) {
32393239
xp->xp_context = EXPAND_TAGS_LISTFILES;
32403240
} else {
32413241
xp->xp_context = EXPAND_TAGS;

‎src/nvim/ex_getln.c

Copy file name to clipboardExpand all lines: src/nvim/ex_getln.c
+52-13Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,15 @@ static int hislen = 0; /* actual length of history tables */
214214
/// user interrupting highlight function to not interrupt command-line.
215215
static bool getln_interrupted_highlight = false;
216216

217+
// "compl_match_array" points the currently displayed list of entries in the
218+
// popup menu. It is NULL when there is no popup menu.
219+
static pumitem_T *compl_match_array = NULL;
220+
static int compl_match_arraysize;
221+
// First column in cmdline of the matched item for completion.
222+
static int compl_startcol;
223+
static int compl_selected;
224+
225+
217226

218227
#ifdef INCLUDE_GENERATED_DECLARATIONS
219228
# include "ex_getln.c.generated.h"
@@ -600,6 +609,13 @@ static int command_line_execute(VimState *state, int key)
600609
} else if (s->c == K_RIGHT) {
601610
s->c = Ctrl_N;
602611
}
612+
if (compl_match_array) {
613+
if (s->c == K_UP) {
614+
s->c = Ctrl_P;
615+
} else if (s->c == K_DOWN) {
616+
s->c = Ctrl_N;
617+
}
618+
}
603619
}
604620

605621
// Hitting CR after "emenu Name.": complete submenu
@@ -615,8 +631,10 @@ static int command_line_execute(VimState *state, int key)
615631
if (!(s->c == p_wc && KeyTyped) && s->c != p_wcm
616632
&& s->c != Ctrl_N && s->c != Ctrl_P && s->c != Ctrl_A
617633
&& s->c != Ctrl_L) {
618-
if (ui_has(kUIWildmenu)) {
619-
ui_call_wildmenu_hide();
634+
if (compl_match_array) {
635+
pum_undisplay(true);
636+
xfree(compl_match_array);
637+
compl_match_array = NULL;
620638
}
621639
if (s->xpc.xp_numfiles != -1) {
622640
(void)ExpandOne(&s->xpc, NULL, NULL, 0, WILD_FREE);
@@ -3746,13 +3764,12 @@ ExpandOne (
37463764
else
37473765
findex = -1;
37483766
}
3749-
if (p_wmnu) {
3750-
if (ui_has(kUIWildmenu)) {
3751-
ui_call_wildmenu_select(findex);
3752-
} else {
3753-
win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files,
3754-
findex, cmd_showtail);
3755-
}
3767+
if (compl_match_array) {
3768+
compl_selected = findex;
3769+
cmdline_pum_display(false);
3770+
} else if (p_wmnu) {
3771+
win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files,
3772+
findex, cmd_showtail);
37563773
}
37573774
if (findex == -1) {
37583775
return vim_strsave(orig_save);
@@ -4069,6 +4086,12 @@ void tilde_replace(char_u *orig_pat, int num_files, char_u **files)
40694086
}
40704087
}
40714088

4089+
void cmdline_pum_display(bool changed_array)
4090+
{
4091+
pum_display(compl_match_array, compl_match_arraysize, compl_selected,
4092+
changed_array, compl_startcol);
4093+
}
4094+
40724095
/*
40734096
* Show all matches for completion on the command line.
40744097
* Returns EXPAND_NOTHING when the character that triggered expansion should
@@ -4102,12 +4125,28 @@ static int showmatches(expand_T *xp, int wildmenu)
41024125
showtail = cmd_showtail;
41034126
}
41044127

4105-
if (ui_has(kUIWildmenu)) {
4106-
Array args = ARRAY_DICT_INIT;
4128+
bool compl_use_pum = (ui_has(kUICmdline)
4129+
? ui_has(kUIPopupmenu)
4130+
: wildmenu && (wop_flags & WOP_PUM))
4131+
|| ui_has(kUIWildmenu);
4132+
4133+
if (compl_use_pum) {
4134+
compl_match_arraysize = num_files;
4135+
compl_match_array = xcalloc(compl_match_arraysize, sizeof(pumitem_T));
41074136
for (i = 0; i < num_files; i++) {
4108-
ADD(args, STRING_OBJ(cstr_to_string((char *)files_found[i])));
4137+
compl_match_array[i].pum_text = L_SHOWFILE(i);
4138+
}
4139+
ssize_t offset = showtail ? sm_gettail(xp->xp_pattern)-xp->xp_pattern : 0;
4140+
if (ui_has(kUICmdline)) {
4141+
compl_startcol = ccline.cmdpos - strnlen((char *)xp->xp_pattern+offset,
4142+
xp->xp_pattern_len-offset);
4143+
} else {
4144+
compl_startcol = ccline.cmdspos
4145+
- mb_string2cells_len(xp->xp_pattern+offset,
4146+
xp->xp_pattern_len-offset);
41094147
}
4110-
ui_call_wildmenu_show(args);
4148+
compl_selected = -1;
4149+
cmdline_pum_display(true);
41114150
return EXPAND_OK;
41124151
}
41134152

‎src/nvim/mbyte.c

Copy file name to clipboardExpand all lines: src/nvim/mbyte.c
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,24 @@ size_t mb_string2cells(const char_u *str)
555555
return clen;
556556
}
557557

558+
/// Get the number of cells occupied by string `str` with maximum length `size`
559+
///
560+
/// @param str The source string, may not be NULL, must be a NUL-terminated
561+
/// string.
562+
/// @param size maximum length of string. It will terminate on earlier NUL.
563+
/// @return The number of cells occupied by string `str`
564+
size_t mb_string2cells_len(const char_u *str, size_t size)
565+
{
566+
size_t clen = 0;
567+
568+
for (const char_u *p = str; *p != NUL && p < str+size;
569+
p += (*utf_ptr2len_len)(p, size+(p-str))) {
570+
clen += utf_ptr2cells(p);
571+
}
572+
573+
return clen;
574+
}
575+
558576
/// Convert a UTF-8 byte sequence to a wide character
559577
///
560578
/// If the sequence is illegal or truncated by a NUL then the first byte is

‎src/nvim/option.c

Copy file name to clipboardExpand all lines: src/nvim/option.c
+4-5Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ static char *(p_ambw_values[]) = { "single", "double", NULL };
284284
static char *(p_bg_values[]) = { "light", "dark", NULL };
285285
static char *(p_nf_values[]) = { "bin", "octal", "hex", "alpha", NULL };
286286
static char *(p_ff_values[]) = { FF_UNIX, FF_DOS, FF_MAC, NULL };
287-
static char *(p_wop_values[]) = { "tagfile", NULL };
288287
static char *(p_wak_values[]) = { "yes", "menu", "no", NULL };
289288
static char *(p_mousem_values[]) = { "extend", "popup", "popup_setpos",
290289
"mac", NULL };
@@ -2608,11 +2607,11 @@ did_set_string_option (
26082607
else if (varp == &p_wim) {
26092608
if (check_opt_wim() == FAIL)
26102609
errmsg = e_invarg;
2611-
}
2612-
/* 'wildoptions' */
2613-
else if (varp == &p_wop) {
2614-
if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
2610+
// 'wildoptions'
2611+
} else if (varp == &p_wop) {
2612+
if (opt_strings_flags(p_wop, p_wop_values, &wop_flags, true) != OK) {
26152613
errmsg = e_invarg;
2614+
}
26162615
}
26172616
/* 'winaltkeys' */
26182617
else if (varp == &p_wak) {

‎src/nvim/option_defs.h

Copy file name to clipboardExpand all lines: src/nvim/option_defs.h
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,12 @@ extern char_u *p_vfile; /* 'verbosefile' */
659659
#endif
660660
EXTERN int p_warn; // 'warn'
661661
EXTERN char_u *p_wop; // 'wildoptions'
662+
EXTERN unsigned wop_flags;
663+
# ifdef IN_OPTION_C
664+
static char *(p_wop_values[]) = { "tagfile", "pum", NULL };
665+
#endif
666+
#define WOP_TAGFILE 0x01
667+
#define WOP_PUM 0x02
662668
EXTERN long p_window; // 'window'
663669
EXTERN char_u *p_wak; // 'winaltkeys'
664670
EXTERN char_u *p_wig; // 'wildignore'

‎src/nvim/options.lua

Copy file name to clipboardExpand all lines: src/nvim/options.lua
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2699,7 +2699,7 @@ return {
26992699
},
27002700
{
27012701
full_name='wildoptions', abbreviation='wop',
2702-
type='string', scope={'global'},
2702+
type='string', list='onecomma', scope={'global'},
27032703
vi_def=true,
27042704
varname='p_wop',
27052705
defaults={if_true={vi=""}}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.