diff --git a/src/Buffer.cpp b/src/Buffer.cpp index ec7431e6fd..05ed24beda 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -634,6 +634,14 @@ bool Buffer::readDocument(Lexer & lex) // read main text bool const res = text().read(*this, lex, errorList, d->inset); + // inform parent buffer about local macros + if (parent()) { + Buffer const * pbuf = parent(); + UserMacroSet::const_iterator cit = usermacros.begin(); + UserMacroSet::const_iterator end = usermacros.end(); + for (; cit != end; ++cit) + pbuf->usermacros.insert(*cit); + } usermacros.clear(); updateMacros(); updateMacroInstances(); diff --git a/src/Buffer.h b/src/Buffer.h index 44ca4d3130..85bc52d157 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -398,7 +398,7 @@ public: /// Collect user macro names at loading time typedef std::set UserMacroSet; - UserMacroSet usermacros; + mutable UserMacroSet usermacros; /// Replace the inset contents for insets which InsetCode is equal /// to the passed \p inset_code. diff --git a/src/factory.cpp b/src/factory.cpp index de7f441b7b..f66bca0c18 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -272,7 +272,7 @@ Inset * createInsetHelper(Buffer & buf, FuncRequest const & cmd) case INCLUDE_CODE: { InsetCommandParams icp(code); InsetCommand::string2params(name, to_utf8(cmd.argument()), icp); - return new InsetInclude(icp); + return new InsetInclude(buf, icp); } case INDEX_CODE: @@ -465,7 +465,7 @@ Inset * readInset(Lexer & lex, Buffer const & buf) inset.reset(new InsetHyperlink(inscmd)); break; case INCLUDE_CODE: - inset.reset(new InsetInclude(inscmd)); + inset.reset(new InsetInclude(buf, inscmd)); break; case INDEX_PRINT_CODE: inset.reset(new InsetPrintIndex(inscmd)); diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index aa0b76c3af..c83006ff11 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -46,6 +46,8 @@ #include "insets/InsetListingsParams.h" #include "insets/RenderPreview.h" +#include "mathed/MacroTable.h" + #include "support/convert.h" #include "support/debug.h" #include "support/docstream.h" @@ -158,17 +160,22 @@ InsetLabel * createLabel(docstring const & label_str) } // namespace anon -InsetInclude::InsetInclude(InsetCommandParams const & p) +InsetInclude::InsetInclude(Buffer const & buf, InsetCommandParams const & p) : InsetCommand(p, "include"), include_label(uniqueID()), preview_(new RenderMonitoredPreview(this)), failedtoload_(false), set_label_(false), label_(0) { + // In order to be able to track macros at loading time, the + // buffer has to be set here and not after construction. + setBuffer(const_cast(buf)); + preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this)); if (isListings(params())) { InsetListingsParams listing_params(to_utf8(p["lstparams"])); label_ = createLabel(from_utf8(listing_params.getParamValue("label"))); - } + } else if (isInputOrInclude(params()) && isBufferValid()) + loadIfNeeded(buffer()); } @@ -408,18 +415,32 @@ Buffer * InsetInclude::loadIfNeeded(Buffer const & parent) const // Buffer creation is not possible. return 0; + // Set parent before loading, such that macros can be tracked + child->setParent(&parent); + if (!child->loadLyXFile(included_file)) { failedtoload_ = true; + child->setParent(0); //close the buffer we just opened theBufferList().release(child); return 0; } - + if (!child->errorList("Parse").empty()) { // FIXME: Do something. } + } else { + // The file was already loaded, so, simply + // inform parent buffer about local macros. + child->setParent(&parent); + MacroNameSet macros; + child->listMacroNames(macros); + MacroNameSet::const_iterator cit = macros.begin(); + MacroNameSet::const_iterator end = macros.end(); + for (; cit != end; ++cit) + parent.usermacros.insert(*cit); } - child->setParent(&parent); + return child; } diff --git a/src/insets/InsetInclude.h b/src/insets/InsetInclude.h index 91b538f696..61ce9bbdba 100644 --- a/src/insets/InsetInclude.h +++ b/src/insets/InsetInclude.h @@ -36,7 +36,7 @@ class RenderMonitoredPreview; class InsetInclude : public InsetCommand { public: /// - InsetInclude(InsetCommandParams const &); + InsetInclude(Buffer const & buf, InsetCommandParams const &); ~InsetInclude(); void setBuffer(Buffer & buffer); diff --git a/status.16x b/status.16x index 4d3b5ae067..a165e248ca 100644 --- a/status.16x +++ b/status.16x @@ -84,6 +84,8 @@ What's new - Fix insertion of a user math macro through the math-insert lfun when a selection is present (bug 6939). +- Don't shadow user math macros defined in child documents (bug 7183). + - Make the modules description in the menu "Document -> Settings" fully translatable (bug 6987).