From: Enrico Forestieri Date: Sun, 2 Apr 2017 22:26:49 +0000 (+0200) Subject: Fix bug #10581 X-Git-Tag: 2.3.0alpha1~136 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=66aa52ff20c6e96d679d917bb3d98ff29117ad15;p=features.git Fix bug #10581 Tell the math parser that we are parsing a macro definition, so that it doesn't try to return a verbatim copy in case of failure. --- diff --git a/src/mathed/MacroTable.cpp b/src/mathed/MacroTable.cpp index d23855c511..2899e40c2e 100644 --- a/src/mathed/MacroTable.cpp +++ b/src/mathed/MacroTable.cpp @@ -71,7 +71,7 @@ bool MacroData::expand(vector const & args, MathData & to) const InsetMathSqrt inset(const_cast(buffer_)); docstring const & definition(display_.empty() ? definition_ : display_); - asArray(definition, inset.cell(0), Parse::QUIET); + asArray(definition, inset.cell(0), Parse::QUIET | Parse::MACRODEF); //lyxerr << "MathData::expand: args: " << args << endl; //LYXERR0("MathData::expand: ar: " << inset.cell(0)); for (DocIterator it = doc_iterator_begin(buffer_, &inset); it; it.forwardChar()) { diff --git a/src/mathed/MathMacro.cpp b/src/mathed/MathMacro.cpp index 8f16e2b696..4bd14d6b72 100644 --- a/src/mathed/MathMacro.cpp +++ b/src/mathed/MathMacro.cpp @@ -672,7 +672,7 @@ void MathMacro::updateRepresentation(Cursor * cur, MacroContext const & mc, // get definition for list edit mode docstring const & display = d->macro_->display(); asArray(display.empty() ? d->macro_->definition() : display, - d->definition_, Parse::QUIET); + d->definition_, Parse::QUIET | Parse::MACRODEF); } diff --git a/src/mathed/MathParser.cpp b/src/mathed/MathParser.cpp index ace167c439..9bc5ff9362 100644 --- a/src/mathed/MathParser.cpp +++ b/src/mathed/MathParser.cpp @@ -1757,7 +1757,8 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, else { success_ = false; - if (!(mode_ & Parse::QUIET)) { + if (!(mode_ & Parse::QUIET) && + !(mode_ & Parse::TRACKMACRO)) { dump(); lyxerr << "found unknown math environment '" << to_utf8(name) << "'" << endl; diff --git a/src/mathed/MathParser_flags.h b/src/mathed/MathParser_flags.h index 9c9c4a3b95..fa9501abe3 100644 --- a/src/mathed/MathParser_flags.h +++ b/src/mathed/MathParser_flags.h @@ -28,7 +28,9 @@ enum flags { /// Wrap unicode symbols in \text{}. USETEXT = 0x08, /// Track macro creation while loading a document - TRACKMACRO = 0x10 + TRACKMACRO = 0x10, + /// Parse a macro definition + MACRODEF = 0x20 }; diff --git a/src/mathed/MathSupport.cpp b/src/mathed/MathSupport.cpp index 1c4f89ca8d..086d219c56 100644 --- a/src/mathed/MathSupport.cpp +++ b/src/mathed/MathSupport.cpp @@ -961,8 +961,13 @@ docstring asString(MathData const & ar) void asArray(docstring const & str, MathData & ar, Parse::flags pf) { + // If the QUIET flag is set, we are going to parse for either + // a paste operation or a macro definition. We try to do the + // right thing in all cases. + bool quiet = pf & Parse::QUIET; - if ((str.size() == 1 && quiet) || (!mathed_parse_cell(ar, str, pf) && quiet)) + bool macro = pf & Parse::MACRODEF; + if ((str.size() == 1 && quiet) || (!mathed_parse_cell(ar, str, pf) && quiet && !macro)) mathed_parse_cell(ar, str, pf | Parse::VERBATIM); }