commit e6418431dd946d257e62b9ff0ddb3ab7fc1aa6c5
Author: Kornel Benko <[email protected]>
Date: Sat Nov 3 11:15:12 2018 +0100
Findadv: Handle the problem with list environments
The problem was, that the different list ennvironments
did not look different in tha latex output used for
search.
So the input of "\item ..." did not give information
if it is description, lyxlist, enumeration or labeling.
In search modus we use now "\item{enumeration}" etc.
---
src/lyxfind.cpp | 39 +++++++++++++++++++++++++++++++--------
src/output_latex.cpp | 15 ++++++++++-----
2 files changed, 41 insertions(+), 13 deletions(-)
diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp
index 50b5e6d..e86d296 100644
--- a/src/lyxfind.cpp
+++ b/src/lyxfind.cpp
@@ -849,7 +849,7 @@ static size_t identifyLeading(string const & s)
while (regex_replace(t, t, REGEX_BOS
"\\\\(((emph|noun|minisec|text(bf|sl|sf|it|tt))|((textcolor|foreignlanguage)\\{[a-z]+\\})|(u|uu)line|(s|x)out|uwave)|((sub)?(((sub)?section)|paragraph)|part|chapter)\\*?)\\{",
"")
|| regex_replace(t, t, REGEX_BOS "\\$", "")
|| regex_replace(t, t, REGEX_BOS "\\\\\\[ ", "")
- || regex_replace(t, t, REGEX_BOS "\\\\item ", "")
+ || regex_replace(t, t, REGEX_BOS " ?\\\\item\\{[a-z]+\\}", "")
|| regex_replace(t, t, REGEX_BOS "\\\\begin\\{[a-zA-Z_]*\\*?\\}
", ""))
;
LYXERR(Debug::FIND, " after removing leading $, \\[ , \\emph{,
\\textbf{, etc.: '" << t << "'");
@@ -868,7 +868,7 @@ typedef map<string, bool> Features;
static Features identifyFeatures(string const & s)
{
static regex const feature("\\\\(([a-z]+(\\{([a-z]+)\\}|\\*)?))\\{");
- static regex const
valid("^(((emph|noun|text(bf|sl|sf|it|tt)|(textcolor|foreignlanguage)\\{[a-z]+\\})|item
|(u|uu)line|(s|x)out|uwave)|((sub)?(((sub)?section)|paragraph)|part|chapter)\\*?)$");
+ static regex const
valid("^(((emph|noun|text(bf|sl|sf|it|tt)|(textcolor|foreignlanguage|item)\\{[a-z]+\\})|(u|uu)line|(s|x)out|uwave)|((sub)?(((sub)?section)|paragraph)|part|chapter)\\*?)$");
smatch sub;
bool displ = true;
Features info;
@@ -914,6 +914,7 @@ class KeyInfo {
isSize,
invalid,
doRemove,
+ isList,
isIgnored /* to be ignored by creating infos */
};
KeyInfo()
@@ -965,7 +966,7 @@ class Intervall {
void addIntervall(int upper);
void addIntervall(int low, int upper); /* if explicit */
void setForDefaultLang(int upTo);
- int findclosing(int start, int end);
+ int findclosing(int start, int end, char up, char down);
void handleParentheses(int lastpos, bool closingAllowed);
void output(ostringstream &os, int lastpos);
// string show(int lastpos);
@@ -1269,7 +1270,7 @@ class LatexInfo {
};
-int Intervall::findclosing(int start, int end)
+int Intervall::findclosing(int start, int end, char up = '{', char down = '}')
{
int skip = 0;
int depth = 0;
@@ -1278,10 +1279,10 @@ int Intervall::findclosing(int start, int end)
c = par[i];
skip = 0;
if (c == '\\') skip = 1;
- else if (c == '{') {
+ else if (c == up) {
depth++;
}
- else if (c == '}') {
+ else if (c == down) {
if (depth == 0) return(i);
--depth;
}
@@ -1577,7 +1578,7 @@ void LatexInfo::buildKeys(bool isPatternString)
// Survives, like known character
makeKey("lyx|latex|tex", KeyInfo(KeyInfo::isIgnored, 0, false),
isPatternString);
- makeKey("item", KeyInfo(KeyInfo::isChar, 0, false), isPatternString);
+ makeKey("item", KeyInfo(KeyInfo::isList, 1, false), isPatternString);
makeKey("begin|end", KeyInfo(KeyInfo::isMath, 1, false), isPatternString);
makeKey("[|]", KeyInfo(KeyInfo::isMath, 1, false), isPatternString);
@@ -1765,6 +1766,28 @@ int LatexInfo::dispatch(ostringstream &os, int
previousStart, KeyInfo &actual)
nextKeyIdx = getNextKey();
break;
}
+ case KeyInfo::isList: {
+ // Discard space before _tokenstart
+ int count;
+ for (count = 0; count < actual._tokenstart; count++) {
+ if (interval.par[actual._tokenstart-count-1] != ' ')
+ break;
+ }
+ if (actual.disabled) {
+ interval.addIntervall(actual._tokenstart-count, actual._dataEnd+1);
+ }
+ else {
+ interval.addIntervall(actual._tokenstart-count, actual._tokenstart);
+ }
+ // Discard extra parentheses '[]'
+ if (interval.par[actual._dataEnd+1] == '[') {
+ int posdown = interval.findclosing(actual._dataEnd+2,
interval.par.length(), '[', ']');
+ interval.addIntervall(actual._dataEnd+1, actual._dataEnd+2);
+ interval.addIntervall(posdown, posdown+1);
+ }
+ nextKeyIdx = getNextKey();
+ break;
+ }
case KeyInfo::isSectioning: {
// Discard space before _tokenstart
int count;
@@ -2271,7 +2294,7 @@ string MatchStringAdv::normalize(docstring const & s,
bool hack_braces) const
while (regex_replace(t, t,
"\\\\((sub)?(((sub)?section)|paragraph)|part)\\*?(\\{(\\{\\})?\\})+", ""))
LYXERR(Debug::FIND, " further removing stale empty \\emph{},
\\textbf{} macros from: " << t);
- while (regex_replace(t, t,
"\\\\(foreignlanguage|textcolor)\\{[a-z]+\\}(\\{(\\\\item |\\{\\})?\\})+", ""));
+ while (regex_replace(t, t,
"\\\\(foreignlanguage|textcolor|item)\\{[a-z]+\\}(\\{(\\{\\})?\\})+", ""));
// FIXME - check what preceeds the brace
if (hack_braces) {
if (opt.ignoreformat)
diff --git a/src/output_latex.cpp b/src/output_latex.cpp
index 96f51df..532250e 100644
--- a/src/output_latex.cpp
+++ b/src/output_latex.cpp
@@ -679,11 +679,16 @@ void parStartCommand(Paragraph const & par, otexstream &
os,
break;
case LATEX_ITEM_ENVIRONMENT:
case LATEX_LIST_ENVIRONMENT:
- os << "\\" + style.itemcommand();
- // Item arguments
- if (!style.itemargs().empty())
- latexArgInsets(par, os, runparams, style.itemargs(),
"item:");
- os << " ";
+ if (runparams.for_search) {
+ os << "\\item{" << style.latexname() << "}";
+ }
+ else {
+ os << "\\" + style.itemcommand();
+ // Item arguments
+ if (!style.itemargs().empty())
+ latexArgInsets(par, os, runparams,
style.itemargs(), "item:");
+ os << " ";
+ }
break;
case LATEX_BIB_ENVIRONMENT:
// ignore this, the inset will write itself