1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-25 04:24:48 +03:00

Use StringView for completion functions

This commit is contained in:
Maxime Coste 2014-04-18 14:02:14 +01:00
parent af2d82dfc1
commit adde2fef75
16 changed files with 31 additions and 31 deletions

View File

@ -95,10 +95,10 @@ void BufferManager::set_last_used_buffer(Buffer& buffer)
m_buffers.emplace(m_buffers.begin(), &buffer);
}
CandidateList BufferManager::complete_buffer_name(const String& prefix,
CandidateList BufferManager::complete_buffer_name(StringView prefix,
ByteCount cursor_pos)
{
String real_prefix = prefix.substr(0, cursor_pos);
auto real_prefix = prefix.substr(0, cursor_pos);
const bool include_dirs = contains(real_prefix, '/');
CandidateList result;
CandidateList subsequence_result;

View File

@ -33,7 +33,7 @@ public:
Buffer& get_buffer(const String& name);
void set_last_used_buffer(Buffer& buffer);
CandidateList complete_buffer_name(const String& prefix,
CandidateList complete_buffer_name(StringView prefix,
ByteCount cursor_pos = -1);
private:

View File

@ -170,10 +170,10 @@ void ClientManager::redraw_clients() const
client->redraw_ifn();
}
CandidateList ClientManager::complete_client_name(const String& prefix,
CandidateList ClientManager::complete_client_name(StringView prefix,
ByteCount cursor_pos) const
{
String real_prefix = prefix.substr(0, cursor_pos);
auto real_prefix = prefix.substr(0, cursor_pos);
CandidateList result;
CandidateList subsequence_result;
for (auto& client : m_clients)

View File

@ -39,7 +39,7 @@ public:
bool validate_client_name(const String& name) const;
void remove_client(Client& client);
CandidateList complete_client_name(const String& name,
CandidateList complete_client_name(StringView name,
ByteCount cursor_pos = -1) const;
private:

View File

@ -36,11 +36,11 @@ void ColorRegistry::register_alias(const String& name, const String& colordesc,
it->second : parse_color_pair(colordesc);
}
CandidateList ColorRegistry::complete_alias_name(const String& prefix,
CandidateList ColorRegistry::complete_alias_name(StringView prefix,
ByteCount cursor_pos) const
{
CandidateList res;
String real_prefix = prefix.substr(0, cursor_pos);
auto real_prefix = prefix.substr(0, cursor_pos);
for (auto& alias : m_aliases)
{
if (prefix_match(alias.first, real_prefix))

View File

@ -19,7 +19,7 @@ public:
void register_alias(const String& name, const String& colordesc,
bool override = false);
CandidateList complete_alias_name(const String& prefix,
CandidateList complete_alias_name(StringView prefix,
ByteCount cursor_pos) const;
private:
std::unordered_map<String, ColorPair> m_aliases;

View File

@ -495,7 +495,7 @@ HookManager& get_hook_manager(const String& scope, Context& context)
throw runtime_error("error: no such hook container " + scope);
}
CandidateList complete_scope(const String& prefix)
CandidateList complete_scope(StringView prefix)
{
CandidateList res;
for (auto scope : { "global", "buffer", "window" })

View File

@ -6,7 +6,7 @@ namespace Kakoune
{
Completions shell_complete(const Context& context, CompletionFlags flags,
const String& prefix, ByteCount cursor_pos)
StringView prefix, ByteCount cursor_pos)
{
ByteCount word_start = 0;
ByteCount word_end = 0;

View File

@ -5,13 +5,13 @@
#include <functional>
#include "units.hh"
#include "string.hh"
namespace Kakoune
{
class Context;
class String;
using CandidateList = std::vector<String>;
struct Completions
@ -36,16 +36,16 @@ enum class CompletionFlags
Fast
};
using Completer = std::function<Completions (const Context&, CompletionFlags,
const String&, ByteCount)>;
StringView, ByteCount)>;
inline Completions complete_nothing(const Context& context, CompletionFlags,
const String&, ByteCount cursor_pos)
StringView, ByteCount cursor_pos)
{
return Completions(cursor_pos, cursor_pos);
}
Completions shell_complete(const Context& context, CompletionFlags,
const String&, ByteCount cursor_pos);
StringView, ByteCount cursor_pos);
}
#endif // completion_hh_INCLUDED

View File

@ -311,7 +311,7 @@ std::vector<String> list_files(const String& prefix,
return result.empty() ? subseq_result : result;
}
std::vector<String> complete_filename(const String& prefix,
std::vector<String> complete_filename(StringView prefix,
const Regex& ignored_regex,
ByteCount cursor_pos)
{
@ -346,7 +346,7 @@ std::vector<String> complete_filename(const String& prefix,
return res;
}
std::vector<String> complete_command(const String& prefix, ByteCount cursor_pos)
std::vector<String> complete_command(StringView prefix, ByteCount cursor_pos)
{
String real_prefix = parse_filename(prefix.substr(0, cursor_pos));
String dirname;

View File

@ -35,11 +35,11 @@ String find_file(const String& filename, memoryview<String> paths);
time_t get_fs_timestamp(const String& filename);
std::vector<String> complete_filename(const String& prefix,
std::vector<String> complete_filename(StringView prefix,
const Regex& ignore_regex,
ByteCount cursor_pos = -1);
std::vector<String> complete_command(const String& prefix,
std::vector<String> complete_command(StringView prefix,
ByteCount cursor_pos = -1);
}

View File

@ -54,12 +54,12 @@ public:
return *group;
}
CandidateList complete_id(const String& prefix, ByteCount cursor_pos) const
CandidateList complete_id(StringView prefix, ByteCount cursor_pos) const
{
return m_functions.complete_id(prefix, cursor_pos);
}
CandidateList complete_group_id(const String& prefix, ByteCount cursor_pos) const
CandidateList complete_group_id(StringView prefix, ByteCount cursor_pos) const
{
return m_functions.complete_id_if(
prefix, cursor_pos, [](const FunctionAndId& func) {

View File

@ -32,7 +32,7 @@ public:
return it->second;
}
CandidateList complete_name(const String& prefix, ByteCount cursor_pos)
CandidateList complete_name(StringView prefix, ByteCount cursor_pos)
{
return m_functions.complete_id(prefix, cursor_pos);
}

View File

@ -67,11 +67,11 @@ public:
}
template<typename Condition>
CandidateList complete_id_if(const String& prefix,
CandidateList complete_id_if(StringView prefix,
ByteCount cursor_pos,
Condition condition) const
{
String real_prefix = prefix.substr(0, cursor_pos);
auto real_prefix = prefix.substr(0, cursor_pos);
CandidateList result;
for (auto& value : m_content)
{
@ -84,7 +84,7 @@ public:
return result;
}
CandidateList complete_id(const String& prefix,
CandidateList complete_id(StringView prefix,
ByteCount cursor_pos) const
{
return complete_id_if(

View File

@ -85,14 +85,14 @@ CandidateList OptionManager::get_matching_names(MatchingFunc func)
return result;
}
CandidateList OptionManager::complete_option_name(const String& prefix,
CandidateList OptionManager::complete_option_name(StringView prefix,
ByteCount cursor_pos)
{
using namespace std::placeholders;
String real_prefix = prefix.substr(0, cursor_pos);
auto result = get_matching_names(std::bind(prefix_match, _1, std::ref(real_prefix)));
auto real_prefix = prefix.substr(0, cursor_pos);
auto result = get_matching_names(std::bind(prefix_match, _1, real_prefix));
if (result.empty())
result = get_matching_names(std::bind(subsequence_match, _1, std::ref(real_prefix)));
result = get_matching_names(std::bind(subsequence_match, _1, real_prefix));
return result;
}

View File

@ -89,7 +89,7 @@ public:
const Option& operator[] (const String& name) const;
Option& get_local_option(const String& name);
CandidateList complete_option_name(const String& prefix,
CandidateList complete_option_name(StringView prefix,
ByteCount cursor_pos);
using OptionList = std::vector<const Option*>;