After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 324942 - Impossible to not have an empty last line
Impossible to not have an empty last line
Status: RESOLVED FIXED
Product: gedit
Classification: Applications
Component: general
2.12.x
Other All
: Normal minor
: 2.14.0
Assigned To: Gedit maintainers
Gedit maintainers
: 658891 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2005-12-24 16:26 UTC by Jonas De Vuyst
Modified: 2011-09-13 17:32 UTC
See Also:
GNOME target: ---
GNOME version: 2.11/2.12


Attachments
patch (2.50 KB, patch)
2006-11-26 12:53 UTC, Steve Frécinaux
committed Details | Review

Description Jonas De Vuyst 2005-12-24 16:26:04 UTC
Please describe the problem:
When opening a file in gEdit there is always an empty line at the bottom of the
document. One can remove this line but when saving the document gEdit will
sneakily insert a "\n" at the end of the document anyway.

gEdit should either not insert this extra "\n" (my preference) or its UI should
not make you think that you can delete this extra line.

Steps to reproduce:
1. 
2. 
3. 


Actual results:


Expected results:


Does this happen every time?


Other information:
Comment 1 Paolo Borelli 2005-12-24 16:28:46 UTC
why?

This is done on purpose, some command line tools get confused by text files missing a final \n.

vim behaves in the same way.
Comment 2 Jonas De Vuyst 2005-12-24 16:40:59 UTC
Ah. Right. I should know that, but vim behaviour never seemed odd too me.

There's a slight difference between vim and gEdit though. Vim never shows an empty last line. It just cuts it and displays a ~. Maybe gEdit could adopt this behaviour too?

I guess it just feels weird to me that when I open a document there's always an extra empty line. Of course, I could probably get used to it...
Comment 3 Paolo Maggi 2005-12-28 15:25:05 UTC
Well, as Jonas suggested we could implement the vim behavior.
pbor: what do you think?
Comment 4 Paolo Borelli 2005-12-28 15:31:01 UTC
Fine by me, but I have not though much if this would cause some implementation burden with how we feed the buffer to GtkTextView
Comment 5 Jørgen Tellnes 2006-02-19 15:58:25 UTC
This "feature" causes much trouble for me, as an empty last line is added on every file opened by gEdit. In PHP, an empty last line signalises that it should output that line, and that makes it impossible to alter HTTP headers, as they already have been sendt when the whitespace was outputted. This means that if the file edited in gedit is a part of a larger script (it often is), it will wreck havoc across the system and destroy login features and everything that deals with HTTP headers, in addition to spawning a lot of warnings and errors by the PHP parser.

As a PHP developer who uses gedit for quick code edits (Zend Studio takes too long to load for a small fix), this is really important for me, so I hope this will be fixed in 2.14 (the one that Ubuntu 6.40 will use). :)
Comment 6 Steve Frécinaux 2006-02-19 16:19:16 UTC
AFAIK, this is not true, since PHP does not take care of the \n following the closing tag, and so PHP does not send headers because of that last empty line. I use gedit with PHP for ages and I've never encountered the issue you're talking about right now.
Comment 7 Jørgen Tellnes 2006-02-20 14:07:54 UTC
ANY whitespace after ?>, even if it is on the same line as ?> is outputted by PHP. So if you just have a \n, it will still output it and cause trouble.

I don't know how it is for you, but every time I edit a PHP document in gedit, it inserts a blank line (that is not visible in gedit until i re-open the document). Every time that happens, PHP complains and says that "output started on ...", and points to the file I edited on the line that gedit added. It causes serious trouble to me, as I then have to edit the last line away in another editor, like ZDE.
Comment 8 greg 2006-03-17 19:16:47 UTC
I'm currently running gedit 2.14.0 and while I do see that empty line in gedit, it is not interfering with PHP5.

My test case consited of two  php files,

index.php:
<?php
include("test.php");
header("Location: http://google.com");
?>

test.php:
<?php
$i=0;
?>

If the blank line was being seen as a real empty line by PHP, I should get an error that headers had already been sent out in test.php. Instead when I go to this page I'm redirected to google. 

It would probably be ideal if the line didn't show up at all in gedit, but it does not appear to be causing problems in 2.14.0.
Comment 9 Steve Frécinaux 2006-11-26 12:53:36 UTC
Created attachment 77163 [details] [review]
patch

+	* 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).
Comment 10 Paolo Borelli 2006-11-26 13:11:57 UTC
Patch looks good to me. As said on irc just add a comment to the saver code.
Comment 11 Steve Frécinaux 2006-11-26 13:18:58 UTC
Fixed in the development version. The fix will be available in the next major release. Thank you for your bug report.
Comment 12 Jean-Philippe Fleury 2011-09-13 17:32:45 UTC
*** Bug 658891 has been marked as a duplicate of this bug. ***