]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
white-space changes, removed definitions.h several enum changes because of this,...
[lyx.git] / src / lyxfunc.C
index 24a0a3406fdc1c701fa79d26ae19b236a6fa1249..4a9debb27939ad9339e91f267ab67e7eb340c49d 100644 (file)
@@ -1,12 +1,12 @@
 /* This file is part of
- * ======================================================
+ * ====================================================== 
  * 
  *           LyX, The Document Processor
  *      
  *         Copyright 1995 Matthias Ettrich
  *          Copyright 1995-1999 The LyX Team.
  *
- * ======================================================*/
+ * ====================================================== */
 
 #include <config.h>
 
@@ -18,7 +18,6 @@
 #pragma implementation
 #endif
 
-#include "definitions.h"
 #include "lyxlookup.h"
 #include "kbmap.h"
 #include "lyxfunc.h"
@@ -28,7 +27,9 @@
 #include "intl.h"
 #include "lyx_main.h"
 #include "lyx_cb.h"
+#if 0
 #include "insets/insetlatex.h"
+#endif
 #include "insets/inseturl.h"
 #include "insets/insetlatexaccent.h"
 #include "insets/insettoc.h"
 #include "insets/insetlot.h"
 #include "insets/insetref.h"
 #include "insets/insetparent.h"
+#include "insets/insetindex.h"
+#include "insets/insetinclude.h"
+#include "insets/insetbib.h"
 #include "mathed/formulamacro.h"
 #include "toolbar.h"
 #include "spellchecker.h" // RVDK_PATCH_5
 #include "minibuffer.h"
 #include "vspace.h"
-#include "insets/insetbib.h"
 #include "LyXView.h"
-#include "insets/insetindex.h"
-#include "insets/insetinclude.h"
 #include "filedlg.h"
 #include "lyx_gui_misc.h"
 #include "support/filetools.h"
 #include "support/FileInfo.h"
+#include "support/LAssert.h"
+#include "support/syscall.h"
+#include "support/lstrings.h"
+#include "support/path.h"
 #include "lyxscreen.h"
 #include "debug.h"
 #include "lyxrc.h"
@@ -58,8 +63,7 @@
 #include "trans_mgr.h"
 #include "ImportLaTeX.h"
 #include "ImportNoweb.h"
-#include "support/syscall.h"
-#include "support/lstrings.h"
+#include "layout.h"
 
 extern bool cursor_follows_scrollbar;
 
@@ -67,12 +71,12 @@ extern void InsertAsciiFile(string const &, bool);
 extern void math_insert_symbol(char const*);
 extern Bool math_insert_greek(char const); // why "Bool"?
 extern BufferList bufferlist;
-extern LyXServer *lyxserver;
+extern LyXServer * lyxserver;
 extern short greek_kb_flag;
-extern FD_form_toc *fd_form_toc;
+extern FD_form_toc * fd_form_toc;
 extern bool selection_possible;
 
-extern kb_keymap *toplevel_keymap;
+extern kb_keymap * toplevel_keymap;
 
 extern void BeforeChange();
 extern void MenuWrite(Buffer*);
@@ -80,7 +84,7 @@ extern void MenuWriteAs(Buffer*);
 extern int  MenuRunLaTeX(Buffer*);
 extern int  MenuBuildProg(Buffer*);
 extern int  MenuRunChktex(Buffer*);
-extern bool MenuRunDvips(Buffer *,bool);
+extern bool MenuRunDvips(Buffer *, bool);
 extern void MenuPrint(Buffer*);
 extern void MenuSendto();
 extern void QuitLyX();
@@ -114,7 +118,7 @@ extern void SetUpdateTimer(float timer= 0.3);
 extern void FreeUpdateTimer();
 extern bool MenuPreview(Buffer*);
 extern bool MenuPreviewPS(Buffer*);
-extern void MenuInsertLabel(const char *);
+extern void MenuInsertLabel(char const *);
 extern void MenuInsertRef();
 extern void MenuLayoutCharacter();
 extern void MenuLayoutParagraph();
