Automatic insert filename completion kicks in only if prefix contains slash

This commit is contained in:
Maxime Coste 2014-03-19 08:05:28 +00:00
parent dc087b3b7c
commit 0db39ccfd0

View File

@ -787,6 +787,7 @@ public:
return { begin.coord(), end.coord(), std::move(result), buffer.timestamp() }; return { begin.coord(), end.coord(), std::move(result), buffer.timestamp() };
} }
template<bool require_slash>
BufferCompletion complete_filename(const Buffer& buffer, BufferCoord cursor_pos) BufferCompletion complete_filename(const Buffer& buffer, BufferCoord cursor_pos)
{ {
auto pos = buffer.iterator_at(cursor_pos); auto pos = buffer.iterator_at(cursor_pos);
@ -803,6 +804,9 @@ public:
return {}; return {};
String prefix{begin, pos}; String prefix{begin, pos};
if (require_slash and not contains(prefix, '/'))
return {};
StringList res; StringList res;
if (prefix.front() == '/') if (prefix.front() == '/')
res = Kakoune::complete_filename(prefix, Regex{}); res = Kakoune::complete_filename(prefix, Regex{});
@ -913,7 +917,7 @@ private:
{ {
if (completer == "filename" and if (completer == "filename" and
try_complete([this](const Buffer& buffer, BufferCoord cursor_pos) try_complete([this](const Buffer& buffer, BufferCoord cursor_pos)
{ return complete_filename(buffer, cursor_pos); })) { return complete_filename<true>(buffer, cursor_pos); }))
return true; return true;
if (completer.substr(0_byte, 7_byte) == "option=" and if (completer.substr(0_byte, 7_byte) == "option=" and
try_complete([&, this](const Buffer& buffer, BufferCoord cursor_pos) try_complete([&, this](const Buffer& buffer, BufferCoord cursor_pos)
@ -974,7 +978,7 @@ public:
{ {
if (key.key == 'f') if (key.key == 'f')
m_completer.try_complete([this](const Buffer& buffer, BufferCoord cursor_pos) m_completer.try_complete([this](const Buffer& buffer, BufferCoord cursor_pos)
{ return m_completer.complete_filename(buffer, cursor_pos); }); { return m_completer.complete_filename<false>(buffer, cursor_pos); });
if (key.key == 'w') if (key.key == 'w')
m_completer.try_complete([this](const Buffer& buffer, BufferCoord cursor_pos) m_completer.try_complete([this](const Buffer& buffer, BufferCoord cursor_pos)
{ return m_completer.complete_word<true>(buffer, cursor_pos); }); { return m_completer.complete_word<true>(buffer, cursor_pos); });