diff --git a/src/context.hh b/src/context.hh index 85d8bc6d..fb7996f6 100644 --- a/src/context.hh +++ b/src/context.hh @@ -3,6 +3,7 @@ #include "selection.hh" #include "optional.hh" +#include "utils.hh" namespace Kakoune { @@ -16,38 +17,6 @@ class DisplayLine; class KeymapManager; class AliasRegistry; -// bool that can be set (to true) multiple times, and will -// be false only when unset the same time; -struct NestedBool -{ - void set() { m_count++; } - void unset() { kak_assert(m_count > 0); m_count--; } - - operator bool() const { return m_count > 0; } -private: - int m_count = 0; -}; - -struct ScopedSetBool -{ - ScopedSetBool(NestedBool& nested_bool, bool condition = true) - : m_nested_bool(nested_bool), m_condition(condition) - { - if (m_condition) - m_nested_bool.set(); - } - - ~ScopedSetBool() - { - if (m_condition) - m_nested_bool.unset(); - } - -private: - NestedBool& m_nested_bool; - bool m_condition; -}; - struct JumpList { void push(SelectionList jump); diff --git a/src/utils.hh b/src/utils.hh index b56d825f..1966f86b 100644 --- a/src/utils.hh +++ b/src/utils.hh @@ -79,6 +79,38 @@ OnScopeEnd on_scope_end(T t) return OnScopeEnd{std::move(t)}; } +// bool that can be set (to true) multiple times, and will +// be false only when unset the same time; +struct NestedBool +{ + void set() { m_count++; } + void unset() { kak_assert(m_count > 0); m_count--; } + + operator bool() const { return m_count > 0; } +private: + int m_count = 0; +}; + +struct ScopedSetBool +{ + ScopedSetBool(NestedBool& nested_bool, bool condition = true) + : m_nested_bool(nested_bool), m_condition(condition) + { + if (m_condition) + m_nested_bool.set(); + } + + ~ScopedSetBool() + { + if (m_condition) + m_nested_bool.unset(); + } + +private: + NestedBool& m_nested_bool; + bool m_condition; +}; + // *** Misc helper functions *** template