diff --git a/src/mathed/InsetMath.h b/src/mathed/InsetMath.h index f60602c5fe..6b178a7a2d 100644 --- a/src/mathed/InsetMath.h +++ b/src/mathed/InsetMath.h @@ -31,7 +31,8 @@ enum HullType { hullXXAlignAt, hullFlAlign, hullMultline, - hullGather + hullGather, + hullRegexp }; HullType hullType(docstring const & name); diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp index f3058c54c1..e14f70be2b 100644 --- a/src/mathed/InsetMathGrid.cpp +++ b/src/mathed/InsetMathGrid.cpp @@ -980,20 +980,27 @@ void InsetMathGrid::mathmlize(MathStream & os) const void InsetMathGrid::write(WriteStream & os) const +{ + write(os, 0, 0, nrows(), ncols()); +} + +void InsetMathGrid::write(WriteStream & os, + row_type beg_row, col_type beg_col, + row_type end_row, col_type end_col) const { MathEnsurer ensurer(os, false); docstring eol; - for (row_type row = 0; row < nrows(); ++row) { + for (row_type row = beg_row; row < end_row; ++row) { os << verboseHLine(rowinfo_[row].lines_); // don't write & and empty cells at end of line col_type lastcol = 0; bool emptyline = true; - for (col_type col = 0; col < ncols(); ++col) + for (col_type col = beg_col; col < end_col; ++col) if (!cell(index(row, col)).empty()) { lastcol = col + 1; emptyline = false; } - for (col_type col = 0; col < lastcol; ++col) { + for (col_type col = beg_col; col < end_col; ++col) { os << cell(index(row, col)); if (os.pendingBrace()) ModeSpecifier specifier(os, TEXT_MODE); @@ -1003,9 +1010,10 @@ void InsetMathGrid::write(WriteStream & os) const os << eol; // append newline only if line wasn't completely empty // and this was not the last line in the grid - if (!emptyline && row + 1 < nrows()) + if (!emptyline && row + 1 < end_row) os << "\n"; } + // @TODO use end_row instead of nrows() ? docstring const s = verboseHLine(rowinfo_[nrows()].lines_); if (!s.empty()) { if (eol.empty()) { diff --git a/src/mathed/InsetMathGrid.h b/src/mathed/InsetMathGrid.h index 437654c864..f085f99f1a 100644 --- a/src/mathed/InsetMathGrid.h +++ b/src/mathed/InsetMathGrid.h @@ -210,6 +210,10 @@ public: /// void write(WriteStream & os) const; /// + void write(WriteStream & os, + row_type beg_row, col_type beg_col, + row_type end_row, col_type end_col) const; + /// void normalize(NormalStream &) const; /// //void maple(MapleStream &) const; diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index 8496734ca8..99bb45fc0a 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -118,7 +118,8 @@ HullType hullType(docstring const & s) if (s == "multline") return hullMultline; if (s == "gather") return hullGather; if (s == "flalign") return hullFlAlign; - lyxerr << "unknown hull type '" << to_utf8(s) << "'" << endl; + if (s == "regexp") return hullRegexp; + lyxerr << "unknown hull type '" << to_utf8(s) << "'" << endl; return HullType(-1); } @@ -137,7 +138,8 @@ docstring hullName(HullType type) case hullMultline: return from_ascii("multline"); case hullGather: return from_ascii("gather"); case hullFlAlign: return from_ascii("flalign"); - default: + case hullRegexp: return from_ascii("regexp"); + default: lyxerr << "unknown hull type '" << type << "'" << endl; return from_ascii("none"); } @@ -556,10 +558,10 @@ bool InsetMathHull::ams() const Inset::DisplayType InsetMathHull::display() const { - return (type_ != hullSimple && type_ != hullNone) ? AlignCenter : Inline; + return (type_ != hullSimple && type_ != hullNone + && type_ != hullRegexp) ? AlignCenter : Inline; } - bool InsetMathHull::numberedType() const { if (type_ == hullNone) @@ -568,6 +570,8 @@ bool InsetMathHull::numberedType() const return false; if (type_ == hullXXAlignAt) return false; + if (type_ == hullRegexp) + return false; for (row_type row = 0; row < nrows(); ++row) if (!nonum_[row]) return true; @@ -631,6 +635,10 @@ void InsetMathHull::header_write(WriteStream & os) const << '{' << static_cast((ncols() + 1)/2) << "}\n"; break; + case hullRegexp: + os << "\\regexp{"; + break; + default: os << "\\begin{unknown" << star(n) << '}'; break; @@ -672,6 +680,10 @@ void InsetMathHull::footer_write(WriteStream & os) const os << "\\end{" << hullName(type_) << "}\n"; break; + case hullRegexp: + os << "}"; + break; + default: os << "\\end{unknown" << star(n) << '}'; break; diff --git a/src/mathed/InsetMathHull.h b/src/mathed/InsetMathHull.h index 2b3d305bcc..9f850b240e 100644 --- a/src/mathed/InsetMathHull.h +++ b/src/mathed/InsetMathHull.h @@ -111,6 +111,10 @@ public: /// void write(std::ostream & os) const; /// + void header_write(WriteStream &) const; + /// + void footer_write(WriteStream &) const; + /// void read(Lexer & lex); /// bool readQuiet(Lexer & lex); @@ -157,10 +161,6 @@ private: /// void validate1(LaTeXFeatures & features); /// - void header_write(WriteStream &) const; - /// - void footer_write(WriteStream &) const; - /// docstring nicelabel(row_type row) const; /// void doExtern(Cursor & cur, FuncRequest & func); diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp index 9e1b63496b..7df9cf92a8 100644 --- a/src/mathed/InsetMathNest.cpp +++ b/src/mathed/InsetMathNest.cpp @@ -964,6 +964,23 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd) break; } + case LFUN_REGEXP_MODE: { + InsetMathHull * i = dynamic_cast(cur.inset().asInsetMath()); + if (i && i->getType() == hullRegexp) { + cur.message(_("Already in regexp mode")); + break; + } + cur.macroModeClose(); + docstring const save_selection = grabAndEraseSelection(cur); + selClearOrDel(cur); + cur.plainInsert(MathAtom(new InsetMathHull(hullRegexp))); + cur.posBackward(); + cur.pushBackward(*cur.nextInset()); + cur.niceInsert(save_selection); + cur.message(_("Regexp editor mode")); + break; + } + case LFUN_MATH_SIZE: { FuncRequest fr = FuncRequest(LFUN_MATH_INSERT, cmd.argument()); doDispatch(cur, fr); diff --git a/src/mathed/MathFactory.cpp b/src/mathed/MathFactory.cpp index 1eea247a3c..d12ac0aa56 100644 --- a/src/mathed/MathFactory.cpp +++ b/src/mathed/MathFactory.cpp @@ -41,6 +41,7 @@ #include "InsetMathTabular.h" #include "InsetMathUnderset.h" #include "InsetMathUnknown.h" +#include "InsetMathHull.h" #include "InsetMathXArrow.h" #include "InsetMathXYMatrix.h" #include "MacroTable.h" @@ -462,6 +463,9 @@ MathAtom createInsetMath(docstring const & s) if (isSpecialChar(s)) return MathAtom(new InsetMathSpecialChar(s)); + if (s == "regexp") + return MathAtom(new InsetMathHull(hullRegexp)); + return MathAtom(new MathMacro(s)); }