diff --git a/src/buffer.cc b/src/buffer.cc index e4084846..f3283d20 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -39,13 +39,13 @@ Buffer::~Buffer() void Buffer::erase(const BufferIterator& begin, const BufferIterator& end) { - append_modification(BufferModification(BufferModification::Erase, - begin, string(begin, end))); + append_modification(Modification(Modification::Erase, begin, + string(begin, end))); } void Buffer::insert(const BufferIterator& position, const BufferString& string) { - append_modification(BufferModification(BufferModification::Insert, position, string)); + append_modification(Modification(Modification::Insert, position, string)); } BufferIterator Buffer::iterator_at(const BufferCoord& line_and_column) const @@ -169,7 +169,7 @@ void Buffer::end_undo_group() m_current_undo_group.clear(); } -BufferModification BufferModification::inverse() const +Modification Modification::inverse() const { Type inverse_type; switch (type) @@ -178,7 +178,7 @@ BufferModification BufferModification::inverse() const case Erase: inverse_type = Insert; break; default: assert(false); } - return BufferModification(inverse_type, position, content); + return Modification(inverse_type, position, content); } bool Buffer::undo() @@ -188,7 +188,7 @@ bool Buffer::undo() --m_history_cursor; - for (const BufferModification& modification : reversed(*m_history_cursor)) + for (const Modification& modification : reversed(*m_history_cursor)) apply_modification(modification.inverse()); } @@ -197,21 +197,21 @@ bool Buffer::redo() if (m_history_cursor == m_history.end()) return false; - for (const BufferModification& modification : *m_history_cursor) + for (const Modification& modification : *m_history_cursor) apply_modification(modification); ++m_history_cursor; } -void Buffer::apply_modification(const BufferModification& modification) +void Buffer::apply_modification(const Modification& modification) { switch (modification.type) { - case BufferModification::Insert: + case Modification::Insert: m_content.insert(modification.position.m_position, modification.content); break; - case BufferModification::Erase: + case Modification::Erase: { size_t size = modification.content.size(); assert(string(modification.position, modification.position + size) @@ -227,7 +227,7 @@ void Buffer::apply_modification(const BufferModification& modification) listener->on_modification(modification); } -void Buffer::append_modification(BufferModification&& modification) +void Buffer::append_modification(Modification&& modification) { for (auto filter : m_filters) filter.second(*this, modification); @@ -265,14 +265,14 @@ void Buffer::notify_saved() m_last_save_undo_index = history_cursor_index; } -void Buffer::register_modification_listener(BufferModificationListener* listener) +void Buffer::register_modification_listener(ModificationListener* listener) { assert(listener); assert(not contains(m_modification_listeners, listener)); m_modification_listeners.push_back(listener); } -void Buffer::unregister_modification_listener(BufferModificationListener* listener) +void Buffer::unregister_modification_listener(ModificationListener* listener) { assert(listener); auto it = std::find(m_modification_listeners.begin(), diff --git a/src/buffer.hh b/src/buffer.hh index 96353cee..4ac11627 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -77,7 +77,7 @@ private: friend class Buffer; }; -struct BufferModification +struct Modification { enum Type { Insert, Erase }; @@ -85,17 +85,17 @@ struct BufferModification BufferIterator position; BufferString content; - BufferModification(Type type, BufferIterator position, + Modification(Type type, BufferIterator position, BufferString content) : type(type), position(position), content(content) {} - BufferModification inverse() const; + Modification inverse() const; }; -class BufferModificationListener +class ModificationListener { public: - virtual void on_modification(const BufferModification& modification) = 0; + virtual void on_modification(const Modification& modification) = 0; }; class Buffer @@ -151,8 +151,8 @@ public: Type type() const { return m_type; } void notify_saved(); - void register_modification_listener(BufferModificationListener* listener); - void unregister_modification_listener(BufferModificationListener* listener); + void register_modification_listener(ModificationListener* listener); + void unregister_modification_listener(ModificationListener* listener); struct filter_id_not_unique : public runtime_error { @@ -191,22 +191,22 @@ private: std::string m_name; const Type m_type; - typedef std::vector UndoGroup; + typedef std::vector UndoGroup; std::vector m_history; std::vector::iterator m_history_cursor; UndoGroup m_current_undo_group; - void apply_modification(const BufferModification& modification); - void revert_modification(const BufferModification& modification); + void apply_modification(const Modification& modification); + void revert_modification(const Modification& modification); - void append_modification(BufferModification&& modification); + void append_modification(Modification&& modification); std::list> m_windows; size_t m_last_save_undo_index; - std::vector m_modification_listeners; + std::vector m_modification_listeners; idvaluemap m_filters; }; diff --git a/src/dynamic_buffer_iterator.cc b/src/dynamic_buffer_iterator.cc index e434ded6..363207e4 100644 --- a/src/dynamic_buffer_iterator.cc +++ b/src/dynamic_buffer_iterator.cc @@ -36,13 +36,13 @@ DynamicBufferIterator::~DynamicBufferIterator() unregister_ifn(); } -void DynamicBufferIterator::on_modification(const BufferModification& modification) +void DynamicBufferIterator::on_modification(const Modification& modification) { if (*this < modification.position) return; size_t length = modification.content.length(); - if (modification.type == BufferModification::Erase) + if (modification.type == Modification::Erase) { // do not move length on the other side of the inequality, // as modification.position + length may be after buffer end @@ -53,7 +53,7 @@ void DynamicBufferIterator::on_modification(const BufferModification& modificati } else { - assert(modification.type == BufferModification::Insert); + assert(modification.type == Modification::Insert); *this += length; } } diff --git a/src/dynamic_buffer_iterator.hh b/src/dynamic_buffer_iterator.hh index 17e74485..873792bd 100644 --- a/src/dynamic_buffer_iterator.hh +++ b/src/dynamic_buffer_iterator.hh @@ -7,7 +7,7 @@ namespace Kakoune { class DynamicBufferIterator : public BufferIterator, - public BufferModificationListener + public ModificationListener { public: DynamicBufferIterator() : BufferIterator() {} @@ -22,7 +22,7 @@ public: { return this->operator= (static_cast(other)); } ~DynamicBufferIterator(); - void on_modification(const BufferModification& modification); + void on_modification(const Modification& modification); private: void register_ifp(); diff --git a/src/filter.hh b/src/filter.hh index 3368ee5c..4999b895 100644 --- a/src/filter.hh +++ b/src/filter.hh @@ -8,9 +8,9 @@ namespace Kakoune { class Buffer; -class BufferModification; +class Modification; -typedef std::function FilterFunc; +typedef std::function FilterFunc; typedef std::pair FilterAndId; } diff --git a/src/filters.cc b/src/filters.cc index 9420fef9..947725cb 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -5,9 +5,9 @@ namespace Kakoune { -void preserve_indent(Buffer& buffer, BufferModification& modification) +void preserve_indent(Buffer& buffer, Modification& modification) { - if (modification.type == BufferModification::Insert and + if (modification.type == Modification::Insert and modification.content == "\n") { BufferIterator line_begin = buffer.iterator_at_line_begin(modification.position - 1); @@ -20,10 +20,10 @@ void preserve_indent(Buffer& buffer, BufferModification& modification) } } -void expand_tabulations(Buffer& buffer, BufferModification& modification) +void expand_tabulations(Buffer& buffer, Modification& modification) { const int tabstop = 8; - if (modification.type == BufferModification::Insert and + if (modification.type == Modification::Insert and modification.content == "\t") { int column = 0; @@ -43,7 +43,7 @@ void expand_tabulations(Buffer& buffer, BufferModification& modification) } } -template +template class SimpleFilterFactory { public: