]> git.lyx.org Git - lyx.git/blobdiff - src/buffer.C
Dekel's patch -- I didn't fix the xforms-0.88 keysyms stuff so it still doesn't finis...
[lyx.git] / src / buffer.C
index 48c62c5263a6b819517829969ab5f7b0813b34df..742aad7b79153234af15ae618b0372647896adb2 100644 (file)
@@ -56,9 +56,6 @@
 #include "insets/insetindex.h" 
 #include "insets/insetinclude.h"
 #include "insets/insettoc.h"
-#include "insets/insetlof.h"
-#include "insets/insetlot.h"
-#include "insets/insetloa.h"
 #include "insets/insetparent.h"
 #include "insets/insetspecialchar.h"
 #include "insets/figinset.h"
@@ -102,6 +99,9 @@ using std::pair;
 using std::vector;
 using std::max;
 using std::set;
+#ifdef HAVE_SSTREAM
+using std::istringstream;
+#endif
 
 // all these externs should eventually be removed.
 extern BufferList bufferlist;
@@ -125,6 +125,7 @@ Buffer::Buffer(string const & file, bool ronly)
        bak_clean = true;
        dep_clean = 0;
        read_only = ronly;
+       unnamed = false;
        users = 0;
        lyxvc.buffer(this);
        if (read_only || (lyxrc.use_tempdir)) {
@@ -232,15 +233,15 @@ void Buffer::fileName(string const & newfile)
 // if par = 0 normal behavior
 // else insert behavior
 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
-#define USE_PARSE_FUNCTION 1
-//#define USE_TABULAR_INSETS 1
 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
 {
        string tmptok;
        int pos = 0;
        char depth = 0; // signed or unsigned?
+#ifndef NEW_INSETS
        LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
        LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
+#endif
        bool the_end_read = false;
 
        LyXParagraph * return_par = 0;
@@ -286,8 +287,12 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
                        continue;
                the_end_read = parseSingleLyXformat2Token(lex, par, return_par,
                                                          token, pos, depth,
-                                                         font, footnoteflag,
-                                                         footnotekind);
+                                                         font
+#ifndef NEW_INSETS
+                                                         , footnoteflag,
+                                                         footnotekind
+#endif
+                       );
        }
    
        if (!return_par)
@@ -299,17 +304,22 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
 }
 
 
+// We'll remove this later. (Lgb)
+static string last_inset_read;
+
+
 bool
 Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                                   LyXParagraph *& return_par,
                                   string const & token, int & pos,
