]> git.lyx.org Git - lyx.git/blobdiff - src/buffer.C
Fix crash when running lyx -dbg insets -e ...
[lyx.git] / src / buffer.C
index f95fa7893c39742c26e2f9ed4d551d8ca6b2344d..53893e39d3924b5aff3e3f9972401d983a921a77 100644 (file)
 #include "BufferView.h"
 #include "ParagraphParameters.h"
 
-using std::stringstream;
 using std::ostream;
 using std::ofstream;
 using std::ifstream;
@@ -127,7 +126,7 @@ extern LyXAction lyxaction;
 
 namespace {
 
-const int LYX_FORMAT = 218;
+const int LYX_FORMAT = 220;
 
 } // namespace anon
 
@@ -278,6 +277,29 @@ void Buffer::setFileName(string const & newfile)
 }
 
 
+// We'll remove this later. (Lgb)
+namespace {
+
+string last_inset_read;
+
+struct ErtComp 
+{
+       ErtComp() : active(false), in_tabular(false) {
+       }
+       string contents;
+       bool active;
+       bool in_tabular;
+};
+
+std::stack<ErtComp> ert_stack;
+ErtComp ert_comp;
+
+
+} // anon
+
+
+int unknown_layouts;
+
 // candidate for move to BufferView
 // (at least some parts in the beginning of the func)
 //
@@ -288,75 +310,97 @@ void Buffer::setFileName(string const & newfile)
 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
 bool Buffer::readLyXformat2(LyXLex & lex, Paragraph * par)
 {
+       unknown_layouts = 0;
+#ifdef NO_LATEX
+       ert_comp.contents.erase();
+       ert_comp.active = false;
+       ert_comp.in_tabular = false;
+#endif
+       
        int pos = 0;
        Paragraph::depth_type depth = 0; 
        bool the_end_read = false;
 
-       Paragraph * return_par = 0;
+       Paragraph * first_par = 0;
        LyXFont font(LyXFont::ALL_INHERIT, params.language);
        if (file_format < 216 && params.language->lang() == "hebrew")
                font.setLanguage(default_language);
-       // If we are inserting, we cheat and get a token in advance
-       bool has_token = false;
-       string pretoken;
 
        if (!par) {
                par = new Paragraph;
        } else {
                // We are inserting into an existing document
                users->text->breakParagraph(users);
-               return_par = users->text->firstParagraph();
+               first_par = users->text->firstParagraph();
                pos = 0;
                markDirty();
                // We don't want to adopt the parameters from the
                // document we insert, so we skip until the text begins:
                while (lex.IsOK()) {
                        lex.nextToken();
-                       pretoken = lex.GetString();
+                       string const pretoken = lex.GetString();
                        if (pretoken == "\\layout") {
-                               has_token = true;
+                               lex.pushToken(pretoken);
                                break;
                        }
                }
        }
 
        while (lex.IsOK()) {
-               if (has_token) {
-                       has_token = false;
-               } else {
-                       lex.nextToken();
-                       pretoken = lex.GetString();
-               }
+               lex.nextToken();
+               string const token = lex.GetString();
 
-               if (pretoken.empty()) continue;
+               if (token.empty()) continue;
+
+               lyxerr[Debug::PARSER] << "Handling token: `"
+                                     << token << "'" << endl;
                
                the_end_read =
-                       parseSingleLyXformat2Token(lex, par, return_par,
-                                                  pretoken, pos, depth,
-                                                  font
-                               );
+                       parseSingleLyXformat2Token(lex, par, first_par,
+                                                  token, pos, depth,
+                                                  font);
        }
    
-       if (!return_par)
-               return_par = par;
+       if (!first_par)
+               first_par = par;
 
-       paragraph = return_par;
-       
-       return the_end_read;
-}
+       paragraph = first_par;
 
+       if (unknown_layouts > 0) {
+               string s = _("Couldn't set the layout for ");
+               if (unknown_layouts == 1) {
+                       s += _("one paragraph");
+               } else {
+                       s += tostr(unknown_layouts);
+                       s += _(" paragraphs");
+               }
+               WriteAlert(_("Textclass Loading Error!"), s,
+                          _("When reading " + fileName()));
+       }       
 
