1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-26 04:52:53 +03:00

Merge branch 'master' into remove-buffer-change-listener

Conflicts:
	src/normal.cc
	src/selectors.cc
	src/selectors.hh
This commit is contained in:
Maxime Coste 2014-05-27 00:35:12 +01:00
commit e1c9e42213
3 changed files with 47 additions and 35 deletions

View File

@ -833,11 +833,11 @@ void select_object(Context& context, int param)
Codepoint key; Codepoint key;
Selection (*func)(const Buffer&, const Selection&, ObjectFlags); Selection (*func)(const Buffer&, const Selection&, ObjectFlags);
} selectors[] = { } selectors[] = {
{ 'w', select_whole_word<Word> }, { 'w', select_word<Word> },
{ 'W', select_whole_word<WORD> }, { 'W', select_word<WORD> },
{ 's', select_whole_sentence }, { 's', select_sentence },
{ 'p', select_whole_paragraph }, { 'p', select_paragraph },
{ 'i', select_whole_indent }, { 'i', select_indent },
}; };
for (auto& sel : selectors) for (auto& sel : selectors)
{ {
@ -1325,7 +1325,7 @@ KeyMap keymap =
{ '.', repeat_last_insert }, { '.', repeat_last_insert },
{ '%', [](Context& context, int) { select_whole_buffer(context.selections()); } }, { '%', [](Context& context, int) { select_buffer(context.selections()); } },
{ ':', command }, { ':', command },
{ '|', pipe<InsertMode::Replace> }, { '|', pipe<InsertMode::Replace> },
@ -1355,7 +1355,7 @@ KeyMap keymap =
{ 'x', repeated(make_select<SelectMode::Replace>(select_line)) }, { 'x', repeated(make_select<SelectMode::Replace>(select_line)) },
{ 'X', repeated(make_select<SelectMode::Extend>(select_line)) }, { 'X', repeated(make_select<SelectMode::Extend>(select_line)) },
{ alt('x'), make_select<SelectMode::Replace>(select_whole_lines) }, { alt('x'), make_select<SelectMode::Replace>(select_lines) },
{ alt('X'), make_select<SelectMode::Replace>(trim_partial_lines) }, { alt('X'), make_select<SelectMode::Replace>(trim_partial_lines) },
{ 'm', make_select<SelectMode::Replace>(select_matching) }, { 'm', make_select<SelectMode::Replace>(select_matching) },

View File

@ -223,7 +223,7 @@ static bool is_end_of_sentence(char c)
return c == '.' or c == ';' or c == '!' or c == '?'; return c == '.' or c == ';' or c == '!' or c == '?';
} }
Selection select_whole_sentence(const Buffer& buffer, const Selection& selection, ObjectFlags flags) Selection select_sentence(const Buffer& buffer, const Selection& selection, ObjectFlags flags)
{ {
BufferIterator first = buffer.iterator_at(selection.cursor()); BufferIterator first = buffer.iterator_at(selection.cursor());
@ -284,7 +284,7 @@ Selection select_whole_sentence(const Buffer& buffer, const Selection& selection
: Selection{last.coord(), first.coord()}; : Selection{last.coord(), first.coord()};
} }
Selection select_whole_paragraph(const Buffer& buffer, const Selection& selection, ObjectFlags flags) Selection select_paragraph(const Buffer& buffer, const Selection& selection, ObjectFlags flags)
{ {
BufferIterator first = buffer.iterator_at(selection.cursor()); BufferIterator first = buffer.iterator_at(selection.cursor());
@ -352,7 +352,15 @@ static CharCount get_indent(const String& str, int tabstop)
return indent; return indent;
} }
Selection select_whole_indent(const Buffer& buffer, const Selection& selection, ObjectFlags flags) static bool is_only_whitespaces(const String& str)
{
auto it = str.begin();
skip_while(it, str.end(),
[](char c){ return c == ' ' or c == '\t' or c == '\n'; });
return it == str.end();
}
Selection select_indent(const Buffer& buffer, const Selection& selection, ObjectFlags flags)
{ {
int tabstop = buffer.options()["tabstop"].get<int>(); int tabstop = buffer.options()["tabstop"].get<int>();
LineCount line = selection.cursor().line; LineCount line = selection.cursor().line;
@ -368,29 +376,25 @@ Selection select_whole_indent(const Buffer& buffer, const Selection& selection,
LineCount end_line = line + 1; LineCount end_line = line + 1;
if (flags & ObjectFlags::ToEnd) if (flags & ObjectFlags::ToEnd)
{ {
LineCount end = buffer.line_count(); const LineCount end = buffer.line_count();
while (end_line < end and (buffer[end_line] == "\n" or get_indent(buffer[end_line], tabstop) >= indent)) while (end_line < end and (buffer[end_line] == "\n" or get_indent(buffer[end_line], tabstop) >= indent))
++end_line; ++end_line;
} }
--end_line; --end_line;
ByteCoord first = begin_line; // remove only whitespaces lines in inner mode
// keep the first line indent in inner mode
if (flags & ObjectFlags::Inner) if (flags & ObjectFlags::Inner)
{ {
CharCount i = 0; while (begin_line < end_line and
for (; i < indent; ++first.column) is_only_whitespaces(buffer[begin_line]))
{ ++begin_line;
auto c = buffer.byte_at(first); while (begin_line < end_line and
if (c == ' ') is_only_whitespaces(buffer[end_line]))
++i; --end_line;
if (c == '\t')
i = (i / tabstop + 1) * tabstop;
} }
} return Selection{begin_line, {end_line, buffer[end_line].length() - 1}};
return Selection{first, {end_line, buffer[end_line].length() - 1}};
} }
Selection select_whole_lines(const Buffer& buffer, const Selection& selection) Selection select_lines(const Buffer& buffer, const Selection& selection)
{ {
// no need to be utf8 aware for is_eol as we only use \n as line seperator // no need to be utf8 aware for is_eol as we only use \n as line seperator
BufferIterator first = buffer.iterator_at(selection.anchor()); BufferIterator first = buffer.iterator_at(selection.anchor());
@ -415,7 +419,7 @@ Selection select_whole_lines(const Buffer& buffer, const Selection& selection)
Selection trim_partial_lines(const Buffer& buffer, const Selection& selection) Selection trim_partial_lines(const Buffer& buffer, const Selection& selection)
{ {
// same as select_whole_lines // same as select_lines
BufferIterator first = buffer.iterator_at(selection.anchor()); BufferIterator first = buffer.iterator_at(selection.anchor());
BufferIterator last = buffer.iterator_at(selection.cursor()); BufferIterator last = buffer.iterator_at(selection.cursor());
BufferIterator& to_line_start = first <= last ? first : last; BufferIterator& to_line_start = first <= last ? first : last;
@ -429,7 +433,7 @@ Selection trim_partial_lines(const Buffer& buffer, const Selection& selection)
return Selection(first.coord(), last.coord()); return Selection(first.coord(), last.coord());
} }
void select_whole_buffer(SelectionList& selections) void select_buffer(SelectionList& selections)
{ {
auto& buffer = selections.buffer(); auto& buffer = selections.buffer();
selections = SelectionList{ buffer, Selection({0,0}, buffer.back_coord()) }; selections = SelectionList{ buffer, Selection({0,0}, buffer.back_coord()) };

View File

@ -159,7 +159,7 @@ constexpr ObjectFlags operator|(ObjectFlags lhs, ObjectFlags rhs)
{ return (ObjectFlags)((int)lhs | (int) rhs); } { return (ObjectFlags)((int)lhs | (int) rhs); }
template<WordType word_type> template<WordType word_type>
Selection select_whole_word(const Buffer& buffer, const Selection& selection, ObjectFlags flags) Selection select_word(const Buffer& buffer, const Selection& selection, ObjectFlags flags)
{ {
Utf8Iterator first = buffer.iterator_at(selection.cursor()); Utf8Iterator first = buffer.iterator_at(selection.cursor());
Utf8Iterator last = first; Utf8Iterator last = first;
@ -200,16 +200,24 @@ Selection select_whole_word(const Buffer& buffer, const Selection& selection, Ob
: utf8_range(last, first); : utf8_range(last, first);
} }
Selection select_whole_sentence(const Buffer& buffer, const Selection& selection, Selection select_sentence(const Buffer& buffer,
const Selection& selection,
ObjectFlags flags); ObjectFlags flags);
Selection select_whole_paragraph(const Buffer& buffer, const Selection& selection,
Selection select_paragraph(const Buffer& buffer,
const Selection& selection,
ObjectFlags flags); ObjectFlags flags);
Selection select_whole_indent(const Buffer& buffer, const Selection& selection,
Selection select_indent(const Buffer& buffer,
const Selection& selection,
ObjectFlags flags); ObjectFlags flags);
Selection select_whole_lines(const Buffer& buffer, const Selection& selection);
void select_whole_buffer(SelectionList& selections); Selection select_lines(const Buffer& buffer, const Selection& selection);
Selection trim_partial_lines(const Buffer& buffer, const Selection& selection); Selection trim_partial_lines(const Buffer& buffer, const Selection& selection);
void select_buffer(SelectionList& selections);
enum Direction { Forward, Backward }; enum Direction { Forward, Backward };
using MatchResults = boost::match_results<BufferIterator>; using MatchResults = boost::match_results<BufferIterator>;