home/src/completion.cc

40 lines
1.3 KiB
C++
Raw Normal View History

#include "completion.hh"
#include "file.hh"
#include "context.hh"
2016-11-29 00:53:50 +01:00
#include "regex.hh"
namespace Kakoune
{
Completions shell_complete(const Context& context, CompletionFlags flags,
StringView prefix, ByteCount cursor_pos)
{
ByteCount word_start = 0;
ByteCount word_end = 0;
bool command = true;
const ByteCount len = prefix.length();
for (ByteCount pos = 0; pos < cursor_pos and pos < len;)
{
command = (pos == 0 or prefix[pos-1] == ';' or prefix[pos-1] == '|' or
(pos > 1 and prefix[pos-1] == '&' and prefix[pos-2] == '&'));
while (pos != len and is_horizontal_blank(prefix[pos]))
++pos;
word_start = pos;
while (pos != len and not is_horizontal_blank(prefix[pos]))
++pos;
word_end = pos;
}
Completions completions{word_start, word_end};
if (command)
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),
2015-11-19 16:31:00 +01:00
context.options()["ignored_files"].get<Regex>(),
cursor_pos - word_start);
return completions;
}
}