-// We'll remove this later. (Lgb)
-namespace {
+       return the_end_read;
+}
 
-string last_inset_read;
 
-} // anon
+void Buffer::insertErtContents(Paragraph * par, int & pos,
+                              LyXFont const & font, bool set_inactive) 
+{
+       if (!ert_comp.contents.empty()) {
+               lyxerr[Debug::INSETS] << "ERT contents:\n"
+                      << ert_comp.contents << endl;
+               Inset * inset = new InsetERT(ert_comp.contents);
+               par->insertInset(pos++, inset, font);
+               ert_comp.contents.erase();
+       }
+       if (set_inactive) {
+               ert_comp.active = false;
+       }
+}
 
 
 bool
 Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
-                                  Paragraph *& return_par,
+                                  Paragraph *& first_par,
                                   string const & token, int & pos,
                                   Paragraph::depth_type & depth, 
                                   LyXFont & font
@@ -374,24 +418,42 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
 #endif
        
        if (token[0] != '\\') {
+#ifdef NO_LATEX
+               if (ert_comp.active) {
+                       ert_comp.contents += token;
+               } else {
+#endif
                for (string::const_iterator cit = token.begin();
                     cit != token.end(); ++cit) {
                        par->insertChar(pos, (*cit), font);
                        ++pos;
                }
                checkminipage = true;
+#ifdef NO_LATEX
+               }
+#endif
        } else if (token == "\\i") {
                Inset * inset = new InsetLatexAccent;
-               inset->Read(this, lex);
+               inset->read(this, lex);
                par->insertInset(pos, inset, font);
                ++pos;
        } else if (token == "\\layout") {
+#ifdef NO_LATEX
+               ert_comp.in_tabular = false;
+               // Do the insetert.
+               insertErtContents(par, pos, font);
+#endif
                 lex.EatLine();
                 string const layoutname = lex.GetString();
                 pair<bool, LyXTextClass::LayoutList::size_type> pp
                         = textclasslist.NumberOfLayout(params.textclass,
                                                        layoutname);
 
+#ifdef NO_LATEX
+               if (compare_no_case(layoutname, "latex") == 0) {
+                       ert_comp.active = true;
+               }
+#endif
 #ifdef USE_CAPTION
                // The is the compability reading of layout caption.
                // It can be removed in LyX version 1.3.0. (Lgb)
@@ -445,8 +507,8 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                        ++pos;
                } else {
 #endif
-                       if (!return_par)
-                               return_par = par;
+                       if (!first_par)
+                               first_par = par;
                        else {
                                par = new Paragraph(par);
                        }
@@ -457,6 +519,12 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                                // layout not found
                                // use default layout "Standard" (0)
                                par->layout = 0;
+                               ++unknown_layouts;
+                               string const s = _("Layout had to be changed from\n")
+                                       + layoutname + _(" to ")
+                                       + textclasslist.NameOfLayout(params.textclass, par->layout);
+                               InsetError * new_inset = new InsetError(s);
+                               par->insertInset(0, new_inset);
                        }
                        // Test whether the layout is obsolete.
                        LyXLayout const & layout =
@@ -553,7 +621,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                istringstream istr(old_float.str());
                LyXLex nylex(0, 0);
                nylex.setStream(istr);
-               inset->Read(this, nylex);
+               inset->read(this, nylex);
                par->insertInset(pos, inset, font);
                ++pos;
        } else if (token == "\\begin_deeper") {
@@ -812,7 +880,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                }
                // Small hack so that files written with klyx will be
                // parsed correctly.
