mirror of
https://github.com/neovim/neovim.git
synced 2025-09-17 08:48:16 +00:00
ext_cmdline: extend "function" to generic "block" mechanism
This commit is contained in:
@@ -67,6 +67,7 @@ void popupmenu_select(Integer selected)
|
|||||||
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
||||||
void tabline_update(Tabpage current, Array tabs)
|
void tabline_update(Tabpage current, Array tabs)
|
||||||
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
||||||
|
|
||||||
void cmdline_show(Array content, Integer pos, String firstc, String prompt,
|
void cmdline_show(Array content, Integer pos, String firstc, String prompt,
|
||||||
Integer indent, Integer level)
|
Integer indent, Integer level)
|
||||||
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
||||||
@@ -76,9 +77,11 @@ void cmdline_char(String c, Integer shift, Integer level)
|
|||||||
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
||||||
void cmdline_hide(Integer level)
|
void cmdline_hide(Integer level)
|
||||||
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
||||||
void cmdline_function_show(void)
|
void cmdline_block_show(Array lines)
|
||||||
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
||||||
void cmdline_function_hide(void)
|
void cmdline_block_append(Array lines)
|
||||||
|
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
||||||
|
void cmdline_block_hide(void)
|
||||||
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
||||||
|
|
||||||
#endif // NVIM_API_UI_EVENTS_IN_H
|
#endif // NVIM_API_UI_EVENTS_IN_H
|
||||||
|
@@ -19643,6 +19643,7 @@ void ex_function(exarg_T *eap)
|
|||||||
int todo;
|
int todo;
|
||||||
hashitem_T *hi;
|
hashitem_T *hi;
|
||||||
int sourcing_lnum_off;
|
int sourcing_lnum_off;
|
||||||
|
bool show_block = false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ":function" without argument: list functions.
|
* ":function" without argument: list functions.
|
||||||
@@ -19816,8 +19817,9 @@ void ex_function(exarg_T *eap)
|
|||||||
goto errret_2;
|
goto errret_2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ui_is_external(kUICmdline)) {
|
if (KeyTyped && ui_is_external(kUICmdline)) {
|
||||||
ui_call_cmdline_function_show();
|
show_block = true;
|
||||||
|
ui_ext_cmdline_block_append(0, (const char *)eap->cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
// find extra arguments "range", "dict", "abort" and "closure"
|
// find extra arguments "range", "dict", "abort" and "closure"
|
||||||
@@ -19908,6 +19910,9 @@ void ex_function(exarg_T *eap)
|
|||||||
EMSG(_("E126: Missing :endfunction"));
|
EMSG(_("E126: Missing :endfunction"));
|
||||||
goto erret;
|
goto erret;
|
||||||
}
|
}
|
||||||
|
if (show_block) {
|
||||||
|
ui_ext_cmdline_block_append(indent, (const char *)theline);
|
||||||
|
}
|
||||||
|
|
||||||
/* Detect line continuation: sourcing_lnum increased more than one. */
|
/* Detect line continuation: sourcing_lnum increased more than one. */
|
||||||
if (sourcing_lnum > sourcing_lnum_off + 1)
|
if (sourcing_lnum > sourcing_lnum_off + 1)
|
||||||
@@ -20200,8 +20205,8 @@ ret_free:
|
|||||||
xfree(name);
|
xfree(name);
|
||||||
did_emsg |= saved_did_emsg;
|
did_emsg |= saved_did_emsg;
|
||||||
need_wait_return |= saved_wait_return;
|
need_wait_return |= saved_wait_return;
|
||||||
if (ui_is_external(kUICmdline)) {
|
if (show_block) {
|
||||||
ui_call_cmdline_function_hide();
|
ui_ext_cmdline_block_leave();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -186,6 +186,8 @@ static int cmd_showtail; /* Only show path tail in lists ? */
|
|||||||
|
|
||||||
static int new_cmdpos; /* position set by set_cmdline_pos() */
|
static int new_cmdpos; /* position set by set_cmdline_pos() */
|
||||||
|
|
||||||
|
static Array cmdline_block; ///< currently displayed block of context
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Type used by call_user_expand_func
|
* Type used by call_user_expand_func
|
||||||
*/
|
*/
|
||||||
@@ -2759,6 +2761,32 @@ void ui_ext_cmdline_show(void)
|
|||||||
ccline.level);
|
ccline.level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ui_ext_cmdline_block_append(int indent, const char *line)
|
||||||
|
{
|
||||||
|
char *buf = xmallocz(indent + strlen(line));
|
||||||
|
memset(buf, ' ', indent);
|
||||||
|
memcpy(buf+indent, line, strlen(line));
|
||||||
|
|
||||||
|
Array item = ARRAY_DICT_INIT;
|
||||||
|
ADD(item, DICTIONARY_OBJ((Dictionary)ARRAY_DICT_INIT));
|
||||||
|
ADD(item, STRING_OBJ(cstr_as_string(buf)));
|
||||||
|
Array content = ARRAY_DICT_INIT;
|
||||||
|
ADD(content, ARRAY_OBJ(item));
|
||||||
|
ADD(cmdline_block, ARRAY_OBJ(content));
|
||||||
|
if (cmdline_block.size > 1) {
|
||||||
|
ui_call_cmdline_block_append(copy_array(content));
|
||||||
|
} else {
|
||||||
|
ui_call_cmdline_block_show(copy_array(cmdline_block));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ui_ext_cmdline_block_leave(void)
|
||||||
|
{
|
||||||
|
api_free_array(cmdline_block);
|
||||||
|
ui_call_cmdline_block_hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Put a character on the command line. Shifts the following text to the
|
* Put a character on the command line. Shifts the following text to the
|
||||||
* right when "shift" is TRUE. Used for CTRL-V, CTRL-K, etc.
|
* right when "shift" is TRUE. Used for CTRL-V, CTRL-K, etc.
|
||||||
|
@@ -8,7 +8,7 @@ if helpers.pending_win32(pending) then return end
|
|||||||
describe('External command line completion', function()
|
describe('External command line completion', function()
|
||||||
local screen
|
local screen
|
||||||
local shown = false
|
local shown = false
|
||||||
local firstc, prompt, content, pos, char, shift, indent, level, current_hide_level, in_function
|
local firstc, prompt, content, pos, char, shift, indent, level, current_hide_level, in_block
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
clear()
|
clear()
|
||||||
@@ -25,10 +25,10 @@ describe('External command line completion', function()
|
|||||||
char, shift = unpack(data)
|
char, shift = unpack(data)
|
||||||
elseif name == "cmdline_pos" then
|
elseif name == "cmdline_pos" then
|
||||||
pos = data[1]
|
pos = data[1]
|
||||||
elseif name == "cmdline_function_show" then
|
elseif name == "cmdline_block_show" then
|
||||||
in_function = true
|
in_block = true
|
||||||
elseif name == "cmdline_function_hide" then
|
elseif name == "cmdline_block_hide" then
|
||||||
in_function = false
|
in_block = false
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
@@ -187,7 +187,7 @@ describe('External command line completion', function()
|
|||||||
~ |
|
~ |
|
||||||
|
|
|
|
||||||
]], nil, nil, function()
|
]], nil, nil, function()
|
||||||
eq(true, in_function)
|
eq(true, in_block)
|
||||||
eq(2, indent)
|
eq(2, indent)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -199,7 +199,7 @@ describe('External command line completion', function()
|
|||||||
~ |
|
~ |
|
||||||
|
|
|
|
||||||
]], nil, nil, function()
|
]], nil, nil, function()
|
||||||
eq(true, in_function)
|
eq(true, in_block)
|
||||||
eq(2, indent)
|
eq(2, indent)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -211,7 +211,7 @@ describe('External command line completion', function()
|
|||||||
~ |
|
~ |
|
||||||
|
|
|
|
||||||
]], nil, nil, function()
|
]], nil, nil, function()
|
||||||
eq(false, in_function)
|
eq(false, in_block)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
feed(':sign<c-f>')
|
feed(':sign<c-f>')
|
||||||
@@ -222,7 +222,7 @@ describe('External command line completion', function()
|
|||||||
[Command Line] |
|
[Command Line] |
|
||||||
|
|
|
|
||||||
]], nil, nil, function()
|
]], nil, nil, function()
|
||||||
eq(false, in_function)
|
eq(false, in_block)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user