-                                  char & depth, LyXFont & font,
-                                  LyXParagraph::footnote_flag & footnoteflag,
-                                  LyXParagraph::footnote_kind & footnotekind)
+                                  char & depth, LyXFont & font
+#ifndef NEW_INSETS
+                                  , LyXParagraph::footnote_flag & footnoteflag,
+                                  LyXParagraph::footnote_kind & footnotekind
+#endif
+       )
 {
        bool the_end_read = false;
-       // We'll remove this later. (Lgb)
-       static string last_inset_read;
        
        if (token[0] != '\\') {
                for (string::const_iterator cit = token.begin();
@@ -349,8 +359,10 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                        par->layout = 
                                textclasslist.NumberOfLayout(params.textclass, 
                                                             layout.obsoleted_by()).second;
+#ifndef NEW_INSETS
                par->footnoteflag = footnoteflag;
                par->footnotekind = footnotekind;
+#endif
                par->depth = depth;
                font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
                if (format < 2.16 && params.language == "hebrew")
@@ -390,6 +402,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                //lyxerr << "old float: " << tmptok << endl;
                
                Inset * inset = 0;
+               string old_float;
                
                if (tmptok == "footnote") {
                        inset = new InsetFoot;
@@ -397,33 +410,60 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                        inset = new InsetMarginal;
                } else if (tmptok == "fig") {
                        inset = new InsetFloat("figure");
-                       //inset = new InsetFigure;
+                       old_float += "placement htbp\n";
                } else if (tmptok == "tab") {
                        inset = new InsetFloat("table");
-                       //inset = new InsetTable;
+                       old_float += "placement htbp\n";
                } else if (tmptok == "alg") {
                        inset = new InsetFloat("algorithm");
-                       //inset = new InsetAlgorithm;
+                       old_float += "placement htbp\n";
                } else if (tmptok == "wide-fig") {
-                       InsetFloat * tmp = new InsetFloat("figure");
+                       InsetFloat * tmp = new InsetFloat("figure");
                        tmp->wide(true);
                        inset = tmp;
-                       //inset = new InsetFigure(true);
+                       old_float += "placement htbp\n";
                } else if (tmptok == "wide-tab") {
-                       InsetFloat * tmp = new InsetFloat("table");
+                       InsetFloat * tmp = new InsetFloat("table");
                        tmp->wide(true);
                        inset = tmp;
-                       //inset = new InsetTable(true);
+                       old_float += "placement htbp\n";
                }
 
                if (!inset) return false; // no end read yet
                
-               string old_float = "\ncollapsed true\n";
+               old_float += "collapsed true\n";
+
+               // Here we need to check for \end_deeper and handle that
+               // before we do the footnote parsing.
+               // This _is_ a hack! (Lgb)
+               while(true) {
+                       lex.next();
+                       string tmp = lex.GetString();
+                       if (tmp == "\\end_deeper") {
+                               lyxerr << "\\end_deeper caught!" << endl;
+                               if (!depth) {
+                                       lex.printError("\\end_deeper: "
+                                                      "depth is already null");
+                               } else
+                                       --depth;
+                               
+                       } else {
+                               old_float += tmp;
+                               old_float += ' ';
+                               break;
+                       }
+               }
+               
                old_float += lex.getLongString("\\end_float");
                old_float += "\n\\end_inset\n";
-               lyxerr << "float body: " << old_float << endl;
-               
+               //lyxerr << "float body: " << old_float << endl;
+
+#ifdef HAVE_SSTREAM
+               istringstream istr(old_float);
+#else
                istrstream istr(old_float.c_str());
+#endif
+               
                LyXLex nylex(0, 0);
                nylex.setStream(istr);
                
@@ -449,7 +489,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                if (pp.first) {
                        params.textclass = pp.second;
                } else {
-                       lex.printError("Unknown textclass `$$Token'");
+                 lex.printError("Unknown textclass `$$Token'");
                        params.textclass = 0;
                }
                if (!textclasslist.Load(params.textclass)) {
@@ -810,149 +850,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                // But insets should read it, it is a part of
                // the inset isn't it? Lgb.
        } else if (token == "\\begin_inset") {
-               // Should be moved out into its own function/method. (Lgb)
-               lex.next();
-               string tmptok = lex.GetString();
-               last_inset_read = tmptok;
-               // test the different insets
-               if (tmptok == "Quotes") {
-                       Inset * inset = new InsetQuotes;
-                       inset->Read(this, lex);
-                       par->InsertInset(pos, inset, font);
-                       ++pos;
-               } else if (tmptok == "External") {
-                       Inset * inset = new InsetExternal;
-                       inset->Read(this, lex);
-                       par->InsertInset(pos, inset, font);
-                       ++pos;
-               } else if (tmptok == "FormulaMacro") {
-                       Inset * inset = new InsetFormulaMacro;
-                       inset->Read(this, lex);
-                       par->InsertInset(pos, inset, font);
-                       ++pos;
-               } else if (tmptok == "Formula") {
-                       Inset * inset = new InsetFormula;
-                       inset->Read(this, lex);
-                       par->InsertInset(pos, inset, font);
-                       ++pos;
-               } else if (tmptok == "Figure") {
-                       Inset * inset = new InsetFig(100, 100, this);
-                       inset->Read(this, lex);
-                       par->InsertInset(pos, inset, font);
-                       ++pos;
-               } else if (tmptok == "Info") {
-                       Inset * inset = new InsetInfo;
-                       inset->Read(this, lex);
-                       par->InsertInset(pos, inset, font);
-                       ++pos;
-               } else if (tmptok == "Include") {
-                       Inset * inset = new InsetInclude(string(), this);
-                       inset->Read(this, lex);
-                       par->InsertInset(pos, inset, font);
-                       ++pos;
-               } else if (tmptok == "ERT") {
-                       Inset * inset = new InsetERT;
-                       inset->Read(this, lex);
-                       par->InsertInset(pos, inset, font);
-                       ++pos;
-               } else if (tmptok == "Tabular") {
-                       Inset * inset = new InsetTabular(this);
-                       inset->Read(this, lex);
-                       par->InsertInset(pos, inset, font);
-                       ++pos;
-               } else if (tmptok == "Text") {
-                       Inset * inset = new InsetText;
-                       inset->Read(this, lex);
-                       par->InsertInset(pos, inset, font);
-                       ++pos;
-               } else if (tmptok == "Foot") {
-                       Inset * inset = new InsetFoot;
-                       inset->Read(this, lex);
-                       par->InsertInset(pos, inset, font);
-                       ++pos;
-               } else if (tmptok == "Marginal") {
-                       Inset * inset = new InsetMarginal;
-                       inset->Read(this, lex);
-                       par->InsertInset(pos, inset, font);
-                       ++pos;
-               } else if (tmptok == "Minipage") {
-                       Inset * inset = new InsetMinipage;
-                       inset->Read(this, lex);
-                       par->InsertInset(pos, inset, font);
-                       ++pos;
-               } else if (tmptok == "Float") {
-                       lex.next();
-                       string tmptok = lex.GetString();
-                       Inset * inset = new InsetFloat(tmptok);
-                       inset->Read(this, lex);
-                       par->InsertInset(pos, inset, font);
-                       ++pos;
-               } else if (tmptok == "List") {
-                       Inset * inset = new InsetList;
-                       inset->Read(this, lex);
-                       par->InsertInset(pos, inset, font);
-                       ++pos;
-               } else if (tmptok == "Theorem") {
-                       Inset * inset = new InsetList;
-                       inset->Read(this, lex);
-                       par->InsertInset(pos, inset, font);
-                       ++pos;
-               } else if (tmptok == "Caption") {
-                       Inset * inset = new InsetCaption;
-                       inset->Read(this, lex);
-                       par->InsertInset(pos, inset, font);
-                       ++pos;
-               } else if (tmptok == "GRAPHICS") {
-                       Inset * inset = new InsetGraphics;
-                               //inset->Read(this, lex);
-                       par->InsertInset(pos, inset, font);
-               } else if (tmptok == "LatexCommand") {
-                       InsetCommand inscmd;
-                       inscmd.Read(this, lex);
-                       Inset * inset = 0;
-                       if (inscmd.getCmdName() == "cite") {
-                               inset = new InsetCitation(inscmd.getContents(), inscmd.getOptions());
-                       } else if (inscmd.getCmdName() == "bibitem") {
-                               lex.printError("Wrong place for bibitem");
-                               inset = inscmd.Clone();
-                       } else if (inscmd.getCmdName() == "BibTeX") {
-                               inset = new InsetBibtex(inscmd.getContents(), inscmd.getOptions(), this);
-                       } else if (inscmd.getCmdName() == "index") {
-                               inset = new InsetIndex(inscmd.getContents());
-                       } else if (inscmd.getCmdName() == "include") {
-                               inset = new InsetInclude(inscmd.getContents(), this);
-                       } else if (inscmd.getCmdName() == "label") {
-                               inset = new InsetLabel(inscmd.getCommand());
-                       } else if (inscmd.getCmdName() == "url"
-                                  || inscmd.getCmdName() == "htmlurl") {
-                               inset = new InsetUrl(inscmd.getCommand());
-                       } else if (inscmd.getCmdName() == "ref"
-                                  || inscmd.getCmdName() == "pageref"
-                                  || inscmd.getCmdName() == "vref"
-                                  || inscmd.getCmdName() == "vpageref"
-                                  || inscmd.getCmdName() == "prettyref") {
-                               if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
-                                       inset = new InsetRef(inscmd, this);
-                               }
-                       } else if (inscmd.getCmdName() == "tableofcontents") {
-                               inset = new InsetTOC(this);
-                       } else if (inscmd.getCmdName() == "listoffigures") {
-                               inset = new InsetLOF(this);
-                       } else if (inscmd.getCmdName() == "listofalgorithms") {
-                               inset = new InsetLOA(this);
-                       } else if (inscmd.getCmdName() == "listoftables") {
-                               inset = new InsetLOT(this);
-                       } else if (inscmd.getCmdName() == "printindex") {
-                               inset = new InsetPrintIndex(this);
-                       } else if (inscmd.getCmdName() == "lyxparent") {
-                               inset = new InsetParent(inscmd.getContents(), this);
-                       }
-                              
-                       if (inset) {
-                               par->InsertInset(pos, inset, font);
-                               ++pos;
-                       }
-               }
+               readInset(lex, par, pos, font);
        } else if (token == "\\SpecialChar") {
                LyXLayout const & layout =
                        textclasslist.Style(params.textclass, 
@@ -985,7 +883,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                par->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
                ++pos;
        } else if (token == "\\LyXTable") {
-#ifdef USE_TABULAR_INSETS
+#ifdef NEW_TABULAR
                Inset * inset = new InsetTabular(this);
                inset->Read(this, lex);
                par->InsertInset(pos, inset, font);
@@ -1012,20 +910,23 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                }
                ++pos;
        } else if (token == "\\bibitem") {  // ale970302
-               if (!par->bibkey)
-                       par->bibkey = new InsetBibKey;
+               if (!par->bibkey) {
+                       InsetCommandParams p( "bibitem" );
+                       par->bibkey = new InsetBibKey(p);
+               }
                par->bibkey->Read(this, lex);                   
-       }else if (token == "\\backslash") {
+       } else if (token == "\\backslash") {
                par->InsertChar(pos, '\\', font);
                ++pos;
-       }else if (token == "\\the_end") {
+       } else if (token == "\\the_end") {
                the_end_read = true;
        } else {
                // This should be insurance for the future: (Asger)
                lex.printError("Unknown token `$$Token'. "
                               "Inserting as text.");
-               for(string::const_iterator cit = token.begin();
-                   cit != token.end(); ++cit) {
+               string::const_iterator cit = token.begin();
+               string::const_iterator end = token.end();
+               for(; cit != end; ++cit) {
                        par->InsertChar(pos, (*cit), font);
                        ++pos;
                }
@@ -1033,13 +934,166 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
        return the_end_read;
 }
 
-bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
+
+void Buffer::readInset(LyXLex & lex, LyXParagraph *& par,
+                      int & pos, LyXFont & font)
 {
-       string token;
+       // consistency check
+       if (lex.GetString() != "\\begin_inset") {
+               lyxerr << "Buffer::readInset: Consistency check failed."
+                      << endl;
+       }
+       
+       lex.next();
+       string tmptok = lex.GetString();
+       last_inset_read = tmptok;
+       // test the different insets
+       if (tmptok == "Quotes") {
+               Inset * inset = new InsetQuotes;
+               inset->Read(this, lex);
+               par->InsertInset(pos, inset, font);
+               ++pos;
+       } else if (tmptok == "External") {
+               Inset * inset = new InsetExternal;
+               inset->Read(this, lex);
+               par->InsertInset(pos, inset, font);
+               ++pos;
+       } else if (tmptok == "FormulaMacro") {
+               Inset * inset = new InsetFormulaMacro;
+               inset->Read(this, lex);
+               par->InsertInset(pos, inset, font);
+               ++pos;
+       } else if (tmptok == "Formula") {
+               Inset * inset = new InsetFormula;
+               inset->Read(this, lex);
+               par->InsertInset(pos, inset, font);
+               ++pos;
+       } else if (tmptok == "Figure") {
+               Inset * inset = new InsetFig(100, 100, this);
+               inset->Read(this, lex);
+               par->InsertInset(pos, inset, font);
+               ++pos;
+       } else if (tmptok == "Info") {
+               Inset * inset = new InsetInfo;
+               inset->Read(this, lex);
+               par->InsertInset(pos, inset, font);
+               ++pos;
+       } else if (tmptok == "Include") {
+               InsetCommandParams p( "Include" );
+               Inset * inset = new InsetInclude(p, this);
+               inset->Read(this, lex);
+               par->InsertInset(pos, inset, font);
+               ++pos;
+       } else if (tmptok == "ERT") {
+               Inset * inset = new InsetERT;
+               inset->Read(this, lex);
+               par->InsertInset(pos, inset, font);
+               ++pos;
+       } else if (tmptok == "Tabular") {
+               Inset * inset = new InsetTabular(this);
+               inset->Read(this, lex);
+               par->InsertInset(pos, inset, font);
+               ++pos;
+       } else if (tmptok == "Text") {
+               Inset * inset = new InsetText;
+               inset->Read(this, lex);
+               par->InsertInset(pos, inset, font);
+               ++pos;
+       } else if (tmptok == "Foot") {
+               Inset * inset = new InsetFoot;
+               inset->Read(this, lex);
+               par->InsertInset(pos, inset, font);
+               ++pos;
+       } else if (tmptok == "Marginal") {
+               Inset * inset = new InsetMarginal;
+               inset->Read(this, lex);
+               par->InsertInset(pos, inset, font);
+               ++pos;
+       } else if (tmptok == "Minipage") {
+               Inset * inset = new InsetMinipage;
+               inset->Read(this, lex);
+               par->InsertInset(pos, inset, font);
+               ++pos;
+       } else if (tmptok == "Float") {
+               lex.next();
+               string tmptok = lex.GetString();
+               Inset * inset = new InsetFloat(tmptok);
+               inset->Read(this, lex);
+               par->InsertInset(pos, inset, font);
+               ++pos;
+       } else if (tmptok == "List") {
+               Inset * inset = new InsetList;
+               inset->Read(this, lex);
+               par->InsertInset(pos, inset, font);
+               ++pos;
+       } else if (tmptok == "Theorem") {
+               Inset * inset = new InsetList;
+               inset->Read(this, lex);
+               par->InsertInset(pos, inset, font);
+               ++pos;
+       } else if (tmptok == "Caption") {
+               Inset * inset = new InsetCaption;
+               inset->Read(this, lex);
+               par->InsertInset(pos, inset, font);
+               ++pos;
+       } else if (tmptok == "GRAPHICS") {
+               Inset * inset = new InsetGraphics;
+               inset->Read(this, lex);
+               par->InsertInset(pos, inset, font);
+               ++pos;
+       } else if (tmptok == "LatexCommand") {
+               InsetCommandParams inscmd;
+               inscmd.Read(lex);
+               Inset * inset = 0;
+               if (inscmd.getCmdName() == "cite") {
+                       inset = new InsetCitation(inscmd);
+               } else if (inscmd.getCmdName() == "bibitem") {
+                       lex.printError("Wrong place for bibitem");
+                       inset = new InsetBibKey(inscmd);
+               } else if (inscmd.getCmdName() == "BibTeX") {
+                       inset = new InsetBibtex(inscmd, this);
+               } else if (inscmd.getCmdName() == "index") {
+                       inset = new InsetIndex(inscmd);
+               } else if (inscmd.getCmdName() == "include") {
+                       inset = new InsetInclude(inscmd, this);
+               } else if (inscmd.getCmdName() == "label") {
+                       inset = new InsetLabel(inscmd);
+               } else if (inscmd.getCmdName() == "url"
+                          || inscmd.getCmdName() == "htmlurl") {
+                       inset = new InsetUrl(inscmd);
+               } else if (inscmd.getCmdName() == "ref"
+                          || inscmd.getCmdName() == "pageref"
+                          || inscmd.getCmdName() == "vref"
+                          || inscmd.getCmdName() == "vpageref"
+                          || inscmd.getCmdName() == "prettyref") {
+                       if (!inscmd.getOptions().empty()
+                           || !inscmd.getContents().empty()) {
+                               inset = new InsetRef(inscmd);
+                       }
+               } else if (inscmd.getCmdName() == "tableofcontents"
+                          || inscmd.getCmdName() == "listofalgorithms"
+                          || inscmd.getCmdName() == "listoffigures"
+                          || inscmd.getCmdName() == "listoftables") {
+                       inset = new InsetTOC(inscmd);
+               } else if (inscmd.getCmdName() == "printindex") {
+                       inset = new InsetPrintIndex(inscmd);
+               } else if (inscmd.getCmdName() == "lyxparent") {
+                       inset = new InsetParent(inscmd, this);
+               }
+               
+               if (inset) {
+                       par->InsertInset(pos, inset, font);
+                       ++pos;
+               }
+       }
+}
+
 
+bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
+{
        if (lex.IsOK()) {
                lex.next();
-               token = lex.GetString();
+               string token(lex.GetString());
                if (token == "\\lyxformat") { // the first token _must_ be...
                        lex.next();
                        format = lex.GetFloat();
@@ -1149,19 +1203,7 @@ bool Buffer::save() const
        
        if (writeFile(fileName(), false)) {
                markLyxClean();
-
-               // now delete the autosavefile
-               string a = OnlyPath(fileName());
-               a += '#';
-               a += OnlyFilename(fileName());
-               a += '#';
-               FileInfo fileinfo(a);
-               if (fileinfo.exist()) {
-                       if (::remove(a.c_str()) != 0) {
-                               WriteFSAlert(_("Could not delete "
-                                              "auto-save file!"), a);
-                       }
-               }
+               removeAutosaveFile(fileName());
        } else {
                // Saving failed, so backup is not backup
                if (lyxrc.make_backup) {
@@ -1249,9 +1291,18 @@ void Buffer::writeFileAscii(string const & fname, int linelen)
        char c, footnoteflag = 0, depth = 0;
        string tmp;
        LyXParagraph::size_type i;
-       int j, h, ltype = 0, ltype_depth = 0,
-               * clen = 0, actcell = 0, actpos = 0, cell = 0, cells = 0,
-               currlinelen = 0;
+       int j;
+       int ltype = 0;
+       int ltype_depth = 0;
+       int actcell = 0;
+       int actpos = 0;
+#ifndef NEW_TABULAR
+       int h;
+       int * clen = 0;
+       int cell = 0;
+       int cells = 0;
+#endif
+       int currlinelen = 0;
        long fpos = 0;
        bool ref_printed = false;
 
@@ -1266,10 +1317,17 @@ void Buffer::writeFileAscii(string const & fname, int linelen)
        while (par) {
                int noparbreak = 0;
                int islatex = 0;
-               if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
-                   !par->previous ||
-                   par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
-        
+               if (
+#ifndef NEW_INSETS
+                       par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
+#endif
+                   !par->previous
+#ifndef NEW_INSETS
+                   || par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE
+#endif
+                       ){
+
+#ifndef NEW_INSETS
                        /* begins a footnote environment ? */ 
                        if (footnoteflag != par->footnoteflag) {
                                footnoteflag = par->footnoteflag;
@@ -1282,6 +1340,7 @@ void Buffer::writeFileAscii(string const & fname, int linelen)
                                        currlinelen += j;
                                }
                        }
+#endif
         
                        /* begins or ends a deeper area ?*/ 
                        if (depth != par->depth) {
@@ -1337,10 +1396,14 @@ void Buffer::writeFileAscii(string const & fname, int linelen)
         
                        /* what about the alignment */ 
                } else {
+#ifndef NEW_INSETS
                        /* dummy layout, that means a footnote ended */ 
                        footnoteflag = LyXParagraph::NO_FOOTNOTE;
                        ofs << ") ";
                        noparbreak = 1;
+#else
+                       lyxerr << "Should this ever happen?" << endl;
+#endif
                }
       
                //LyXLayout const & layout =
@@ -2086,9 +2149,11 @@ void Buffer::latexParagraphs(ostream & ofs, LyXParagraph * par,
                        tmpholder = 0;
                }
 #endif
+#ifndef NEW_INSETS
                if (par->IsDummy())
                        lyxerr[Debug::LATEX] << "Error in latexParagraphs."
                                             << endl;
+#endif
                LyXLayout const & layout =
                        textclasslist.Style(params.textclass,
                                            par->layout);
@@ -2112,11 +2177,18 @@ void Buffer::latexParagraphs(ostream & ofs, LyXParagraph * par,
                ftcount = -1;
                if (layout.isEnvironment()
                     || par->pextra_type != LyXParagraph::PEXTRA_NONE) {
-                       par = par->TeXEnvironment(this, params, ofs, texrow,
-                                                 ftnote, ft_texrow, ftcount);
+                       par = par->TeXEnvironment(this, params, ofs, texrow
+#ifndef NEW_INSETS
+                                                 ,ftnote, ft_texrow, ftcount
+#endif
+                               );
                } else {
-                       par = par->TeXOnePar(this, params, ofs, texrow, false,
-                                            ftnote, ft_texrow, ftcount);
+                       par = par->TeXOnePar(this, params, ofs, texrow, false
+#ifndef NEW_INSETS
+                                            ,
+                                            ftnote, ft_texrow, ftcount
+#endif
+                               );
                }
 
                // Write out what we've generated...
@@ -2272,7 +2344,9 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
                                sgmlOpenTag(ofs, depth, temp);
 
                                par = par->next;
+#ifndef NEW_INSETS
                                linuxDocHandleFootnote(ofs, par, depth);
+#endif
                                continue;
                        }
                }
@@ -2353,13 +2427,17 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
                        break;
                }
 
+#ifndef NEW_INSETS
                do {
+#endif
                        SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
 
                        par = par->next;
+#ifndef NEW_INSETS
                        linuxDocHandleFootnote(ofs, par, depth);
                }
                while(par && par->IsDummy());
+#endif
 
                ofs << "\n";
                // write closing SGML tags
@@ -2391,6 +2469,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
 }
 
 
+#ifndef NEW_INSETS
 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
                                    int const depth)
 {
@@ -2403,6 +2482,7 @@ void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
                par = par->next;
        }
 }
+#endif
 
 
 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
@@ -2410,8 +2490,11 @@ void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
                                  LyXParagraph * & par)
 {
        LyXParagraph * tpar = par;
-       while (tpar && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE) &&
-              (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
+       while (tpar
+#ifndef NEW_INSETS
+              && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE)
+#endif
+              && (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
                                                             "Caption").second))
                tpar = tpar->next;
        if (tpar &&
@@ -2428,6 +2511,7 @@ void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
 }
 
 
+#ifndef NEW_INSETS
 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
                                   int const depth)
 {
@@ -2535,6 +2619,7 @@ void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
        if(!extra_par.empty()) os << extra_par;
        if(!tag.empty()) sgmlCloseTag(os, depth, tag);
 }
+#endif
 
 
 // push a tag in a style stack
@@ -2629,7 +2714,11 @@ void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
             i < par->size(); ++i) {
 
                // handle quote tag
-               if (i == main_body && !par->IsDummy()) {
+               if (i == main_body
+#ifndef NEW_INSETS
+                   && !par->IsDummy()
+#endif
+                       ) {
                        if (main_body > 0)
                                font1 = style.font;
                }
@@ -3025,16 +3114,19 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
                        break;
                }
 
+#ifndef NEW_INSETS
                do {
+#endif
                        string extra_par;
                        SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
                                            depth + 1 + command_depth);
                        par = par->next;
+#ifndef NEW_INSETS
                        DocBookHandleFootnote(ofs, par,
                                              depth + 1 + command_depth);
                }
                while(par && par->IsDummy());
-
+#endif
                string end_tag;
                // write closing SGML tags
                switch(style.latextype) {
@@ -3309,7 +3401,7 @@ int Buffer::runLiterate()
        users->owner()->getMiniBuffer()->Set(_("Running Literate..."));   
 
        // Remove all error insets
-       bool a = users->removeAutoInsets();
+       bool removedErrorInsets = users->removeAutoInsets();
 
        // generate the Literate file if necessary
        makeLaTeXFile(lit_name, org_path, false);
@@ -3342,7 +3434,7 @@ int Buffer::runLiterate()
 
        // if we removed error insets before we ran LaTeX or if we inserted
        // error insets after we ran LaTeX this must be run:
-        if (a || (res & Literate::ERRORS)){
+        if (removedErrorInsets || (res & Literate::ERRORS)){
                 users->redraw();
                 users->fitCursor();
                 //users->updateScrollbar();
@@ -3376,10 +3468,10 @@ int Buffer::buildProgram()
         users->owner()->getMiniBuffer()->Set(_("Building Program..."));   
  
         // Remove all error insets
-        bool a = users->removeAutoInsets();
+        bool removedErrorInsets = users->removeAutoInsets();
  
         // generate the LaTeX file if necessary
-        if (!isNwClean() || a) {
+        if (!isNwClean() || removedErrorInsets) {
                 makeLaTeXFile(lit_name, org_path, false);
                 markNwDirty();
         }
@@ -3413,7 +3505,7 @@ int Buffer::buildProgram()
         // if we removed error insets before we ran Literate/Build or
        // if we inserted error insets after we ran Literate/Build this
        // must be run:
-       if (a || (res & Literate::ERRORS)){
+       if (removedErrorInsets || (res & Literate::ERRORS)){
                users->redraw();
                users->fitCursor();
                //users->updateScrollbar();
@@ -3607,6 +3699,7 @@ vector<vector<Buffer::TocItem> > Buffer::getTocList()
        vector<vector<TocItem> > l(4);
        LyXParagraph * par = paragraph;
        while (par) {
+#ifndef NEW_INSETS
                if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
                        if (textclasslist.Style(params.textclass, 
                                                par->GetLayout()).labeltype
@@ -3633,6 +3726,7 @@ vector<vector<Buffer::TocItem> > Buffer::getTocList()
                                }
                        }
                } else if (!par->IsDummy()) {
+#endif
                        char labeltype = textclasslist.Style(params.textclass, 
                                                             par->GetLayout()).labeltype;
       
@@ -3647,7 +3741,9 @@ vector<vector<Buffer::TocItem> > Buffer::getTocList()
                                tmp.str =  par->String(this, true);
                                l[TOC_TOC].push_back(tmp);
                        }
+#ifndef NEW_INSETS
                }
+#endif
                par = par->next;
        }
        return l;
@@ -3668,7 +3764,7 @@ vector<pair<string,string> > Buffer::getBibkeyList()
        LyXParagraph * par = paragraph;
        while (par) {
                if (par->bibkey)
-                       keys.push_back(pair<string,string>(par->bibkey->getContents(),
+                       keys.push_back(pair<string, string>(par->bibkey->getContents(),
                                                           par->String(this, false)));
                par = par->next;
        }