-               if (return_par) {
+               if (first_par) {
                        par->params().spacing(Spacing(tmp_space, tmp_val));
                } else {
                        params.spacing.set(tmp_space, tmp_val);
@@ -848,6 +916,10 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
        } else if (token == "\\size") {
                lex.next();
                font.setLyXSize(lex.GetString());
+#ifndef NO_LATEX
+#ifdef WITH_WARNINGS
+#warning compatability hack needed
+#endif
        } else if (token == "\\latex") {
                lex.next();
                string const tok = lex.GetString();
@@ -861,6 +933,23 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                else
                        lex.printError("Unknown LaTeX font flag "
                                       "`$$Token'");
+#else
+       } else if (token == "\\latex") {
+               lex.next();
+               string const tok = lex.GetString();
+               if (tok == "no_latex") {
+                       // Do the insetert.
+                       insertErtContents(par, pos, font);
+               } else if (tok == "latex") {
+                       ert_comp.active = true;
+               } else if (tok == "default") {
+                       // Do the insetert.
+                       insertErtContents(par, pos, font);
+               } else {
+                       lex.printError("Unknown LaTeX font flag "
+                                      "`$$Token'");
+               }
+#endif
        } else if (token == "\\lang") {
                lex.next();
                string const tok = lex.GetString();
@@ -943,7 +1032,16 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                // But insets should read it, it is a part of
                // the inset isn't it? Lgb.
        } else if (token == "\\begin_inset") {
+#ifdef NO_LATEX
+               insertErtContents(par, pos, font, false);
+               ert_stack.push(ert_comp);
+               ert_comp = ErtComp();
+#endif
                readInset(lex, par, pos, font);
+#ifdef NO_LATEX
+               ert_comp = ert_stack.top();
+               ert_stack.pop();
+#endif
        } else if (token == "\\SpecialChar") {
                LyXLayout const & layout =
                        textclasslist.Style(params.textclass, 
@@ -968,16 +1066,34 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                        }
                } else {
                        Inset * inset = new InsetSpecialChar;
-                       inset->Read(this, lex);
+                       inset->read(this, lex);
                        par->insertInset(pos, inset, font);
                }
                ++pos;
        } else if (token == "\\newline") {
+#ifdef NO_LATEX
+
+               if (!ert_comp.in_tabular && ert_comp.active) {
+                       ert_comp.contents += char(Paragraph::META_NEWLINE);
+               } else {
+                       // Since we cannot know it this is only a regular
+                       // newline or a tabular cell delimter we have to
+                       // handle the ERT here.
+                       insertErtContents(par, pos, font, false);
+
+                       par->insertChar(pos, Paragraph::META_NEWLINE, font);
+                       ++pos;
+               }
+#else
                par->insertChar(pos, Paragraph::META_NEWLINE, font);
                ++pos;
+#endif
        } else if (token == "\\LyXTable") {
+#ifdef NO_LATEX
+               ert_comp.in_tabular = true;
+#endif
                Inset * inset = new InsetTabular(*this);
-               inset->Read(this, lex);
+               inset->read(this, lex);
                par->insertInset(pos, inset, font);
                ++pos;
                // because of OLD_TABULAR_READ where tabulars have been
@@ -1006,14 +1122,32 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                        InsetCommandParams p("bibitem", "dummy");
                        par->bibkey = new InsetBibKey(p);
                }
-               par->bibkey->Read(this, lex);                   
+               par->bibkey->read(this, lex);                   
        } else if (token == "\\backslash") {
+#ifdef NO_LATEX
+               if (ert_comp.active) {
+                       ert_comp.contents += "\\";
+               } else {
+#endif
                par->insertChar(pos, '\\', font);
                ++pos;
+#ifdef NO_LATEX
+               }
+#endif
        } else if (token == "\\the_end") {
+#ifdef NO_LATEX
+               // If we still have some ert active here we have to insert
+               // it so we don't loose it. (Lgb)
+               insertErtContents(par, pos, font);
+#endif
                the_end_read = true;
                minipar = parBeforeMinipage = 0;
        } else {
+#ifdef NO_LATEX
+               if (ert_comp.active) {
+                       ert_comp.contents += token;
+               } else {
+#endif
                // This should be insurance for the future: (Asger)
                lex.printError("Unknown token `$$Token'. "
                               "Inserting as text.");
@@ -1023,6 +1157,9 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                        par->insertChar(pos, (*cit), font);
                        ++pos;
                }
+#ifdef NO_LATEX
+               }
+#endif
        }
 #ifndef NO_PEXTRA_REALLY
        // now check if we have a minipage paragraph as at this
@@ -1083,7 +1220,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                            lyxerr << "WP:" << mini->width() << endl;
                            mini->width(tostr(par->params().pextraWidthp())+"%");
                        }
