The attached patch let LyX support \linebreak:

- fileformat change
- tex2lyx support for \linebreak
- tex2lyx support for \newline
- rename LFUN_BREAK_LINE to LFUN_NEW_LINE because this is what the lfun does 
and to avoid confusions
- new menu entry
- new shortcut C-S-Return for \linebreak

The whole thing is, I hope so, very well tested. The only thing I'm not sure is the appearance of the line break on screen: It's the same as for \\ and \newline, but in a different color (the one of \pagebreak) and with the label "line break" behind it to visualize the users that \linebreak is differen from \newline. I could use another label if you like or omit this.

When there are no objections about the appearance, I'll commit this.

regards Uwe
Index: development/FORMAT
===================================================================
--- development/FORMAT	(revision 21760)
+++ development/FORMAT	(working copy)
@@ -1,6 +1,9 @@
 LyX file-format changes
 -----------------------
 
+2007-11-24 Uwe Stöhr <[EMAIL PROTECTED]>
+	* Format incremented to 301: support for \linebreak
+
 2007-11-23 Uwe Stöhr <[EMAIL PROTECTED]>
 	* Format incremented to 300: support for \pagebreak
 
Index: lib/bind/aqua.bind
===================================================================
--- lib/bind/aqua.bind	(revision 21760)
+++ lib/bind/aqua.bind	(working copy)
@@ -26,7 +26,8 @@
 \bind "M-~S-i s p"		"hyphenation-point-insert"
 \bind "M-~S-i s k"		"ligature-break-insert"
 \bind "M-~S-i s b"		"protected-space-insert"
-\bind "M-~S-i s l"		"break-line"
+\bind "M-~S-i s l"		"new-line"
+\bind "M-~S-i s r"		"line-break"
 \bind "M-~S-i s i"		"dots-insert"
 \bind "M-~S-i s e"		"end-of-sentence-period-insert"
 \bind "M-~S-i s q"		"self-insert \""
Index: lib/bind/cua.bind
===================================================================
--- lib/bind/cua.bind	(revision 21763)
+++ lib/bind/cua.bind	(working copy)
@@ -196,7 +196,8 @@
 \bind "C-Delete"		"word-delete-forward"
 \bind "C-BackSpace"		"word-delete-backward"
 \bind "M-Return"		"break-paragraph inverse"
-\bind "C-Return"		"break-line"
+\bind "C-Return"		"new-line"
+\bind "C-S-Return"		"line-break"
 \bind "C-k"			"line-delete-forward"
 \bind "C-space"			"space-insert protected"
 \bind "C-M-space"			"space-insert normal"
Index: lib/bind/emacs.bind
===================================================================
--- lib/bind/emacs.bind	(revision 21763)
+++ lib/bind/emacs.bind	(working copy)
@@ -209,7 +209,8 @@
 \bind "M-d"			"word-delete-forward"
 \bind "C-BackSpace"		"word-delete-backward"
 \bind "M-Return"		"break-paragraph inverse"
-\bind "C-Return"		"break-line"
+\bind "C-Return"		"new-line"
+\bind "C-S-Return"		"line-break"
 \bind "C-S-L"			"ligature-break-insert"
 \bind "C-space"			"space-insert protected"
 \bind "C-M-space"			"space-insert normal"
Index: lib/bind/mac.bind
===================================================================
--- lib/bind/mac.bind	(revision 21760)
+++ lib/bind/mac.bind	(working copy)
@@ -178,7 +178,8 @@
 \bind "M-Delete"		"word-delete-forward"
 \bind "M-BackSpace"		"word-delete-backward"
 \bind "M-Return"		"break-paragraph inverse"
-\bind "C-Return"		"break-line"
+\bind "C-Return"		"new-line"
+\bind "C-S-Return"		"line-break"
 \bind "C-k"			"line-delete-forward"
 \bind "M-space"			"space-insert protected"
 \bind "C-M-space"			"space-insert normal"
Index: lib/bind/xemacs.bind
===================================================================
--- lib/bind/xemacs.bind	(revision 21763)
+++ lib/bind/xemacs.bind	(working copy)
@@ -220,7 +220,8 @@
 \bind "M-d"                     "word-delete-forward"
 \bind "C-BackSpace"		"word-delete-backward"
 \bind "M-Return"		"break-paragraph inverse"
