summaryrefslogtreecommitdiff
path: root/src/buffer.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2014-12-17 13:56:45 +0000
committerMaxime Coste <frrrwww@gmail.com>2014-12-17 13:56:45 +0000
commit5f3a477277828f3c698dd844c8df3614b55dd85b (patch)
tree3ec08c340e60b781d3231ee53928ec2536f7aec3 /src/buffer.cc
parent3b9f40fd5876ab63db2273a1298a2de123c92af5 (diff)
Add support for BufInsert/BufErase hooks
Diffstat (limited to 'src/buffer.cc')
-rw-r--r--src/buffer.cc19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/buffer.cc b/src/buffer.cc
index df427e60..9bc6c6a6 100644
--- a/src/buffer.cc
+++ b/src/buffer.cc
@@ -374,6 +374,11 @@ void Buffer::apply_modification(const Modification& modification)
}
}
+static String change_spec(ByteCoord coord, ByteCount len)
+{
+ return to_string(coord.line) + "." + to_string(coord.column) + "+" + to_string(len);
+}
+
BufferIterator Buffer::insert(const BufferIterator& pos, StringView content)
{
kak_assert(is_valid(pos.coord()));
@@ -391,7 +396,11 @@ BufferIterator Buffer::insert(const BufferIterator& pos, StringView content)
auto coord = pos == end() ? ByteCoord{line_count()} : pos.coord();
if (not (m_flags & Flags::NoUndo))
m_current_undo_group.emplace_back(Modification::Insert, coord, real_content);
- return {*this, do_insert(pos.coord(), real_content)};
+ BufferIterator it{*this, do_insert(pos.coord(), real_content)};
+
+ run_hook_in_own_context("BufInsert", change_spec(pos.coord(), real_content.length()));
+
+ return it;
}
BufferIterator Buffer::erase(BufferIterator begin, BufferIterator end)
@@ -406,7 +415,13 @@ BufferIterator Buffer::erase(BufferIterator begin, BufferIterator end)
if (not (m_flags & Flags::NoUndo))
m_current_undo_group.emplace_back(Modification::Erase, begin.coord(),
InternedString(string(begin.coord(), end.coord())));
- return {*this, do_erase(begin.coord(), end.coord())};
+
+ ByteCount len = distance(begin.coord(), end.coord());
+ BufferIterator it{*this, do_erase(begin.coord(), end.coord())};
+
+ run_hook_in_own_context("BufErase", change_spec(begin.coord(), len));
+
+ return it;
}
bool Buffer::is_modified() const