This patch

1 replaces mathcursor->interpret(arg) calls in MathFormulaBase
  with mathcursor->insert(asArray(arg)), which does the same
        and additionally allows the insertion of multiple
        symbols in one call (so 'math-insert \alpha_\beta'
        works now as e.g. request by Bo Peng.

2 removes some dead code from MathCursor::interpret(string)

3 moves some special code for the handling of math-matrix from
  MathCursor::interpret(string) to the dispatch() where it
  belongs

4 moves the remaining code of MathCursor::interpret(string)
  to  MathMacroClose, as this is the only place where it
  is needed after 1

5 removes MathCursor::interpret(string) as it is not needed
  anymore after 1-4


I'd call 1 a 'bugfix' as 'math-insert' is now more consistent with
'self-insert' which can insert several chars in a row as well.

Apart from that it removes 31 lines and cleans up the math cursor a bit.

Ok to apply?

Andre'

-- 
Those who desire to give up Freedom in order to gain Security,
will not have, nor do they deserve, either one. (T. Jefferson)
Index: lib/ui/default.ui
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/ui/default.ui,v
retrieving revision 1.101
diff -u -p -r1.101 default.ui
--- lib/ui/default.ui   14 Oct 2002 12:56:21 -0000      1.101
+++ lib/ui/default.ui   22 Oct 2002 08:31:19 -0000
@@ -218,7 +218,7 @@ Menuset
        Item "AMS gather environment" "command-sequence math-mode; math-mutate gather;"
        Item "AMS multline environment" "command-sequence math-mode; math-mutate 
multline;"
   Separator
-       Item "Array environment|y" "math-insert matrix 2 2"
+       Item "Array environment|y" "math-matrix 2 2"
        Item "Cases environment|C" "math-insert \cases"
   Separator
        Submenu "Font Change|f" "insert_math_font"
Index: src/mathed/formulabase.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formulabase.C,v
retrieving revision 1.216
diff -u -p -r1.216 formulabase.C
--- src/mathed/formulabase.C    15 Oct 2002 16:17:40 -0000      1.216
+++ src/mathed/formulabase.C    22 Oct 2002 08:31:19 -0000
@@ -621,7 +621,7 @@ Inset::RESULT InsetFormulaBase::localDis
        case LFUN_GREEK:
                handleFont(bv, cmd.argument, "lyxgreek1");
                if (cmd.argument.size())
-                       mathcursor->interpret(cmd.argument);
+                       mathcursor->insert(asArray(cmd.argument));
                break;
 
        case LFUN_MATH_MODE:
@@ -644,13 +644,22 @@ Inset::RESULT InsetFormulaBase::localDis
 #endif
                break;
 
-       case LFUN_INSERT_MATRIX:
-               if (!cmd.argument.empty()) {
-                       bv->lockedInsetStoreUndo(Undo::EDIT);
-                       mathcursor->interpret("matrix " + cmd.argument);
+       case LFUN_INSERT_MATRIX: {
+               bv->lockedInsetStoreUndo(Undo::EDIT);
+               unsigned int m = 1;
+               unsigned int n = 1;
+               string v_align;
+               string h_align;
+               istringstream is(argument);
+               is >> m >> n >> v_align >> h_align;
+               m = max(1u, m);
+               n = max(1u, n);
+               v_align += 'c';
+               mathcursor->niceInsert(
+                       MathAtom(new MathArrayInset("array", m, n, v_align[0], 
+h_align)));
                        updateLocal(bv, true);
-               }
                break;
+       }
 
        case LFUN_SUPERSCRIPT:
        case LFUN_SUBSCRIPT:
@@ -707,15 +716,23 @@ Inset::RESULT InsetFormulaBase::localDis
                argument = "\n";
                // fall through
 
-       case -1:
+// FIXME: We probably should swap parts of "math-insert" and "self-insert"
+// handling such that "self-insert" works on "arbitrary stuff" too, and
+// math-insert only handles special math things like "matrix".
        case LFUN_INSERT_MATH:
+               bv->lockedInsetStoreUndo(Undo::EDIT);
+               mathcursor->insert(asArray(argument));
+               updateLocal(bv, true);
+               break;
+       
+       case -1:
        case LFUN_SELFINSERT:
                if (!argument.empty()) {
                        bv->lockedInsetStoreUndo(Undo::EDIT);
                        if (argument.size() == 1)
                                result = mathcursor->interpret(argument[0]) ? 
DISPATCHED : FINISHED_RIGHT;
                        else
-                               result = mathcursor->interpret(argument) ? DISPATCHED 
: FINISHED_RIGHT;
+                               mathcursor->insert(asArray(argument));
                        updateLocal(bv, true);
                }
                break;
Index: src/mathed/math_cursor.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_cursor.C,v
retrieving revision 1.321
diff -u -p -r1.321 math_cursor.C
--- src/mathed/math_cursor.C    15 Oct 2002 16:17:40 -0000      1.321
+++ src/mathed/math_cursor.C    22 Oct 2002 08:31:19 -0000
@@ -536,8 +536,24 @@ void MathCursor::macroModeClose()
        string s = p->name();
        --pos();
        array().erase(pos());
-       if (s != "\\")
-               interpret(s);
+
+       // do nothing if the macro name is empty
+       if (s == "\\")
+               return;
+
+       //lyxerr << "interpret 1: '" << s << "'\n";
+       //lyxerr << "char: '" << s[0] << "'  int: " << int(s[0]) << endl;
+       //owner_->getIntl()->getTransManager().TranslateAndInsert(s[0], lt);
+       //lyxerr << "trans: '" << s[0] << "'  int: " << int(s[0]) << endl;
+
+       string name = s.substr(1);
+
+       // prevent entering of recursive macros
+       if (formula()->lyxCode() == Inset::MATHMACRO_CODE
+                       && formula()->getInsetName() == name)
+               lyxerr << "can't enter recursive macro\n";
+
+       niceInsert(createMathInset(name));
 }
 
 