-                       mini->inset.par = par;
+                       mini->inset.paragraph(par);
                        // Insert the minipage last in the
                        // previous paragraph.
                        if (par->params().pextraHfill()) {
@@ -1143,8 +1280,8 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                par->previous(0);
                parBeforeMinipage = p;
                minipar = par;
-               if (!return_par || (return_par == par))
-                       return_par = p;
+               if (!first_par || (first_par == par))
+                       first_par = p;
 
                InsetMinipage * mini = new InsetMinipage;
                mini->pos(static_cast<InsetMinipage::Position>(minipar->params().pextraAlignment()));
@@ -1153,7 +1290,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                    lyxerr << "WP:" << mini->width() << endl;
                    mini->width(tostr(par->params().pextraWidthp())+"%");
                }
-               mini->inset.par = minipar;
+               mini->inset.paragraph(minipar);
                        
                // Insert the minipage last in the
                // previous paragraph.
@@ -1190,7 +1327,7 @@ void Buffer::readInset(LyXLex & lex, Paragraph *& par,
        // test the different insets
        if (tmptok == "LatexCommand") {
                InsetCommandParams inscmd;
-               inscmd.Read(lex);
+               inscmd.read(lex);
 
                string const cmdName = inscmd.getCmdName();
                
@@ -1276,7 +1413,7 @@ void Buffer::readInset(LyXLex & lex, Paragraph *& par,
                        inset = new InsetFloatList;
                }
                
-               if (inset) inset->Read(this, lex);
+               if (inset) inset->read(this, lex);
        }
        
        if (inset) {
@@ -1577,8 +1714,10 @@ string const Buffer::asciiParagraph(Paragraph const * par,
        } else {
                lyxerr << "Should this ever happen?" << endl;
        }
-      
+
+#ifndef NO_LATEX
        LyXFont const font1 = LyXFont(LyXFont::ALL_INHERIT, params.language);
+#endif
        for (Paragraph::size_type i = 0; i < par->size(); ++i) {
                if (!i && !noparbreak) {
                        if (linelen > 0)
@@ -1617,6 +1756,7 @@ string const Buffer::asciiParagraph(Paragraph const * par,
                                currlinelen += (ltype_depth-depth)*2;
                        }
                }
+#ifndef NO_LATEX
                LyXFont const font2 = par->getFontSettings(params, i);
                if (font1.latex() != font2.latex()) {
                        if (font2.latex() == LyXFont::OFF)
@@ -1626,6 +1766,7 @@ string const Buffer::asciiParagraph(Paragraph const * par,
                } else {
                        islatex = 0;
                }
+#endif
                
                char c = par->getUChar(params, i);
                if (islatex)
@@ -1635,7 +1776,7 @@ string const Buffer::asciiParagraph(Paragraph const * par,
                {
                        Inset const * inset = par->getInset(i);
                        if (inset) {
-                               if (!inset->Ascii(this, buffer)) {
+                               if (!inset->ascii(this, buffer)) {
                                        string dummy;
                                        string const s =
                                                rsplit(buffer.str().c_str(),
@@ -1691,7 +1832,7 @@ string const Buffer::asciiParagraph(Paragraph const * par,
                        } else if (c != '\0')
                                buffer << c;
                        else if (c == '\0')
-                               lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
+                               lyxerr[Debug::INFO] << "writeAsciiFile: NULL char in structure." << endl;
                        ++currlinelen;
                        break;
                }
@@ -1761,7 +1902,7 @@ void Buffer::makeLaTeXFile(string const & fname,
                texrow.newline();
                texrow.newline();
        }
-       lyxerr.debug() << "lyx header finished" << endl;
+       lyxerr[Debug::INFO] << "lyx header finished" << endl;
        // There are a few differences between nice LaTeX and usual files:
        // usual is \batchmode and has a 
        // special input@path to allow the including of figures
@@ -2177,7 +2318,7 @@ void Buffer::makeLaTeXFile(string const & fname,
                ofs << "\\begin{document}\n";
                texrow.newline();
        } // only_body
-       lyxerr.debug() << "preamble finished, now the body." << endl;
+       lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
 
        if (!lyxrc.language_auto_begin) {
                ofs << subst(lyxrc.language_command_begin, "$$lang",
@@ -2223,7 +2364,7 @@ void Buffer::makeLaTeXFile(string const & fname,
                lyxerr << "File was not closed properly." << endl;
        }
        
-       lyxerr.debug() << "Finished making latex file." << endl;
+       lyxerr[Debug::INFO] << "Finished making latex file." << endl;
 }
 
 
@@ -2305,7 +2446,8 @@ void Buffer::sgmlOpenTag(ostream & os, Paragraph::depth_type depth,
                         string const & latexname) const
 {
        if (!latexname.empty() && latexname != "!-- --")
-               os << string(depth, ' ') << "<" << latexname << ">\n";
+               os << "<!-- " << depth << " -->" << "<" << latexname << ">";
+       //os << string(depth, ' ') << "<" << latexname << ">\n";
 }
 
 
@@ -2313,7 +2455,8 @@ void Buffer::sgmlCloseTag(ostream & os, Paragraph::depth_type depth,
                          string const & latexname) const
 {
        if (!latexname.empty() && latexname != "!-- --")
-               os << string(depth, ' ') << "</" << latexname << ">\n";
+               os << "<!-- " << depth << " -->" << "</" << latexname << ">\n";
+       //os << string(depth, ' ') << "</" << latexname << ">\n";
 }
 
 
@@ -2375,7 +2518,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
                // treat <toc> as a special case for compatibility with old code
                if (par->getChar(0) == Paragraph::META_INSET) {
                        Inset * inset = par->getInset(0);
-                       Inset::Code lyx_code = inset->LyxCode();
+                       Inset::Code lyx_code = inset->lyxCode();
                        if (lyx_code == Inset::TOC_CODE){
                                string const temp = "toc";
                                sgmlOpenTag(ofs, depth, temp);
@@ -2408,7 +2551,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
 
                case LATEX_COMMAND:
                        if (depth!= 0)
-                               LinuxDocError(par, 0,
+                               linuxDocError(par, 0,
                                              _("Error : Wrong depth for"
                                                " LatexType Command.\n"));
 
@@ -2462,7 +2605,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
                        break;
                }
 
-               SimpleLinuxDocOnePar(ofs, par, depth);
+               simpleLinuxDocOnePar(ofs, par, depth);
 
                par = par->next();
 
@@ -2496,7 +2639,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
 }
 
 
-void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
+void Buffer::docBookHandleCaption(ostream & os, string & inner_tag,
                                  Paragraph::depth_type depth, int desc_on,
                                  Paragraph * & par)
 {
@@ -2511,7 +2654,7 @@ void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
                                                         "Caption").second) {
                sgmlOpenTag(os, depth + 1, inner_tag);
                string extra_par;
-               SimpleDocBookOnePar(os, extra_par, tpar,
+               simpleDocBookOnePar(os, extra_par, tpar,
                                    desc_on, depth + 2);
                sgmlCloseTag(os, depth+1, inner_tag);
                if (!extra_par.empty())
@@ -2578,7 +2721,7 @@ void reset(PAR_TAG & p1, PAR_TAG const & p2)
 
 
 // Handle internal paragraph parsing -- layout already processed.
-void Buffer::SimpleLinuxDocOnePar(ostream & os,
+void Buffer::simpleLinuxDocOnePar(ostream & os,
                                  Paragraph * par, 
                                  Paragraph::depth_type /*depth*/)
 {
@@ -2722,12 +2865,16 @@ void Buffer::SimpleLinuxDocOnePar(ostream & os,
 
                if (c == Paragraph::META_INSET) {
                        Inset * inset = par->getInset(i);
-                       inset->Linuxdoc(this, os);
+                       inset->linuxdoc(this, os);
                        font_old = font;
                        continue;
                }
 
-               if (font.latex() == LyXFont::ON || style.latexparam() == "CDATA") {
+               if (
+#ifndef NO_LATEX
+                       font.latex() == LyXFont::ON ||
+#endif
+                   style.latexparam() == "CDATA") {
                        // "TeX"-Mode on == > SGML-Mode on.
                        if (c != '\0')
                                os << c;
@@ -2771,7 +2918,7 @@ void Buffer::SimpleLinuxDocOnePar(ostream & os,
 
 
 // Print an error message.
-void Buffer::LinuxDocError(Paragraph * par, int pos,
+void Buffer::linuxDocError(Paragraph * par, int pos,
                           string const & message) 
 {
        // insert an error marker in text
@@ -2897,7 +3044,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
 
                case LATEX_COMMAND:
                        if (depth != 0)
-                               LinuxDocError(par, 0,
+                               linuxDocError(par, 0,
                                              _("Error : Wrong depth for "
                                                "LatexType Command.\n"));
                        
@@ -2931,7 +3078,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
                        // more WYSIWYM handling.
                        if (par->getChar(0) == Paragraph::META_INSET) {
                                Inset * inset = par->getInset(0);
-                               Inset::Code lyx_code = inset->LyxCode();
+                               Inset::Code lyx_code = inset->lyxCode();
                                if (lyx_code == Inset::LABEL_CODE){
                                        command_name += " id=\"";
                                        command_name += (static_cast<InsetCommand *>(inset))->getContents();
@@ -3015,7 +3162,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
                }
 
                string extra_par;
-               SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
+               simpleDocBookOnePar(ofs, extra_par, par, desc_on,
                                    depth + 1 + command_depth);
                par = par->next();
 
@@ -3081,7 +3228,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
 }
 
 
-void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
+void Buffer::simpleDocBookOnePar(ostream & os, string & extra,
                                 Paragraph * par, int & desc_on,
                                 Paragraph::depth_type depth) const
 {
@@ -3093,8 +3240,8 @@ void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
        LyXFont font_old = style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
 
        int char_line_count = depth;
-       if (!style.free_spacing)
-               os << string(depth,' ');
+       //if (!style.free_spacing)
+       //      os << string(depth,' ');
 
        // parsing main loop
        for (Paragraph::size_type i = 0;
@@ -3116,8 +3263,8 @@ void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
 
                if (c == Paragraph::META_INSET) {
                        Inset * inset = par->getInset(i);
-                       std::ostringstream ost;
-                       inset->DocBook(this, ost);
+                       ostringstream ost;
+                       inset->docBook(this, ost);
                        string tmp_out = ost.str().c_str();
 
                        //
@@ -3140,11 +3287,13 @@ void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
                                else
                                        os << tmp_out;
                        }
+#ifndef NO_LATEX
                } else if (font.latex() == LyXFont::ON) {
                        // "TeX"-Mode on ==> SGML-Mode on.
                        if (c != '\0')
                                os << c;
                        ++char_line_count;
+#endif
                } else {
                        string sgml_string;
                        if (par->linuxDocConvertChar(c, sgml_string)
@@ -3175,7 +3324,7 @@ void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
                // <term> not closed...
                os << "</term>";
        }
-       os << '\n';
+       if(style.free_spacing) os << '\n';
 }
 
 
@@ -3186,7 +3335,7 @@ int Buffer::runChktex()
 {
        if (!users->text) return 0;
 
-       ProhibitInput(users);
+       users->owner()->prohibitInput();
 
        // get LaTeX-Filename
        string const name = getLatexName();
@@ -3224,7 +3373,7 @@ int Buffer::runChktex()
                users->redraw();
                users->fitCursor(users->text);
        }
-       AllowInput(users);
+       users->owner()->allowInput();
 
        return res;
 }
@@ -3317,7 +3466,7 @@ string const Buffer::getIncludeonlyList(char delim)
        string lst;
        for (inset_iterator it = inset_iterator_begin();
            it != inset_iterator_end(); ++it) {
-               if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
+               if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
                        InsetInclude * insetinc = 
                                static_cast<InsetInclude *>(*it);
                        if (insetinc->isIncludeOnly()) {
@@ -3327,7 +3476,7 @@ string const Buffer::getIncludeonlyList(char delim)
                        }
                }
        }
-       lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
+       lyxerr[Debug::INFO] << "Includeonly(" << lst << ')' << endl;
        return lst;
 }
 
@@ -3386,7 +3535,7 @@ Buffer::Lists const Buffer::getLists() const
                                par->inset_iterator_end();
                        
                        for (; it != end; ++it) {
-                               if ((*it)->LyxCode() == Inset::FLOAT_CODE) {
+                               if ((*it)->lyxCode() == Inset::FLOAT_CODE) {
                                        InsetFloat * il =
                                                static_cast<InsetFloat*>(*it);
                                        
@@ -3395,7 +3544,7 @@ Buffer::Lists const Buffer::getLists() const
                                        // Now find the caption in the float...
                                        // We now tranverse the paragraphs of
                                        // the inset...
-                                       Paragraph * tmp = il->inset.par;
+                                       Paragraph * tmp = il->inset.paragraph();
                                        while (tmp) {
                                                if (tmp->layout == cap) {
                                                        SingleList & item = l[type];
@@ -3442,11 +3591,11 @@ vector<pair<string, string> > const Buffer::getBibkeyList()
                for (inset_iterator it = inset_iterator_begin();
                        it != inset_iterator_end(); ++it) {
                        // Search for Bibtex or Include inset
-                       if ((*it)->LyxCode() == Inset::BIBTEX_CODE) {
+                       if ((*it)->lyxCode() == Inset::BIBTEX_CODE) {
                                vector<pair<string,string> > tmp =
                                        static_cast<InsetBibtex*>(*it)->getKeys(this);
                                keys.insert(keys.end(), tmp.begin(), tmp.end());
-                       } else if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
+                       } else if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
                                vector<pair<string,string> > const tmp =
                                        static_cast<InsetInclude*>(*it)->getKeys();
                                keys.insert(keys.end(), tmp.begin(), tmp.end());
@@ -3491,18 +3640,18 @@ void Buffer::markDepClean(string const & name)
 }
 
 
-bool Buffer::Dispatch(string const & command)
+bool Buffer::dispatch(string const & command)
 {
        // Split command string into command and argument
        string cmd;
        string line = frontStrip(command);
        string const arg = strip(frontStrip(split(line, cmd, ' ')));
 
-       return Dispatch(lyxaction.LookupFunc(cmd), arg);
+       return dispatch(lyxaction.LookupFunc(cmd), arg);
 }
 
 
-bool Buffer::Dispatch(int action, string const & argument)
+bool Buffer::dispatch(int action, string const & argument)
 {
        bool dispatched = true;
        switch (action) {
@@ -3534,7 +3683,7 @@ void Buffer::redraw()
 }
 
 
-void Buffer::ChangeLanguage(Language const * from, Language const * to)
+void Buffer::changeLanguage(Language const * from, Language const * to)
 {
 
        Paragraph * par = paragraph;
@@ -3564,12 +3713,12 @@ Buffer::inset_iterator::inset_iterator(Paragraph * paragraph,
        it = par->InsetIterator(pos);
        if (it == par->inset_iterator_end()) {
                par = par->next();
-               SetParagraph();
+               setParagraph();
        }
 }
 
 
-void Buffer::inset_iterator::SetParagraph()
+void Buffer::inset_iterator::setParagraph()
 {
        while (par) {
                it = par->inset_iterator_begin();
@@ -3580,3 +3729,36 @@ void Buffer::inset_iterator::SetParagraph()
        //it = 0;
        // We maintain an invariant that whenever par = 0 then it = 0
 }
+
+
+Inset * Buffer::getInsetFromID(int id_arg) const
+{
+       for (inset_iterator it = inset_const_iterator_begin();
+                it != inset_const_iterator_end(); ++it)
+       {
+               if ((*it)->id() == id_arg)
+                       return *it;
+               Inset * in = (*it)->getInsetFromID(id_arg);
+               if (in)
+                       return in;
+       }
+       return 0;
+}
+
+
+Paragraph * Buffer::getParFromID(int id) const
+{
+       if (id < 0) return 0;
+       Paragraph * par = paragraph;
+       while (par) {
+               if (par->id() == id) {
+                       return par;
+               }
+               Paragraph * tmp = par->getParFromID(id);
+               if (tmp) {
+                       return tmp;
+               }
+               par = par->next();
+       }
+       return 0;
+}