diff --git a/src/commands.cc b/src/commands.cc index 35f6a593..49373008 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -758,7 +758,7 @@ static constexpr auto hooks = { "BufWritePre", "BufOpenFifo", "BufCloseFifo", "BufReadFifo", "BufSetOption", "InsertBegin", "InsertChar", "InsertDelete", "InsertEnd", "InsertIdle", "InsertKey", "InsertMove", "InsertCompletionHide", "InsertCompletionShow", "InsertCompletionSelect", - "KakBegin", "KakEnd", "FocusIn", "FocusOut", "RuntimeError", "PromptIdle", + "KakBegin", "KakEnd", "FocusIn", "FocusOut", "GlobalSetOption", "RuntimeError", "PromptIdle", "NormalBegin", "NormalEnd", "NormalIdle", "NormalKey", "ModeChange", "RawKey", "WinClose", "WinCreate", "WinDisplay", "WinResize", "WinSetOption", }; diff --git a/src/scope.cc b/src/scope.cc new file mode 100644 index 00000000..f2879356 --- /dev/null +++ b/src/scope.cc @@ -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); +} + +} diff --git a/src/scope.hh b/src/scope.hh index 58cc9477..c4b52586 100644 --- a/src/scope.hh +++ b/src/scope.hh @@ -43,14 +43,17 @@ private: Highlighters m_highlighters; }; -class GlobalScope : public Scope, public Singleton +class GlobalScope : public Scope, public OptionManagerWatcher, public Singleton { public: - GlobalScope() : m_option_registry(m_options) {} + GlobalScope(); + ~GlobalScope(); OptionsRegistry& option_registry() { return m_option_registry; } const OptionsRegistry& option_registry() const { return m_option_registry; } private: + void on_option_changed(const Option& option); + OptionsRegistry m_option_registry; };