Hooks now takes a non-const context
This commit is contained in:
parent
bdc47ddef8
commit
621be2ceab
|
@ -49,7 +49,11 @@ Buffer::Buffer(String name, Flags flags, std::vector<String> lines)
|
|||
|
||||
Buffer::~Buffer()
|
||||
{
|
||||
m_hooks.run_hook("BufClose", m_name, Context(Editor(*this)));
|
||||
{
|
||||
Editor hook_editor{*this};
|
||||
Context hook_context{hook_editor};
|
||||
m_hooks.run_hook("BufClose", m_name, hook_context);
|
||||
}
|
||||
|
||||
BufferManager::instance().unregister_buffer(*this);
|
||||
assert(m_change_listeners.empty());
|
||||
|
|
|
@ -344,12 +344,9 @@ void add_hook(const CommandParameters& params, Context& context)
|
|||
// copy so that the lambda gets a copy as well
|
||||
Regex regex(params[2].begin(), params[2].end());
|
||||
String command = params[3];
|
||||
auto hook_func = [=](const String& param, const Context& context) {
|
||||
auto hook_func = [=](const String& param, Context& context) {
|
||||
if (boost::regex_match(param.begin(), param.end(), regex))
|
||||
{
|
||||
Context new_context(context.editor());
|
||||
CommandManager::instance().execute(command, new_context);
|
||||
}
|
||||
CommandManager::instance().execute(command, context);
|
||||
};
|
||||
|
||||
const String& scope = params[0];
|
||||
|
|
|
@ -10,7 +10,7 @@ void HookManager::add_hook(const String& hook_name, HookFunc hook)
|
|||
|
||||
void HookManager::run_hook(const String& hook_name,
|
||||
const String& param,
|
||||
const Context& context) const
|
||||
Context& context) const
|
||||
{
|
||||
if (m_parent)
|
||||
m_parent->run_hook(hook_name, param, context);
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace Kakoune
|
|||
{
|
||||
|
||||
class Context;
|
||||
typedef std::function<void (const String&, const Context&)> HookFunc;
|
||||
typedef std::function<void (const String&, Context&)> HookFunc;
|
||||
|
||||
class HookManager
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ public:
|
|||
|
||||
void add_hook(const String& hook_name, HookFunc hook);
|
||||
void run_hook(const String& hook_name, const String& param,
|
||||
const Context& context) const;
|
||||
Context& context) const;
|
||||
|
||||
private:
|
||||
HookManager()
|
||||
|
|
|
@ -18,7 +18,8 @@ Window::Window(Buffer& buffer)
|
|||
{
|
||||
HighlighterRegistry& registry = HighlighterRegistry::instance();
|
||||
|
||||
m_hooks.run_hook("WinCreate", buffer.name(), Context(*this));
|
||||
Context hook_context{*this};
|
||||
m_hooks.run_hook("WinCreate", buffer.name(), hook_context);
|
||||
m_options.register_watcher(*this);
|
||||
|
||||
m_highlighters.append(registry["expand_tabs"](*this, {}));
|
||||
|
@ -185,7 +186,8 @@ void Window::on_incremental_insertion_end()
|
|||
void Window::on_option_changed(const String& name, const Option& option)
|
||||
{
|
||||
String desc = name + "=" + option.as_string();
|
||||
m_hooks.run_hook("WinSetOption", desc, Context(*this));
|
||||
Context hook_context{*this};
|
||||
m_hooks.run_hook("WinSetOption", desc, hook_context);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user