summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2019-03-24 19:20:29 +1100
committerMaxime Coste <mawww@kakoune.org>2019-03-24 19:28:46 +1100
commitb531bab1cef58fcebc6c786bd63d6217a135204d (patch)
tree7c68e57fd6bdeaf487a119147befb7ac40daf2db /src
parent045efdc49ed39f90d4a0be56b3a9e4896533e7e2 (diff)
Add support for -shell-script-* completion in :prompt
Fixes #2754
Diffstat (limited to 'src')
-rw-r--r--src/commands.cc21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/commands.cc b/src/commands.cc
index d2809254..31470f8f 100644
--- a/src/commands.cc
+++ b/src/commands.cc
@@ -272,6 +272,21 @@ private:
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)
{
if (prefix_match("global", scope))
@@ -1862,6 +1877,8 @@ const CommandDesc prompt_cmd = {
{ "buffer-completion", { false, "use buffer completion for prompt" } },
{ "command-completion", { false, "use 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-abort", { true, "command to execute whenever the prompt is canceled" } } },
ParameterDesc::Flags::None, 2, 2
@@ -1899,6 +1916,10 @@ const CommandDesc prompt_cmd = {
};
else if (parser.get_switch("shell-completion"))
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") ?
PromptFlags::Password : PromptFlags::None;