On Sun, Mar 05, 2000 at 06:10:36PM -0800, Kayvan A. Sylvan wrote:
> > In what way is this different from preespacing?
> 
> I assume you mean freespacing? 
> 
> It's supposed to do the same thing, but the freespacing hack does not work
> and I didn't find it till after I'd implemented mine. :-)

After shooting my mouth off before, now I have a correct fix. This one
basically does a few things right (as opposed to my previous fix):

1) It continues to work with old Literate Lyx files, thus making the updates
   to Literate.lyx and noweb2lyx.lyx unnecessary.

2) It fixes the already existing free_spacing feature instead of adding
   a redundant attribute.

3) Patch the input routine in lyxfunc.C so that the user's attempt to enter
   a protected-space while in a free_spacing layout is thwarted.

I don't really think that protected space (or any of the other special char
insets) make a whole lot of sense in the layouts that enable free_spacing.

Anyways, here is the patch. Check it over carefully.

-- 
Kayvan A. Sylvan                   | Proud husband of      | Father to my kids:
Sylvan Associates, Inc.            | Laura Isabella Sylvan | Katherine Yelena
http://www.successlinks.com/kayvan | Reach your goals now! | Robin Gregory
Index: lib/layouts/literate-scrap.inc
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/layouts/literate-scrap.inc,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 literate-scrap.inc
--- lib/layouts/literate-scrap.inc      1999/09/27 18:44:33     1.1.1.1
+++ lib/layouts/literate-scrap.inc      2000/03/06 11:32:54
@@ -2,8 +2,7 @@
 # Suggested style to write your code:
 # Within same scrap, lines are separated by new-lines (Ctrl-return), use:
 #  ItemSep               0.4
-#     . disavantage: lyx doesn't allow space on first column, use proteced space
-#                    must type ctrl-return every single line
+#     . disavantage: must type ctrl-return every single line
 #     . advantage:   looks better (IMHO)
 #                    resembles more closelly the produced paper doc. (more WYSIWYG)
 #
