Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gedit/ChangeLog,v
retrieving revision 1.883
diff -u -p -B -r1.883 ChangeLog
--- ChangeLog	25 Nov 2006 22:30:40 -0000	1.883
+++ ChangeLog	26 Nov 2006 11:56:23 -0000
@@ -1,3 +1,12 @@
+2006-11-26  Steve Frécinaux  <code@istique.net>
+
+	* gedit/gedit-document-loader.c: don't add the trailing \n to the
+	buffer (to avoid having an empty last line). This is the way vim does.
+	Fixes bug #324942.
+	
+	* gedit/gedit-document-saver.c: always add a trailing \n (to be
+	consistent with the way the loader works).
+
 2006-11-25  Steve Frécinaux  <code@istique.net>
 
 	* gedit/gedit-window.c: show the whole file URI in the document menu
Index: gedit/gedit-document-loader.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-document-loader.c,v
retrieving revision 1.9
diff -u -p -B -r1.9 gedit-document-loader.c
--- gedit/gedit-document-loader.c	25 Aug 2006 09:30:34 -0000	1.9
+++ gedit/gedit-document-loader.c	26 Nov 2006 11:56:27 -0000
@@ -257,6 +257,11 @@ insert_text_in_document (GeditDocumentLo
 	gtk_source_buffer_begin_not_undoable_action (
 				GTK_SOURCE_BUFFER (loader->priv->document));
 
+	/* If the last char is a newline, don't add it to the buffer
+	(otherwise GtkTextView shows it as an empty line). See bug #324942. */
+	if (text[len-1] == '\n')
+		len--;
+
 	/* Insert text in the buffer */
 	gtk_text_buffer_set_text (GTK_TEXT_BUFFER (loader->priv->document), 
 				  text, 
Index: gedit/gedit-document-saver.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-document-saver.c,v
retrieving revision 1.14
diff -u -p -B -r1.14 gedit-document-saver.c
--- gedit/gedit-document-saver.c	1 Oct 2006 18:27:06 -0000	1.14
+++ gedit/gedit-document-saver.c	26 Nov 2006 11:56:28 -0000
@@ -191,7 +191,6 @@ write_document_contents (gint           
 	GtkTextIter end_iter;
 	gchar *contents;
 	gsize len;
-	gboolean add_cr;
 	ssize_t written;
 	gboolean res;
 
@@ -202,11 +201,6 @@ write_document_contents (gint           
 
 	len = strlen (contents);
 
-	if (len >= 1)
-		add_cr = (*(contents + len - 1) != '\n');
-	else
-		add_cr = FALSE;
-
 	if (encoding != gedit_encoding_get_utf8 ())
 	{
 		gchar *converted_contents;
@@ -263,8 +257,7 @@ write_document_contents (gint           
 		while (to_write > 0);
 	}
 
-	/* Add \n at the end if needed */
-	if (res && add_cr)
+	if (res)
 	{
 		if (encoding != gedit_encoding_get_utf8 ())
 		{