-\bind "C-Return"		"break-line"
+\bind "C-Return"		"new-line"
+\bind "C-S-Return"		"line-break"
 \bind "C-S-L"			"ligature-break-insert"
 \bind "C-space"			"space-insert protected"
 \bind "C-M-space"		"space-insert normal"
Index: lib/lyx2lyx/LyX.py
===================================================================
--- lib/lyx2lyx/LyX.py	(revision 21760)
+++ lib/lyx2lyx/LyX.py	(working copy)
@@ -80,7 +80,7 @@
                    ("1_3",     [221], minor_versions("1.3" , 7)),
                    ("1_4", range(222,246), minor_versions("1.4" , 5)),
                    ("1_5", range(246,277), minor_versions("1.5" , 2)),
-                   ("1_6", range(277,301), minor_versions("1.6" , 0))] # Uwe: \pagebreak
+                   ("1_6", range(277,302), minor_versions("1.6" , 0))] # Uwe: \linebreak
 
 
 def formats_list():
Index: lib/lyx2lyx/lyx_1_6.py
===================================================================
--- lib/lyx2lyx/lyx_1_6.py	(revision 21760)
+++ lib/lyx2lyx/lyx_1_6.py	(working copy)
@@ -799,6 +799,17 @@
       i = i + 1
 
 
+def revert_linebreak(document):
+    'Reverts linebreak to newline'
+    i = 0
+    while True:
+      i = find_token(document.body, "\\linebreak", i)
+      if i == -1:
+          return
+      document.body[i] = document.body[i].replace("\\linebreak", "\\newline")
+      i = i + 1
+
+
 ##
 # Conversion hub
 #
@@ -827,10 +838,12 @@
            [297, [convert_usorbian]],
            [298, []],
            [299, []],
-           [300, []]
+           [300, []],
+           [301, []]
           ]
 
