From 1b1031627ca9626b3a40d746d9ef3be7891729cb Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 11 Dec 2013 13:57:10 +0000 Subject: [PATCH] Add Buffer::run_hook_in_own_context helper method --- src/buffer.cc | 22 ++++++++++++---------- src/buffer.hh | 2 ++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/buffer.cc b/src/buffer.cc index 294ea74a..3f6fdadd 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -45,15 +45,15 @@ Buffer::Buffer(String name, Flags flags, std::vector lines, if (flags & Flags::File) { if (flags & Flags::New) - m_hooks.run_hook("BufNew", m_name, hook_handler.context()); + run_hook_in_own_context("BufNew", m_name); else { kak_assert(m_fs_timestamp != InvalidTime); - m_hooks.run_hook("BufOpen", m_name, hook_handler.context()); + run_hook_in_own_context("BufOpen", m_name); } } - m_hooks.run_hook("BufCreate", m_name, hook_handler.context()); + run_hook_in_own_context("BufCreate", m_name); // now we may begin to record undo data m_flags = flags; @@ -64,11 +64,7 @@ Buffer::Buffer(String name, Flags flags, std::vector lines, Buffer::~Buffer() { - { - Editor hook_editor{*this}; - InputHandler hook_handler(hook_editor); - m_hooks.run_hook("BufClose", m_name, hook_handler.context()); - } + run_hook_in_own_context("BufClose", m_name); m_options.unregister_watcher(*this); BufferManager::instance().unregister_buffer(*this); @@ -762,9 +758,15 @@ void Buffer::set_fs_timestamp(time_t ts) void Buffer::on_option_changed(const Option& option) { - String desc = option.name() + "=" + option.get_as_string(); + run_hook_in_own_context("BufSetOption", + option.name() + "=" + option.get_as_string()); +} + +void Buffer::run_hook_in_own_context(const String& hook_name, const String& param) +{ Editor hook_editor{*this}; InputHandler hook_handler(hook_editor); - m_hooks.run_hook("BufSetOption", desc, hook_handler.context()); + m_hooks.run_hook(hook_name, param, hook_handler.context()); } + } diff --git a/src/buffer.hh b/src/buffer.hh index 5d4abda4..7f8ef25e 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -164,6 +164,8 @@ public: KeymapManager& keymaps() { return m_keymaps; } const KeymapManager& keymaps() const { return m_keymaps; } + void run_hook_in_own_context(const String& hook_name, const String& param); + std::unordered_set& change_listeners() const { return m_change_listeners; } void reload(std::vector lines, time_t fs_timestamp = InvalidTime);