diff --git a/src/buffer.cc b/src/buffer.cc index e0c4c3ffc..8e63350b9 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -108,30 +108,6 @@ BufferCoord Buffer::clamp(BufferCoord coord) const return coord; } -BufferIterator Buffer::iterator_at_line_begin(LineCount line) const -{ - line = Kakoune::clamp(line, 0_line, line_count()-1); - kak_assert(line_length(line) > 0); - return BufferIterator(*this, { line, 0 }); -} - -BufferIterator Buffer::iterator_at_line_begin(const BufferIterator& iterator) const -{ - return iterator_at_line_begin(iterator.line()); -} - -BufferIterator Buffer::iterator_at_line_end(LineCount line) const -{ - line = Kakoune::clamp(line, 0_line, line_count()-1); - kak_assert(line_length(line) > 0); - return ++BufferIterator(*this, { line, line_length(line) - 1 }); -} - -BufferIterator Buffer::iterator_at_line_end(const BufferIterator& iterator) const -{ - return iterator_at_line_end(iterator.line()); -} - BufferIterator Buffer::begin() const { return BufferIterator(*this, { 0_line, 0 }); @@ -729,8 +705,7 @@ bool Buffer::is_valid(const BufferCoord& c) const bool Buffer::is_end(const BufferCoord& c) const { - return (c.line == line_count() and c.column == 0) or - (c.line == line_count() - 1 and c.column == m_lines.back().length()); + return c >= BufferCoord{line_count() - 1, m_lines.back().length()}; } char Buffer::byte_at(const BufferCoord& c) const diff --git a/src/buffer.hh b/src/buffer.hh index a1ea0dbe5..3da319525 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -151,19 +151,6 @@ public: // returns nearest valid coordinates from given ones BufferCoord clamp(BufferCoord coord) const; - // returns an iterator pointing to the first character of the line - // iterator is on - BufferIterator iterator_at_line_begin(const BufferIterator& iterator) const; - // the same but taking a line number instead of an iterator - BufferIterator iterator_at_line_begin(LineCount line) const; - - // returns an iterator pointing to the character after the last of the - // line iterator is on (which is the first of the next line if iterator is - // not on the last one) - BufferIterator iterator_at_line_end(const BufferIterator& iterator) const; - // the same but taking a line number instead of an iterator - BufferIterator iterator_at_line_end(LineCount line) const; - const String& name() const { return m_name; } String display_name() const; diff --git a/src/filters.cc b/src/filters.cc index 53f6576dd..a35a45024 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -42,7 +42,7 @@ void expand_tabulations(Buffer& buffer, Selection& selection, String& content) { int column = 0; const auto position = buffer.iterator_at(selection.last()); - for (auto it = buffer.iterator_at_line_begin(position); + for (auto it = buffer.iterator_at(position.line()); it != position; ++it) { kak_assert(*it != '\n'); @@ -67,7 +67,7 @@ struct RegexFilter void operator() (Buffer& buffer, Selection& selection, String& content) { const auto position = buffer.iterator_at(selection.last()); - auto line_begin = buffer.iterator_at_line_begin(position); + auto line_begin = buffer.iterator_at(position.line()); boost::match_results results; if (boost::regex_match(content.c_str(), m_insert_match) and boost::regex_match(line_begin, position, results, m_line_match)) diff --git a/src/highlighters.cc b/src/highlighters.cc index 064c16605..8e56c8ebd 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -235,7 +235,7 @@ void expand_tabulations(const Window& window, DisplayBuffer& display_buffer) atom_it = line.split(atom_it, (it+1).coord()); int column = 0; - for (auto line_it = buffer.iterator_at_line_begin(it); + for (auto line_it = buffer.iterator_at(it.line()); line_it != it; ++line_it) { kak_assert(*line_it != '\n'); diff --git a/src/normal.cc b/src/normal.cc index 65347c483..bd3bf3c73 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -92,7 +92,7 @@ void goto_commands(Context& context) { context.push_jump(); const Buffer& buf = editor.buffer(); - editor.select(buf.iterator_at_line_begin(buf.line_count() - 1), mode); + editor.select(buf.iterator_at(buf.line_count() - 1), mode); break; } case 'e': @@ -103,7 +103,7 @@ void goto_commands(Context& context) if (context.has_window()) { auto line = context.window().position().line; - editor.select(editor.buffer().iterator_at_line_begin(line), mode); + editor.select(editor.buffer().iterator_at(line), mode); } break; case 'b': @@ -111,7 +111,7 @@ void goto_commands(Context& context) { auto& window = context.window(); auto line = window.position().line + window.dimensions().line - 1; - editor.select(editor.buffer().iterator_at_line_begin(line), mode); + editor.select(editor.buffer().iterator_at(line), mode); } break; case 'c': @@ -119,7 +119,7 @@ void goto_commands(Context& context) { auto& window = context.window(); auto line = window.position().line + window.dimensions().line / 2; - editor.select(editor.buffer().iterator_at_line_begin(line), mode); + editor.select(editor.buffer().iterator_at(line), mode); } break; case 'a': @@ -608,8 +608,8 @@ void scroll(Context& context) position.line += (window.dimensions().line - 2); cursor_line = position.line + window.dimensions().line - 1; } - auto cursor_pos = utf8::advance(buffer.iterator_at_line_begin(position.line), - buffer.iterator_at_line_end(position.line), + auto cursor_pos = utf8::advance(buffer.iterator_at(position.line), + buffer.iterator_at(position.line+1), position.column); window.select(cursor_pos); window.set_position(position); diff --git a/src/unit_tests.cc b/src/unit_tests.cc index 789e9c79c..90c707c62 100644 --- a/src/unit_tests.cc +++ b/src/unit_tests.cc @@ -68,7 +68,7 @@ void test_editor() } editor.undo(); - Selection sel{ buffer.iterator_at_line_begin(2_line), buffer.end()-1 }; + Selection sel{ buffer.iterator_at(2_line), buffer.end()-1 }; editor.select(sel, SelectMode::Replace); editor.insert("",InsertMode::Replace); kak_assert(not buffer.is_end(editor.main_selection().first()));