From 3d7d0fecca885b00a7ae80180ea1841fab2c5993 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 11 Apr 2024 11:37:18 +1000 Subject: Introduce "local" scope in evaluate-commands When using `eval` a new scope named 'local' gets pushed for the whole evaluation, this makes it possible to temporarily set an option/hook/alias... Local scopes nest so nested evals do work as expected. Remove the now trivial with-option command --- src/context.hh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/context.hh') diff --git a/src/context.hh b/src/context.hh index 7834bde4..7ff4166e 100644 --- a/src/context.hh +++ b/src/context.hh @@ -42,6 +42,8 @@ private: using LastSelectFunc = std::function; +struct LocalScope; + // A Context is used to access non singleton objects for various services // in commands. // @@ -97,7 +99,10 @@ public: void set_client(Client& client); void set_window(Window& window); - Scope& scope() const; + friend struct LocalScope; + + Scope& scope(bool allow_local = true) const; + Scope* local_scope() const { return m_local_scopes.empty() ? nullptr : m_local_scopes.back(); } OptionManager& options() const { return scope().options(); } HookManager& hooks() const { return scope().hooks(); } @@ -155,6 +160,7 @@ private: SafePtr m_input_handler; SafePtr m_window; SafePtr m_client; + std::vector m_local_scopes; class SelectionHistory { public: -- cgit v1.2.3