parent
045efdc49e
commit
b531bab1ce
|
@ -247,6 +247,15 @@ but not really useful in that context.
|
||||||
will have this command executed whenever the prompt content changes
|
will have this command executed whenever the prompt content changes
|
||||||
or the prompt is aborted, respectively.
|
or the prompt is aborted, respectively.
|
||||||
|
|
||||||
|
Completion support can be controlled with the same switches provided
|
||||||
|
by the *define-command* command, see
|
||||||
|
<<declaring-new-commands,Declaring new commands>>.
|
||||||
|
|
||||||
|
For *-shell-script-completions* and *-shell-script-candidates*
|
||||||
|
completions, token_to_complete will always be 1, and the full
|
||||||
|
prompt content will be passed as a single token. In other words,
|
||||||
|
word splitting does not take place.
|
||||||
|
|
||||||
*on-key* <command>::
|
*on-key* <command>::
|
||||||
wait for next key from user, then execute <command>, the key is
|
wait for next key from user, then execute <command>, the key is
|
||||||
available through the `key` value, accessible through `$kak_key`
|
available through the `key` value, accessible through `$kak_key`
|
||||||
|
|
|
@ -272,6 +272,21 @@ private:
|
||||||
int m_token = -1;
|
int m_token = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename Completer>
|
||||||
|
struct PromptCompleterAdapter
|
||||||
|
{
|
||||||
|
PromptCompleterAdapter(Completer completer) : m_completer{completer} {}
|
||||||
|
|
||||||
|
Completions operator()(const Context& context, CompletionFlags flags,
|
||||||
|
StringView prefix, ByteCount cursor_pos)
|
||||||
|
{
|
||||||
|
return m_completer(context, flags, {String{String::NoCopy{}, prefix}}, 0, cursor_pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Completer m_completer;
|
||||||
|
};
|
||||||
|
|
||||||
Scope* get_scope_ifp(StringView scope, const Context& context)
|
Scope* get_scope_ifp(StringView scope, const Context& context)
|
||||||
{
|
{
|
||||||
if (prefix_match("global", scope))
|
if (prefix_match("global", scope))
|
||||||
|
@ -1862,6 +1877,8 @@ const CommandDesc prompt_cmd = {
|
||||||
{ "buffer-completion", { false, "use buffer completion for prompt" } },
|
{ "buffer-completion", { false, "use buffer completion for prompt" } },
|
||||||
{ "command-completion", { false, "use command completion for prompt" } },
|
{ "command-completion", { false, "use command completion for prompt" } },
|
||||||
{ "shell-completion", { false, "use shell command completion for prompt" } },
|
{ "shell-completion", { false, "use shell command completion for prompt" } },
|
||||||
|
{ "shell-script-completion", { true, "use shell command completion for prompt" } },
|
||||||
|
{ "shell-script-candidates", { true, "use shell command completion for prompt" } },
|
||||||
{ "on-change", { true, "command to execute whenever the prompt changes" } },
|
{ "on-change", { true, "command to execute whenever the prompt changes" } },
|
||||||
{ "on-abort", { true, "command to execute whenever the prompt is canceled" } } },
|
{ "on-abort", { true, "command to execute whenever the prompt is canceled" } } },
|
||||||
ParameterDesc::Flags::None, 2, 2
|
ParameterDesc::Flags::None, 2, 2
|
||||||
|
@ -1899,6 +1916,10 @@ const CommandDesc prompt_cmd = {
|
||||||
};
|
};
|
||||||
else if (parser.get_switch("shell-completion"))
|
else if (parser.get_switch("shell-completion"))
|
||||||
completer = shell_complete;
|
completer = shell_complete;
|
||||||
|
else if (auto shell_script = parser.get_switch("shell-script-completion"))
|
||||||
|
completer = PromptCompleterAdapter{ShellScriptCompleter{shell_script->str()}};
|
||||||
|
else if (auto shell_script = parser.get_switch("shell-script-candidates"))
|
||||||
|
completer = PromptCompleterAdapter{ShellCandidatesCompleter{shell_script->str()}};
|
||||||
|
|
||||||
const auto flags = parser.get_switch("password") ?
|
const auto flags = parser.get_switch("password") ?
|
||||||
PromptFlags::Password : PromptFlags::None;
|
PromptFlags::Password : PromptFlags::None;
|
||||||
|
|
1
test/shell/prompt-shell-script-candidates/cmd
Normal file
1
test/shell/prompt-shell-script-candidates/cmd
Normal file
|
@ -0,0 +1 @@
|
||||||
|
:foo<ret>b<tab><tab><ret>
|
1
test/shell/prompt-shell-script-candidates/in
Normal file
1
test/shell/prompt-shell-script-candidates/in
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
test/shell/prompt-shell-script-candidates/out
Normal file
1
test/shell/prompt-shell-script-candidates/out
Normal file
|
@ -0,0 +1 @@
|
||||||
|
bar
|
3
test/shell/prompt-shell-script-candidates/rc
Normal file
3
test/shell/prompt-shell-script-candidates/rc
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
define-command foo %{
|
||||||
|
prompt -shell-script-candidates %{ printf 'foo\nbar\nhaz\n' } ': ' %{exec i %val{text} <esc>}
|
||||||
|
}
|
1
test/shell/prompt-shell-script-completion/cmd
Normal file
1
test/shell/prompt-shell-script-completion/cmd
Normal file
|
@ -0,0 +1 @@
|
||||||
|
:foo<ret>b<tab><tab><ret>
|
1
test/shell/prompt-shell-script-completion/in
Normal file
1
test/shell/prompt-shell-script-completion/in
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
test/shell/prompt-shell-script-completion/out
Normal file
1
test/shell/prompt-shell-script-completion/out
Normal file
|
@ -0,0 +1 @@
|
||||||
|
foo
|
3
test/shell/prompt-shell-script-completion/rc
Normal file
3
test/shell/prompt-shell-script-completion/rc
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
define-command foo %{
|
||||||
|
prompt -shell-script-completion %{ printf 'foo\nbar\nhaz\n' } ': ' %{exec i %val{text} <esc>}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user