Extract shell_complete lambda as a proper function
This commit is contained in:
parent
56c3d9d137
commit
0b509735ca
38
src/completion.cc
Normal file
38
src/completion.cc
Normal file
|
@ -0,0 +1,38 @@
|
|||
#include "completion.hh"
|
||||
#include "file.hh"
|
||||
#include "context.hh"
|
||||
|
||||
namespace Kakoune
|
||||
{
|
||||
|
||||
Completions shell_complete(const Context& context, CompletionFlags flags,
|
||||
const String& prefix, ByteCount cursor_pos)
|
||||
{
|
||||
ByteCount word_start = 0;
|
||||
ByteCount word_end = 0;
|
||||
|
||||
bool first = true;
|
||||
const ByteCount len = prefix.length();
|
||||
for (ByteCount pos = 0; pos < cursor_pos;)
|
||||
{
|
||||
if (pos != 0)
|
||||
first = false;
|
||||
while (pos != len and is_blank(prefix[pos]))
|
||||
++pos;
|
||||
word_start = pos;
|
||||
while (pos != len and not is_blank(prefix[pos]))
|
||||
++pos;
|
||||
word_end = pos;
|
||||
}
|
||||
Completions completions{word_start, word_end};
|
||||
if (first)
|
||||
completions.candidates = complete_command(prefix.substr(word_start, word_end),
|
||||
cursor_pos - word_start);
|
||||
else
|
||||
completions.candidates = complete_filename(prefix.substr(word_start, word_end),
|
||||
context.options()["ignored_files"].get<Regex>(),
|
||||
cursor_pos - word_start);
|
||||
return completions;
|
||||
}
|
||||
|
||||
}
|
|
@ -40,5 +40,8 @@ inline Completions complete_nothing(const Context& context, CompletionFlags,
|
|||
return Completions(cursor_pos, cursor_pos);
|
||||
}
|
||||
|
||||
Completions shell_complete(const Context& context, CompletionFlags,
|
||||
const String&, ByteCount cursor_pos);
|
||||
|
||||
}
|
||||
#endif // completion_hh_INCLUDED
|
||||
|
|
|
@ -421,38 +421,8 @@ void command(Context& context, int)
|
|||
template<InsertMode mode>
|
||||
void pipe(Context& context, int)
|
||||
{
|
||||
auto completer = [](const Context& context, CompletionFlags flags,
|
||||
const String& prefix, ByteCount cursor_pos)
|
||||
{
|
||||
ByteCount word_start = 0;
|
||||
ByteCount word_end = 0;
|
||||
|
||||
bool first = true;
|
||||
const ByteCount len = prefix.length();
|
||||
for (ByteCount pos = 0; pos < cursor_pos;)
|
||||
{
|
||||
if (pos != 0)
|
||||
first = false;
|
||||
while (pos != len and is_blank(prefix[pos]))
|
||||
++pos;
|
||||
word_start = pos;
|
||||
while (pos != len and not is_blank(prefix[pos]))
|
||||
++pos;
|
||||
word_end = pos;
|
||||
}
|
||||
Completions completions{word_start, word_end};
|
||||
if (first)
|
||||
completions.candidates = complete_command(prefix.substr(word_start, word_end),
|
||||
cursor_pos - word_start);
|
||||
else
|
||||
completions.candidates = complete_filename(prefix.substr(word_start, word_end),
|
||||
context.options()["ignored_files"].get<Regex>(),
|
||||
cursor_pos - word_start);
|
||||
return completions;
|
||||
};
|
||||
|
||||
const char* prompt = mode == InsertMode::Replace ? "pipe:" : "pipe (ins):";
|
||||
context.input_handler().prompt(prompt, get_color("Prompt"), completer,
|
||||
context.input_handler().prompt(prompt, get_color("Prompt"), shell_complete,
|
||||
[](const String& cmdline, PromptEvent event, Context& context)
|
||||
{
|
||||
if (event != PromptEvent::Validate)
|
||||
|
|
Loading…
Reference in New Issue
Block a user