A much-requested feature, this enables carriage returns in ERT to mean exactly that rather than the main-text "return is new par" behaviour.
Also a bit of a cleanup. Comments ? regards john p.s. I am interested in looking at an alltt-based insetcode to replace lyx-code environment. It looks pretty easy from a naive look. Index: buffer.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.C,v retrieving revision 1.477 diff -u -p -r1.477 buffer.C --- buffer.C 3 Jun 2003 15:10:06 -0000 1.477 +++ buffer.C 5 Jun 2003 23:51:15 -0000 @@ -414,7 +414,7 @@ void Buffer::insertStringAsLines(Paragra for(string::const_iterator cit = str.begin(); cit != str.end(); ++cit) { if (*cit == '\n') { - if (autobreakrows && (!par->empty() || layout->keepempty)) { + if (autobreakrows && (!par->empty() || par->allowEmpty())) { breakParagraph(params, paragraphs, par, pos, layout->isEnvironment()); ++par; @@ -425,12 +425,10 @@ void Buffer::insertStringAsLines(Paragra } // do not insert consecutive spaces if !free_spacing } else if ((*cit == ' ' || *cit == '\t') && - space_inserted && !layout->free_spacing && - !par->isFreeSpacing()) - { + space_inserted && !par->isFreeSpacing()) { continue; } else if (*cit == '\t') { - if (!layout->free_spacing && !par->isFreeSpacing()) { + if (!par->isFreeSpacing()) { // tabs are like spaces here par->insertChar(pos, ' ', font); ++pos; @@ -1522,7 +1520,7 @@ void Buffer::simpleLinuxDocOnePar(ostrea bool ws; string str; boost::tie(ws, str) = sgml::escapeChar(c); - if (ws && !style->free_spacing && !par->isFreeSpacing()) { + if (ws && !par->isFreeSpacing()) { // in freespacing mode, spaces are // non-breaking characters if (desc_on) {// if char is ' ' then... @@ -1907,9 +1905,9 @@ void Buffer::simpleDocBookOnePar(ostream if (style->pass_thru) { os << c; - } else if (style->free_spacing || par->isFreeSpacing() || c != ' ') { + } else if (par->isFreeSpacing() || c != ' ') { os << str; - } else if (desc_on ==1) { + } else if (desc_on == 1) { ++char_line_count; os << "\n</term><listitem><para>"; desc_on = 2; Index: paragraph.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.C,v retrieving revision 1.282 diff -u -p -r1.282 paragraph.C --- paragraph.C 4 Jun 2003 16:14:36 -0000 1.282 +++ paragraph.C 5 Jun 2003 23:51:17 -0000 @@ -623,7 +623,7 @@ void Paragraph::makeSameLayout(Paragraph int Paragraph::stripLeadingSpaces() { - if (layout()->free_spacing || isFreeSpacing()) + if (isFreeSpacing()) return 0; int i = 0; @@ -1409,8 +1409,21 @@ ParagraphParameters const & Paragraph::p bool Paragraph::isFreeSpacing() const { + if (layout()->free_spacing) + return true; + // for now we just need this, later should we need this in some // other way we can always add a function to Inset::() too. + if (pimpl_->inset_owner && pimpl_->inset_owner->owner()) + return (pimpl_->inset_owner->owner()->lyxCode() == Inset::ERT_CODE); + return false; +} + + +bool Paragraph::allowEmpty() const +{ + if (layout()->keepempty) + return true; if (pimpl_->inset_owner && pimpl_->inset_owner->owner()) return (pimpl_->inset_owner->owner()->lyxCode() == Inset::ERT_CODE); return false; Index: paragraph.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.h,v retrieving revision 1.87 diff -u -p -r1.87 paragraph.h --- paragraph.h 4 Jun 2003 07:14:03 -0000 1.87 +++ paragraph.h 5 Jun 2003 23:51:17 -0000 @@ -283,8 +283,11 @@ public: /// int stripLeadingSpaces(); - /// + /// return true if we allow multiple spaces bool isFreeSpacing() const; + + /// return true if we allow this par to stay empty + bool allowEmpty() const; /// ParagraphParameters & params(); Index: paragraph_funcs.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph_funcs.C,v retrieving revision 1.44 diff -u -p -r1.44 paragraph_funcs.C --- paragraph_funcs.C 29 May 2003 01:13:16 -0000 1.44 +++ paragraph_funcs.C 5 Jun 2003 23:51:19 -0000 @@ -71,7 +71,7 @@ void breakParagraph(BufferParams const & tmp->setLabelWidthString(par->params().labelWidthString()); } - bool const isempty = (par->layout()->keepempty && par->empty()); + bool const isempty = (par->allowEmpty() && par->empty()); if (!isempty && (par->size() > pos || par->empty() || flag == 2)) { tmp->layout(par->layout()); @@ -937,10 +937,10 @@ int readParToken(Buffer & buf, Paragraph lex.next(); font.setLyXColor(lex.getString()); } else if (token == "\\InsetSpace" || token == "\\SpecialChar") { - LyXLayout_ptr const & layout = par.layout(); // Insets don't make sense in a free-spacing context! ---Kayvan - if (layout->free_spacing || par.isFreeSpacing()) { +#warning this will break insetcode using alltt probably + if (par.isFreeSpacing()) { if (token == "\\InsetSpace") par.insertChar(par.size(), ' ', font, change); else if (lex.isOK()) { Index: paragraph_pimpl.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph_pimpl.C,v retrieving revision 1.71 diff -u -p -r1.71 paragraph_pimpl.C --- paragraph_pimpl.C 29 May 2003 01:13:17 -0000 1.71 +++ paragraph_pimpl.C 5 Jun 2003 23:51:20 -0000 @@ -429,8 +429,7 @@ void Paragraph::Pimpl::simpleTeXBlanks(o && getChar(i - 1) != ' ' && (i < size() - 1) // same in FreeSpacing mode - && !style.free_spacing - && !owner_->isFreeSpacing() + && !owner_->isFreeSpacing() // In typewriter mode, we want to avoid // ! . ? : at the end of a line && !(font.family() == LyXFont::TYPEWRITER_FAMILY Index: text.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v retrieving revision 1.365 diff -u -p -r1.365 text.C --- text.C 28 May 2003 16:36:53 -0000 1.365 +++ text.C 5 Jun 2003 23:51:24 -0000 @@ -1461,10 +1461,9 @@ void LyXText::breakParagraph(ParagraphLi LyXLayout_ptr const & layout = cursor.par()->layout(); // this is only allowed, if the current paragraph is not empty or caption - // and if it has not the keepempty flag aktive - if (cursor.par()->empty() - && layout->labeltype != LABEL_SENSITIVE - && !layout->keepempty) + // and if it has not the keepempty flag active + if (cursor.par()->empty() && !cursor.par()->allowEmpty() + && layout->labeltype != LABEL_SENSITIVE) return; setUndo(bv(), Undo::FINISH, cursor.par()); @@ -1487,7 +1486,7 @@ void LyXText::breakParagraph(ParagraphLi // breakParagraph call should return a bool if it inserts the // paragraph before or behind and we should react on that one // but we can fix this in 1.3.0 (Jug 20020509) - bool const isempty = (layout->keepempty && cursor.par()->empty()); + bool const isempty = (cursor.par()->allowEmpty() && cursor.par()->empty()); ::breakParagraph(bv()->buffer()->params, paragraphs, cursor.par(), cursor.pos(), keep_layout); Index: text2.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v retrieving revision 1.368 diff -u -p -r1.368 text2.C --- text2.C 5 Jun 2003 11:34:54 -0000 1.368 +++ text2.C 5 Jun 2003 23:51:26 -0000 @@ -2224,7 +2224,7 @@ bool LyXText::deleteEmptyParagraphMechan return false; // Do not delete empty paragraphs with keepempty set. - if (old_cursor.par()->layout()->keepempty) + if (old_cursor.par()->allowEmpty()) return false; // only do our magic if we changed paragraph Index: insets/insetert.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetert.C,v retrieving revision 1.129 diff -u -p -r1.129 insetert.C --- insets/insetert.C 3 Jun 2003 15:10:08 -0000 1.129 +++ insets/insetert.C 5 Jun 2003 23:51:30 -0000 @@ -346,7 +346,7 @@ int InsetERT::latex(Buffer const *, ostr } ++par; if (par != end) { - os << "\n\n"; + os << "\n"; lines += 2; } }