Index: src/buffer.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.C,v
retrieving revision 1.50
diff -u -r1.50 buffer.C
--- src/buffer.C        2000/03/06 02:42:37     1.50
+++ src/buffer.C        2000/03/06 11:33:04
@@ -911,11 +911,39 @@
                par->SetFont(pos, font);
                ++pos;
        } else if (token == "\\SpecialChar") {
-               inset = new InsetSpecialChar;
-               inset->Read(lex);
-               par->InsertChar(pos, LyXParagraph::META_INSET); 
-               par->InsertInset(pos, inset);
-               par->SetFont(pos, font);
+               LyXLayout const & layout =
+                       textclasslist.Style(params.textclass, 
+                                           par->GetLayout());
+
+               // Insets don't make sense in a free-spacing context! ---Kayvan
+               if (layout.free_spacing)
+               {
+                       if (lex.IsOK()) {
+                               string next_token;
+                               lex.next();
+                               next_token = lex.GetString();
+                               if (next_token == "\\-") {
+                                       par->InsertChar(pos, '-');
+                                       par->SetFont(pos, font);
+                               } else if (next_token == "\\protected_separator") {
+                                       par->InsertChar(pos, ' ');
+                                       par->SetFont(pos, font);
+                               } else {
+                                       lex.printError("Token `$$Token' "
+                                                      "is in free space "
+                                                      "paragraph layout!");
+                                       pos--;
+                               }
+                       }
+               }
+               else
+               {
+                       inset = new InsetSpecialChar;
+                       inset->Read(lex);
+                       par->InsertChar(pos, LyXParagraph::META_INSET); 
+                       par->InsertInset(pos, inset);
+                       par->SetFont(pos, font);
+               }
                ++pos;
        } else if (token == "\\Figure") {
                inset = new InsetFig(100, 100, this);
@@ -943,10 +971,19 @@
                ++pos;
        } else if (token == "\\protected_separator") { // obsolete
 #if 1
-               inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
-               par->InsertChar(pos, LyXParagraph::META_INSET);
-               par->InsertInset(pos, inset);
-               par->SetFont(pos, font);
+               LyXLayout const & layout =
+                       textclasslist.Style(params.textclass, 
+                                           par->GetLayout());
+
+               if (layout.free_spacing) {
+                       par->InsertChar(pos, ' ');
+                       par->SetFont(pos, font);
+               } else {
+                       inset = new 
+InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
+                       par->InsertChar(pos, LyXParagraph::META_INSET);
+                       par->InsertInset(pos, inset);
+                       par->SetFont(pos, font);
+               }
 #else
                par->InsertChar(pos, LyXParagraph::META_PROTECTED_SEPARATOR);
                par->SetFont(pos, font);
Index: src/lyxfunc.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.C,v
retrieving revision 1.48
diff -u -r1.48 lyxfunc.C
--- src/lyxfunc.C       2000/03/01 04:56:55     1.48
+++ src/lyxfunc.C       2000/03/06 11:33:10
@@ -1642,7 +1642,19 @@
                
        case LFUN_PROTECTEDSPACE:
 #if 1
-               owner->view()->protectedBlank();
+       {
+               LyXLayout const & style =
+                       textclasslist.Style(owner->view()->buffer()->params.textclass,
+                                           
+owner->view()->text->cursor.par->GetLayout());
+
+               if (style.free_spacing) {
+                       owner->view()->text->InsertChar(' ');
+                       owner->view()->update(-1);
+               } else {
+                       owner->view()->protectedBlank();
+               }
+               moveCursorUpdate(false);
+       }
 #else
                owner->view()->beforeChange();
                owner->view()->text->
Index: src/text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v
retrieving revision 1.33
diff -u -r1.33 text.C
--- src/text.C  2000/03/06 02:42:38     1.33
+++ src/text.C  2000/03/06 11:33:33
@@ -2390,24 +2390,12 @@
                cursor.par->ParFromPos(cursor.pos)->next);
 
        /* When the free-spacing option is set for the current layout,
-        * all spaces are converted to protected spaces. */
-       // Thinko!
-#warning think about this
-#if 0
-       bool freeSpacingBo = 
+        * disable the double-space checking */
+
+       bool freeSpacing = 
                textclasslist.Style(parameters->textclass,
                               cursor.row->par->GetLayout()).free_spacing;
 
-       // Thinkee: (not done)
-       // It seems that we should insert a InsetSpecialChar, do we really
-       // have to? I don't know the free spacing politics too deeply.
-       // Some others should have a look at this.
-       if (freeSpacingBo && IsLineSeparatorChar(c) 
-           && (!cursor.pos || cursor.par->IsLineSeparator(cursor.pos - 1))) {
-               c = LyXParagraph::META_PROTECTED_SEPARATOR;
-       }
-#endif
-       
        /* table stuff -- begin*/
        if (cursor.par->table) {
                InsertCharInTable(c);
@@ -2442,7 +2430,7 @@
 
        bool jumped_over_space = false;
    
-       if (IsLineSeparatorChar(c)) {
+       if (!freeSpacing && IsLineSeparatorChar(c)) {
 #ifndef FIX_DOUBLE_SPACE
                if (cursor.pos < lastpos
                    && cursor.par->IsLineSeparator(cursor.pos)) {
Index: src/text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.30
diff -u -r1.30 text2.C
--- src/text2.C 2000/02/29 02:19:16     1.30
+++ src/text2.C 2000/03/06 11:33:41
@@ -3221,6 +3221,11 @@
        // this is the delete-empty-paragraph-mechanism.
        if (selection) return;
 
+       // if free-spacing, then return also.
+       if (textclasslist.Style(parameters->textclass,
+                               old_cursor.row->par->GetLayout()).free_spacing)
+               return;
+
 #ifdef FIX_DOUBLE_SPACE
        /* Ok I'll put some comments here about what is missing.
           I have fixed BackSpace (and thus Delete) to not delete

Reply via email to