From 268c214f5617d76288134f5f21d8d6ed16749194 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 26 Jun 2017 14:39:17 +0100 Subject: [PATCH] Change completion_extra_word_char to be a list of codepoints instead of a string --- src/insert_completer.cc | 2 +- src/main.cc | 6 +++--- src/option_types.hh | 9 +++++++++ src/word_db.cc | 8 ++------ 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/insert_completer.cc b/src/insert_completer.cc index 05eb6785..dd259756 100644 --- a/src/insert_completer.cc +++ b/src/insert_completer.cc @@ -79,7 +79,7 @@ WordDB& get_word_db(const Buffer& buffer) template InsertCompletion complete_word(const SelectionList& sels, const OptionManager& options) { - StringView extra_word_char = options["completion_extra_word_char"].get(); + auto& extra_word_char = options["completion_extra_word_char"].get>(); auto is_word_pred = [extra_word_char](Codepoint c) { return is_word(c) or contains(extra_word_char, c); }; const Buffer& buffer = sels.buffer(); diff --git a/src/main.cc b/src/main.cc index acd4d037..85d79ea7 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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& 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( + reg.declare_option, check_extra_word_char>( "completion_extra_word_char", "Additional characters to be considered as words for insert completion", - ""_str); + {}); } static Client* local_client = nullptr; diff --git a/src/option_types.hh b/src/option_types.hh index 3c430ca1..ac1a5270 100644 --- a/src/option_types.hh +++ b/src/option_types.hh @@ -57,6 +57,15 @@ inline void option_from_string(StringView str, bool& opt) } constexpr StringView option_type_name(Meta::Type) { 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) { return "codepoint"; } + constexpr char list_separator = ':'; template diff --git a/src/word_db.cc b/src/word_db.cc index 6c5167d6..a486b86b 100644 --- a/src/word_db.cc +++ b/src/word_db.cc @@ -30,13 +30,9 @@ static WordList get_words(StringView content, ConstArrayView extra_wo return res; } -static Vector get_extra_word_chars(const Buffer& buffer) +static ConstArrayView get_extra_word_chars(const Buffer& buffer) { - auto& str = buffer.options()["completion_extra_word_char"].get(); - Vector res; - for (utf8::iterator it{str.begin(), str}; it != str.end(); ++it) - res.push_back(*it); - return res; + return buffer.options()["completion_extra_word_char"].get>(); } void WordDB::add_words(StringView line)