-revert =  [[299, [revert_pagebreak]],
+revert =  [[300, [revert_linebreak]],
+           [299, [revert_pagebreak]],
            [298, [revert_hyperlinktype]],
            [297, [revert_macro_optional_params]],
            [296, [revert_albanian, revert_lowersorbian, revert_uppersorbian]],
Index: lib/ui/stdmenus.inc
===================================================================
--- lib/ui/stdmenus.inc	(revision 21760)
+++ lib/ui/stdmenus.inc	(working copy)
@@ -360,7 +360,8 @@
 		Separator
 		Item "Hyphenation Point|H" "hyphenation-point-insert"
 		Item "Ligature Break|k" "ligature-break-insert"
-		Item "Line Break|B" "break-line"
+		Item "New Line|w" "new-line"
+		Item "Line Break|B" "line-break"
 		Separator
 		Item "New Page|N" "newpage-insert"
 		Item "Page Break|a" "pagebreak-insert"
Index: src/Buffer.cpp
===================================================================
--- src/Buffer.cpp	(revision 21760)
+++ src/Buffer.cpp	(working copy)
@@ -153,7 +153,7 @@
 
 namespace {
 
-int const LYX_FORMAT = 300; // Uwe: \pagebreak
+int const LYX_FORMAT = 301; // Uwe: \linebreak
 
 } // namespace anon
 
Index: src/insets/InsetCollapsable.cpp
===================================================================
--- src/insets/InsetCollapsable.cpp	(revision 21760)
+++ src/insets/InsetCollapsable.cpp	(working copy)
@@ -651,7 +651,7 @@
 	case LFUN_BIBITEM_INSERT:
 	case LFUN_BOX_INSERT:
 	case LFUN_BRANCH_INSERT:
-	case LFUN_BREAK_LINE:
+	case LFUN_NEW_LINE:
 	case LFUN_CAPTION_INSERT:
 	case LFUN_CLEARPAGE_INSERT:
 	case LFUN_CLEARDOUBLEPAGE_INSERT:
Index: src/insets/InsetNewline.cpp
===================================================================
--- src/insets/InsetNewline.cpp	(revision 21760)
+++ src/insets/InsetNewline.cpp	(working copy)
@@ -20,7 +20,9 @@
 #include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
 
+#include "support/docstring.h"
 
+
 namespace lyx {
 
 using std::endl;
@@ -35,7 +37,7 @@
 
 void InsetNewline::write(Buffer const &, ostream & os) const
 {
-	os << "\n\\newline\n";
+	os << "\n" << getLyXName() << '\n';
 }
 
 
@@ -48,10 +50,10 @@
 }
 
 
-int InsetNewline::latex(Buffer const &, odocstream &,
+int InsetNewline::latex(Buffer const &, odocstream & os,
 			OutputParams const &) const
 {
-	lyxerr << "Eek, calling InsetNewline::latex !" << endl;
+	os << from_ascii(getCmdName()) << '\n';
 	return 0;
 }
 
@@ -74,6 +76,9 @@
 
 void InsetNewline::draw(PainterInfo & pi, int x, int y) const
 {
+	FontInfo font;
+	font.setColor(ColorName());
+
 	frontend::FontMetrics const & fm = theFontMetrics(pi.base.font);
 	int const wid = fm.width('n');
 	int const asc = fm.maxAscent();
@@ -95,7 +100,7 @@
 		xp[2] = int(x + wid * 0.625);
 	}
 
-	pi.pain.lines(xp, yp, 3, Color_eolmarker);
+	pi.pain.lines(xp, yp, 3, ColorName());
 
 	yp[0] = int(y - 0.500 * asc * 0.75);
 	yp[1] = int(y - 0.500 * asc * 0.75);
@@ -111,7 +116,18 @@
 		xp[2] = int(x);
 	}
 
-	pi.pain.lines(xp, yp, 3, Color_eolmarker);
+	pi.pain.lines(xp, yp, 3, ColorName());
+
+	// add label text behind the newline marker to divide from \newline
+	int w = 0;
+	int a = 0;
+	int d = 0;
+	theFontMetrics(font).rectText(insetLabel(), w, a, d);
+	
+	int const text_start = int(x + 2 * wid);
+			
+	pi.pain.rectText(text_start, yp[0] + d, insetLabel(), font,
+		Color_none, Color_none);
 }
 
 
Index: src/insets/InsetNewline.h
===================================================================
--- src/insets/InsetNewline.h	(revision 21760)
+++ src/insets/InsetNewline.h	(working copy)
@@ -14,6 +14,7 @@
 
 
 #include "Inset.h"
+#include "gettext.h"
 
 
 namespace lyx {
@@ -37,12 +38,21 @@
 
 	virtual void read(Buffer const &, Lexer & lex);
 
-	virtual void write(Buffer const & buf, std::ostream & os) const;
+	virtual void write(Buffer const &, std::ostream & os) const;
 	/// We don't need \begin_inset and \end_inset
 	virtual bool directWrite() const { return true; }
 	/// is this equivalent to a space (which is BTW different from
 	// a line separator)?
 	bool isSpace() const;
+
+	virtual docstring insetLabel() const { return _(""); }
+
+	virtual std::string getLyXName() const { return "\\newline"; }
+
+	virtual std::string getCmdName() const { return "\\\\"; }
+
+	virtual ColorCode ColorName() const { return Color_eolmarker; }
+
 private:
 	virtual Inset * clone() const
 	{
@@ -50,7 +60,26 @@
 	}
 };
 
+class InsetLinebreak : public InsetNewline {
+public:
+	InsetLinebreak() {}
 
+	docstring insetLabel() const { return _("line break"); }
+
+	std::string getLyXName() const { return "\\linebreak"; }
+
+	std::string getCmdName() const { return "\\linebreak{}"; }
+
+	ColorCode ColorName() const { return Color_pagebreak; }
+
+private:
+	virtual Inset * clone() const
+	{
+		return new InsetLinebreak;
+	}
+};
+
+
 } // namespace lyx
 
 #endif // INSET_NEWLINE_H
Index: src/insets/InsetTabular.cpp
===================================================================
--- src/insets/InsetTabular.cpp	(revision 21760)
+++ src/insets/InsetTabular.cpp	(working copy)
@@ -3769,7 +3769,7 @@
 	}
 
 	// disable in non-fixed-width cells
