Change completion_extra_word_char to be a list of codepoints instead of a string

This commit is contained in:
Maxime Coste 2017-06-26 14:39:17 +01:00
parent 1a64ba18d3
commit 268c214f56
4 changed files with 15 additions and 10 deletions

View File

@ -79,7 +79,7 @@ WordDB& get_word_db(const Buffer& buffer)
template<bool other_buffers>
InsertCompletion complete_word(const SelectionList& sels, const OptionManager& options)
{
StringView extra_word_char = options["completion_extra_word_char"].get<String>();
auto& extra_word_char = options["completion_extra_word_char"].get<Vector<Codepoint, MemoryDomain::Options>>();
auto is_word_pred = [extra_word_char](Codepoint c) { return is_word(c) or contains(extra_word_char, c); };
const Buffer& buffer = sels.buffer();

View File

@ -251,7 +251,7 @@ static void check_timeout(const int& timeout)
throw runtime_error{"the minimum acceptable timeout is 50 milliseconds"};
}
static void check_extra_word_char(const String& extra_chars)
static void check_extra_word_char(const Vector<Codepoint, MemoryDomain::Options>& extra_chars)
{
if (contains_that(extra_chars, is_blank))
throw runtime_error{"blanks are not accepted for extra completion characters"};
@ -324,10 +324,10 @@ void register_options()
reg.declare_option("debug", "various debug flags", DebugFlags::None);
reg.declare_option("readonly", "prevent buffers from being modified", false);
reg.declare_option<String, check_extra_word_char>(
reg.declare_option<Vector<Codepoint, MemoryDomain::Options>, check_extra_word_char>(
"completion_extra_word_char",
"Additional characters to be considered as words for insert completion",
""_str);
{});
}
static Client* local_client = nullptr;

View File

@ -57,6 +57,15 @@ inline void option_from_string(StringView str, bool& opt)
}
constexpr StringView option_type_name(Meta::Type<bool>) { return "bool"; }
inline String option_to_string(Codepoint opt) { return to_string(opt); }
inline void option_from_string(StringView str, Codepoint& opt)
{
if (str.char_length() != 1)
throw runtime_error{format("'{}' is not a single codepoint", str)};
opt = str[0_char];
}
constexpr StringView option_type_name(Meta::Type<Codepoint>) { return "codepoint"; }
constexpr char list_separator = ':';
template<typename T, MemoryDomain domain>

View File

@ -30,13 +30,9 @@ static WordList get_words(StringView content, ConstArrayView<Codepoint> extra_wo
return res;
}
static Vector<Codepoint> get_extra_word_chars(const Buffer& buffer)
static ConstArrayView<Codepoint> get_extra_word_chars(const Buffer& buffer)
{
auto& str = buffer.options()["completion_extra_word_char"].get<String>();
Vector<Codepoint> res;
for (utf8::iterator<const char*> it{str.begin(), str}; it != str.end(); ++it)
res.push_back(*it);
return res;
return buffer.options()["completion_extra_word_char"].get<Vector<Codepoint, MemoryDomain::Options>>();
}
void WordDB::add_words(StringView line)