@@ -1108,68 +1124,6 @@ bool MathCursor::idxLeft()
 bool MathCursor::idxRight()
 {
        return par()->idxRight(idx(), pos());
-}
-
-
-bool MathCursor::interpret(string const & s)
-{
-       //lyxerr << "interpret 1: '" << s << "'\n";
-       if (s.empty())
-               return true;
-
-       //lyxerr << "char: '" << s[0] << "'  int: " << int(s[0]) << endl;
-       //owner_->getIntl()->getTransManager().TranslateAndInsert(s[0], lt);
-       //lyxerr << "trans: '" << s[0] << "'  int: " << int(s[0]) << endl;
-
-       if (s.size() >= 6 && s.substr(0, 6) == "matrix") {
-               unsigned int m = 1;
-               unsigned int n = 1;
-               string v_align;
-               string h_align;
-               istringstream is(s.substr(6).c_str());
-               is >> m >> n >> v_align >> h_align;
-               m = max(1u, m);
-               n = max(1u, n);
-               v_align += 'c';
-               niceInsert(MathAtom(new MathArrayInset("array", m, n, v_align[0], 
h_align)));
-               return true;
-       }
-
-       if (s.size() >= 7 && s.substr(0, 7) == "replace") {
-               ReplaceData rep;
-               istringstream is(s.substr(7).c_str());
-               string from, to;
-               is >> from >> to;
-               mathed_parse_cell(rep.from, from);
-               mathed_parse_cell(rep.to, to);
-               lyxerr << "replacing '" << from << "' with '" << to << "'\n";
-               par()->replace(rep);
-               return true;
-       }
-
-       string name = s.substr(1);
-
-       if (name == "over" || name == "choose" || name == "atop") {
-               MathAtom t(createMathInset(name));
-               t.nucleus()->asNestInset()->cell(0) = array();
-               array().clear();
-               pos() = 0;
-               niceInsert(t);
-               popRight();
-               left();
-               return true;
-       }
-
-       // prevent entering of recursive macros
-       if (formula()->lyxCode() == Inset::MATHMACRO_CODE
-               && formula()->getInsetName() == name)
-       {
-               lyxerr << "can't enter recursive macro\n";
-               return true;
-       }
-
-       niceInsert(createMathInset(name));
-       return true;
 }
 
 
Index: src/mathed/math_cursor.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_cursor.h,v
retrieving revision 1.132
diff -u -p -r1.132 math_cursor.h
--- src/mathed/math_cursor.h    15 Oct 2002 16:17:40 -0000      1.132
+++ src/mathed/math_cursor.h    22 Oct 2002 08:31:19 -0000
@@ -123,8 +123,6 @@ public:
        size_type size() const;
        ///
        bool script(bool);
-       ///
-       bool interpret(string const &);
        /// 
        bool interpret(char);
        /// interpret name a name of a macro

Reply via email to