diff --git a/src/lay/lay/layApplication.cc b/src/lay/lay/layApplication.cc index b3fb02ce6..89433d867 100644 --- a/src/lay/lay/layApplication.cc +++ b/src/lay/lay/layApplication.cc @@ -835,7 +835,7 @@ ApplicationBase::init_app () mc->finish (); // as this regenerates the macro collection, autorun_early is required again - // note: this does no re-execute macros that have been executed already + // note: this does not re-execute macros that have been executed already lym::MacroCollection::root ().autorun_early (); } diff --git a/src/lay/lay/layMacroController.cc b/src/lay/lay/layMacroController.cc index e3f3dbb76..2eb517e76 100644 --- a/src/lay/lay/layMacroController.cc +++ b/src/lay/lay/layMacroController.cc @@ -62,13 +62,15 @@ MacroController::add_macro_category (const std::string &name, const std::string void MacroController::finish () { - lym::MacroCollection::root ().clear (); + lym::MacroCollection &root = lym::MacroCollection::root (); + + root.clear (); // Scan built-in macros // These macros are always taken, even if there are no macros requested (they are required to // fully form the API). - lym::MacroCollection::root ().add_folder (tl::to_string (QObject::tr ("Built-In")), ":/built-in-macros", "macros", true); - lym::MacroCollection::root ().add_folder (tl::to_string (QObject::tr ("Built-In")), ":/built-in-pymacros", "pymacros", true); + root.add_folder (tl::to_string (QObject::tr ("Built-In")), ":/built-in-macros", "macros", true); + root.add_folder (tl::to_string (QObject::tr ("Built-In")), ":/built-in-pymacros", "pymacros", true); // scans the macros from techs and packages (this will allow autorun-early on them) // and updates m_external_paths @@ -92,13 +94,13 @@ MacroController::finish () description += " - " + tl::to_string (tr ("%1 branch").arg (tl::to_qstring (*f))); } - lym::MacroCollection::root ().add_folder (description, mp, m_macro_categories[c].name, p->readonly); + root.add_folder (description, mp, m_macro_categories[c].name, p->readonly); } } else if (p->cat == m_macro_categories[c].name) { - lym::MacroCollection::root ().add_folder (p->description, p->path, m_macro_categories[c].name, p->readonly); + root.add_folder (p->description, p->path, m_macro_categories[c].name, p->readonly); } @@ -121,7 +123,7 @@ MacroController::finish () if (! m_no_implicit_macros) { for (std::vector ::const_iterator p = m_external_paths.begin (); p != m_external_paths.end (); ++p) { - lym::MacroCollection *mc = lym::MacroCollection::root ().add_folder (p->description, p->path, p->cat, p->readonly); + lym::MacroCollection *mc = root.add_folder (p->description, p->path, p->cat, p->readonly); if (mc) { mc->set_virtual_mode (p->type); } diff --git a/src/lym/lym/gsiDeclLymMacro.cc b/src/lym/lym/gsiDeclLymMacro.cc index 28e1ac4d7..4555c562e 100644 --- a/src/lym/lym/gsiDeclLymMacro.cc +++ b/src/lym/lym/gsiDeclLymMacro.cc @@ -123,6 +123,14 @@ public: void register_gsi (const char *name) { + // do not register an interpreter again (this is important as registration code + // may be executed again and we do not want to have two interpreters for the same thing) + for (tl::Registrar::iterator cls = tl::Registrar::begin (); cls != tl::Registrar::end (); ++cls) { + if (cls.current_name () == name) { + return; + } + } + // makes the object owned by the C++ side keep (); @@ -220,6 +228,16 @@ public: m->set_interpreter (lym::Macro::DSLInterpreter); m->set_format (storage_scheme ()); + // avoid registering the same template twice + for (auto t = m_templates.begin (); t != m_templates.end (); ++t) { + if ((*t)->path () == m->path ()) { + delete *t; + *t = m; + return m; + } + } + + // not present yet - install at end m_templates.push_back (m); return m; }