-	case LFUN_BREAK_LINE:
+	case LFUN_NEW_LINE:
 	case LFUN_BREAK_PARAGRAPH:
 	case LFUN_BREAK_PARAGRAPH_SKIP: {
 		if (tabular.getPWidth(cur.idx()).zero()) {
Index: src/lfuns.h
===================================================================
--- src/lfuns.h	(revision 21760)
+++ src/lfuns.h	(working copy)
@@ -125,7 +125,8 @@
 	// 60
 	LFUN_CHAR_DELETE_FORWARD,
 	LFUN_CHAR_DELETE_BACKWARD,
-	LFUN_BREAK_LINE,
+	LFUN_NEW_LINE,
+	LFUN_LINE_BREAK,
 	LFUN_BREAK_PARAGRAPH,
 	LFUN_QUOTE_INSERT,
 	// 65
Index: src/LyXAction.cpp
===================================================================
--- src/LyXAction.cpp	(revision 21760)
+++ src/LyXAction.cpp	(working copy)
@@ -105,7 +105,6 @@
 		{ LFUN_BOOKMARK_GOTO, "bookmark-goto", NoBuffer, Edit },
 		{ LFUN_BOOKMARK_SAVE, "bookmark-save", ReadOnly, Edit },
 		{ LFUN_BOOKMARK_CLEAR, "bookmark-clear", NoBuffer, Edit },
-		{ LFUN_BREAK_LINE, "break-line", Noop, Edit },
 		{ LFUN_BREAK_PARAGRAPH, "break-paragraph", Noop, Edit },
 		{ LFUN_BREAK_PARAGRAPH_SKIP, "break-paragraph-skip", Noop, Edit },
 		{ LFUN_BUILD_PROGRAM, "build-program", ReadOnly, Buffer },
@@ -214,6 +213,7 @@
 		{ LFUN_LAYOUT_TABULAR, "layout-tabular", Noop, Layout },
 		{ LFUN_LINE_BEGIN, "line-begin", ReadOnly | NoUpdate, Edit },
 		{ LFUN_LINE_BEGIN_SELECT, "line-begin-select", ReadOnly | SingleParUpdate, Edit },
+		{ LFUN_LINE_BREAK, "line-break", Noop, Edit },
 		{ LFUN_LINE_DELETE, "line-delete-forward", Noop, Edit }, // there is no line-delete-backward
 		{ LFUN_LINE_END, "line-end", ReadOnly | NoUpdate, Edit },
 		{ LFUN_LINE_END_SELECT, "line-end-select", ReadOnly | SingleParUpdate, Edit },
@@ -256,13 +256,14 @@
 		{ LFUN_MENU_OPEN, "menu-open", NoBuffer, Buffer },
 		{ LFUN_MENU_SEPARATOR_INSERT, "menu-separator-insert", Noop, Edit },
 		{ LFUN_META_PREFIX, "meta-prefix", NoBuffer, System },
+		{ LFUN_NEW_LINE, "new-line", Noop, Edit },
+		{ LFUN_NEXT_INSET_TOGGLE, "next-inset-toggle", ReadOnly, Edit },
+		{ LFUN_NOTE_INSERT, "note-insert", Noop, Edit },
+		{ LFUN_NOTE_NEXT, "note-next", ReadOnly, Edit },
 		{ LFUN_BRANCH_INSERT, "branch-insert", Noop, Edit },
+		{ LFUN_BOX_INSERT, "box-insert", Noop, Edit },
 		{ LFUN_FLEX_INSERT, "flex-insert", Noop, Edit },
-		{ LFUN_NOTE_INSERT, "note-insert", Noop, Edit },
-		{ LFUN_BOX_INSERT, "box-insert", Noop, Edit },
-		{ LFUN_NOTE_NEXT, "note-next", ReadOnly, Edit },
 		{ LFUN_INSET_TOGGLE, "", ReadOnly, Hidden },
-		{ LFUN_NEXT_INSET_TOGGLE, "next-inset-toggle", ReadOnly, Edit },
 		{ LFUN_ALL_INSETS_TOGGLE, "all-insets-toggle", ReadOnly, Edit },
 		{ LFUN_PARAGRAPH_DOWN, "paragraph-down", ReadOnly | NoUpdate, Edit },
 		{ LFUN_PARAGRAPH_DOWN_SELECT, "paragraph-down-select", ReadOnly, Edit },
Index: src/mathed/InsetMathGrid.cpp
===================================================================
--- src/mathed/InsetMathGrid.cpp	(revision 21760)
+++ src/mathed/InsetMathGrid.cpp	(working copy)
@@ -1117,7 +1117,7 @@
 		}
 		break;
 
-	case LFUN_BREAK_LINE: {
+	case LFUN_NEW_LINE: {
 		cur.recordUndoInset();
 		row_type const r = cur.row();
 		addRow(r);
Index: src/mathed/InsetMathHull.cpp
===================================================================
--- src/mathed/InsetMathHull.cpp	(revision 21760)
+++ src/mathed/InsetMathHull.cpp	(working copy)
@@ -1045,7 +1045,7 @@
 		// just swallow this
 		break;
 
-	case LFUN_BREAK_LINE:
+	case LFUN_NEW_LINE:
 		// some magic for the common case
 		if (type_ == hullSimple || type_ == hullEquation) {
 			cur.recordUndoInset();
@@ -1176,7 +1176,7 @@
 	case LFUN_DOWN:
 		status.enabled(true);
 		return true;
-	case LFUN_BREAK_LINE:
+	case LFUN_NEW_LINE:
 	case LFUN_MATH_NUMBER:
 	case LFUN_MATH_NONUMBER:
 	case LFUN_MATH_EXTERN:
Index: src/Paragraph.cpp
===================================================================
--- src/Paragraph.cpp	(revision 21762)
+++ src/Paragraph.cpp	(working copy)
@@ -702,7 +702,6 @@
 			if (runparams.moving_arg)
 				os << "\\protect ";
 
-			os << "\\\\\n";
 		}
 		texrow.newline();
 		texrow.start(owner_->id(), i + 1);
Index: src/tex2lyx/text.cpp
===================================================================
--- src/tex2lyx/text.cpp	(revision 21760)
+++ src/tex2lyx/text.cpp	(working copy)
@@ -2187,6 +2187,13 @@
 			}
 		}
 
+		else if (t.cs() == "newline" ||
+			t.cs() == "linebreak") {
+			context.check_layout(os);
+			os << "\n\\" << t.cs() << "\n";
+			skip_braces(p); // eat {}
+		}
+
 		else if (t.cs() == "input" || t.cs() == "include"
 			 || t.cs() == "verbatiminput") {
 			string name = '\\' + t.cs();
Index: src/Text.cpp
===================================================================
--- src/Text.cpp	(revision 21760)
+++ src/Text.cpp	(working copy)
@@ -232,6 +232,10 @@
 		}
 	} else if (token == "\\backslash") {
 		par.appendChar('\\', font, change);
+	} else if (token == "\\linebreak") {
+		auto_ptr<Inset> inset(new InsetLinebreak);
+		inset->read(buf, lex);
+		par.insertInset(par.size(), inset.release(), font, change);
 	} else if (token == "\\newline") {
 		auto_ptr<Inset> inset(new InsetNewline);
 		inset->read(buf, lex);
Index: src/Text3.cpp
===================================================================
--- src/Text3.cpp	(revision 21760)
+++ src/Text3.cpp	(working copy)
@@ -670,7 +670,7 @@
 		break;
 	}
 
