]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/text.cpp
Make undo action no-ops when the buffer is read-only
[lyx.git] / src / tex2lyx / text.cpp
index 10b9c093b0b6c1188bb01fa79c9d2090e8eb23d3..76d11a7cb8830ff8e80fc0c6793a357472c3fc35 100644 (file)
@@ -54,7 +54,7 @@ void output_arguments(ostream &, Parser &, bool, bool, const string &, Context &
 
 
 void parse_text_in_inset(Parser & p, ostream & os, unsigned flags, bool outer,
-               Context const & context, InsetLayout const * layout,
+               Context & context, InsetLayout const * layout,
                string const & rdelim)
 {
        bool const forcePlainLayout =
@@ -64,6 +64,10 @@ void parse_text_in_inset(Parser & p, ostream & os, unsigned flags, bool outer,
                newcontext.layout = &context.textclass.plainLayout();
        else
                newcontext.font = context.font;
+       // Inherit commands to pass through
+       newcontext.pass_thru_cmds = context.pass_thru_cmds;
+       // and table cell
+       newcontext.in_table_cell = context.in_table_cell;
        if (layout)
                output_arguments(os, p, outer, false, string(), newcontext,
                                 layout->latexargs());
@@ -79,6 +83,7 @@ void parse_text_in_inset(Parser & p, ostream & os, unsigned flags, bool outer,
                output_arguments(os, p, outer, false, "post", newcontext,
                                 layout->postcommandargs());
        newcontext.check_end_layout(os);
+       context.cell_align = newcontext.cell_align;
 }
 
 
@@ -93,7 +98,8 @@ void parse_text_in_inset(Parser & p, ostream & os, unsigned flags, bool outer,
                context.textclass.insetLayouts().find(from_ascii(name));
        if (it != context.textclass.insetLayouts().end())
                layout = &(it->second);
-       parse_text_in_inset(p, os, flags, outer, context, layout, rdelim);
+       Context newcontext = context;
+       parse_text_in_inset(p, os, flags, outer, newcontext, layout, rdelim);
 }
 
 /// parses a paragraph snippet, useful for example for \\emph{...}
@@ -319,7 +325,7 @@ char const * const known_tex_extensions[] = {"tex", 0};
 char const * const known_spaces[] = { " ", "space", 
 ",", "thinspace",//                                   \\, = \\thinspace
 "quad", "qquad", "enspace", "enskip",
-";", ">", "medspace",//                               \\; = \\> = \medspace
+";", ">", "medspace",//                               \\; = \\> = \\medspace
 ":", "thickspace",//                                  \\: = \\thickspace
 "!", "negthinspace",//                                \\! = \\negthinspace
 "negmedspace", "negthickspace",
@@ -1733,7 +1739,13 @@ void parse_environment(Parser & p, ostream & os, bool outer,
                        os << "wide " << convert<string>(is_starred)
                           << "\nsideways false"
                           << "\nstatus open\n\n";
+                       set<string> pass_thru_cmds = parent_context.pass_thru_cmds;
+                       if (unstarred_name == "algorithm")
+                               // in algorithm, \; has special meaning
+                               parent_context.pass_thru_cmds.insert(";");
                        parse_text_in_inset(p, os, FLAG_END, outer, parent_context);
+                       if (unstarred_name == "algorithm")
+                               parent_context.pass_thru_cmds = pass_thru_cmds;
                        end_inset(os);
                        // We don't need really a new paragraph, but
                        // we must make sure that the next item gets a \begin_layout.
@@ -1869,7 +1881,13 @@ void parse_environment(Parser & p, ostream & os, bool outer,
                        eat_whitespace(p, os, parent_context, false);
                        parent_context.check_layout(os);
                        begin_inset(os, "IPA\n");
+                       set<string> pass_thru_cmds = parent_context.pass_thru_cmds;
+                       // These commands have special meanings in IPA
+                       parent_context.pass_thru_cmds.insert("!");
+                       parent_context.pass_thru_cmds.insert(";");
+                       parent_context.pass_thru_cmds.insert(":");
                        parse_text_in_inset(p, os, FLAG_END, outer, parent_context);
+                       parent_context.pass_thru_cmds = pass_thru_cmds;
                        end_inset(os);
                        p.skip_spaces();
                        preamble.registerAutomaticallyLoadedPackage("tipa");
@@ -4121,7 +4139,13 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        begin_inset(os, "IPA\n");
                        bool merging_hyphens_allowed = context.merging_hyphens_allowed;
                        context.merging_hyphens_allowed = false;
+                       set<string> pass_thru_cmds = context.pass_thru_cmds;
+                       // These commands have special meanings in IPA
+                       context.pass_thru_cmds.insert("!");
+                       context.pass_thru_cmds.insert(";");
+                       context.pass_thru_cmds.insert(":");
                        parse_text_in_inset(p, os, FLAG_ITEM, outer, context);
+                       context.pass_thru_cmds = pass_thru_cmds;
                        context.merging_hyphens_allowed = merging_hyphens_allowed;
                        end_inset(os);
                        preamble.registerAutomaticallyLoadedPackage("tipa");
@@ -5081,6 +5105,13 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        continue;
                }
 
+               if (t.cs() == "endgraf" && context.in_table_cell) {
+                       context.new_paragraph(os);
+                       context.check_layout(os);
+                       skip_spaces_braces(p);
+                       continue;
+               }
+
                if (t.cs() == "input" || t.cs() == "include"
                    || t.cs() == "verbatiminput"
                    || t.cs() == "lstinputlisting"
@@ -5505,28 +5536,36 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                // the code for the alignment was put here
                // put them in their own if if this is fixed
                if (t.cs() == "fboxrule" || t.cs() == "fboxsep"
-                   || t.cs() == "shadowsize"
-                   || t.cs() == "raggedleft" || t.cs() == "centering"
-                   || t.cs() == "raggedright") {
+                   || t.cs() == "shadowsize") {
                        if (t.cs() == "fboxrule")
                                fboxrule = "";
                        if (t.cs() == "fboxsep")
                                fboxsep = "";
                        if (t.cs() == "shadowsize")
                                shadow_size = "";
-                       if (t.cs() != "raggedleft" && t.cs() != "centering"
-                        && t.cs() != "raggedright") {
+                       p.skip_spaces(true);
+                       while (p.good() && p.next_token().cat() != catSpace
+                              && p.next_token().cat() != catNewline
+                              && p.next_token().cat() != catEscape) {
+                               if (t.cs() == "fboxrule")
+                                       fboxrule = fboxrule + p.get_token().asInput();
+                               if (t.cs() == "fboxsep")
+                                       fboxsep = fboxsep + p.get_token().asInput();
+                               if (t.cs() == "shadowsize")
+                                       shadow_size = shadow_size + p.get_token().asInput();
+                       }
+                       continue;
+               }
+
+               if (t.cs() == "raggedleft" || t.cs() == "centering" || t.cs() == "raggedright") {
+                       if (context.in_table_cell) {
+                               if (t.cs() == "raggedleft")
+                                       context.cell_align = 'r';
+                               else if (t.cs() == "centering")
+                                       context.cell_align = 'c';
+                               else if (t.cs() == "raggedright")
+                                       context.cell_align = 'l';
                                p.skip_spaces(true);
-                               while (p.good() && p.next_token().cat() != catSpace
-                                      && p.next_token().cat() != catNewline
-                                      && p.next_token().cat() != catEscape) {
-                                       if (t.cs() == "fboxrule")
-                                               fboxrule = fboxrule + p.get_token().asInput();
-                                       if (t.cs() == "fboxsep")
-                                               fboxsep = fboxsep + p.get_token().asInput();
-                                       if (t.cs() == "shadowsize")
-                                               shadow_size = shadow_size + p.get_token().asInput();
-                               }
                        } else {
                                output_ert_inset(os, t.asInput(), context);
                        }
@@ -5586,7 +5625,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        continue;
                }
 
-               if ((where = is_known(t.cs(), known_spaces))) {
+               if ((where = is_known(t.cs(), known_spaces))
+                   && (context.pass_thru_cmds.find(t.cs()) == context.pass_thru_cmds.end())) {
                        context.check_layout(os);
                        begin_inset(os, "space ");
                        os << '\\' << known_coded_spaces[where - known_spaces]