Allow macros to call other macros, only recursive macro calls are forbidden
This commit is contained in:
parent
c3d53d588d
commit
48f98eae97
|
@ -661,19 +661,19 @@ void start_or_end_macro_recording(Context& context)
|
||||||
|
|
||||||
void replay_macro(Context& context)
|
void replay_macro(Context& context)
|
||||||
{
|
{
|
||||||
static bool running_macro = false;
|
|
||||||
if (running_macro)
|
|
||||||
throw runtime_error("nested macros not supported");
|
|
||||||
|
|
||||||
int count = context.numeric_param();
|
int count = context.numeric_param();
|
||||||
context.input_handler().on_next_key([count](const Key& key, Context& context) mutable {
|
context.input_handler().on_next_key([count](const Key& key, Context& context) mutable {
|
||||||
if (key.modifiers == Key::Modifiers::None)
|
if (key.modifiers == Key::Modifiers::None)
|
||||||
{
|
{
|
||||||
|
static std::unordered_set<char> running_macros;
|
||||||
|
if (contains(running_macros, key.key))
|
||||||
|
throw runtime_error("recursive macros call detected");
|
||||||
|
|
||||||
memoryview<String> reg_val = RegisterManager::instance()[key.key].values(context);
|
memoryview<String> reg_val = RegisterManager::instance()[key.key].values(context);
|
||||||
if (not reg_val.empty())
|
if (not reg_val.empty())
|
||||||
{
|
{
|
||||||
running_macro = true;
|
running_macros.insert(key.key);
|
||||||
auto stop_macro = on_scope_end([&] { running_macro = false; });
|
auto stop = on_scope_end([&]{ running_macros.erase(key.key); });
|
||||||
|
|
||||||
auto keys = parse_keys(reg_val[0]);
|
auto keys = parse_keys(reg_val[0]);
|
||||||
scoped_edition edition(context.editor());
|
scoped_edition edition(context.editor());
|
||||||
|
|
Loading…
Reference in New Issue
Block a user