Make '_' the default extra_word_chars, and remove built-in support
Fixes #2599
This commit is contained in:
parent
6c54c4740d
commit
1553d91d27
|
@ -347,7 +347,7 @@ static void check_matching_pairs(const Vector<Codepoint, MemoryDomain::Options>&
|
|||
{
|
||||
if ((pairs.size() % 2) != 0)
|
||||
throw runtime_error{"matching pairs should have a pair number of element"};
|
||||
if (not all_of(pairs, is_punctuation))
|
||||
if (not all_of(pairs, [](Codepoint cp) { return is_punctuation(cp); }))
|
||||
throw runtime_error{"matching pairs can only be punctuation"};
|
||||
}
|
||||
|
||||
|
@ -422,7 +422,7 @@ void register_options()
|
|||
reg.declare_option<Vector<Codepoint, MemoryDomain::Options>, check_extra_word_chars>(
|
||||
"extra_word_chars",
|
||||
"Additional characters to be considered as words for insert completion",
|
||||
{});
|
||||
{ '_' });
|
||||
reg.declare_option<Vector<Codepoint, MemoryDomain::Options>, check_matching_pairs>(
|
||||
"matching_pairs",
|
||||
"set of pair of characters to be considered as matching pairs",
|
||||
|
|
|
@ -1327,7 +1327,7 @@ void select_object(Context& context, NormalParams params)
|
|||
return;
|
||||
|
||||
const Codepoint cp = *key.codepoint();
|
||||
if (is_punctuation(cp) or cp == '_')
|
||||
if (is_punctuation(cp, {}))
|
||||
{
|
||||
auto re = Regex{"\\Q" + to_string(cp), RegexCompileFlags::Backward};
|
||||
return select_and_set_last<mode>(
|
||||
|
|
|
@ -63,6 +63,7 @@ select_to_next_word(const Context& context, const Selection& selection)
|
|||
Utf8Iterator end = begin+1;
|
||||
|
||||
auto is_word = [&](Codepoint c) { return Kakoune::is_word<word_type>(c, extra_word_chars); };
|
||||
auto is_punctuation = [&](Codepoint c) { return Kakoune::is_punctuation(c, extra_word_chars); };
|
||||
|
||||
if (is_word(*begin))
|
||||
skip_while(end, buffer.end(), is_word);
|
||||
|
@ -96,6 +97,7 @@ select_to_next_word_end(const Context& context, const Selection& selection)
|
|||
skip_while(end, buffer.end(), is_horizontal_blank);
|
||||
|
||||
auto is_word = [&](Codepoint c) { return Kakoune::is_word<word_type>(c, extra_word_chars); };
|
||||
auto is_punctuation = [&](Codepoint c) { return Kakoune::is_punctuation(c, extra_word_chars); };
|
||||
|
||||
if (is_word(*end))
|
||||
skip_while(end, buffer.end(), is_word);
|
||||
|
@ -124,6 +126,7 @@ select_to_previous_word(const Context& context, const Selection& selection)
|
|||
Utf8Iterator end = begin;
|
||||
|
||||
auto is_word = [&](Codepoint c) { return Kakoune::is_word<word_type>(c, extra_word_chars); };
|
||||
auto is_punctuation = [&](Codepoint c) { return Kakoune::is_punctuation(c, extra_word_chars); };
|
||||
|
||||
bool with_end = skip_while_reverse(end, buffer.begin(), is_horizontal_blank);
|
||||
if (is_word(*end))
|
||||
|
|
|
@ -233,7 +233,7 @@ Vector<StringView> wrap_lines(StringView text, ColumnCount max_width)
|
|||
Vector<StringView> lines;
|
||||
while (it != end)
|
||||
{
|
||||
const CharCategories cat = categorize(*it, {});
|
||||
const CharCategories cat = categorize(*it, {'_'});
|
||||
if (cat == CharCategories::EndOfLine)
|
||||
{
|
||||
lines.emplace_back(line_begin.base(), it.base());
|
||||
|
@ -242,7 +242,7 @@ Vector<StringView> wrap_lines(StringView text, ColumnCount max_width)
|
|||
}
|
||||
|
||||
Utf8It word_end = it+1;
|
||||
while (word_end != end and categorize(*word_end, {}) == cat)
|
||||
while (word_end != end and categorize(*word_end, {'_'}) == cat)
|
||||
++word_end;
|
||||
|
||||
while (word_end > line_begin and
|
||||
|
|
|
@ -32,9 +32,9 @@ inline bool is_blank(Codepoint c) noexcept
|
|||
enum WordType { Word, WORD };
|
||||
|
||||
template<WordType word_type = Word>
|
||||
inline bool is_word(Codepoint c, ConstArrayView<Codepoint> extra_word_chars = {}) noexcept
|
||||
inline bool is_word(Codepoint c, ConstArrayView<Codepoint> extra_word_chars = {'_'}) noexcept
|
||||
{
|
||||
return c == '_' or iswalnum((wchar_t)c) or contains(extra_word_chars, c);
|
||||
return iswalnum((wchar_t)c) or contains(extra_word_chars, c);
|
||||
}
|
||||
|
||||
template<>
|
||||
|
@ -43,9 +43,9 @@ inline bool is_word<WORD>(Codepoint c, ConstArrayView<Codepoint>) noexcept
|
|||
return not is_blank(c);
|
||||
}
|
||||
|
||||
inline bool is_punctuation(Codepoint c) noexcept
|
||||
inline bool is_punctuation(Codepoint c, ConstArrayView<Codepoint> extra_word_chars = {'_'}) noexcept
|
||||
{
|
||||
return not (is_word(c) or is_blank(c));
|
||||
return not (is_word(c, extra_word_chars) or is_blank(c));
|
||||
}
|
||||
|
||||
inline bool is_basic_alpha(Codepoint c) noexcept
|
||||
|
|
|
@ -31,16 +31,13 @@ struct WordSplitter
|
|||
Iterator& operator++()
|
||||
{
|
||||
const auto* end = m_splitter->m_content.end();
|
||||
auto is_word = [&](const char* ptr) {
|
||||
const Codepoint c = utf8::codepoint(ptr, end);
|
||||
return Kakoune::is_word(c) or contains(m_splitter->m_extra_word_chars, c);
|
||||
};
|
||||
auto extra_chars = m_splitter->m_extra_word_chars;
|
||||
|
||||
m_word_begin = m_word_end;
|
||||
while (m_word_begin != end and not is_word(m_word_begin))
|
||||
while (m_word_begin != end and not is_word(utf8::codepoint(m_word_begin, end), extra_chars))
|
||||
utf8::to_next(m_word_begin, end);
|
||||
m_word_end = m_word_begin;
|
||||
while (m_word_end != end and is_word(m_word_end))
|
||||
while (m_word_end != end and is_word(utf8::codepoint(m_word_end, end), extra_chars))
|
||||
utf8::to_next(m_word_end, end);
|
||||
return *this;
|
||||
}
|
||||
|
|
1
test/normal/previous-word-no-underscore/cmd
Normal file
1
test/normal/previous-word-no-underscore/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
b
|
1
test/normal/previous-word-no-underscore/in
Normal file
1
test/normal/previous-word-no-underscore/in
Normal file
|
@ -0,0 +1 @@
|
|||
foo_%(b)ar
|
1
test/normal/previous-word-no-underscore/rc
Normal file
1
test/normal/previous-word-no-underscore/rc
Normal file
|
@ -0,0 +1 @@
|
|||
set-option global extra_word_chars
|
1
test/normal/previous-word-no-underscore/selections
Normal file
1
test/normal/previous-word-no-underscore/selections
Normal file
|
@ -0,0 +1 @@
|
|||
'_'
|
Loading…
Reference in New Issue
Block a user