commit 66aa52ff20c6e96d679d917bb3d98ff29117ad15 Author: Enrico Forestieri <for...@lyx.org> Date: Mon Apr 3 00:26:49 2017 +0200
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. --- src/mathed/MacroTable.cpp | 2 +- src/mathed/MathMacro.cpp | 2 +- src/mathed/MathParser.cpp | 3 ++- src/mathed/MathParser_flags.h | 4 +++- src/mathed/MathSupport.cpp | 7 ++++++- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/mathed/MacroTable.cpp b/src/mathed/MacroTable.cpp index d23855c..2899e40 100644 --- a/src/mathed/MacroTable.cpp +++ b/src/mathed/MacroTable.cpp @@ -71,7 +71,7 @@ bool MacroData::expand(vector<MathData> const & args, MathData & to) const InsetMathSqrt inset(const_cast<Buffer *>(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 8f16e2b..4bd14d6 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 ace167c..9bc5ff9 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 9c9c4a3..fa9501a 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 1c4f89c..086d219 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); }