diff options
| author | Maxime Coste <mawww@kakoune.org> | 2024-04-11 11:37:18 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2024-04-12 15:28:40 +1000 |
| commit | 3d7d0fecca885b00a7ae80180ea1841fab2c5993 (patch) | |
| tree | 94218f4a6dab3f448ceaff034e51079a0ecc2e3c /src/context.hh | |
| parent | b1c114bf6d950684df0524e450782a151e6a0323 (diff) | |
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
Diffstat (limited to 'src/context.hh')
| -rw-r--r-- | src/context.hh | 8 |
1 files changed, 7 insertions, 1 deletions
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<void (Context&)>; +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<InputHandler> m_input_handler; SafePtr<Window> m_window; SafePtr<Client> m_client; + std::vector<Scope*> m_local_scopes; class SelectionHistory { public: |