-	case LFUN_BREAK_LINE: {
+	case LFUN_NEW_LINE: {
 		// Not allowed by LaTeX (labels or empty par)
 		if (cur.pos() > cur.paragraph().beginOfBody()) {
 			// this avoids a double undo
@@ -684,6 +684,21 @@
 		}
 		break;
 	}
+	
+	case LFUN_LINE_BREAK: {
+		// Not allowed by LaTeX (labels or empty par)
+		if (cur.pos() > cur.paragraph().beginOfBody()) {
+			// this avoids a double undo
+			// FIXME: should not be needed, ideally
+			if (!cur.selection())
+				cur.recordUndo();
+			cap::replaceSelection(cur);
+			cur.insert(new InsetLinebreak);
+			cur.posForward();
+			moveCursor(cur, false);
+		}
+		break;
+	}
 
 	case LFUN_CHAR_DELETE_FORWARD:
 		if (!cur.selection()) {
@@ -2089,8 +2104,9 @@
 	case LFUN_PARAGRAPH_UP:
 	case LFUN_PARAGRAPH_DOWN:
 	case LFUN_LINE_BEGIN:
+	case LFUN_LINE_BREAK:
 	case LFUN_LINE_END:
-	case LFUN_BREAK_LINE:
+	case LFUN_NEW_LINE:
 	case LFUN_CHAR_DELETE_FORWARD:
 	case LFUN_DELETE_FORWARD_SKIP:
 	case LFUN_CHAR_DELETE_BACKWARD:

Reply via email to