mirror of
https://github.com/mawww/kakoune.git
synced 2024-11-28 09:07:19 +03:00
Add an alternative -shell-candidates shell completion support
-shell-candidates use a shell script that returns all the candidates and then sort them using Kakoune ranked matches system instead of delegating the whole completion to the shell script (as shell-completion does)
This commit is contained in:
parent
b0d72ebce0
commit
840b7658fd
@ -6,9 +6,9 @@
|
|||||||
decl str-list ctagsfiles 'tags'
|
decl str-list ctagsfiles 'tags'
|
||||||
|
|
||||||
def -params 0..1 \
|
def -params 0..1 \
|
||||||
-shell-completion '
|
-shell-candidates '
|
||||||
( for tags in $(printf %s "${kak_opt_ctagsfiles}" | tr \':\' \'\n\');
|
( for tags in $(printf %s "${kak_opt_ctagsfiles}" | tr \':\' \'\n\');
|
||||||
do readtags -t "${tags}" -p "$1"
|
do readtags -t "${tags}" -p ""
|
||||||
done ) | cut -f 1 | sort | uniq' \
|
done ) | cut -f 1 | sort | uniq' \
|
||||||
-docstring 'Jump to tag definition' \
|
-docstring 'Jump to tag definition' \
|
||||||
tag \
|
tag \
|
||||||
|
@ -827,6 +827,36 @@ void define_command(const ParametersParser& parser, Context& context, const Shel
|
|||||||
return Completions{ 0_byte, pos_in_token, split(output, '\n', 0) };
|
return Completions{ 0_byte, pos_in_token, split(output, '\n', 0) };
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
else if (auto shell_cmd_opt = parser.get_switch("shell-candidates"))
|
||||||
|
{
|
||||||
|
String shell_cmd = shell_cmd_opt->str();
|
||||||
|
Vector<String> candidates;
|
||||||
|
int token = -1;
|
||||||
|
completer = [shell_cmd, candidates, token](
|
||||||
|
const Context& context, CompletionFlags flags, CommandParameters params,
|
||||||
|
size_t token_to_complete, ByteCount pos_in_token) mutable
|
||||||
|
{
|
||||||
|
if (token != token_to_complete)
|
||||||
|
{
|
||||||
|
if (flags == CompletionFlags::Fast) // no shell on fast completion
|
||||||
|
return Completions{};
|
||||||
|
|
||||||
|
ShellContext shell_context{
|
||||||
|
params,
|
||||||
|
{ { "token_to_complete", to_string(token_to_complete) } }
|
||||||
|
};
|
||||||
|
String output = ShellManager::instance().eval(shell_cmd, context, {},
|
||||||
|
ShellManager::Flags::WaitForStdout,
|
||||||
|
shell_context).first;
|
||||||
|
candidates = split(output, '\n', 0);
|
||||||
|
token = token_to_complete;
|
||||||
|
}
|
||||||
|
|
||||||
|
return token == token_to_complete ?
|
||||||
|
Completions{ 0_byte, pos_in_token, complete(params[token_to_complete], pos_in_token, candidates) }
|
||||||
|
: Completions{};
|
||||||
|
};
|
||||||
|
}
|
||||||
else if (parser.get_switch("command-completion"))
|
else if (parser.get_switch("command-completion"))
|
||||||
{
|
{
|
||||||
completer = [](const Context& context, CompletionFlags flags,
|
completer = [](const Context& context, CompletionFlags flags,
|
||||||
@ -857,7 +887,8 @@ const CommandDesc define_command_cmd = {
|
|||||||
{ "client-completion", { false, "complete parameters using client name completion" } },
|
{ "client-completion", { false, "complete parameters using client name completion" } },
|
||||||
{ "buffer-completion", { false, "complete parameters using buffer name completion" } },
|
{ "buffer-completion", { false, "complete parameters using buffer name completion" } },
|
||||||
{ "command-completion", { false, "complete parameters using kakoune command completion" } },
|
{ "command-completion", { false, "complete parameters using kakoune command completion" } },
|
||||||
{ "shell-completion", { true, "complete the parameters using the given shell-script" } } },
|
{ "shell-completion", { true, "complete the parameters using the given shell-script" } },
|
||||||
|
{ "shell-candidates", { true, "get the parameter candidates using the given shell-script" } } },
|
||||||
ParameterDesc::Flags::None,
|
ParameterDesc::Flags::None,
|
||||||
2, 2
|
2, 2
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user