@@ -167,12 +171,12 @@ LyXFunc::~LyXFunc()
 inline
 void LyXFunc::moveCursorUpdate(bool selecting)
 {
-       if (selecting || owner->currentBuffer()->text->mark_set) {
-               owner->currentBuffer()->text->SetSelection();
+       if (selecting || owner->buffer()->text->mark_set) {
+               owner->buffer()->text->SetSelection();
                owner->currentView()->getScreen()->ToggleToggle();
-               owner->currentBuffer()->update(0);
+               owner->buffer()->update(0);
        } else {
-               owner->currentBuffer()->update(-2); // this IS necessary
+               owner->buffer()->update(-2); // this IS necessary
                // (Matthias) 
        }
        owner->currentView()->getScreen()->ShowCursor();
@@ -214,10 +218,10 @@ int LyXFunc::processKeyEvent(XEvent *ev)
        
        // this function should be used always [asierra060396]
        if (owner->currentView()->available() &&
-           owner->currentBuffer()->the_locking_inset &&
+           owner->buffer()->the_locking_inset &&
            keysym_return == XK_Escape) {
-               UnlockInset(owner->currentBuffer()->the_locking_inset);
-               owner->currentBuffer()->text->CursorRight();
+               UnlockInset(owner->buffer()->the_locking_inset);
+               owner->buffer()->text->CursorRight();
                return 0;
        }
 
@@ -255,7 +259,7 @@ int LyXFunc::processKeyEvent(XEvent *ev)
 
        if (lyxerr.debugging(Debug::KEY)) {
                char buf[100];
-               keyseq.print(buf,100);
+               keyseq.print(buf, 100);
                lyxerr << "Key ["
                       << action << "]["
                       << buf << "]["
@@ -268,16 +272,16 @@ int LyXFunc::processKeyEvent(XEvent *ev)
 
        if(keyseq.length>1 || keyseq.length<-1){
                char buf[100];
-               keyseq.print(buf,100);
+               keyseq.print(buf, 100);
                owner->getMiniBuffer()->Set(buf);
        }
 
-       if (action==-1) {
+       if (action == -1) {
                if (keyseq.length<-1) { // unknown key sequence...
                        char buf[100];
                        LyXBell();
-                       keyseq.print(buf,100);
-                       owner->getMiniBuffer()->Set(_("Unknown sequence:"),buf);
+                       keyseq.print(buf, 100);
+                       owner->getMiniBuffer()->Set(_("Unknown sequence:"), buf);
                        return 0;
                }
        
@@ -294,7 +298,7 @@ int LyXFunc::processKeyEvent(XEvent *ev)
                        return 0;
                }
        } else
-               if (action==LFUN_SELFINSERT) {
+               if (action == LFUN_SELFINSERT) {
                        argument = s_r[0];
                }
     
@@ -429,7 +433,7 @@ string LyXFunc::Dispatch(int ac,
         // Now that we know which action, if the buffer is RO let's check 
        // whether the action is legal.  Alejandro 970603
         if (owner->currentView()->available() && 
-            owner->currentBuffer()->isReadonly() && 
+            owner->buffer()->isReadonly() && 
             lyxaction.isFuncRO(action)) {
                setErrorMessage(N_("Document is read-only"));
                lyxerr.debug() << "Error: Document is read-only." << endl;
@@ -439,42 +443,42 @@ string LyXFunc::Dispatch(int ac,
        // If in math mode pass the control to
        // the math inset [asierra060396]
        if (owner->currentView()->available() &&
-           owner->currentBuffer()->the_locking_inset) {
-               if (action>1 || (action==LFUN_UNKNOWN_ACTION && keyseq.length>=-1)) {
-                       if (action==LFUN_UNKNOWN_ACTION && argument.empty()) {
+           owner->buffer()->the_locking_inset) {
+               if (action>1 || (action == LFUN_UNKNOWN_ACTION && keyseq.length>= -1)) {
+                       if (action == LFUN_UNKNOWN_ACTION && argument.empty()) {
                                argument = keyseq.getiso();
                        }
                        // Undo/Redo pre 0.13 is a bit tricky for insets.                   
-                       if (action==LFUN_UNDO) {
+                       if (action == LFUN_UNDO) {
                                int slx, sly;
-                               UpdatableInset* inset =
-                                       owner->currentBuffer()->the_locking_inset;
+                               UpdatableInset* inset = 
+                                       owner->buffer()->the_locking_inset;
                                inset->GetCursorPos(slx, sly);
                                UnlockInset(inset);
                                MenuUndo();
-                               inset = (UpdatableInset*)owner->currentBuffer()->text->cursor.par->GetInset(owner->currentBuffer()->text->cursor.pos);
+                               inset = (UpdatableInset*)owner->buffer()->text->cursor.par->GetInset(owner->buffer()->text->cursor.pos);
                                if (inset) 
                                        inset->Edit(slx, sly);
                                return string();
                        } else 
-                               if (action==LFUN_REDO) {
+                               if (action == LFUN_REDO) {
                                        int slx, sly;
-                                       UpdatableInset* inset = owner->currentBuffer()->the_locking_inset;
+                                       UpdatableInset* inset = owner->buffer()->the_locking_inset;
                                        inset->GetCursorPos(slx, sly);
                                        UnlockInset(inset);
                                        MenuRedo();
-                                       inset = (UpdatableInset*)owner->currentBuffer()->text->cursor.par->GetInset(owner->currentBuffer()->text->cursor.pos);
+                                       inset = (UpdatableInset*)owner->buffer()->text->cursor.par->GetInset(owner->buffer()->text->cursor.pos);
                                        if (inset)
                                                inset->Edit(slx, sly);
                                        return string();
                                } else
-                                       if (owner->currentBuffer()->the_locking_inset->LocalDispatch(action, argument.c_str()))
+                                       if (owner->buffer()->the_locking_inset->LocalDispatch(action, argument.c_str()))
                                                return string();
                                        else {
                                                setMessage(N_("Text mode"));
-                                               if (action==LFUN_RIGHT || action==-1)
-                                                       owner->currentBuffer()->text->CursorRight();
-                                               if (action==LFUN_LEFT || action==LFUN_RIGHT)
+                                               if (action == LFUN_RIGHT || action == -1)
+                                                       owner->buffer()->text->CursorRight();
+                                               if (action == LFUN_LEFT || action == LFUN_RIGHT)
                                                        return string();
                                        }
                }
@@ -483,8 +487,7 @@ string LyXFunc::Dispatch(int ac,
        switch(action) {
                // --- Misc -------------------------------------------
        case LFUN_WORDFINDFORWARD  : 
-       case LFUN_WORDFINDBACKWARD : { 
-               LyXText *ltCur;
+       case LFUN_WORDFINDBACKWARD : {
                static string last_search;
                string searched_string;
            
@@ -495,7 +498,7 @@ string LyXFunc::Dispatch(int ac,
                        searched_string = last_search;
                }
 
-               ltCur =  owner->currentView()->currentBuffer()->text ;   
+               LyXText * ltCur = owner->currentView()->buffer()->text ;
 
                if (!searched_string.empty() &&
                    (    (action == LFUN_WORDFINDBACKWARD) ? 
@@ -504,17 +507,17 @@ string LyXFunc::Dispatch(int ac,
                         )){
 
                        // ??? What is that ???
-                       owner->currentView()->currentBuffer()->update(-2);
+                       owner->currentView()->buffer()->update(-2);
 
                        // ??? Needed ???
                        // clear the selection (if there is any) 
                        owner->currentView()->getScreen()->ToggleSelection();
-                       owner->currentView()->currentBuffer()->text->ClearSelection();
+                       owner->currentView()->buffer()->text->ClearSelection();
 
                        // Move cursor so that successive C-s 's will not stand in place. 
                        if( action == LFUN_WORDFINDFORWARD ) 
-                               owner->currentBuffer()->text->CursorRightOneWord();
-                       owner->currentBuffer()->text->FinishUndo();
+                               owner->buffer()->text->CursorRightOneWord();
+                       owner->buffer()->text->FinishUndo();
                        moveCursorUpdate(false);
 
                        // ??? Needed ???
@@ -533,10 +536,10 @@ string LyXFunc::Dispatch(int ac,
        {
                if (owner->currentView()->available()
                    && owner->currentView()->getScreen()) {
-                       owner->currentBuffer()->update(-2);
+                       owner->buffer()->update(-2);
                }
                char buf[100];
-               keyseq.print(buf,100, true);
+               keyseq.print(buf, 100, true);
                owner->getMiniBuffer()->Set(buf, string(), string(), 1);
        }
        break;
@@ -566,33 +569,33 @@ string LyXFunc::Dispatch(int ac,
        break;  
 
        case LFUN_READ_ONLY_TOGGLE:
-               if (owner->currentBuffer()->lyxvc.inUse()) {
-                       owner->currentBuffer()->lyxvc.toggleReadOnly();
+               if (owner->buffer()->lyxvc.inUse()) {
+                       owner->buffer()->lyxvc.toggleReadOnly();
                } else {
-                       owner->currentBuffer()->setReadonly(
-                               !owner->currentBuffer()->isReadonly());
+                       owner->buffer()->setReadonly(
+                               !owner->buffer()->isReadonly());
                }
                break;
                
        case LFUN_CENTER: // this is center and redraw.
                BeforeChange();
-               if (owner->currentBuffer()->text->cursor.y >
+               if (owner->buffer()->text->cursor.y >
                    owner->currentView()->getWorkArea()->h / 2) {
                        owner->currentView()->getScreen()->
-                               Draw(owner->currentBuffer()->text->cursor.y -
+                               Draw(owner->buffer()->text->cursor.y -
                                     owner->currentView()->getWorkArea()->h/2);
-               } else { // <=
+               } else { // <= 
                        owner->currentView()->getScreen()->
                                Draw(0);
                }
-               owner->currentBuffer()->update(0);
+               owner->buffer()->update(0);
                owner->currentView()->redraw();
                break;
                
        case LFUN_APPENDIX:
                if (owner->currentView()->available()) {
-                       owner->currentBuffer()->text->toggleAppendix();
-                       owner->currentBuffer()->update(1);
+                       owner->buffer()->text->toggleAppendix();
+                       owner->buffer()->update(1);
                }
                break;
 
@@ -614,11 +617,11 @@ string LyXFunc::Dispatch(int ac,
                break;
                
        case LFUN_MENUWRITE:
-               MenuWrite(owner->currentBuffer());
+               MenuWrite(owner->buffer());
                break;
                
        case LFUN_MENUWRITEAS:
-               MenuWriteAs(owner->currentBuffer());
+               MenuWriteAs(owner->buffer());
                break;
                
        case LFUN_MENURELOAD:
@@ -626,56 +629,56 @@ string LyXFunc::Dispatch(int ac,
                break;
                
        case LFUN_PREVIEW:
-               MenuPreview(owner->currentBuffer());
+               MenuPreview(owner->buffer());
                break;
                        
        case LFUN_PREVIEWPS:
-               MenuPreviewPS(owner->currentBuffer());
+               MenuPreviewPS(owner->buffer());
                break;
                
        case LFUN_RUNLATEX:
-               MenuRunLaTeX(owner->currentBuffer());
+               MenuRunLaTeX(owner->buffer());
                break;
                
         case LFUN_BUILDPROG:
-                MenuBuildProg(owner->currentBuffer());
+                MenuBuildProg(owner->buffer());
                 break;
                 
        case LFUN_RUNCHKTEX:
-               MenuRunChktex(owner->currentBuffer());
+               MenuRunChktex(owner->buffer());
                break;
                
        case LFUN_RUNDVIPS:
-               MenuRunDvips(owner->currentBuffer(), false);
+               MenuRunDvips(owner->buffer(), false);
                break;
                
        case LFUN_MENUPRINT:
-               MenuPrint(owner->currentBuffer());
+               MenuPrint(owner->buffer());
                break;
                
        case LFUN_FAX:
-               MenuFax(owner->currentBuffer());
+               MenuFax(owner->buffer());
                break;
                        
        case LFUN_EXPORT:
        {
                //needs argument as string
-               string extyp=argument;
+               string extyp= argument;
                
                // latex
                if (extyp == "latex") {
                        // make sure that this buffer is not linuxdoc
-                       MenuMakeLaTeX(owner->currentBuffer());
+                       MenuMakeLaTeX(owner->buffer());
                }
                // linuxdoc
                else if (extyp == "linuxdoc") {
                        // make sure that this buffer is not latex
-                       MenuMakeLinuxDoc(owner->currentBuffer());
+                       MenuMakeLinuxDoc(owner->buffer());
                }
                // docbook
                else if (extyp == "docbook") {
                        // make sure that this buffer is not latex or linuxdoc
-                       MenuMakeDocBook(owner->currentBuffer());
+                       MenuMakeDocBook(owner->buffer());
                }
                // dvi
                else if (extyp == "dvi") {
@@ -686,48 +689,54 @@ string LyXFunc::Dispatch(int ac,
                        // *.log and *.aux files also. (Asger)
                        bool flag = lyxrc->use_tempdir;
                        lyxrc->use_tempdir = false;
-                       MenuRunLaTeX(owner->currentBuffer());
+                       MenuRunLaTeX(owner->buffer());
                        lyxrc->use_tempdir = flag;
                }
                // postscript
                else if (extyp == "postscript") {
                        // Start Print-dialog. Not as good as dvi... Bernhard.
-                       MenuPrint(owner->currentBuffer());
+                       MenuPrint(owner->buffer());
                        // Since the MenuPrint is a pop-up, we can't use
                        // the same trick as above. (Asger)
                        // MISSING: Move of ps-file :-(
                }
                // ascii
                else if (extyp == "ascii") {
-                       MenuMakeAscii(owner->currentBuffer());
+                       MenuMakeAscii(owner->buffer());
                }
                else if (extyp == "custom") {
                        MenuSendto();
                        break;
                }
                // HTML
-               else if (extyp == "html") {
+               else if (extyp == "html" && lyxrc->html_command != "none") {
                        // First, create LaTeX file
-                       MenuMakeLaTeX(owner->currentBuffer());
-
-                       // And now, run tth
-                       string file = owner->currentBuffer()->getFileName();
-                       file = ChangeExtension(file, ".tex", false);
+                       MenuMakeLaTeX(owner->buffer());
+
+                       // And now, run the converter
+                       string file = owner->buffer()->getFileName();
+                       Path path(OnlyPath(file));
+                       // the tex file name has to be correct for
+                       // latex, but the html file name can be
+                       // anything.
                        string result = ChangeExtension(file, ".html", false);
-                       string tmp = lyxrc->tth_command + " < " + file 
-                           + " > " + result ;
+                       file = ChangeExtension(SpaceLess(file), ".tex", false);
+                       string tmp = lyxrc->html_command;
+                       tmp = subst(tmp, "$$FName", file);
+                       tmp = subst(tmp, "$$OutName", result);
                        Systemcalls one;
                        int res = one.startscript(Systemcalls::System, tmp);
                        if (res == 0) {
-                               setMessage(string(
-                                 _("Document exported as HTML to file: ")) + result);
+                               setMessage(_("Document exported as HTML to file `")
+                                          + MakeDisplayPath(result) +'\'');
                        } else {
-                               setErrorMessage(string(
-                                 _("An unexpected error occured while converting document to HTML in file:")) + result);
+                               setErrorMessage(_("Unable to convert to HTML the file `")
+                                               + MakeDisplayPath(file) 
+                                               + '\'');
                        }
                }
                else {
-                       setErrorMessage(string(_("Unknown export type: "))
+                       setErrorMessage(_("Unknown export type: ")
                                        + extyp);
                }
        }
@@ -736,7 +745,7 @@ string LyXFunc::Dispatch(int ac,
        case LFUN_IMPORT:
        {
                //needs argument as string
-               string imtyp=argument;
+               string imtyp= argument;
                
                // latex
                if (imtyp == "latex") {
@@ -781,36 +790,36 @@ string LyXFunc::Dispatch(int ac,
                
        case LFUN_TOC_INSERT:
        {
-               Inset *new_inset =
-                       new InsetTOC(owner->currentBuffer());
-               owner->currentBuffer()->insertInset(new_inset,
+               Inset *new_inset = 
+                       new InsetTOC(owner->buffer());
+               owner->buffer()->insertInset(new_inset,
                                                    "Standard", true);
                break;
        }
        
        case LFUN_LOF_INSERT:
        {
-               Inset *new_inset =
-                       new InsetLOF(owner->currentBuffer());
-               owner->currentBuffer()->insertInset(new_inset,
+               Inset *new_inset = 
+                       new InsetLOF(owner->buffer());
+               owner->buffer()->insertInset(new_inset,
                                                    "Standard", true);
                break;
        }
        
        case LFUN_LOA_INSERT:
        {
-               Inset *new_inset =
-                       new InsetLOA(owner->currentBuffer());
-               owner->currentBuffer()->insertInset(new_inset,
+               Inset *new_inset = 
+                       new InsetLOA(owner->buffer());
+               owner->buffer()->insertInset(new_inset,
                                                    "Standard", true);
                break;
        }
 
        case LFUN_LOT_INSERT:
        {
-               Inset *new_inset =
-                       new InsetLOT(owner->currentBuffer());
-               owner->currentBuffer()->insertInset(new_inset,
+               Inset *new_inset = 
+                       new InsetLOT(owner->buffer());
+               owner->buffer()->insertInset(new_inset,
                                                    "Standard", true);
                break;
        }
@@ -872,7 +881,7 @@ string LyXFunc::Dispatch(int ac,
                break;
                
        case LFUN_REMOVEERRORS:
-               if (owner->currentBuffer()->removeAutoInsets()) {
+               if (owner->buffer()->removeAutoInsets()) {
                        owner->currentView()->redraw();
                        owner->currentView()->fitCursor();
                        owner->currentView()->updateScrollbar();
@@ -937,12 +946,12 @@ string LyXFunc::Dispatch(int ac,
 
        case LFUN_FOOTMELT:
                if (owner->currentView()->available()
-                   && !owner->currentBuffer()->text->selection
-                   && owner->currentBuffer()->text->cursor.par->footnoteflag
+                   && !owner->buffer()->text->selection
+                   && owner->buffer()->text->cursor.par->footnoteflag
                    != LyXParagraph::NO_FOOTNOTE)
                { // only melt footnotes with FOOTMELT, not margins etc
-                 if(owner->currentBuffer()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
-                       MeltCB(ob,0);
+                 if(owner->buffer()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE)
+                       MeltCB(ob, 0);
                }
                else
                        FootCB(ob, 0); 
@@ -950,12 +959,12 @@ string LyXFunc::Dispatch(int ac,
 
        case LFUN_MARGINMELT:
                if (owner->currentView()->available()
-                   && !owner->currentBuffer()->text->selection
-                   && owner->currentBuffer()->text->cursor.par->footnoteflag
+                   && !owner->buffer()->text->selection
+                   && owner->buffer()->text->cursor.par->footnoteflag
                    != LyXParagraph::NO_FOOTNOTE)
                { // only melt margins
-                 if(owner->currentBuffer()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
-                       MeltCB(ob,0);
+                 if(owner->buffer()->text->cursor.par->footnotekind == LyXParagraph::MARGIN)
+                       MeltCB(ob, 0);
                }
                else
                        MarginCB(ob, 0); 
@@ -964,42 +973,42 @@ string LyXFunc::Dispatch(int ac,
                // --- version control -------------------------------
        case LFUN_VC_REGISTER:
        {
-               if (!owner->currentBuffer()->lyxvc.inUse())
-                       owner->currentBuffer()->lyxvc.registrer();
+               if (!owner->buffer()->lyxvc.inUse())
+                       owner->buffer()->lyxvc.registrer();
        }
        break;
                
        case LFUN_VC_CHECKIN:
        {
-               if (owner->currentBuffer()->lyxvc.inUse()
-                   && !owner->currentBuffer()->isReadonly())
-                       owner->currentBuffer()->lyxvc.checkIn();
+               if (owner->buffer()->lyxvc.inUse()
+                   && !owner->buffer()->isReadonly())
+                       owner->buffer()->lyxvc.checkIn();
        }
        break;
                
        case LFUN_VC_CHECKOUT:
        {
-               if (owner->currentBuffer()->lyxvc.inUse()
-                   && owner->currentBuffer()->isReadonly())
-                       owner->currentBuffer()->lyxvc.checkOut();
+               if (owner->buffer()->lyxvc.inUse()
+                   && owner->buffer()->isReadonly())
+                       owner->buffer()->lyxvc.checkOut();
        }
        break;
        
        case LFUN_VC_REVERT:
        {
-               owner->currentBuffer()->lyxvc.revert();
+               owner->buffer()->lyxvc.revert();
        }
        break;
                
        case LFUN_VC_UNDO:
        {
-               owner->currentBuffer()->lyxvc.undoLast();
+               owner->buffer()->lyxvc.undoLast();
        }
        break;
                
        case LFUN_VC_HISTORY:
        {
-               owner->currentBuffer()->lyxvc.showLog();
+               owner->buffer()->lyxvc.showLog();
                break;
        }
        
@@ -1012,7 +1021,7 @@ string LyXFunc::Dispatch(int ac,
                // remember the previous buffer, not bufferlist.
 //                     if (owner->currentView()->available()){   
 //                             BeforeChange();
-//                             owner->currentBuffer()->update(-2);
+//                             owner->buffer()->update(-2);
 //                     }
 //                     owner->currentView()->setBuffer(bufferlist.prev());
 
@@ -1040,12 +1049,12 @@ string LyXFunc::Dispatch(int ac,
                Buffer * tmpbuf = 0;
                tmpbuf = NewLyxFile(argument);
                if (tmpbuf)
-                       owner->currentView()->setBuffer(tmpbuf);
+                       owner->currentView()->buffer(tmpbuf);
        }
                break;
                        
        case LFUN_FILE_OPEN:
-               owner->currentView()->setBuffer(
+               owner->currentView()->buffer(
                        bufferlist.loadLyXFile(argument));
                break;
 
@@ -1067,7 +1076,7 @@ string LyXFunc::Dispatch(int ac,
 
                // Pretend we got the name instead.
                Dispatch(int(LFUN_LAYOUT), 
-                        lyxstyle.NameOfLayout(owner->currentBuffer()->
+                        textclasslist.NameOfLayout(owner->buffer()->
                                               text->parameters->
                                               textclass,
                                               sel).c_str());
@@ -1082,12 +1091,12 @@ string LyXFunc::Dispatch(int ac,
                // Derive layout number from given argument (string)
                // and current buffer's textclass (number). */    
                int layoutno = -1;
-               layoutno =
-                       lyxstyle.NumberOfLayout(owner->
-                                               currentBuffer()->
+               layoutno = 
+                       textclasslist.NumberOfLayout(owner->
+                                               buffer()->
                                                text->parameters->
                                                textclass,
-                                               argument);
+                                               argument).second;
 
                // see if we found the layout number:
                if (layoutno == -1) {
@@ -1099,14 +1108,14 @@ string LyXFunc::Dispatch(int ac,
                if (current_layout != layoutno) {
                        owner->currentView()->getScreen()->HideCursor();
                        current_layout = layoutno;
-                       owner->currentBuffer()->update(-2);
-                       owner->currentBuffer()->text->
+                       owner->buffer()->update(-2);
+                       owner->buffer()->text->
                                SetLayout(layoutno);
                        owner->getToolbar()->combox->
-                               select(owner->currentBuffer()->
+                               select(owner->buffer()->
                                       text->cursor.par->
                                       GetLayout() + 1);
-                       owner->currentBuffer()->update(1);
+                       owner->buffer()->update(1);
                }
        }
        break;
@@ -1192,26 +1201,26 @@ string LyXFunc::Dispatch(int ac,
                break;
                
        case LFUN_UPCASE_WORD:
-               owner->currentBuffer()->update(-2);
+               owner->buffer()->update(-2);
                FreeUpdateTimer();
-               owner->currentBuffer()->text->ChangeWordCase(2);
-               owner->currentBuffer()->update(1);
+               owner->buffer()->text->ChangeWordCase(LyXText::text_uppercase);
+               owner->buffer()->update(1);
                SetUpdateTimer();
                break;
                
        case LFUN_LOWCASE_WORD:
-               owner->currentBuffer()->update(-2);
+               owner->buffer()->update(-2);
                FreeUpdateTimer();
-               owner->currentBuffer()->text->ChangeWordCase(0);
-               owner->currentBuffer()->update(1);
+               owner->buffer()->text->ChangeWordCase(LyXText::text_lowercase);
+               owner->buffer()->update(1);
                SetUpdateTimer();
                break;
                
        case LFUN_CAPITALIZE_WORD:
-               owner->currentBuffer()->update(-2);
+               owner->buffer()->update(-2);
                FreeUpdateTimer();
-               owner->currentBuffer()->text->ChangeWordCase(1);
-               owner->currentBuffer()->update(1);
+               owner->buffer()->text->ChangeWordCase(LyXText::text_capitalization);
+               owner->buffer()->update(1);
                SetUpdateTimer();
                break;
                
@@ -1225,10 +1234,10 @@ string LyXFunc::Dispatch(int ac,
                
        case LFUN_REFTOGGLE:
        {
-               InsetRef *inset =
+               InsetRef *inset = 
                        (InsetRef*)getInsetByCode(Inset::REF_CODE);
                if (inset) {
-                       if (inset->getFlag()==InsetRef::REF)
+                       if (inset->getFlag() == InsetRef::REF)
                                inset->setFlag(InsetRef::PAGE_REF);
                        else
                                inset->setFlag(InsetRef::REF);
@@ -1249,7 +1258,7 @@ string LyXFunc::Dispatch(int ac,
        {
                string label(argument);
                if (label.empty()) {
-                       InsetRef *inset =
+                       InsetRef *inset = 
                                (InsetRef*)getInsetByCode(Inset::REF_CODE);
                        if (inset)
                                 label = inset->getContents();
@@ -1257,7 +1266,7 @@ string LyXFunc::Dispatch(int ac,
                
                if (!label.empty()) {
                        owner->currentView()->savePosition();
-                       owner->currentBuffer()->gotoLabel(label.c_str());
+                       owner->buffer()->gotoLabel(label.c_str());
                }
        }
        break;
@@ -1274,23 +1283,23 @@ string LyXFunc::Dispatch(int ac,
                // --- Cursor Movements -----------------------------
        case LFUN_RIGHT:
        {
-               Buffer *tmpbuffer = owner->currentBuffer();
-               LyXText *tmptext = owner->currentBuffer()->text;
+               Buffer *tmpbuffer = owner->buffer();
+               LyXText *tmptext = owner->buffer()->text;
                if(!tmptext->mark_set)
                        BeforeChange();
                tmpbuffer->update(-2);
                if (tmptext->cursor.pos < tmptext->cursor.par->Last()
                    && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
-                   == LYX_META_INSET
+                   == LyXParagraph::META_INSET
                    && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
-                   && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable()==2){
+                   && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == 2){
                        Inset* tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
                        setMessage(tmpinset->EditMessage());
-                       tmpinset->Edit(0,0);
+                       tmpinset->Edit(0, 0);
                        break;
                }
                tmptext->CursorRight();
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(false);
                owner->getMiniBuffer()->Set(CurrentState());
        }
@@ -1300,153 +1309,153 @@ string LyXFunc::Dispatch(int ac,
        {
                // This is soooo ugly. Isn`t it possible to make
                // it simpler? (Lgb)
-               LyXText *txt= owner->currentBuffer()->text;
+               LyXText *txt= owner->buffer()->text;
                if(!txt->mark_set) BeforeChange();
-               owner->currentBuffer()->update(-2);
+               owner->buffer()->update(-2);
                txt->CursorLeft();
                if (txt->cursor.pos < txt->cursor.par->Last()
                    && txt->cursor.par->GetChar(txt->cursor.pos)
-                   == LYX_META_INSET
+                   == LyXParagraph::META_INSET
                    && txt->cursor.par->GetInset(txt->cursor.pos)
-                   && txt->cursor.par->GetInset(txt->cursor.pos)->Editable()==2) {
+                   && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == 2) {
                        Inset* tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
                        setMessage(tmpinset->EditMessage());
                        tmpinset->Edit(tmpinset->Width(txt->GetFont(txt->cursor.par,
-                                                                   txt->cursor.pos)),0);
+                                                                   txt->cursor.pos)), 0);
                        //                      tmpinset->Edit(-1, 0);  // -1 means go rightmost
                        break;
                }
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(false);
                owner->getMiniBuffer()->Set(CurrentState());
        }
        break;
                
        case LFUN_UP:
-               if(!owner->currentBuffer()->text->mark_set) BeforeChange();
-               owner->currentBuffer()->update(-3);
-               owner->currentBuffer()->text->CursorUp();
-               owner->currentBuffer()->text->FinishUndo();
+               if(!owner->buffer()->text->mark_set) BeforeChange();
+               owner->buffer()->update(-3);
+               owner->buffer()->text->CursorUp();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(false);
                owner->getMiniBuffer()->Set(CurrentState());
                break;
                
        case LFUN_DOWN:
-               if(!owner->currentBuffer()->text->mark_set)
+               if(!owner->buffer()->text->mark_set)
                        BeforeChange();
-               owner->currentBuffer()->update(-3);
-               owner->currentBuffer()->text->CursorDown();
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->update(-3);
+               owner->buffer()->text->CursorDown();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(false);
                owner->getMiniBuffer()->Set(CurrentState());
                break;
 
        case LFUN_UP_PARAGRAPH:
-               if(!owner->currentBuffer()->text->mark_set)
+               if(!owner->buffer()->text->mark_set)
                        BeforeChange();
-               owner->currentBuffer()->update(-3);
-               owner->currentBuffer()->text->CursorUpParagraph();
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->update(-3);
+               owner->buffer()->text->CursorUpParagraph();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(false);
                owner->getMiniBuffer()->Set(CurrentState());
                break;
                
        case LFUN_DOWN_PARAGRAPH:
-               if(!owner->currentBuffer()->text->mark_set)
+               if(!owner->buffer()->text->mark_set)
                        BeforeChange();
-               owner->currentBuffer()->update(-3);
-               owner->currentBuffer()->text->CursorDownParagraph();
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->update(-3);
+               owner->buffer()->text->CursorDownParagraph();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(false);
                owner->getMiniBuffer()->Set(CurrentState());
                break;
                
        case LFUN_PRIOR:
-               if(!owner->currentBuffer()->text->mark_set)
+               if(!owner->buffer()->text->mark_set)
                        BeforeChange();
-               owner->currentBuffer()->update(-3);
+               owner->buffer()->update(-3);
                owner->currentView()->cursorPrevious();
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(false);
                owner->getMiniBuffer()->Set(CurrentState());
                break;
                
        case LFUN_NEXT:
-               if(!owner->currentBuffer()->text->mark_set)
+               if(!owner->buffer()->text->mark_set)
                        BeforeChange();
-               owner->currentBuffer()->update(-3);
+               owner->buffer()->update(-3);
                owner->currentView()->cursorNext();
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(false);
                owner->getMiniBuffer()->Set(CurrentState());
                break;
                
        case LFUN_HOME:
-               if(!owner->currentBuffer()->text->mark_set)
+               if(!owner->buffer()->text->mark_set)
                        BeforeChange();
-               owner->currentBuffer()->update(-2);
-               owner->currentBuffer()->text->CursorHome();
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->update(-2);
+               owner->buffer()->text->CursorHome();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(false);
                owner->getMiniBuffer()->Set(CurrentState());
                break;
                
        case LFUN_END:
-               if(!owner->currentBuffer()->text->mark_set)
+               if(!owner->buffer()->text->mark_set)
                        BeforeChange();
-               owner->currentBuffer()->update(-2);
-               owner->currentBuffer()->text->CursorEnd();
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->update(-2);
+               owner->buffer()->text->CursorEnd();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(false);
                owner->getMiniBuffer()->Set(CurrentState());
                break;
                
        case LFUN_TAB:
-               if(!owner->currentBuffer()->text->mark_set)
+               if(!owner->buffer()->text->mark_set)
                        BeforeChange();
-               owner->currentBuffer()->update(-2);
-               owner->currentBuffer()->text->CursorTab();
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->update(-2);
+               owner->buffer()->text->CursorTab();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(false);
                owner->getMiniBuffer()->Set(CurrentState());
                break;
                
        case LFUN_WORDRIGHT:
-               if(!owner->currentBuffer()->text->mark_set)
+               if(!owner->buffer()->text->mark_set)
                        BeforeChange();
-               owner->currentBuffer()->update(-2);
-               owner->currentBuffer()->text->CursorRightOneWord();
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->update(-2);
+               owner->buffer()->text->CursorRightOneWord();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(false);
                owner->getMiniBuffer()->Set(CurrentState());
                break;
                
        case LFUN_WORDLEFT:
-               if(!owner->currentBuffer()->text->mark_set)
+               if(!owner->buffer()->text->mark_set)
                        BeforeChange();
-               owner->currentBuffer()->update(-2);
-               owner->currentBuffer()->text->CursorLeftOneWord();
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->update(-2);
+               owner->buffer()->text->CursorLeftOneWord();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(false);
                owner->getMiniBuffer()->Set(CurrentState());
                break;
                
        case LFUN_BEGINNINGBUF:
-               if(!owner->currentBuffer()->text->mark_set)
+               if(!owner->buffer()->text->mark_set)
                        BeforeChange();
-               owner->currentBuffer()->update(-2);
-               owner->currentBuffer()->text->CursorTop();
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->update(-2);
+               owner->buffer()->text->CursorTop();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(false);
                owner->getMiniBuffer()->Set(CurrentState());
                break;
                
        case LFUN_ENDBUF:
-               if(!owner->currentBuffer()->text->mark_set)
+               if(!owner->buffer()->text->mark_set)
                        BeforeChange();
-               owner->currentBuffer()->update(-2);
-               owner->currentBuffer()->text->CursorBottom();
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->update(-2);
+               owner->buffer()->text->CursorBottom();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(false);
                owner->getMiniBuffer()->Set(CurrentState());
                break;
@@ -1454,113 +1463,113 @@ string LyXFunc::Dispatch(int ac,
       
                /* cursor selection ---------------------------- */
        case LFUN_RIGHTSEL:
-               owner->currentBuffer()->update(-2);
-               owner->currentBuffer()->text->CursorRight();
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->update(-2);
+               owner->buffer()->text->CursorRight();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(true);
                owner->getMiniBuffer()->Set(CurrentState());
                break;
                
        case LFUN_LEFTSEL:
-               owner->currentBuffer()->update(-2);
-               owner->currentBuffer()->text->CursorLeft();
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->update(-2);
+               owner->buffer()->text->CursorLeft();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(true);
                owner->getMiniBuffer()->Set(CurrentState());
                break;
                
        case LFUN_UPSEL:
-               owner->currentBuffer()->update(-2);
-               owner->currentBuffer()->text->CursorUp();
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->update(-2);
+               owner->buffer()->text->CursorUp();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(true);
                owner->getMiniBuffer()->Set(CurrentState());
                break;
                
        case LFUN_DOWNSEL:
-               owner->currentBuffer()->update(-2);
-               owner->currentBuffer()->text->CursorDown();
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->update(-2);
+               owner->buffer()->text->CursorDown();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(true);
                owner->getMiniBuffer()->Set(CurrentState());
                break;
 
        case LFUN_UP_PARAGRAPHSEL:
-               owner->currentBuffer()->update(-2);
-               owner->currentBuffer()->text->CursorUpParagraph();
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->update(-2);
+               owner->buffer()->text->CursorUpParagraph();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(true);
                owner->getMiniBuffer()->Set(CurrentState());
                break;
                
        case LFUN_DOWN_PARAGRAPHSEL:
-               owner->currentBuffer()->update(-2);
-               owner->currentBuffer()->text->CursorDownParagraph();
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->update(-2);
+               owner->buffer()->text->CursorDownParagraph();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(true);
                owner->getMiniBuffer()->Set(CurrentState());
                break;
                
        case LFUN_PRIORSEL:
-               owner->currentBuffer()->update(-2);
+               owner->buffer()->update(-2);
                owner->currentView()->cursorPrevious();
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(true);
                owner->getMiniBuffer()->Set(CurrentState());
                break;
                
        case LFUN_NEXTSEL:
-               owner->currentBuffer()->update(-2);
+               owner->buffer()->update(-2);
                owner->currentView()->cursorNext();
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(true);
                owner->getMiniBuffer()->Set(CurrentState());
                break;
                
        case LFUN_HOMESEL:
-               owner->currentBuffer()->update(-2);
-               owner->currentBuffer()->text->CursorHome();
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->update(-2);
+               owner->buffer()->text->CursorHome();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(true);
                owner->getMiniBuffer()->Set(CurrentState());
                break;
                
        case LFUN_ENDSEL:
-               owner->currentBuffer()->update(-2);
-               owner->currentBuffer()->text->CursorEnd();
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->update(-2);
+               owner->buffer()->text->CursorEnd();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(true);
                owner->getMiniBuffer()->Set(CurrentState());
                break;
                
        case LFUN_WORDRIGHTSEL:
-               owner->currentBuffer()->update(-2);
-               owner->currentBuffer()->text->CursorRightOneWord();
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->update(-2);
+               owner->buffer()->text->CursorRightOneWord();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(true);
                owner->getMiniBuffer()->Set(CurrentState());
                break;
                
        case LFUN_WORDLEFTSEL:
-               owner->currentBuffer()->update(-2);
-               owner->currentBuffer()->text->CursorLeftOneWord();
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->update(-2);
+               owner->buffer()->text->CursorLeftOneWord();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(true);
                owner->getMiniBuffer()->Set(CurrentState());
                break;
                
        case LFUN_BEGINNINGBUFSEL:
-               owner->currentBuffer()->update(-2);
-               owner->currentBuffer()->text->CursorTop();
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->update(-2);
+               owner->buffer()->text->CursorTop();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(true);
                owner->getMiniBuffer()->Set(CurrentState());
                break;
                
        case LFUN_ENDBUFSEL:
-               owner->currentBuffer()->update(-2);
-               owner->currentBuffer()->text->CursorBottom();
-               owner->currentBuffer()->text->FinishUndo();
+               owner->buffer()->update(-2);
+               owner->buffer()->text->CursorBottom();
+               owner->buffer()->text->FinishUndo();
                moveCursorUpdate(true);
                owner->getMiniBuffer()->Set(CurrentState());
                break;
@@ -1568,7 +1577,7 @@ string LyXFunc::Dispatch(int ac,
                // --- text changing commands ------------------------
        case LFUN_BREAKLINE:
                BeforeChange();
-               owner->currentBuffer()->text->InsertChar(LYX_META_NEWLINE);
+               owner->buffer()->text->InsertChar(LyXParagraph::META_NEWLINE);
                SmallUpdate(1);
                SetUpdateTimer(0.01);
                moveCursorUpdate(false);
@@ -1576,34 +1585,34 @@ string LyXFunc::Dispatch(int ac,
                
        case LFUN_PROTECTEDSPACE:
                BeforeChange();
-               owner->currentBuffer()->text->
-                       InsertChar(LYX_META_PROTECTED_SEPARATOR);
+               owner->buffer()->text->
+                       InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
                SmallUpdate(1);
                SetUpdateTimer();
                 moveCursorUpdate(false);
                break;
                
        case LFUN_SETMARK:
-               if(owner->currentBuffer()->text->mark_set) {
+               if(owner->buffer()->text->mark_set) {
                        BeforeChange();
-                       owner->currentBuffer()->update(0);
+                       owner->buffer()->update(0);
                        setMessage(N_("Mark removed"));
                } else {
                        BeforeChange();
-                       owner->currentBuffer()->text->mark_set = 1;
-                       owner->currentBuffer()->update(0);
+                       owner->buffer()->text->mark_set = 1;
+                       owner->buffer()->update(0);
                        setMessage(N_("Mark set"));
                }
-               owner->currentBuffer()->text->sel_cursor =
-                       owner->currentBuffer()->text->cursor;
+               owner->buffer()->text->sel_cursor = 
+                       owner->buffer()->text->cursor;
                break;
                
        case LFUN_DELETE:
                FreeUpdateTimer();
-               if (!owner->currentBuffer()->text->selection) {
-                       owner->currentBuffer()->text->Delete();
-                       owner->currentBuffer()->text->sel_cursor =
-                               owner->currentBuffer()->text->cursor;
+               if (!owner->buffer()->text->selection) {
+                       owner->buffer()->text->Delete();
+                       owner->buffer()->text->sel_cursor = 
+                               owner->buffer()->text->cursor;
                        SmallUpdate(1);
                        // It is possible to make it a lot faster still
                        // just comment out the lone below...
@@ -1618,17 +1627,17 @@ string LyXFunc::Dispatch(int ac,
        {
                // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
                
-               LyXCursor cursor = owner->currentBuffer()->text->cursor;
+               LyXCursor cursor = owner->buffer()->text->cursor;
 
                FreeUpdateTimer();
-               if (!owner->currentBuffer()->text->selection) {
+               if (!owner->buffer()->text->selection) {
                        if (cursor.pos == cursor.par->Last()) {
-                               owner->currentBuffer()->text->CursorRight();
-                               cursor = owner->currentBuffer()->text->cursor;
+                               owner->buffer()->text->CursorRight();
+                               cursor = owner->buffer()->text->cursor;
                                if (cursor.pos == 0
                                    && !(cursor.par->added_space_top 
                                         == VSpace (VSpace::NONE))) {
-                                       owner->currentBuffer()->text->SetParagraph
+                                       owner->buffer()->text->SetParagraph
                                                (cursor.par->line_top,
                                                 cursor.par->line_bottom,
                                                 cursor.par->pagebreak_top, 
@@ -1637,19 +1646,19 @@ string LyXFunc::Dispatch(int ac,
                                                 cursor.par->added_space_bottom,
                                                 cursor.par->align, 
                                                 cursor.par->labelwidthstring, 0);
-                                       owner->currentBuffer()->text->CursorLeft();
-                                       owner->currentBuffer()->update (1);
+                                       owner->buffer()->text->CursorLeft();
+                                       owner->buffer()->update (1);
                                } else {
-                                       owner->currentBuffer()->text->CursorLeft();
-                                       owner->currentBuffer()->text->Delete();
-                                       owner->currentBuffer()->text->sel_cursor =
-                                               owner->currentBuffer()->text->cursor;
+                                       owner->buffer()->text->CursorLeft();
+                                       owner->buffer()->text->Delete();
+                                       owner->buffer()->text->sel_cursor = 
+                                               owner->buffer()->text->cursor;
                                        SmallUpdate(1);
                                }
                        } else {
-                               owner->currentBuffer()->text->Delete();
-                               owner->currentBuffer()->text->sel_cursor =
-                                       owner->currentBuffer()->text->cursor;
+                               owner->buffer()->text->Delete();
+                               owner->buffer()->text->sel_cursor = 
+                                       owner->buffer()->text->cursor;
                                SmallUpdate(1);
                        }
                } else {
@@ -1661,20 +1670,20 @@ string LyXFunc::Dispatch(int ac,
 
        /* -------> Delete word forward. */
        case LFUN_DELETE_WORD_FORWARD:
-               owner->currentBuffer()->update(-2);
+               owner->buffer()->update(-2);
                FreeUpdateTimer();
-               owner->currentBuffer()->text->DeleteWordForward();
-               owner->currentBuffer()->update( 1 );
+               owner->buffer()->text->DeleteWordForward();
+               owner->buffer()->update( 1 );
                SetUpdateTimer();
                moveCursorUpdate(false);
                break;
 
                /* -------> Delete word backward. */
        case LFUN_DELETE_WORD_BACKWARD:
-               owner->currentBuffer()->update(-2);
+               owner->buffer()->update(-2);
                FreeUpdateTimer();
-               owner->currentBuffer()->text->DeleteWordBackward();
-               owner->currentBuffer()->update( 1 );
+               owner->buffer()->text->DeleteWordBackward();
+               owner->buffer()->update( 1 );
                SetUpdateTimer();
                moveCursorUpdate(false);
                break;
@@ -1682,9 +1691,9 @@ string LyXFunc::Dispatch(int ac,
                /* -------> Kill to end of line. */
        case LFUN_DELETE_LINE_FORWARD:
                FreeUpdateTimer();
-               owner->currentBuffer()->update(-2);
-               owner->currentBuffer()->text->DeleteLineForward();
-               owner->currentBuffer()->update( 1 );
+               owner->buffer()->update(-2);
+               owner->buffer()->text->DeleteLineForward();
+               owner->buffer()->update( 1 );
                SetUpdateTimer();
                moveCursorUpdate(false);
                break;
@@ -1692,30 +1701,30 @@ string LyXFunc::Dispatch(int ac,
                /* -------> Set mark off. */
        case LFUN_MARK_OFF:
                BeforeChange();
-               owner->currentBuffer()->update(0);
-               owner->currentBuffer()->text->sel_cursor =
-                       owner->currentBuffer()->text->cursor;
+               owner->buffer()->update(0);
+               owner->buffer()->text->sel_cursor = 
+                       owner->buffer()->text->cursor;
                setMessage(N_("Mark off"));
                break;
 
                /* -------> Set mark on. */
        case LFUN_MARK_ON:
                BeforeChange();
-               owner->currentBuffer()->text->mark_set = 1;
-               owner->currentBuffer()->update( 0 );
-               owner->currentBuffer()->text->sel_cursor =
-                       owner->currentBuffer()->text->cursor;
+               owner->buffer()->text->mark_set = 1;
+               owner->buffer()->update( 0 );
+               owner->buffer()->text->sel_cursor = 
+                       owner->buffer()->text->cursor;
                setMessage(N_("Mark on"));
                break;
                
        case LFUN_BACKSPACE:
        {
                FreeUpdateTimer();
-               if (!owner->currentBuffer()->text->selection) {
+               if (!owner->buffer()->text->selection) {
                        if (owner->getIntl()->getTrans()->backspace()) {
-                               owner->currentBuffer()->text->Backspace();
-                               owner->currentBuffer()->text->sel_cursor =
-                                       owner->currentBuffer()->text->cursor;
+                               owner->buffer()->text->Backspace();
+                               owner->buffer()->text->sel_cursor = 
+                                       owner->buffer()->text->cursor;
                                SmallUpdate(1);
                                // It is possible to make it a lot faster still
                                // just comment out the lone below...
@@ -1732,14 +1741,14 @@ string LyXFunc::Dispatch(int ac,
        {
                // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
                
-               LyXCursor cursor = owner->currentBuffer()->text->cursor;
+               LyXCursor cursor = owner->buffer()->text->cursor;
                
                FreeUpdateTimer();
-               if (!owner->currentBuffer()->text->selection) {
+               if (!owner->buffer()->text->selection) {
                        if (cursor.pos == 0 
                            && !(cursor.par->added_space_top 
                                 == VSpace (VSpace::NONE))) {
-                               owner->currentBuffer()->text->SetParagraph 
+                               owner->buffer()->text->SetParagraph 
                                        (cursor.par->line_top,      
                                         cursor.par->line_bottom,
                                         cursor.par->pagebreak_top, 
@@ -1747,10 +1756,10 @@ string LyXFunc::Dispatch(int ac,
                                         VSpace(VSpace::NONE), cursor.par->added_space_bottom,
                                         cursor.par->align, 
                                         cursor.par->labelwidthstring, 0);
-                               owner->currentBuffer()->update (1);
+                               owner->buffer()->update (1);
                        } else {
-                               owner->currentBuffer()->text->Backspace();
-                               owner->currentBuffer()->text->sel_cursor 
+                               owner->buffer()->text->Backspace();
+                               owner->buffer()->text->sel_cursor 
                                        = cursor;
                                SmallUpdate (1);
                        }
@@ -1763,22 +1772,22 @@ string LyXFunc::Dispatch(int ac,
        case LFUN_BREAKPARAGRAPH:
        {
                BeforeChange();
-               owner->currentBuffer()->text->BreakParagraph(0);
+               owner->buffer()->text->BreakParagraph(0);
                SmallUpdate(1);
                SetUpdateTimer(0.01);
-               owner->currentBuffer()->text->sel_cursor =
-                       owner->currentBuffer()->text->cursor;
+               owner->buffer()->text->sel_cursor = 
+                       owner->buffer()->text->cursor;
                break;
        }
 
        case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
        {
                BeforeChange();
-               owner->currentBuffer()->text->BreakParagraph(1);
+               owner->buffer()->text->BreakParagraph(1);
                SmallUpdate(1);
                SetUpdateTimer(0.01);
-               owner->currentBuffer()->text->sel_cursor =
-                       owner->currentBuffer()->text->cursor;
+               owner->buffer()->text->sel_cursor = 
+                       owner->buffer()->text->cursor;
                break;
        }
        
@@ -1788,12 +1797,12 @@ string LyXFunc::Dispatch(int ac,
                // indentation and add a "defskip" at the top.
                // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
                
-               LyXCursor cursor = owner->currentBuffer()->text->cursor;
+               LyXCursor cursor = owner->buffer()->text->cursor;
                
                BeforeChange();
                if (cursor.pos == 0) {
                        if (cursor.par->added_space_top == VSpace(VSpace::NONE)) {
-                               owner->currentBuffer()->text->SetParagraph
+                               owner->buffer()->text->SetParagraph
                                        (cursor.par->line_top,      
                                         cursor.par->line_bottom,
                                         cursor.par->pagebreak_top, 
@@ -1801,21 +1810,21 @@ string LyXFunc::Dispatch(int ac,
                                         VSpace(VSpace::DEFSKIP), cursor.par->added_space_bottom,
                                         cursor.par->align, 
                                         cursor.par->labelwidthstring, 1);
-                               owner->currentBuffer()->update(1);
+                               owner->buffer()->update(1);
                        } 
                }
                else {
-                       owner->currentBuffer()->text->BreakParagraph(0);
+                       owner->buffer()->text->BreakParagraph(0);
                        SmallUpdate(1);
                }
                SetUpdateTimer(0.01);
-               owner->currentBuffer()->text->sel_cursor = cursor;
+               owner->buffer()->text->sel_cursor = cursor;
        }
        break;
        
        case LFUN_QUOTE:
                BeforeChange();
-               owner->currentBuffer()->text->InsertChar('\"');  // This " matches the single quote in the code
+               owner->buffer()->text->InsertChar('\"');  // This " matches the single quote in the code
                SmallUpdate(1);
                SetUpdateTimer();
                 moveCursorUpdate(false);
@@ -1829,7 +1838,7 @@ string LyXFunc::Dispatch(int ac,
                        new_inset = new InsetUrl("htmlurl", "", "");
                else
                        new_inset = new InsetUrl("url", "", "");
-               owner->currentBuffer()->insertInset(new_inset);
+               owner->buffer()->insertInset(new_inset);
                new_inset->Edit(0, 0);
        }
        break;
@@ -1838,9 +1847,10 @@ string LyXFunc::Dispatch(int ac,
 
        case LFUN_CHARATCURSOR:
        {
-               int pos = owner->currentBuffer()->text->cursor.pos;
-               if(pos < owner->currentBuffer()->text->cursor.par->last)
-                       dispatch_buffer = owner->currentBuffer()->text->
+               LyXParagraph::size_type pos = 
+                 owner->buffer()->text->cursor.pos;
+               if(pos < owner->buffer()->text->cursor.par->size())
+                       dispatch_buffer = owner->buffer()->text->
                                cursor.par->text[pos];
                else
                        dispatch_buffer = "EOF";
@@ -1849,8 +1859,8 @@ string LyXFunc::Dispatch(int ac,
        
        case LFUN_GETXY:
                dispatch_buffer = 
-                        tostr(owner->currentBuffer()->text->cursor.x) + ' '
-                       + tostr(owner->currentBuffer()->text->cursor.y);
+                        tostr(owner->buffer()->text->cursor.x) + ' '
+                       + tostr(owner->buffer()->text->cursor.y);
                break;
                
        case LFUN_SETXY:
@@ -1858,18 +1868,18 @@ string LyXFunc::Dispatch(int ac,
                int  x;
                long y;
                sscanf(argument.c_str(), " %d %ld", &x, &y);
-               owner->currentBuffer()->text->SetCursorFromCoordinates(x, y);
+               owner->buffer()->text->SetCursorFromCoordinates(x, y);
        }
        break;
        
        case LFUN_GETLAYOUT:
                dispatch_buffer =  
-                       tostr(owner->currentBuffer()->text->cursor.par->layout);
+                       tostr(owner->buffer()->text->cursor.par->layout);
                break;
                        
        case LFUN_GETFONT:
        {
-               LyXFont *font = &(owner->currentBuffer()->text->current_font);
+               LyXFont *font = &(owner->buffer()->text->current_font);
                 if(font->shape() == LyXFont::ITALIC_SHAPE)
                        dispatch_buffer = 'E';
                 else if(font->shape() == LyXFont::SMALLCAPS_SHAPE)
@@ -1882,7 +1892,7 @@ string LyXFunc::Dispatch(int ac,
 
        case LFUN_GETLATEX:
        {
-               LyXFont *font = &(owner->currentBuffer()->text->current_font);
+               LyXFont *font = &(owner->buffer()->text->current_font);
                 if(font->latex() == LyXFont::ON)
                        dispatch_buffer = 'L';
                 else
@@ -1891,16 +1901,16 @@ string LyXFunc::Dispatch(int ac,
        break;
 
        case LFUN_GETNAME:
-               setMessage(owner->currentBuffer()->getFileName());
+               setMessage(owner->buffer()->getFileName());
                lyxerr.debug() << "FNAME["
-                              << owner->currentBuffer()->getFileName()
+                              << owner->buffer()->getFileName()
                               << "] " << endl;
                break;
                
        case LFUN_NOTIFY:
        {
                char buf[100];
-               keyseq.print(buf,100);
+               keyseq.print(buf, 100);
                dispatch_buffer = buf;
                lyxserver->notifyClient(dispatch_buffer);
        }
@@ -1917,25 +1927,25 @@ string LyXFunc::Dispatch(int ac,
 
                // Either change buffer or load the file
                if (bufferlist.exists(s))
-                       owner->currentView()->setBuffer(bufferlist.getBuffer(s));
+                       owner->currentView()->buffer(bufferlist.getBuffer(s));
                else
-                       owner->currentView()->setBuffer(bufferlist.loadLyXFile(s));
+                       owner->currentView()->buffer(bufferlist.loadLyXFile(s));
 
                // Set the cursor  
-               owner->currentBuffer()->setCursorFromRow(row);
+               owner->buffer()->setCursorFromRow(row);
 
                // Recenter screen
                BeforeChange();
-               if (owner->currentBuffer()->text->cursor.y >
+               if (owner->buffer()->text->cursor.y >
                    owner->currentView()->getWorkArea()->h / 2) {
                        owner->currentView()->getScreen()->
-                               Draw(owner->currentBuffer()->text->cursor.y -
+                               Draw(owner->buffer()->text->cursor.y -
                                     owner->currentView()->getWorkArea()->h/2);
-               } else { // <=
+               } else { // <= 
                        owner->currentView()->getScreen()->
                                Draw(0);
                }
-               owner->currentBuffer()->update(0);
+               owner->buffer()->update(0);
                owner->currentView()->redraw();
        }
        break;
@@ -1970,25 +1980,25 @@ string LyXFunc::Dispatch(int ac,
        {
                char c;
                
-               if (keyseq.length==-1 && keyseq.getiso()!=0) 
-                       c=keyseq.getiso();
+               if (keyseq.length == -1 && keyseq.getiso()!= 0) 
+                       c= keyseq.getiso();
                else
-                       c=0;
+                       c= 0;
                
                owner->getIntl()->getTrans()->
                        deadkey(c, get_accent(action).accent, 
-                               owner->currentBuffer()->text);
+                               owner->buffer()->text);
                
                // Need to reset, in case the minibuffer calls these
                // actions
                keyseq.reset();
-               keyseq.length=0;
+               keyseq.length= 0;
                
                // copied verbatim from do_accent_char
                SmallUpdate(1);
                SetUpdateTimer();
-               owner->currentBuffer()->text->sel_cursor = 
-                       owner->currentBuffer()->text->cursor;
+               owner->buffer()->text->sel_cursor = 
+                       owner->buffer()->text->cursor;
        }   
        break;
        
@@ -2032,14 +2042,14 @@ string LyXFunc::Dispatch(int ac,
        break;
        
        // --- insert characters ----------------------------------------
-
+#if 0
        case LFUN_INSERT_INSET_LATEX:
        {
                Inset *new_inset = new InsetLatex(argument);
-               owner->currentBuffer()->insertInset(new_inset);
+               owner->buffer()->insertInset(new_inset);
        }
        break;
-
+#endif
        // ---  Mathed stuff. If we are here, there is no locked inset yet.
        
        // Greek mode     
@@ -2069,9 +2079,9 @@ string LyXFunc::Dispatch(int ac,
        case LFUN_INSERT_MATRIX:
        {          
                if (owner->currentView()->available()) { 
-                       owner->currentBuffer()->
+                       owner->buffer()->
                                open_new_inset(new InsetFormula(false));
-                       owner->currentBuffer()->
+                       owner->buffer()->
                                the_locking_inset->LocalDispatch(action, argument.c_str());
                }
        }          
@@ -2086,7 +2096,7 @@ string LyXFunc::Dispatch(int ac,
        case LFUN_MATH_DISPLAY:
        {
                if (owner->currentView()->available())
-                       owner->currentBuffer()->open_new_inset(new InsetFormula(true));
+                       owner->buffer()->open_new_inset(new InsetFormula(true));
                break;
        }
                    
@@ -2099,7 +2109,7 @@ string LyXFunc::Dispatch(int ac,
                        else {
                            string s1 = token(s, ' ', 1);
                            int na = s1.empty() ? 0: atoi(s1.c_str());
-                           owner->currentBuffer()->
+                           owner->buffer()->
                              open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na));
                        }
                }
@@ -2110,7 +2120,7 @@ string LyXFunc::Dispatch(int ac,
        {
                
                if (owner->currentView()->available())
-                       owner->currentBuffer()->open_new_inset(new InsetFormula);
+                       owner->buffer()->open_new_inset(new InsetFormula);
                setMessage(N_("Math editor mode"));
        }
        break;
@@ -2124,7 +2134,7 @@ string LyXFunc::Dispatch(int ac,
        
        case LFUN_INSERT_CITATION:
        {   
-               InsetCitation *new_inset = new InsetCitation();
+               InsetCitation * new_inset = new InsetCitation();
                // ale970405
                // The note, if any, must be after the key, delimited
                // by a | so both key and remark can have spaces.
@@ -2135,10 +2145,10 @@ string LyXFunc::Dispatch(int ac,
                                new_inset->setOptions(token(lsarg, '|', 1));
                        } else
                                new_inset->setContents(lsarg);
-                       owner->currentBuffer()->insertInset(new_inset);
+                       owner->buffer()->insertInset(new_inset);
                } else {
-                       owner->currentBuffer()->insertInset(new_inset);
-                       new_inset->Edit(0,0);
+                       owner->buffer()->insertInset(new_inset);
+                       new_inset->Edit(0, 0);
                }
        }
        break;
@@ -2152,14 +2162,14 @@ string LyXFunc::Dispatch(int ac,
                string bibstyle = token(lsarg, ' ', 1);
                if (bibstyle.empty())
                        bibstyle = "plain";
-               InsetBibtex *new_inset 
+               InsetBibtex * new_inset 
                        = new InsetBibtex(token(lsarg, ' ', 0),
                                          bibstyle,
-                                         owner->currentBuffer());
+                                         owner->buffer());
                
-               owner->currentBuffer()->insertInset(new_inset);
+               owner->buffer()->insertInset(new_inset);
                if (lsarg.empty()) {
-                       new_inset->Edit(0,0);
+                       new_inset->Edit(0, 0);
                }
        }
        break;
@@ -2167,8 +2177,8 @@ string LyXFunc::Dispatch(int ac,
        // BibTeX data bases
        case LFUN_BIBDB_ADD:
        {
-               InsetBibtex *inset =
-                       (InsetBibtex*)getInsetByCode(Inset::BIBTEX_CODE);
+               InsetBibtex * inset = 
+                       static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
                if (inset) {
                        inset->addDatabase(argument);
                }
@@ -2177,8 +2187,8 @@ string LyXFunc::Dispatch(int ac,
                    
        case LFUN_BIBDB_DEL:
        {
-               InsetBibtex *inset =
-                       (InsetBibtex*)getInsetByCode(Inset::BIBTEX_CODE);
+               InsetBibtex * inset = 
+                       static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
                if (inset) {
                        inset->delDatabase(argument);
                }
@@ -2187,8 +2197,8 @@ string LyXFunc::Dispatch(int ac,
        
        case LFUN_BIBTEX_STYLE:
        {
-               InsetBibtex *inset =
-                       (InsetBibtex*)getInsetByCode(Inset::BIBTEX_CODE);
+               InsetBibtex * inset = 
+                       static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
                if (inset) {
                        inset->setOptions(argument);
                }
@@ -2198,11 +2208,11 @@ string LyXFunc::Dispatch(int ac,
        case LFUN_INDEX_INSERT:
        case LFUN_INDEX_INSERT_LAST:
        {
-               InsetIndex *new_inset = new InsetIndex();
+               InsetIndex * new_inset = new InsetIndex();
                if (!argument.empty()) {
                        string lsarg(argument);
                        new_inset->setContents(lsarg);
-                       owner->currentBuffer()->insertInset(new_inset);
+                       owner->buffer()->insertInset(new_inset);
                } else {
                  //reh 98/09/21
                  //get the current word for an argument
@@ -2210,76 +2220,78 @@ string LyXFunc::Dispatch(int ac,
                  
                  // grab a word
 
-                 int lastpos =owner->currentBuffer()->text->cursor.pos-1;
-
-                 //this shouldn't happen, but let's be careful
-                 if (lastpos < 0) lastpos=0;
-                 
+                 LyXParagraph::size_type lastpos = 
+                         owner->buffer()->text->cursor.pos - 1;
+                 // If this can't happen, let's make sure that it really don't
+                 Assert(owner->buffer()->text->cursor.pos - 1 >= 0);
                  // get the current word
                  // note that this must be done before 
                  // inserting the inset, or the inset will break
                  // the word
-                 string curstring(owner->currentBuffer()->text->cursor.par->GetWord(lastpos));
+                 string curstring(owner->buffer()
+                                  ->text->cursor.par->GetWord(lastpos));
 
                  //make the new inset and write the current word into it
-                 InsetIndex *new_inset = new InsetIndex();
+                 InsetIndex * new_inset = new InsetIndex();
 
                  new_inset->setContents(curstring);
 
                  //don't edit it if the call was to INSERT_LAST
-                 if(action!=LFUN_INDEX_INSERT_LAST) {
-                     new_inset->Edit(0,0);
+                 if(action!= LFUN_INDEX_INSERT_LAST) {
+                     new_inset->Edit(0, 0);
                  } else {
                      //it looks blank on the screen unless
                      //we do  something.  put it here.
 
                      // move the cursor to the returned value of lastpos
                      // but only for the auto-insert
-                     owner->currentBuffer()->text->cursor.pos=lastpos;
+                     owner->buffer()->text->cursor.pos= lastpos;
                  }
 
                  //put the new inset into the buffer.
                  // there should be some way of knowing the user
                  //cancelled & avoiding this, but i don't know how
-                 owner->currentBuffer()->insertInset(new_inset);
+                 owner->buffer()->insertInset(new_inset);
                }
        }
        break;
 
        case LFUN_INDEX_PRINT:
        {
-               Inset *new_inset = new InsetPrintIndex(owner->currentBuffer());
-               owner->currentBuffer()->insertInset(new_inset, "Standard", true);
+               Inset * new_inset = new InsetPrintIndex(owner->buffer());
+               owner->buffer()->insertInset(new_inset, "Standard", true);
        }
        break;
 
        case LFUN_PARENTINSERT:
        {
                lyxerr << "arg " << argument << endl;
-               Inset *new_inset = new InsetParent(argument, owner->currentBuffer());
-               owner->currentBuffer()->insertInset(new_inset, "Standard", true);
+               Inset * new_inset = new InsetParent(argument, owner->buffer());
+               owner->buffer()->insertInset(new_inset, "Standard", true);
        }
        break;
 
        case LFUN_CHILDINSERT:
        {
-               Inset *new_inset = new InsetInclude(argument,owner->currentBuffer());
-               owner->currentBuffer()->insertInset(new_inset, "Standard", true);
-               new_inset->Edit(0,0);
+               Inset * new_inset = new InsetInclude(argument,
+                                                    owner->buffer());
+               owner->buffer()->insertInset(new_inset, "Standard", true);
+               new_inset->Edit(0, 0);
        }
        break;
 
        case LFUN_CHILDOPEN:
        {
-               string filename = MakeAbsPath(argument, 
-                                              OnlyPath(owner->currentBuffer()->getFileName()));
+               string filename =
+                       MakeAbsPath(argument, 
+                                   OnlyPath(owner->buffer()->getFileName()));
                setMessage(N_("Opening child document ") +
                           MakeDisplayPath(filename) + "...");
                owner->currentView()->savePosition();
                if (bufferlist.exists(filename))
-                 owner->currentView()->setBuffer(bufferlist.getBuffer(filename));
+                 owner->currentView()->buffer(bufferlist.getBuffer(filename));
                else
-                 owner->currentView()->setBuffer(bufferlist.loadLyXFile(filename));
+                 owner->currentView()->buffer(bufferlist.loadLyXFile(filename));
        }
        break;
 
@@ -2308,8 +2320,8 @@ string LyXFunc::Dispatch(int ac,
                        setErrorMessage(N_("Unknown kind of footnote"));
                        break;
                }
-               owner->currentBuffer()->text->InsertFootnoteEnvironment(kind);
-               owner->currentBuffer()->update(1);
+               owner->buffer()->text->InsertFootnoteEnvironment(kind);
+               owner->buffer()->update(1);
        }
        break;
        
@@ -2340,21 +2352,21 @@ string LyXFunc::Dispatch(int ac,
        case LFUN_SELFINSERT:
        {
                for (string::size_type i = 0; i < argument.length(); ++i) {
-                       owner->currentBuffer()->text->InsertChar(argument[i]);
+                       owner->buffer()->text->InsertChar(argument[i]);
                        // This needs to be in the loop, or else we
                        // won't break lines correctly. (Asger)
                        SmallUpdate(1);
                }
                SetUpdateTimer();
-               owner->currentBuffer()->text->sel_cursor =
-                       owner->currentBuffer()->text->cursor;
+               owner->buffer()->text->sel_cursor = 
+                       owner->buffer()->text->cursor;
                moveCursorUpdate(false);
        }
        break;
 
        case LFUN_UNKNOWN_ACTION:
        {
-               if (owner->currentBuffer()->isReadonly()) {
+               if (owner->buffer()->isReadonly()) {
                        LyXBell();
                        setErrorMessage(N_("Document is read only"));
                        break;
@@ -2369,26 +2381,27 @@ string LyXFunc::Dispatch(int ac,
                         * true (on). */
                
                        if ( lyxrc->auto_region_delete ) {
-                               if (owner->currentBuffer()->text->selection){
-                                       owner->currentBuffer()->text->CutSelection(false);
-                                       owner->currentBuffer()->update(-1);
+                               if (owner->buffer()->text->selection){
+                                       owner->buffer()->text->CutSelection(false);
+                                       owner->buffer()->update(-1);
                                }
                        }
                        
                        BeforeChange();
-                       for (string::size_type i = 0; i < argument.length(); ++i) {
+                       for (string::size_type i = 0;
+                            i < argument.length(); ++i) {
                                if (greek_kb_flag) {
                                        if (!math_insert_greek(argument[i]))
-                                               owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->currentBuffer()->text);
+                                               owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->buffer()->text);
                                } else
-                                       owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->currentBuffer()->text);
+                                       owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->buffer()->text);
                        }
                        
                        SmallUpdate(1);
                        SetUpdateTimer();
 
-                       owner->currentBuffer()->text->sel_cursor =
-                               owner->currentBuffer()->text->cursor;
+                       owner->buffer()->text->sel_cursor = 
+                               owner->buffer()->text->cursor;
                        moveCursorUpdate(false);
                        return string();
                } else {
@@ -2406,7 +2419,7 @@ string LyXFunc::Dispatch(int ac,
        } // end of switch
   exit_with_message:
 
-       string res=getMessage();
+       string res= getMessage();
 
        if (res.empty()) {
                if (!commandshortcut.empty()) {
@@ -2439,7 +2452,7 @@ void LyXFunc::MenuNew(bool fromTemplate)
        LyXFileDlg fileDlg;
 
        if (owner->currentView()->available()) {
-               string trypath = owner->currentBuffer()->filepath;
+               string trypath = owner->buffer()->filepath;
                // If directory is writeable, use this as default.
                if (IsDirWriteable(trypath) == 1)
                        initpath = trypath;
@@ -2467,7 +2480,7 @@ void LyXFunc::MenuNew(bool fromTemplate)
        // Check if the document already is open
        if (bufferlist.exists(s)){
                switch(AskConfirmation(_("Document is already open:"), 
-                                      MakeDisplayPath(s,50),
+                                      MakeDisplayPath(s, 50),
                                       _("Do you want to close that document now?\n"
                                         "('No' will just switch to the open version)")))
                {
@@ -2477,7 +2490,7 @@ void LyXFunc::MenuNew(bool fromTemplate)
                                return;
                        break;
                case 2: // No: switch to the open document
-                       owner->currentView()->setBuffer(bufferlist.getBuffer(s));
+                       owner->currentView()->buffer(bufferlist.getBuffer(s));
                        return;
                case 3: // Cancel: Do nothing
                        owner->getMiniBuffer()->Set(_("Canceled."));
@@ -2490,13 +2503,13 @@ void LyXFunc::MenuNew(bool fromTemplate)
                FilePtr myfile(s, FilePtr::read);
                if (myfile() &&
                    AskQuestion(_("File already exists:"), 
-                               MakeDisplayPath(s,50),
+                               MakeDisplayPath(s, 50),
                                _("Do you want to open the document?"))) {
                        // loads document
                        owner->getMiniBuffer()->Set(_("Opening document"), 
                                                    MakeDisplayPath(s), "...");
                        XFlush(fl_display);
-                       owner->currentView()->setBuffer(
+                       owner->currentView()->buffer(
                                bufferlist.loadLyXFile(s));
                        owner->getMiniBuffer()->Set(_("Document"),
                                                    MakeDisplayPath(s),
@@ -2518,7 +2531,7 @@ void LyXFunc::MenuNew(bool fromTemplate)
   
        // find a free buffer
        lyxerr.debug() << "Find a free buffer." << endl;
-       owner->currentView()->setBuffer(bufferlist.newFile(s,templname));
+       owner->currentView()->buffer(bufferlist.newFile(s, templname));
 }
 
 
@@ -2528,7 +2541,7 @@ void LyXFunc::MenuOpen()
        LyXFileDlg fileDlg;
   
        if (owner->currentView()->available()) {
-               string trypath = owner->currentBuffer()->filepath;
+               string trypath = owner->buffer()->filepath;
                // If directory is writeable, use this as default.
                if (IsDirWriteable(trypath) == 1)
                        initpath = trypath;
@@ -2560,7 +2573,7 @@ void LyXFunc::MenuOpen()
                                    MakeDisplayPath(filename), "...");
        Buffer * openbuf = bufferlist.loadLyXFile(filename);
        if (openbuf) {
-               owner->currentView()->setBuffer(openbuf);
+               owner->currentView()->buffer(openbuf);
                owner->getMiniBuffer()->Set(_("Document"),
                                            MakeDisplayPath(filename),
                                            _("opened."));
@@ -2577,7 +2590,7 @@ void LyXFunc::doImportASCII(bool linorpar)
        LyXFileDlg fileDlg;
   
        if (owner->currentView()->available()) {
-               string trypath = owner->currentBuffer()->filepath;
+               string trypath = owner->buffer()->filepath;
                // If directory is writeable, use this as default.
                if (IsDirWriteable(trypath) == 1)
                        initpath = trypath;
@@ -2606,7 +2619,7 @@ void LyXFunc::doImportASCII(bool linorpar)
        // Check if the document already is open
        if (bufferlist.exists(s)){
                switch(AskConfirmation(_("Document is already open:"), 
-                                      MakeDisplayPath(s,50),
+                                      MakeDisplayPath(s, 50),
                                       _("Do you want to close that document now?\n"
                                         "('No' will just switch to the open version)")))
                {
@@ -2616,7 +2629,7 @@ void LyXFunc::doImportASCII(bool linorpar)
                                return;
                        break;
                case 2: // No: switch to the open document
-                       owner->currentView()->setBuffer(bufferlist.getBuffer(s));
+                       owner->currentView()->buffer(bufferlist.getBuffer(s));
                        return;
                case 3: // Cancel: Do nothing
                        owner->getMiniBuffer()->Set(_("Canceled."));
@@ -2633,11 +2646,11 @@ void LyXFunc::doImportASCII(bool linorpar)
                return;
        }
 
-       owner->currentView()->setBuffer(bufferlist.newFile(s,string()));
+       owner->currentView()->buffer(bufferlist.newFile(s, string()));
        owner->getMiniBuffer()->Set(_("Importing ASCII file"),
                                    MakeDisplayPath(filename), "...");
        // Insert ASCII file
-       InsertAsciiFile(filename,linorpar);
+       InsertAsciiFile(filename, linorpar);
        owner->getMiniBuffer()->Set(_("ASCII file "),
                                    MakeDisplayPath(filename),
                                    _("imported."));
@@ -2650,7 +2663,7 @@ void LyXFunc::doImportLaTeX(bool isnoweb)
        LyXFileDlg fileDlg;
   
        if (owner->currentView()->available()) {
-               string trypath = owner->currentBuffer()->filepath;
+               string trypath = owner->buffer()->filepath;
                // If directory is writeable, use this as default.
                if (IsDirWriteable(trypath) == 1)
                        initpath = trypath;
@@ -2685,7 +2698,7 @@ void LyXFunc::doImportLaTeX(bool isnoweb)
        string LyXfilename = ChangeExtension(filename, ".lyx", false);
        if (bufferlist.exists(LyXfilename)){
                switch(AskConfirmation(_("Document is already open:"), 
-                                      MakeDisplayPath(LyXfilename,50),
+                                      MakeDisplayPath(LyXfilename, 50),
                                       _("Do you want to close that document now?\n"
                                         "('No' will just switch to the open version)")))
                {
@@ -2695,7 +2708,7 @@ void LyXFunc::doImportLaTeX(bool isnoweb)
                                return;
                        break;
                case 2: // No: switch to the open document
-                       owner->currentView()->setBuffer(
+                       owner->currentView()->buffer(
                                bufferlist.getBuffer(LyXfilename));
                        return;
                case 3: // Cancel: Do nothing
@@ -2727,7 +2740,7 @@ void LyXFunc::doImportLaTeX(bool isnoweb)
                openbuf = myImport.run();
        }
        if (openbuf) {
-               owner->currentView()->setBuffer(openbuf);
+               owner->currentView()->buffer(openbuf);
                owner->getMiniBuffer()->Set(isnoweb ?
                                            _("Noweb file ") : _("LateX file "),
                                            MakeDisplayPath(filename),
@@ -2751,7 +2764,7 @@ void LyXFunc::MenuInsertLyXFile(string const & filen)
                LyXFileDlg fileDlg;
 
                if (owner->currentView()->available()) {
-                       string trypath = owner->currentBuffer()->filepath;
+                       string trypath = owner->buffer()->filepath;
                        // If directory is writeable, use this as default.
                        if (IsDirWriteable(trypath) == 1)
                                initpath = trypath;
@@ -2782,7 +2795,7 @@ void LyXFunc::MenuInsertLyXFile(string const & filen)
        // Inserts document
        owner->getMiniBuffer()->Set(_("Inserting document"),
                                    MakeDisplayPath(filename), "...");
-       bool res = owner->currentBuffer()->insertLyXFile(filename);
+       bool res = owner->buffer()->insertLyXFile(filename);
        if (res) {
                owner->getMiniBuffer()->Set(_("Document"),
                                            MakeDisplayPath(filename),
@@ -2796,39 +2809,39 @@ void LyXFunc::MenuInsertLyXFile(string const & filen)
 
 void LyXFunc::reloadBuffer()
 {
-       string fn = owner->currentBuffer()->getFileName();
-       if (bufferlist.close(owner->currentBuffer()))
-               owner->currentView()->setBuffer(bufferlist.loadLyXFile(fn));
+       string fn = owner->buffer()->getFileName();
+       if (bufferlist.close(owner->buffer()))
+               owner->currentView()->buffer(bufferlist.loadLyXFile(fn));
 }
 
 
 void LyXFunc::CloseBuffer()
 {
-       if (bufferlist.close(owner->currentBuffer()) && !quitting) {
-               if (bufferlist.isEmpty()) {
+       if (bufferlist.close(owner->buffer()) && !quitting) {
+               if (bufferlist.empty()) {
                        // need this otherwise SEGV may occur while trying to
                        // set variables that don't exist
                        // since there's no current buffer
                        CloseAllBufferRelatedPopups();
                }
                else {
-                       owner->currentView()->setBuffer(bufferlist.first());
+                       owner->currentView()->buffer(bufferlist.first());
                }
        }
 }
 
 
-Inset* LyXFunc::getInsetByCode(Inset::Code code)
+Inset * LyXFunc::getInsetByCode(Inset::Code code)
 {
        bool found = false;
-       Inset* inset = 0;
-       LyXCursor cursor = owner->currentBuffer()->text->cursor;
-       int pos = cursor.pos;
-       LyXParagraph *par = cursor.par;
+       Inset * inset = 0;
+       LyXCursor cursor = owner->buffer()->text->cursor;
+       LyXParagraph::size_type pos = cursor.pos;
+       LyXParagraph * par = cursor.par;
        
        while (par && !found) {
                while ((inset = par->ReturnNextInsetPointer(pos))){
-                       if (inset->LyxCode()==code) {
+                       if (inset->LyxCode() == code) {
                                found = true;
                                break;
                        }