X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flyxfind.cpp;h=c0d86409f9c3987ea81e0ed4f7822dc6522f6484;hb=531fed9543b07cb06d23ba8f7276691d8fd6b9d6;hp=c3f2b77929cd05d193646982d968528b7cb034c7;hpb=1f7d90d6367010d32f77a536a246e8fed9b3d381;p=features.git diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index c3f2b77929..c0d86409f9 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -838,7 +838,7 @@ string correctRegex(string t, bool withformat) * and \{, \}, \[, \] => {, }, [, ] */ string s(""); - regex wordre("(\\\\)*(\\\\(([A-Za-z]+|[\\{\\}])( |\\{\\})?|[\\[\\]\\{\\}]))"); + regex wordre("(\\\\)*(\\\\(([A-Za-z]+|[\\{\\}%])( |\\{\\})?|[\\[\\]\\{\\}]))"); size_t lastpos = 0; smatch sub; bool backslashed = false; @@ -875,7 +875,7 @@ string correctRegex(string t, bool withformat) replace = accents["braceright"]; else { // else part should not exist - LASSERT(1, /**/); + LASSERT(0, /**/); } } else { @@ -885,7 +885,7 @@ string correctRegex(string t, bool withformat) replace = "\\}"; else { // else part should not exist - LASSERT(1, /**/); + LASSERT(0, /**/); } } } @@ -893,6 +893,8 @@ string correctRegex(string t, bool withformat) replace = "{"; else if (sub.str(4) == "}") replace = "}"; + else if (sub.str(4) == "%") + replace = "%"; else { AccentsIterator it_ac = accents.find(sub.str(4)); if (it_ac == accents.end()) { @@ -1086,6 +1088,15 @@ void MatchStringAdv::FillResults(MatchResult &found_mr) valid_matches = 0; } +static void setFindParams(OutputParams &runparams) +{ + runparams.flavor = Flavor::XeTeX; + //runparams.use_polyglossia = true; + runparams.linelen = 10000; //lyxrc.plaintext_linelen; + // No side effect of file copying and image conversion + runparams.dryrun = true; +} + static docstring buffer_to_latex(Buffer & buffer) { //OutputParams runparams(&buffer.params().encoding()); @@ -1093,21 +1104,18 @@ static docstring buffer_to_latex(Buffer & buffer) odocstringstream ods; otexstream os(ods); runparams.nice = true; - runparams.flavor = Flavor::XeTeX; - runparams.linelen = 10000; //lyxrc.plaintext_linelen; - // No side effect of file copying and image conversion - runparams.dryrun = true; + setFindParams(runparams); if (ignoreFormats.getDeleted()) - runparams.for_searchAdv = OutputParams::SearchWithoutDeleted; + runparams.for_search = OutputParams::SearchWithoutDeleted; else - runparams.for_searchAdv = OutputParams::SearchWithDeleted; + runparams.for_search = OutputParams::SearchWithDeleted; if (ignoreFormats.getNonContent()) { - runparams.for_searchAdv |= OutputParams::SearchNonOutput; + runparams.for_search |= OutputParams::SearchNonOutput; } pit_type const endpit = buffer.paragraphs().size(); for (pit_type pit = 0; pit != endpit; ++pit) { - TeXOnePar(buffer, buffer.text(), pit, os, runparams); - LYXERR(Debug::FIND, "searchString up to here: " << ods.str()); + TeXOnePar(buffer, buffer.text(), pit, os, runparams, string(), -1, -1, true); + LYXERR(Debug::FINDVERBOSE, "searchString up to here: " << ods.str()); } return ods.str(); } @@ -1154,7 +1162,7 @@ static string latexNamesToUtf8(docstring strIn) add = addtmp; else if (addtmp.length() > lastpos) add += addtmp.substr(lastpos, addtmp.length() - lastpos); - LYXERR(Debug::FIND, "Adding to search string: '" + LYXERR(Debug::FINDVERBOSE, "Adding to search string: '" << add << "'"); return add; } @@ -1168,19 +1176,17 @@ static docstring stringifySearchBuffer(Buffer & buffer, FindAndReplaceOptions co // OutputParams runparams(&buffer.params().encoding()); OutputParams runparams(encodings.fromLyXName("utf8")); runparams.nice = true; - runparams.flavor = Flavor::XeTeX; - runparams.linelen = 10000; //lyxrc.plaintext_linelen; - runparams.dryrun = true; + setFindParams(runparams); int option = AS_STR_INSETS |AS_STR_PLAINTEXT; if (ignoreFormats.getDeleted()) { option |= AS_STR_SKIPDELETE; - runparams.for_searchAdv = OutputParams::SearchWithoutDeleted; + runparams.for_search = OutputParams::SearchWithoutDeleted; } else { - runparams.for_searchAdv = OutputParams::SearchWithDeleted; + runparams.for_search = OutputParams::SearchWithDeleted; } if (ignoreFormats.getNonContent()) { - runparams.for_searchAdv |= OutputParams::SearchNonOutput; + runparams.for_search |= OutputParams::SearchNonOutput; } string t(""); for (pos_type pit = pos_type(0); pit < (pos_type)buffer.paragraphs().size(); ++pit) { @@ -1188,7 +1194,7 @@ static docstring stringifySearchBuffer(Buffer & buffer, FindAndReplaceOptions co string add = latexNamesToUtf8(par.asString(pos_type(0), par.size(), option, &runparams)); - LYXERR(Debug::FIND, "Adding to search string: '" + LYXERR(Debug::FINDVERBOSE, "Adding to search string: '" << add << "'"); t += add; } @@ -1219,8 +1225,8 @@ static size_t identifyLeading(string const & s) || regex_replace(t, t, "^ ?\\\\item\\{[a-z]+\\}", "") || regex_replace(t, t, "^\\\\begin\\{[a-zA-Z_]*\\*?\\}", "")) ; - LYXERR(Debug::FIND, " after removing leading $, \\[ , \\emph{, \\textbf{, etc.: '" << t << "'"); - return s.find(t); + LYXERR(Debug::FINDVERBOSE, " after removing leading $, \\[ , \\emph{, \\textbf{, etc.: '" << t << "'"); + return s.size() - t.size(); } /* @@ -2023,7 +2029,7 @@ void Intervall::handleCloseP(int i, bool closingAllowed) { if (actualdeptindex <= 0) { if (! closingAllowed) - LYXERR(Debug::FIND, "Bad closing parenthesis in latex"); /* should not happen, but the latex input may be wrong */ + LYXERR(Debug::FINDVERBOSE, "Bad closing parenthesis in latex"); /* should not happen, but the latex input may be wrong */ // if we are at the very end addIntervall(i, i+1); } @@ -2748,6 +2754,7 @@ void LatexInfo::buildKeys(bool isPatternString) makeKey("triangleuppar|triangledownpar|droppar", KeyInfo(KeyInfo::isStandard, 1, true), isPatternString); makeKey("triangleleftpar|shapepar|dropuppar", KeyInfo(KeyInfo::isStandard, 1, true), isPatternString); makeKey("hphantom|vphantom|note|footnote|shortcut|include|includegraphics", KeyInfo(KeyInfo::isStandard, 1, true), isPatternString); + makeKey("textgreek|textcyrillic", KeyInfo(KeyInfo::isStandard, 1, true), false); makeKey("parbox", KeyInfo(KeyInfo::doRemove, 1, true), isPatternString); // like ('tiny{}' or '\tiny ' ... ) makeKey("footnotesize|tiny|scriptsize|small|large|Large|LARGE|huge|Huge", KeyInfo(KeyInfo::isSize, 0, false), isPatternString); @@ -3361,7 +3368,7 @@ static string correctlanguagesetting(string par, bool isPatternString, bool with if (withformat) { // Split the latex input into pieces which // can be digested by our search engine - LYXERR(Debug::FIND, "input: \"" << par << "\""); + LYXERR(Debug::FINDVERBOSE, "input: \"" << par << "\""); if (isPatternString && (pbuf != nullptr)) { // Check if we should disable/enable test for language // We check for polyglossia, because in runparams.flavor we use Flavor::XeTeX string doclang = pbuf->params().language->polyglossia(); @@ -3379,7 +3386,7 @@ static string correctlanguagesetting(string par, bool isPatternString, bool with } result = splitOnKnownMacros(par.substr(0,parlen), isPatternString); - LYXERR(Debug::FIND, "After splitOnKnownMacros:\n\"" << result << "\""); + LYXERR(Debug::FINDVERBOSE, "After splitOnKnownMacros:\n\"" << result << "\""); } else result = par.substr(0, parlen); @@ -3394,7 +3401,7 @@ static string correctlanguagesetting(string par, bool isPatternString, bool with features += " " + a; // LYXERR(Debug::INFO, "Identified regex format:" << a); } - LYXERR(Debug::FIND, "Identified Features" << features); + LYXERR(Debug::FINDVERBOSE, "Identified Features" << features); } } else if (regex_with_format) { @@ -3404,7 +3411,7 @@ static string correctlanguagesetting(string par, bool isPatternString, bool with bool b = it->second; if (b && ! info[a]) { missed++; - LYXERR(Debug::FIND, "Missed(" << missed << " " << a <<", srclen = " << parlen ); + LYXERR(Debug::FINDVERBOSE, "Missed(" << missed << " " << a <<", srclen = " << parlen ); return ""; } } @@ -3418,24 +3425,23 @@ static string correctlanguagesetting(string par, bool isPatternString, bool with // Remove trailing closure of math, macros and environments, so to catch parts of them. -static int identifyClosing(string & t) +static void identifyClosing(string & t, bool ignoreformat) { - int open_braces = 0; do { - LYXERR(Debug::FIND, "identifyClosing(): t now is '" << t << "'"); + LYXERR(Debug::FINDVERBOSE, "identifyClosing(): t now is '" << t << "'"); if (regex_replace(t, t, "(.*[^\\\\])\\$$", "$1")) continue; if (regex_replace(t, t, "(.*[^\\\\])\\\\\\]$", "$1")) continue; - if (regex_replace(t, t, "(.*[^\\\\])\\\\end\\{[a-zA-Z_]*\\*?\\}$", "$1")) - continue; - if (regex_replace(t, t, "(.*[^\\\\])\\}$", "$1")) { - ++open_braces; + if (regex_replace(t, t, "(.*[^\\\\])\\\\end\\{[a-zA-Z_]+\\*?\\}$", "$1")) continue; + if (! ignoreformat) { + if (regex_replace(t, t, "(.*[^\\\\])\\}$", "$1")) + continue; } break; } while (true); - return open_braces; + return; } static int num_replaced = 0; @@ -3562,7 +3568,7 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions & opt) } opt.matchAtStart = false; if (!use_regexp) { - identifyClosing(par_as_string); // Removes math closings ($, ], ...) at end of string + identifyClosing(par_as_string, opt.ignoreformat); // Removes math closings ($, ], ...) at end of string if (opt.ignoreformat) { lead_size = 0; } @@ -3583,14 +3589,14 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions & opt) string regexp2_str = "(" + lead_as_regex_string + ")(.*?)" + par_as_regex_string_nolead; CreateRegexp(opt, regexp_str, regexp2_str); use_regexp = true; - LYXERR(Debug::FIND, "Setting regexp to : '" << regexp_str << "'"); - LYXERR(Debug::FIND, "Setting regexp2 to: '" << regexp2_str << "'"); + LYXERR(Debug::FINDVERBOSE|Debug::FIND, "Setting regexp to : '" << regexp_str << "'"); + LYXERR(Debug::FINDVERBOSE|Debug::FIND, "Setting regexp2 to: '" << regexp2_str << "'"); return; } if (!opt.ignoreformat) { lead_size = identifyLeading(par_as_string); - LYXERR(Debug::FIND, "Lead_size: " << lead_size); + LYXERR(Debug::FINDVERBOSE, "Lead_size: " << lead_size); lead_as_string = par_as_string.substr(0, lead_size); par_as_string_nolead = par_as_string.substr(lead_size, par_as_string.size() - lead_size); } @@ -3604,13 +3610,13 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions & opt) (void)regex_replace(par_as_string_nolead, par_as_string_nolead, "\\$$", ""); (void)regex_replace(par_as_string_nolead, par_as_string_nolead, "}$", ""); par_as_string = par_as_string_nolead; - LYXERR(Debug::FIND, "lead_as_regexp is '" << lead_as_regexp << "'"); - LYXERR(Debug::FIND, "par_as_string now is '" << par_as_string << "'"); + LYXERR(Debug::FINDVERBOSE, "lead_as_regexp is '" << lead_as_regexp << "'"); + LYXERR(Debug::FINDVERBOSE, "par_as_string now is '" << par_as_string << "'"); } - // LYXERR(Debug::FIND, "par_as_string before escape_for_regex() is '" << par_as_string << "'"); + // LYXERR(Debug::FINDVERBOSE, "par_as_string before escape_for_regex() is '" << par_as_string << "'"); par_as_string = escape_for_regex(par_as_string, !opt.ignoreformat); // Insert (.*?) before trailing closure of math, macros and environments, so to catch parts of them. - // LYXERR(Debug::FIND, "par_as_string now is '" << par_as_string << "'"); + // LYXERR(Debug::FINDVERBOSE, "par_as_string now is '" << par_as_string << "'"); ++close_wildcards; size_t lng = par_as_string.size(); if (!opt.ignoreformat) { @@ -3630,15 +3636,15 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions & opt) if (lng < par_as_string.size()) par_as_string = par_as_string.substr(0,lng); } - LYXERR(Debug::FIND, "par_as_string after correctRegex is '" << par_as_string << "'"); + LYXERR(Debug::FINDVERBOSE, "par_as_string after correctRegex is '" << par_as_string << "'"); if ((lng > 0) && (par_as_string[0] == '^')) { par_as_string = par_as_string.substr(1); --lng; opt.matchAtStart = true; } - // LYXERR(Debug::FIND, "par_as_string now is '" << par_as_string << "'"); - // LYXERR(Debug::FIND, "Open braces: " << open_braces); - // LYXERR(Debug::FIND, "Replaced text (to be used as regex): " << par_as_string); + // LYXERR(Debug::FINDVERBOSE, "par_as_string now is '" << par_as_string << "'"); + // LYXERR(Debug::FINDVERBOSE, "Open braces: " << open_braces); + // LYXERR(Debug::FINDVERBOSE, "Replaced text (to be used as regex): " << par_as_string); // If entered regexp must match at begin of searched string buffer // Kornel: Added parentheses to use $1 for size of the leading string @@ -3660,8 +3666,8 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions & opt) regexp_str = "(" + lead_as_regexp + ")()" + par_as_string; regexp2_str = "(" + lead_as_regexp + ")(.*?)" + par_as_string; } - LYXERR(Debug::FIND, "Setting regexp to : '" << regexp_str << "'"); - LYXERR(Debug::FIND, "Setting regexp2 to: '" << regexp2_str << "'"); + LYXERR(Debug::FINDVERBOSE|Debug::FIND, "Setting regexp to : '" << regexp_str << "'"); + LYXERR(Debug::FINDVERBOSE|Debug::FIND, "Setting regexp2 to: '" << regexp2_str << "'"); CreateRegexp(opt, regexp_str, regexp2_str, par_as_string); } } @@ -3692,12 +3698,12 @@ MatchResult MatchStringAdv::findAux(DocIterator const & cur, int len, bool at_be mres.match_len = -1; return mres; } - LYXERR(Debug::FIND, "After normalization: Matching against:\n'" << str << "'"); + LYXERR(Debug::FINDVERBOSE, "After normalization: Matching against:\n'" << str << "'"); LASSERT(use_regexp, /**/); { // use_regexp always true - LYXERR(Debug::FIND, "Searching in regexp mode: at_begin=" << at_begin); + LYXERR(Debug::FINDVERBOSE, "Searching in regexp mode: at_begin=" << at_begin); #if QTSEARCH QString qstr = QString::fromStdString(str); QRegularExpression const *p_regexp; @@ -3831,7 +3837,7 @@ MatchResult MatchStringAdv::operator()(DocIterator const & cur, int len, bool at { MatchResult mres = findAux(cur, len, at_begin); int res = mres.match_len; - LYXERR(Debug::FIND, + LYXERR(Debug::FINDVERBOSE, "res=" << res << ", at_begin=" << at_begin << ", matchAtStart=" << opt.matchAtStart << ", inTexted=" << cur.inTexted()); @@ -3878,14 +3884,9 @@ string MatchStringAdv::normalize(docstring const & s, bool ignore_format) const // Remove \n at begin while (!t.empty() && t[0] == '\n') t = t.substr(1); - // Remove [%]*\n at end + // Remove \n* at end while (!t.empty() && t[t.size() - 1] == '\n') { - size_t count = 1; - if (!ignore_format) { - while ((t.size() > 1 + count) && (t[t.size() - 1 - count] == '%')) - count++; - } - t = t.substr(0, t.size() - count); + t = t.substr(0, t.size() - 1); } size_t pos; // Handle all other '\n' @@ -3922,11 +3923,11 @@ string MatchStringAdv::normalize(docstring const & s, bool ignore_format) const // Remove stale empty \emph{}, \textbf{} and similar blocks from latexify // Kornel: Added textsl, textsf, textit, texttt and noun // + allow to seach for colored text too - LYXERR(Debug::FIND, "Removing stale empty macros from: " << t); + LYXERR(Debug::FINDVERBOSE, "Removing stale empty macros from: " << t); while (regex_replace(t, t, "\\\\(emph|noun|text(bf|sl|sf|it|tt)|(u|uu)line|(s|x)out|uwave)(\\{(\\{\\})?\\})+", "")) - LYXERR(Debug::FIND, " further removing stale empty \\emph{}, \\textbf{} macros from: " << t); + LYXERR(Debug::FINDVERBOSE, " further removing stale empty \\emph{}, \\textbf{} macros from: " << t); while (regex_replace(t, t, "\\\\((sub)?(((sub)?section)|paragraph)|part)\\*?(\\{(\\{\\})?\\})+", "")) - LYXERR(Debug::FIND, " further removing stale empty \\emph{}, \\textbf{} macros from: " << t); + LYXERR(Debug::FINDVERBOSE, " further removing stale empty \\emph{}, \\textbf{} macros from: " << t); while (regex_replace(t, t, "\\\\(foreignlanguage|textcolor|item)\\{[a-z]+\\}(\\{(\\{\\})?\\})+", "")); return t; @@ -3935,7 +3936,7 @@ string MatchStringAdv::normalize(docstring const & s, bool ignore_format) const docstring stringifyFromCursor(DocIterator const & cur, int len) { - LYXERR(Debug::FIND, "Stringifying with len=" << len << " from cursor at pos: " << cur); + LYXERR(Debug::FINDVERBOSE, "Stringifying with len=" << len << " from cursor at pos: " << cur); if (cur.inTexted()) { Paragraph const & par = cur.paragraph(); // TODO what about searching beyond/across paragraph breaks ? @@ -3945,26 +3946,25 @@ docstring stringifyFromCursor(DocIterator const & cur, int len) // OutputParams runparams(&cur.buffer()->params().encoding()); OutputParams runparams(encodings.fromLyXName("utf8")); runparams.nice = true; - runparams.flavor = Flavor::XeTeX; - runparams.linelen = 10000; //lyxrc.plaintext_linelen; - // No side effect of file copying and image conversion - runparams.dryrun = true; + setFindParams(runparams); int option = AS_STR_INSETS | AS_STR_PLAINTEXT; if (ignoreFormats.getDeleted()) { option |= AS_STR_SKIPDELETE; - runparams.for_searchAdv = OutputParams::SearchWithoutDeleted; + runparams.for_search = OutputParams::SearchWithoutDeleted; } else { - runparams.for_searchAdv = OutputParams::SearchWithDeleted; + runparams.for_search = OutputParams::SearchWithDeleted; } if (ignoreFormats.getNonContent()) { - runparams.for_searchAdv |= OutputParams::SearchNonOutput; + runparams.for_search |= OutputParams::SearchNonOutput; } - LYXERR(Debug::FIND, "Stringifying with cur: " + LYXERR(Debug::FINDVERBOSE, "Stringifying with cur: " << cur << ", from pos: " << cur.pos() << ", end: " << end); - return from_utf8(latexNamesToUtf8(par.asString(cur.pos(), end, - option, - &runparams))); + docstring res = from_utf8(latexNamesToUtf8(par.asString(cur.pos(), end, + option, + &runparams))); + LYXERR(Debug::FIND, "Stringified text from pos(" << cur.pos() << ") len(" << len << "): " << res); + return res; } else if (cur.inMathed()) { CursorSlice cs = cur.top(); MathData md = cs.cell(); @@ -3975,11 +3975,11 @@ docstring stringifyFromCursor(DocIterator const & cur, int len) MathData md2; for (MathData::const_iterator it = md.begin() + cs.pos(); it != it_end; ++it) md2.push_back(*it); - docstring s = from_utf8(latexNamesToUtf8(asString(md2))); - LYXERR(Debug::FIND, "Stringified math: '" << s << "'"); - return s; + docstring res = from_utf8(latexNamesToUtf8(asString(md2))); + LYXERR(Debug::FINDVERBOSE|Debug::FIND, "Stringified math from pos(" << cur.pos() << ") len(" << len << "): " << res); + return res; } - LYXERR(Debug::FIND, "Don't know how to stringify from here: " << cur); + LYXERR(Debug::FINDVERBOSE|Debug::FIND, "Don't know how to stringify from here: " << cur); return docstring(); } @@ -3990,8 +3990,8 @@ docstring stringifyFromCursor(DocIterator const & cur, int len) docstring latexifyFromCursor(DocIterator const & cur, int len) { /* - LYXERR(Debug::FIND, "Latexifying with len=" << len << " from cursor at pos: " << cur); - LYXERR(Debug::FIND, " with cur.lastpost=" << cur.lastpos() << ", cur.lastrow=" + LYXERR(Debug::FINDVERBOSE, "Latexifying with len=" << len << " from cursor at pos: " << cur); + LYXERR(Debug::FINDVERBOSE, " with cur.lastpost=" << cur.lastpos() << ", cur.lastrow=" << cur.lastrow() << ", cur.lastcol=" << cur.lastcol()); */ Buffer const & buf = *cur.buffer(); @@ -4001,18 +4001,15 @@ docstring latexifyFromCursor(DocIterator const & cur, int len) //OutputParams runparams(&buf.params().encoding()); OutputParams runparams(encodings.fromLyXName("utf8")); runparams.nice = false; - runparams.flavor = Flavor::XeTeX; - runparams.linelen = 8000; //lyxrc.plaintext_linelen; - // No side effect of file copying and image conversion - runparams.dryrun = true; + setFindParams(runparams); if (ignoreFormats.getDeleted()) { - runparams.for_searchAdv = OutputParams::SearchWithoutDeleted; + runparams.for_search = OutputParams::SearchWithoutDeleted; } else { - runparams.for_searchAdv = OutputParams::SearchWithDeleted; + runparams.for_search = OutputParams::SearchWithDeleted; } if (ignoreFormats.getNonContent()) { - runparams.for_searchAdv |= OutputParams::SearchNonOutput; + runparams.for_search |= OutputParams::SearchNonOutput; } if (cur.inTexted()) { @@ -4021,10 +4018,9 @@ docstring latexifyFromCursor(DocIterator const & cur, int len) if (len != -1 && endpos > cur.pos() + len) endpos = cur.pos() + len; TeXOnePar(buf, *cur.innerText(), cur.pit(), os, runparams, - string(), cur.pos(), endpos); - string s = lyx::to_utf8(ods.str()); - LYXERR(Debug::FIND, "Latexified +modified text: '" << s << "'"); - return(lyx::from_utf8(s)); + string(), cur.pos(), endpos, true); + LYXERR(Debug::FIND, "Latexified text from pos(" << cur.pos() << ") len(" << len << "): " << ods.str()); + return(ods.str()); } else if (cur.inMathed()) { // Retrieve the math environment type, and add '$' or '$[' or others (\begin{equation}) accordingly for (int s = cur.depth() - 1; s >= 0; --s) { @@ -4059,9 +4055,9 @@ docstring latexifyFromCursor(DocIterator const & cur, int len) break; } } - LYXERR(Debug::FIND, "Latexified math: '" << lyx::to_utf8(ods.str()) << "'"); + LYXERR(Debug::FINDVERBOSE|Debug::FIND, "Latexified math from pos(" << cur.pos() << ") len(" << len << "): " << ods.str()); } else { - LYXERR(Debug::FIND, "Don't know how to stringify from here: " << cur); + LYXERR(Debug::FINDVERBOSE|Debug::FIND, "Don't know how to stringify from here: " << cur); } return ods.str(); } @@ -4161,7 +4157,7 @@ MatchResult findAdvFinalize(DocIterator & cur, MatchStringAdv const & match, Mat max_match = mres; } if (max_match.match_len <= 0) return fail; - LYXERR(Debug::FIND, "Ok"); + LYXERR(Debug::FINDVERBOSE, "Ok"); // Compute the match length int len = 1; @@ -4257,7 +4253,7 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match) MatchResult orig_mres; while (!theApp()->longOperationCancelled() && cur) { //(void) findAdvForwardInnermost(cur); - LYXERR(Debug::FIND, "findForwardAdv() cur: " << cur); + LYXERR(Debug::FINDVERBOSE, "findForwardAdv() cur: " << cur); MatchResult mres = match(cur, -1, false); string msg = "Starting"; if (repeat) @@ -4271,7 +4267,7 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match) if (match_len <= 0) { // This should exit nested insets, if any, or otherwise undefine the currsor. cur.pos() = cur.lastpos(); - LYXERR(Debug::FIND, "Advancing pos: cur=" << cur); + LYXERR(Debug::FINDVERBOSE, "Advancing pos: cur=" << cur); cur.forwardPos(); } else { // match_len > 0 @@ -4288,7 +4284,7 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match) if (increment < 1) increment = 1; } - LYXERR(Debug::FIND, "Set increment to " << increment); + LYXERR(Debug::FINDVERBOSE, "Set increment to " << increment); while (increment > 0) { DocIterator old_cur = cur; if (cur.pos() + increment >= cur.lastpos()) { @@ -4342,10 +4338,9 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match) mres = orig_mres; } // LYXERR0("Leaving first loop"); - LYXERR(Debug::FIND, "Finalizing 1"); + LYXERR(Debug::FINDVERBOSE, "Finalizing 1"); MatchResult found_match = findAdvFinalize(cur, match, mres); if (found_match.match_len > 0) { - LASSERT(found_match.pos_len > 0, /**/); match.FillResults(found_match); return found_match.pos_len; } @@ -4370,7 +4365,7 @@ MatchResult findMostBackwards(DocIterator & cur, MatchStringAdv const & match, M MatchResult mr = findAdvFinalize(tmp_cur, match, expected); Inset & inset = cur.inset(); for (; cur != cur_begin; cur.backwardPos()) { - LYXERR(Debug::FIND, "findMostBackwards(): cur=" << cur); + LYXERR(Debug::FINDVERBOSE, "findMostBackwards(): cur=" << cur); DocIterator new_cur = cur; new_cur.backwardPos(); if (new_cur == cur || &new_cur.inset() != &inset || !match(new_cur).match_len) @@ -4380,7 +4375,7 @@ MatchResult findMostBackwards(DocIterator & cur, MatchStringAdv const & match, M break; mr = new_mr; } - LYXERR(Debug::FIND, "findMostBackwards(): exiting with cur=" << cur); + LYXERR(Debug::FINDVERBOSE, "findMostBackwards(): exiting with cur=" << cur); return mr; } @@ -4406,11 +4401,11 @@ int findBackwardsAdv(DocIterator & cur, MatchStringAdv & match) cur.pos() = cur.lastpos(); else cur.pos() = cur_orig.pos(); - LYXERR(Debug::FIND, "findBackAdv2: cur: " << cur); + LYXERR(Debug::FINDVERBOSE, "findBackAdv2: cur: " << cur); DocIterator cur_prev_iter; do { found_match = match(cur); - LYXERR(Debug::FIND, "findBackAdv3: found_match=" + LYXERR(Debug::FINDVERBOSE, "findBackAdv3: found_match=" << (found_match.match_len > 0) << ", cur: " << cur); if (found_match.match_len > 0) { MatchResult found_mr = findMostBackwards(cur, match, found_match); @@ -4475,7 +4470,7 @@ static bool allNonLowercase(Cursor const & cur, int len) pos_type beg_pos = cur.selectionBegin().pos(); pos_type end_pos = cur.selectionBegin().pos() + len; if (len > cur.lastpos() + 1 - beg_pos) { - LYXERR(Debug::FIND, "This should not happen, more debug needed"); + LYXERR(Debug::FINDVERBOSE, "This should not happen, more debug needed"); len = cur.lastpos() + 1 - beg_pos; end_pos = beg_pos + len; } @@ -4492,13 +4487,13 @@ static bool firstUppercase(Cursor const & cur) char_type ch1, ch2; pos_type pos = cur.selectionBegin().pos(); if (pos >= cur.lastpos() - 1) { - LYXERR(Debug::FIND, "No upper-case at cur: " << cur); + LYXERR(Debug::FINDVERBOSE, "No upper-case at cur: " << cur); return false; } ch1 = cur.paragraph().getChar(pos); ch2 = cur.paragraph().getChar(pos + 1); bool result = isUpperCase(ch1) && isLowerCase(ch2); - LYXERR(Debug::FIND, "firstUppercase(): " + LYXERR(Debug::FINDVERBOSE, "firstUppercase(): " << "ch1=" << ch1 << "(" << char(ch1) << "), ch2=" << ch2 << "(" << char(ch2) << ")" << ", result=" << result << ", cur=" << cur); @@ -4565,7 +4560,7 @@ static int findAdvReplace(BufferView * bv, FindAndReplaceOptions const & opt, Ma || sel_beg.idx() != sel_end.idx()) return 0; int sel_len = sel_end.pos() - sel_beg.pos(); - LYXERR(Debug::FIND, "sel_beg: " << sel_beg << ", sel_end: " << sel_end + LYXERR(Debug::FINDVERBOSE, "sel_beg: " << sel_beg << ", sel_end: " << sel_end << ", sel_len: " << sel_len << endl); if (sel_len == 0) return 0; @@ -4586,7 +4581,7 @@ static int findAdvReplace(BufferView * bv, FindAndReplaceOptions const & opt, Ma repl_buffer.setUnnamed(true); LASSERT(repl_buffer.readString(lyx), return 0); if (opt.keep_case && sel_len >= 2) { - LYXERR(Debug::FIND, "keep_case true: cur.pos()=" << cur.pos() << ", sel_len=" << sel_len); + LYXERR(Debug::FINDVERBOSE, "keep_case true: cur.pos()=" << cur.pos() << ", sel_len=" << sel_len); if (cur.inTexted()) { if (firstUppercase(cur)) changeFirstCase(repl_buffer, text_uppercase, text_lowercase); @@ -4599,13 +4594,13 @@ static int findAdvReplace(BufferView * bv, FindAndReplaceOptions const & opt, Ma repl_buffer.changeLanguage( repl_buffer.language(), cur.getFont().language()); - LYXERR(Debug::FIND, "Replacing by pasteParagraphList()ing repl_buffer"); - LYXERR(Debug::FIND, "Before pasteParagraphList() cur=" << cur << endl); + LYXERR(Debug::FINDVERBOSE, "Replacing by pasteParagraphList()ing repl_buffer"); + LYXERR(Debug::FINDVERBOSE, "Before pasteParagraphList() cur=" << cur << endl); cap::pasteParagraphList(cur, repl_buffer.paragraphs(), repl_buffer.params().documentClassPtr(), repl_buffer.params().authors(), bv->buffer().errorList("Paste")); - LYXERR(Debug::FIND, "After pasteParagraphList() cur=" << cur << endl); + LYXERR(Debug::FINDVERBOSE, "After pasteParagraphList() cur=" << cur << endl); sel_len = repl_buffer.paragraphs().begin()->size(); } else if (cur.inMathed()) { odocstringstream ods; @@ -4613,29 +4608,27 @@ static int findAdvReplace(BufferView * bv, FindAndReplaceOptions const & opt, Ma // OutputParams runparams(&repl_buffer.params().encoding()); OutputParams runparams(encodings.fromLyXName("utf8")); runparams.nice = false; - runparams.flavor = Flavor::XeTeX; - runparams.linelen = 8000; //lyxrc.plaintext_linelen; - runparams.dryrun = true; - TeXOnePar(repl_buffer, repl_buffer.text(), 0, os, runparams); + setFindParams(runparams); + TeXOnePar(repl_buffer, repl_buffer.text(), 0, os, runparams, string(), -1, -1, true); //repl_buffer.getSourceCode(ods, 0, repl_buffer.paragraphs().size(), false); docstring repl_latex = ods.str(); - LYXERR(Debug::FIND, "Latexified replace_buffer: '" << repl_latex << "'"); + LYXERR(Debug::FINDVERBOSE, "Latexified replace_buffer: '" << repl_latex << "'"); string s; (void)regex_replace(to_utf8(repl_latex), s, "\\$(.*)\\$", "$1"); (void)regex_replace(s, s, "\\\\\\[(.*)\\\\\\]", "$1"); repl_latex = from_utf8(s); - LYXERR(Debug::FIND, "Replacing by insert()ing latex: '" << repl_latex << "' cur=" << cur << " with depth=" << cur.depth()); + LYXERR(Debug::FINDVERBOSE, "Replacing by insert()ing latex: '" << repl_latex << "' cur=" << cur << " with depth=" << cur.depth()); MathData ar(cur.buffer()); asArray(repl_latex, ar, Parse::NORMAL); cur.insert(ar); sel_len = ar.size(); - LYXERR(Debug::FIND, "After insert() cur=" << cur << " with depth: " << cur.depth() << " and len: " << sel_len); + LYXERR(Debug::FINDVERBOSE, "After insert() cur=" << cur << " with depth: " << cur.depth() << " and len: " << sel_len); } if (cur.pos() >= sel_len) cur.pos() -= sel_len; else cur.pos() = 0; - LYXERR(Debug::FIND, "After pos adj cur=" << cur << " with depth: " << cur.depth() << " and len: " << sel_len); + LYXERR(Debug::FINDVERBOSE, "After pos adj cur=" << cur << " with depth: " << cur.depth() << " and len: " << sel_len); bv->putSelectionAt(DocIterator(cur), sel_len, !opt.forward); bv->processUpdateFlags(Update::Force); return 1; @@ -4707,7 +4700,7 @@ bool findAdv(BufferView * bv, FindAndReplaceOptions & opt) // Should never happen, maybe LASSERT() here? pos_len = cur.lastpos() - cur.pos(); } - LYXERR(Debug::FIND, "Putting selection at cur=" << cur << " with len: " << pos_len); + LYXERR(Debug::FINDVERBOSE|Debug::FIND, "Putting selection at cur=" << cur << " with len: " << pos_len); bv->putSelectionAt(cur, pos_len, !opt.forward); return true; @@ -4728,7 +4721,7 @@ ostringstream & operator<<(ostringstream & os, FindAndReplaceOptions const & opt << int(opt.scope) << ' ' << int(opt.restr); - LYXERR(Debug::FIND, "built: " << os.str()); + LYXERR(Debug::FINDVERBOSE, "built: " << os.str()); return os; } @@ -4736,7 +4729,7 @@ ostringstream & operator<<(ostringstream & os, FindAndReplaceOptions const & opt istringstream & operator>>(istringstream & is, FindAndReplaceOptions & opt) { - // LYXERR(Debug::FIND, "parsing"); + // LYXERR(Debug::FINDVERBOSE, "parsing"); string s; string line; getline(is, line); @@ -4748,7 +4741,7 @@ istringstream & operator>>(istringstream & is, FindAndReplaceOptions & opt) break; getline(is, line); } - // LYXERR(Debug::FIND, "file_buf_name: '" << s << "'"); + // LYXERR(Debug::FINDVERBOSE, "file_buf_name: '" << s << "'"); opt.find_buf_name = from_utf8(s); is >> opt.casesensitive >> opt.matchword >> opt.forward >> opt.expandmacros >> opt.ignoreformat >> opt.replace_all; is.get(); // Waste space before replace string @@ -4762,7 +4755,7 @@ istringstream & operator>>(istringstream & is, FindAndReplaceOptions & opt) break; getline(is, line); } - // LYXERR(Debug::FIND, "repl_buf_name: '" << s << "'"); + // LYXERR(Debug::FINDVERBOSE, "repl_buf_name: '" << s << "'"); opt.repl_buf_name = from_utf8(s); is >> opt.keep_case; int i; @@ -4772,7 +4765,7 @@ istringstream & operator>>(istringstream & is, FindAndReplaceOptions & opt) opt.restr = FindAndReplaceOptions::SearchRestriction(i); /* - LYXERR(Debug::FIND, "parsed: " << opt.casesensitive << ' ' << opt.matchword << ' ' << opt.forward << ' ' + LYXERR(Debug::FINDVERBOSE, "parsed: " << opt.casesensitive << ' ' << opt.matchword << ' ' << opt.forward << ' ' << opt.expandmacros << ' ' << opt.ignoreformat << ' ' << opt.keep_case << ' ' << opt.scope << ' ' << opt.restr); */