From: Richard Kimberly Heck Date: Fri, 13 Nov 2020 00:10:24 +0000 (-0500) Subject: Send all updateMacro stuff through the insets. X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=57a225a6cb682b90fdcaa89d3eb4682ada246c31;p=features.git Send all updateMacro stuff through the insets. --- diff --git a/src/Buffer.cpp b/src/Buffer.cpp index c0a133fadd..f4b513c69a 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -3760,98 +3760,7 @@ MacroData const * Buffer::getMacro(docstring const & name, void Buffer::Impl::updateMacros(DocIterator & it, DocIterator & scope) { - pit_type const lastpit = it.lastpit(); - - // look for macros in each paragraph - while (it.pit() <= lastpit) { - Paragraph & par = it.paragraph(); - - // iterate over the insets of the current paragraph - for (auto const & insit : par.insetList()) { - it.pos() = insit.pos; - - if (InsetText const * itext = insit.inset->asInsetText()) { - // collect macros in inset - it.push_back(CursorSlice(*insit.inset)); - if (itext->producesOutput()) { - // the simple case - updateMacros(it, scope); - } else { - // We don't want macros declared in notes, comments, etc, - // to affect anything outside them. - // New scope which ends just behind the inset - DocIterator new_scope = it; - ++new_scope.pos(); - updateMacros(it, new_scope); - } - it.pop_back(); - continue; - } - - if (insit.inset->asInsetTabular()) { - CursorSlice slice(*insit.inset); - size_t const numcells = slice.nargs(); - for (; slice.idx() < numcells; slice.forwardIdx()) { - it.push_back(slice); - updateMacros(it, scope); - it.pop_back(); - } - continue; - } - - // is it an external file? - if (insit.inset->lyxCode() == INCLUDE_CODE) { - // get buffer of external file - InsetInclude const & incinset = - static_cast(*insit.inset); - macro_lock = true; - Buffer * child = incinset.loadIfNeeded(); - macro_lock = false; - if (!child) - continue; - - // register its position, but only when it is - // included first in the buffer - children_positions.insert({child, it}); - - // register child with its scope - position_to_children[it] = Impl::ScopeBuffer(scope, child); - continue; - } - - InsetMath * im = insit.inset->asInsetMath(); - if (doing_export && im) { - InsetMathHull * hull = im->asHullInset(); - if (hull) - hull->recordLocation(it); - } - - if (insit.inset->lyxCode() != MATHMACRO_CODE) - continue; - - // get macro data - InsetMathMacroTemplate & macroTemplate = - *insit.inset->asInsetMath()->asMacroTemplate(); - MacroContext mc(owner_, it); - macroTemplate.updateToContext(mc); - - // valid? - bool valid = macroTemplate.validMacro(); - // FIXME: Should be fixNameAndCheckIfValid() in fact, - // then the BufferView's cursor will be invalid in - // some cases which leads to crashes. - if (!valid) - continue; - - // register macro - macro_table.addMacroDefinition(macroTemplate.name(), it, scope, - MacroData(const_cast(owner_), it)); - } - - // next paragraph - it.pit()++; - it.pos() = 0; - } + owner_->inset().updateMacros(it, scope); }