From db5050fab0718d9f446a9af3f4507e30b29bbc83 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 12 Nov 2013 20:36:42 +0000 Subject: [PATCH] Add BufSetOption hook support --- src/buffer.cc | 12 ++++++++++++ src/buffer.hh | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/buffer.cc b/src/buffer.cc index 1d9c9baa..2422e7ac 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -25,6 +25,7 @@ Buffer::Buffer(String name, Flags flags, std::vector lines, m_keymaps(GlobalKeymaps::instance()) { BufferManager::instance().register_buffer(*this); + m_options.register_watcher(*this); if (lines.empty()) lines.emplace_back("\n"); @@ -55,6 +56,9 @@ Buffer::Buffer(String name, Flags flags, std::vector lines, // now we may begin to record undo data m_flags = flags; + + for (auto& option : m_options.flatten_options()) + on_option_changed(*option); } Buffer::~Buffer() @@ -65,6 +69,7 @@ Buffer::~Buffer() m_hooks.run_hook("BufClose", m_name, hook_context); } + m_options.unregister_watcher(*this); BufferManager::instance().unregister_buffer(*this); kak_assert(m_change_listeners.empty()); } @@ -754,4 +759,11 @@ void Buffer::set_fs_timestamp(time_t ts) m_fs_timestamp = ts; } +void Buffer::on_option_changed(const Option& option) +{ + String desc = option.name() + "=" + option.get_as_string(); + Editor hook_editor{*this}; + Context hook_context{hook_editor}; + m_hooks.run_hook("BufSetOption", desc, hook_context); +} } diff --git a/src/buffer.hh b/src/buffer.hh index 8727d217..5d4abda4 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -81,7 +81,7 @@ public: // The Buffer class permits to read and mutate this file // representation. It also manage modifications undo/redo and // provides tools to deal with the line/column nature of text. -class Buffer : public SafeCountable +class Buffer : public SafeCountable, public OptionManagerWatcher { public: enum class Flags @@ -170,6 +170,9 @@ public: void check_invariant() const; private: + + void on_option_changed(const Option& option) override; + struct Line { ByteCount start;