Add BufSetOption hook support

This commit is contained in:
Maxime Coste 2013-11-12 20:36:42 +00:00
parent bc3c21f436
commit db5050fab0
2 changed files with 16 additions and 1 deletions

View File

@ -25,6 +25,7 @@ Buffer::Buffer(String name, Flags flags, std::vector<String> lines,
m_keymaps(GlobalKeymaps::instance()) m_keymaps(GlobalKeymaps::instance())
{ {
BufferManager::instance().register_buffer(*this); BufferManager::instance().register_buffer(*this);
m_options.register_watcher(*this);
if (lines.empty()) if (lines.empty())
lines.emplace_back("\n"); lines.emplace_back("\n");
@ -55,6 +56,9 @@ Buffer::Buffer(String name, Flags flags, std::vector<String> lines,
// now we may begin to record undo data // now we may begin to record undo data
m_flags = flags; m_flags = flags;
for (auto& option : m_options.flatten_options())
on_option_changed(*option);
} }
Buffer::~Buffer() Buffer::~Buffer()
@ -65,6 +69,7 @@ Buffer::~Buffer()
m_hooks.run_hook("BufClose", m_name, hook_context); m_hooks.run_hook("BufClose", m_name, hook_context);
} }
m_options.unregister_watcher(*this);
BufferManager::instance().unregister_buffer(*this); BufferManager::instance().unregister_buffer(*this);
kak_assert(m_change_listeners.empty()); kak_assert(m_change_listeners.empty());
} }
@ -754,4 +759,11 @@ void Buffer::set_fs_timestamp(time_t ts)
m_fs_timestamp = 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);
}
} }

View File

@ -81,7 +81,7 @@ public:
// The Buffer class permits to read and mutate this file // The Buffer class permits to read and mutate this file
// representation. It also manage modifications undo/redo and // representation. It also manage modifications undo/redo and
// provides tools to deal with the line/column nature of text. // provides tools to deal with the line/column nature of text.
class Buffer : public SafeCountable class Buffer : public SafeCountable, public OptionManagerWatcher
{ {
public: public:
enum class Flags enum class Flags
@ -170,6 +170,9 @@ public:
void check_invariant() const; void check_invariant() const;
private: private:
void on_option_changed(const Option& option) override;
struct Line struct Line
{ {
ByteCount start; ByteCount start;