-void LatexInfo::makeKey(string key, KeyInfo keyI)
-{
- KeyInfo keyII(keyI);
- keys[key] = keyII;
-}
-
-void LatexInfo::buildKeys()
-{
- KeyInfo foreign = KeyInfo(KeyInfo::isMain, 2);
- KeyInfo standard = KeyInfo(KeyInfo::isStandard,1);
- KeyInfo regex = KeyInfo(KeyInfo::isRegex, 1);
- KeyInfo color = KeyInfo(KeyInfo::isStandard, 2);
- KeyInfo character = KeyInfo(KeyInfo::isChar, 1);
- KeyInfo toremove = KeyInfo(KeyInfo::doRemove, 1);
- KeyInfo leadremove = KeyInfo(KeyInfo::leadRemove,1);
- KeyInfo ignoreMe = KeyInfo(KeyInfo::isIgnored, 0);
-
- makeKey("textsf",standard);
- makeKey("texttt",standard);
- makeKey("textbf",standard);
- makeKey("textit",standard);
- makeKey("emph",standard);
- makeKey("noun",standard);
- makeKey("uuline",standard);
- makeKey("uline",standard);
- makeKey("sout",standard);
- makeKey("xout",standard);
- makeKey("uwave",standard);
- makeKey("regexp",regex);
- makeKey("textcolor",color);
- makeKey("foreignlanguage",foreign);
- makeKey("backslash",character);
- makeKey("textbackslash",character);
- makeKey("inputencoding", toremove);
- makeKey("shortcut", toremove);
- toremove.parenthesiscount = 0;
- makeKey("noindent", toremove);
- makeKey("url", leadremove);
- makeKey("href", leadremove);
- makeKey("menuitem", leadremove);
- makeKey("footnote", leadremove);
- makeKey("code", leadremove);
- makeKey("lyx", ignoreMe);
+void LatexInfo::makeKey(const string &keysstring, KeyInfo keyI, bool isPatternString)
+{
+ stringstream s(keysstring);
+ string key;
+ const char delim = '|';
+ while (getline(s, key, delim)) {
+ KeyInfo keyII(keyI);
+ if (isPatternString) {
+ keyII.used = false;
+ }
+ else if ( !keys[key].used)
+ keyII.disabled = true;
+ keys[key] = keyII;
+ }
+}
+
+void LatexInfo::buildKeys(bool isPatternString)
+{
+
+ static bool keysBuilt = false;
+ if (keysBuilt && !isPatternString) return;
+
+ // Known standard keys with 1 parameter.
+ // Split is done, if not at start of region
+ makeKey("textsf|textss|texttt", KeyInfo(KeyInfo::isStandard, 1, ignoreFormats.getFamily()), isPatternString);
+ makeKey("textbf", KeyInfo(KeyInfo::isStandard, 1, ignoreFormats.getSeries()), isPatternString);
+ makeKey("textit|textsc|textsl", KeyInfo(KeyInfo::isStandard, 1, ignoreFormats.getShape()), isPatternString);
+ makeKey("uuline|uline|uwave", KeyInfo(KeyInfo::isStandard, 1, ignoreFormats.getUnderline()), isPatternString);
+ makeKey("emph|noun", KeyInfo(KeyInfo::isStandard, 1, ignoreFormats.getMarkUp()), isPatternString);
+ makeKey("sout|xout", KeyInfo(KeyInfo::isStandard, 1, ignoreFormats.getStrikeOut()), isPatternString);
+
+ makeKey("section|subsection|subsubsection|paragraph|subparagraph|minisec",
+ KeyInfo(KeyInfo::isSectioning, 1, ignoreFormats.getSectioning()), isPatternString);
+ makeKey("section*|subsection*|subsubsection*|paragraph*",
+ KeyInfo(KeyInfo::isSectioning, 1, ignoreFormats.getSectioning()), isPatternString);
+ makeKey("part|part*|chapter|chapter*", KeyInfo(KeyInfo::isSectioning, 1, ignoreFormats.getSectioning()), isPatternString);
+ makeKey("title|subtitle|author|subject|publishers|dedication|uppertitleback|lowertitleback|extratitle|lyxaddress|lyxrightaddress", KeyInfo(KeyInfo::isTitle, 1, ignoreFormats.getFrontMatter()), isPatternString);
+ // Regex
+ makeKey("regexp", KeyInfo(KeyInfo::isRegex, 1, false), isPatternString);
+
+ // Split is done, if not at start of region
+ makeKey("textcolor", KeyInfo(KeyInfo::isStandard, 2, ignoreFormats.getColor()), isPatternString);
+ makeKey("latexenvironment", KeyInfo(KeyInfo::isStandard, 2, false), isPatternString);
+
+ // Split is done always.
+ makeKey("foreignlanguage", KeyInfo(KeyInfo::isMain, 2, ignoreFormats.getLanguage()), isPatternString);
+
+ // Known charaters
+ // No split
+ makeKey("backslash|textbackslash|slash", KeyInfo(KeyInfo::isChar, 0, false), isPatternString);
+ makeKey("textasciicircum|textasciitilde", KeyInfo(KeyInfo::isChar, 0, false), isPatternString);
+ makeKey("textasciiacute|texemdash", KeyInfo(KeyInfo::isChar, 0, false), isPatternString);
+ makeKey("dots|ldots", KeyInfo(KeyInfo::isChar, 0, false), isPatternString);
+ // Spaces
+ makeKey("quad|qquad|hfill|dotfill", KeyInfo(KeyInfo::isChar, 0, false), isPatternString);
+ makeKey("textvisiblespace|nobreakspace", KeyInfo(KeyInfo::isChar, 0, false), isPatternString);
+ makeKey("negthickspace|negmedspace|negthinspace", KeyInfo(KeyInfo::isChar, 0, false), isPatternString);
+ // Skip
+ // makeKey("enskip|smallskip|medskip|bigskip|vfill", KeyInfo(KeyInfo::isChar, 0, false), isPatternString);
+ // Custom space/skip, remove the content (== length value)
+ makeKey("vspace|vspace*|hspace|hspace*|mspace", KeyInfo(KeyInfo::noContent, 1, false), isPatternString);
+ // Found in fr/UserGuide.lyx
+ makeKey("og|fg", KeyInfo(KeyInfo::isChar, 0, false), isPatternString);
+ // quotes
+ makeKey("textquotedbl|quotesinglbase|lyxarrow", KeyInfo(KeyInfo::isChar, 0, false), isPatternString);
+ makeKey("textquotedblleft|textquotedblright", KeyInfo(KeyInfo::isChar, 0, false), isPatternString);
+ // Known macros to remove (including their parameter)
+ // No split
+ makeKey("input|inputencoding|label|ref|index|bibitem", KeyInfo(KeyInfo::doRemove, 1, false), isPatternString);
+ makeKey("addtocounter|setlength", KeyInfo(KeyInfo::noContent, 2, true), isPatternString);
+ // handle like standard keys with 1 parameter.
+ makeKey("url|href|vref|thanks", KeyInfo(KeyInfo::isStandard, 1, false), isPatternString);
+
+ // Ignore deleted text
+ makeKey("lyxdeleted", KeyInfo(KeyInfo::doRemove, 3, false), isPatternString);
+ // but preserve added text
+ makeKey("lyxadded", KeyInfo(KeyInfo::doRemove, 2, false), isPatternString);
+
+ // Macros to remove, but let the parameter survive
+ // No split
+ makeKey("menuitem|textmd|textrm", KeyInfo(KeyInfo::isStandard, 1, true), isPatternString);
+
+ // Remove language spec from content of these insets
+ makeKey("code", KeyInfo(KeyInfo::noMain, 1, false), isPatternString);
+
+ // Same effect as previous, parameter will survive (because there is no one anyway)
+ // No split
+ makeKey("noindent|textcompwordmark|maketitle", KeyInfo(KeyInfo::isStandard, 0, true), isPatternString);
+ // Remove table decorations
+ makeKey("hline|tabularnewline|toprule|bottomrule|midrule", KeyInfo(KeyInfo::doRemove, 0, true), isPatternString);
+ // Discard shape-header.
+ // For footnote or shortcut too, because of lang settings
+ // and wrong handling if used 'KeyInfo::noMain'
+ makeKey("circlepar|diamondpar|heartpar|nutpar", KeyInfo(KeyInfo::isStandard, 1, true), isPatternString);
+ makeKey("trianglerightpar|hexagonpar|starpar", KeyInfo(KeyInfo::isStandard, 1, true), isPatternString);
+ makeKey("triangleuppar|triangledownpar|droppar", KeyInfo(KeyInfo::isStandard, 1, true), isPatternString);
+ makeKey("triangleleftpar|shapepar|dropuppar", KeyInfo(KeyInfo::isStandard, 1, true), isPatternString);
+ makeKey("hphantom|vphantom|footnote|shortcut|include|includegraphics", KeyInfo(KeyInfo::isStandard, 1, true), isPatternString);
+ 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);
+
+ // Survives, like known character
+ makeKey("lyx|LyX|latex|LaTeX|latexe|LaTeXe|tex|TeX", KeyInfo(KeyInfo::isChar, 0, false), isPatternString);
+ makeKey("item|listitem", KeyInfo(KeyInfo::isList, 1, false), isPatternString);
+
+ makeKey("begin|end", KeyInfo(KeyInfo::isMath, 1, false), isPatternString);
+ makeKey("[|]", KeyInfo(KeyInfo::isMath, 1, false), isPatternString);
+ makeKey("$", KeyInfo(KeyInfo::isMath, 1, false), isPatternString);
+
+ makeKey("par|uldepth|ULdepth|protect|nobreakdash|medskip|relax", KeyInfo(KeyInfo::isStandard, 0, true), isPatternString);
+ // Remove RTL/LTR marker
+ makeKey("l|r|textlr|textfr|textar|beginl|endl", KeyInfo(KeyInfo::isStandard, 0, true), isPatternString);
+ makeKey("lettrine", KeyInfo(KeyInfo::cleanToStart, 0, true), isPatternString);
+ makeKey("lyxslide", KeyInfo(KeyInfo::isSectioning, 1, true), isPatternString);
+ makeKey("endarguments", KeyInfo(KeyInfo::endArguments, 0, true), isPatternString);
+ makeKey("twocolumn", KeyInfo(KeyInfo::removeWithArg, 2, true), isPatternString);
+ makeKey("tnotetext|ead|fntext|cortext|address", KeyInfo(KeyInfo::removeWithArg, 0, true), isPatternString);
+ makeKey("lyxend", KeyInfo(KeyInfo::isStandard, 0, true), isPatternString);
+ if (isPatternString) {
+ // Allow the first searched string to rebuild the keys too
+ keysBuilt = false;
+ }
+ else {
+ // no need to rebuild again
+ keysBuilt = true;
+ }