summaryrefslogtreecommitdiff
path: root/src/selectors.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2017-06-26 15:28:41 +0100
committerMaxime Coste <mawww@kakoune.org>2017-06-26 15:28:41 +0100
commitf41d78083aa8d3883bcd4ed819e6784e09e69dba (patch)
treea67d2432ecf7f2ed499760eb245120dcae0221f5 /src/selectors.cc
parentdc378aed7290eb9fd90b752a2841fa2457bb91d0 (diff)
Use the extra_word_chars option in word based normal commands
the completion_extra_word_chars is now gone, superseeded by extra_word_chars that gets used both for completion and for normal mode. Fixes #1304
Diffstat (limited to 'src/selectors.cc')
-rw-r--r--src/selectors.cc54
1 files changed, 37 insertions, 17 deletions
diff --git a/src/selectors.cc b/src/selectors.cc
index 62ef8363..597619f8 100644
--- a/src/selectors.cc
+++ b/src/selectors.cc
@@ -36,17 +36,24 @@ Selection utf8_range(const Utf8Iterator& first, const Utf8Iterator& last)
return {first.base().coord(), last.base().coord()};
}
+ConstArrayView<Codepoint> get_extra_word_chars(const Context& context)
+{
+ return context.options()["extra_word_chars"].get<Vector<Codepoint, MemoryDomain::Options>>();
+}
+
}
template<WordType word_type>
Optional<Selection>
select_to_next_word(const Context& context, const Selection& selection)
{
+ auto extra_word_chars = get_extra_word_chars(context);
auto& buffer = context.buffer();
Utf8Iterator begin{buffer.iterator_at(selection.cursor()), buffer};
if (begin+1 == buffer.end())
return {};
- if (categorize<word_type>(*begin) != categorize<word_type>(*(begin+1)))
+ if (categorize<word_type>(*begin, extra_word_chars) !=
+ categorize<word_type>(*(begin+1), extra_word_chars))
++begin;
if (not skip_while(begin, buffer.end(),
@@ -54,10 +61,12 @@ select_to_next_word(const Context& context, const Selection& selection)
return {};
Utf8Iterator end = begin+1;
- if (word_type == Word and is_punctuation(*begin))
+ auto is_word = [&](Codepoint c) { return Kakoune::is_word<word_type>(c, extra_word_chars); };
+
+ if (is_word(*begin))
+ skip_while(end, buffer.end(), is_word);
+ else if (is_punctuation(*begin))
skip_while(end, buffer.end(), is_punctuation);
- else if (is_word<word_type>(*begin))
- skip_while(end, buffer.end(), is_word<word_type>);
skip_while(end, buffer.end(), is_horizontal_blank);
@@ -70,11 +79,13 @@ template<WordType word_type>
Optional<Selection>
select_to_next_word_end(const Context& context, const Selection& selection)
{
+ auto extra_word_chars = get_extra_word_chars(context);
auto& buffer = context.buffer();
Utf8Iterator begin{buffer.iterator_at(selection.cursor()), buffer};
if (begin+1 == buffer.end())
return {};
- if (categorize<word_type>(*begin) != categorize<word_type>(*(begin+1)))
+ if (categorize<word_type>(*begin, extra_word_chars) !=
+ categorize<word_type>(*(begin+1), extra_word_chars))
++begin;
if (not skip_while(begin, buffer.end(),
@@ -83,10 +94,12 @@ select_to_next_word_end(const Context& context, const Selection& selection)
Utf8Iterator end = begin;
skip_while(end, buffer.end(), is_horizontal_blank);
- if (word_type == Word and is_punctuation(*end))
+ auto is_word = [&](Codepoint c) { return Kakoune::is_word<word_type>(c, extra_word_chars); };
+
+ if (is_word(*end))
+ skip_while(end, buffer.end(), is_word);
+ else if (is_punctuation(*end))
skip_while(end, buffer.end(), is_punctuation);
- else if (is_word<word_type>(*end))
- skip_while(end, buffer.end(), is_word<word_type>);
return utf8_range(begin, end-1);
}
@@ -97,23 +110,26 @@ template<WordType word_type>
Optional<Selection>
select_to_previous_word(const Context& context, const Selection& selection)
{
+ auto extra_word_chars = get_extra_word_chars(context);
auto& buffer = context.buffer();
Utf8Iterator begin{buffer.iterator_at(selection.cursor()), buffer};
if (begin == buffer.begin())
return {};
- if (categorize<word_type>(*begin) != categorize<word_type>(*(begin-1)))
+ if (categorize<word_type>(*begin, extra_word_chars) !=
+ categorize<word_type>(*(begin-1), extra_word_chars))
--begin;
skip_while_reverse(begin, buffer.begin(), [](Codepoint c){ return is_eol(c); });
Utf8Iterator end = begin;
+ auto is_word = [&](Codepoint c) { return Kakoune::is_word<word_type>(c, extra_word_chars); };
+
bool with_end = skip_while_reverse(end, buffer.begin(), is_horizontal_blank);
- if (word_type == Word and is_punctuation(*end))
+ if (is_word(*end))
+ with_end = skip_while_reverse(end, buffer.begin(), is_word);
+ else if (is_punctuation(*end))
with_end = skip_while_reverse(end, buffer.begin(), is_punctuation);
- else if (is_word<word_type>(*end))
- with_end = skip_while_reverse(end, buffer.begin(), is_word<word_type>);
-
return utf8_range(begin, with_end ? end : end+1);
}
template Optional<Selection> select_to_previous_word<WordType::Word>(const Context&, const Selection&);
@@ -124,21 +140,25 @@ Optional<Selection>
select_word(const Context& context, const Selection& selection,
int count, ObjectFlags flags)
{
+ auto extra_word_chars = get_extra_word_chars(context);
auto& buffer = context.buffer();
+
+ auto is_word = [&](Codepoint c) { return Kakoune::is_word<word_type>(c, extra_word_chars); };
+
Utf8Iterator first{buffer.iterator_at(selection.cursor()), buffer};
- if (not is_word<word_type>(*first))
+ if (not is_word(*first))
return {};
Utf8Iterator last = first;
if (flags & ObjectFlags::ToBegin)
{
- skip_while_reverse(first, buffer.begin(), is_word<word_type>);
- if (not is_word<word_type>(*first))
+ skip_while_reverse(first, buffer.begin(), is_word);
+ if (not is_word(*first))
++first;
}
if (flags & ObjectFlags::ToEnd)
{
- skip_while(last, buffer.end(), is_word<word_type>);
+ skip_while(last, buffer.end(), is_word);
if (not (flags & ObjectFlags::Inner))
skip_while(last, buffer.end(), is_horizontal_blank);
--last;