Add a GlobalSetOption hook
This commit is contained in:
parent
56e005e996
commit
07113e7ee5
|
@ -758,7 +758,7 @@ static constexpr auto hooks = {
|
||||||
"BufWritePre", "BufOpenFifo", "BufCloseFifo", "BufReadFifo", "BufSetOption",
|
"BufWritePre", "BufOpenFifo", "BufCloseFifo", "BufReadFifo", "BufSetOption",
|
||||||
"InsertBegin", "InsertChar", "InsertDelete", "InsertEnd", "InsertIdle", "InsertKey",
|
"InsertBegin", "InsertChar", "InsertDelete", "InsertEnd", "InsertIdle", "InsertKey",
|
||||||
"InsertMove", "InsertCompletionHide", "InsertCompletionShow", "InsertCompletionSelect",
|
"InsertMove", "InsertCompletionHide", "InsertCompletionShow", "InsertCompletionSelect",
|
||||||
"KakBegin", "KakEnd", "FocusIn", "FocusOut", "RuntimeError", "PromptIdle",
|
"KakBegin", "KakEnd", "FocusIn", "FocusOut", "GlobalSetOption", "RuntimeError", "PromptIdle",
|
||||||
"NormalBegin", "NormalEnd", "NormalIdle", "NormalKey", "ModeChange", "RawKey",
|
"NormalBegin", "NormalEnd", "NormalIdle", "NormalKey", "ModeChange", "RawKey",
|
||||||
"WinClose", "WinCreate", "WinDisplay", "WinResize", "WinSetOption",
|
"WinClose", "WinCreate", "WinDisplay", "WinResize", "WinSetOption",
|
||||||
};
|
};
|
||||||
|
|
26
src/scope.cc
Normal file
26
src/scope.cc
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#include "scope.hh"
|
||||||
|
#include "context.hh"
|
||||||
|
|
||||||
|
namespace Kakoune
|
||||||
|
{
|
||||||
|
|
||||||
|
GlobalScope::GlobalScope()
|
||||||
|
: m_option_registry(m_options)
|
||||||
|
{
|
||||||
|
options().register_watcher(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
GlobalScope::~GlobalScope()
|
||||||
|
{
|
||||||
|
options().unregister_watcher(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalScope::on_option_changed(const Option& option)
|
||||||
|
{
|
||||||
|
Context empty_context{Context::EmptyContextFlag{}};
|
||||||
|
hooks().run_hook("GlobalSetOption",
|
||||||
|
format("{}={}", option.name(), option.get_as_string()),
|
||||||
|
empty_context);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -43,14 +43,17 @@ private:
|
||||||
Highlighters m_highlighters;
|
Highlighters m_highlighters;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GlobalScope : public Scope, public Singleton<GlobalScope>
|
class GlobalScope : public Scope, public OptionManagerWatcher, public Singleton<GlobalScope>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GlobalScope() : m_option_registry(m_options) {}
|
GlobalScope();
|
||||||
|
~GlobalScope();
|
||||||
|
|
||||||
OptionsRegistry& option_registry() { return m_option_registry; }
|
OptionsRegistry& option_registry() { return m_option_registry; }
|
||||||
const OptionsRegistry& option_registry() const { return m_option_registry; }
|
const OptionsRegistry& option_registry() const { return m_option_registry; }
|
||||||
private:
|
private:
|
||||||
|
void on_option_changed(const Option& option);
|
||||||
|
|
||||||
OptionsRegistry m_option_registry;
|
OptionsRegistry m_option_registry;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user