I think it's a bug. I didn't notice it before as I usually use addons plugin with "Strip trailing blank lines" option checked. Patch attached, also modified to use utils_get_eol_char().
Best regards, Eugene.
Hi Eugene,
I'm not sure it is a bug, the pref setting is there is to ensure that the file ends in a newline, so an empty file will become just a new line (see od below). Thats working correctly AFAICT.
lex@fred5 ~ $ od untitled 0000000 000012 0000001
Cheers Lex
On 16 October 2010 17:19, Eugene Arshinov earshinov@gmail.com wrote:
I think it's a bug. I didn't notice it before as I usually use addons plugin with "Strip trailing blank lines" option checked. Patch attached, also modified to use utils_get_eol_char().
Best regards, Eugene. _______________________________________________ Geany-devel mailing list Geany-devel@uvena.de http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel
On Sat, 16 Oct 2010 17:49:27 +1100% Lex Trotman elextr@gmail.com wrote:
Hi Eugene,
I'm not sure it is a bug, the pref setting is there is to ensure that the file ends in a newline, so an empty file will become just a new line (see od below). Thats working correctly AFAICT.
lex@fred5 ~ $ od untitled 0000000 000012 0000001
Cheers Lex
Hi.
Yes, of course it's logical that newline is always added, even for empty files. But it becomes that for non-empty files you get one empty line at the end, for empty files -- two empty lines. It's not quite useful and (IMHO) bad.
Best regards, Eugene.
On 16 October 2010 19:52, Eugene Arshinov earshinov@gmail.com wrote:
On Sat, 16 Oct 2010 17:49:27 +1100% Lex Trotman elextr@gmail.com wrote:
Hi Eugene,
I'm not sure it is a bug, the pref setting is there is to ensure that the file ends in a newline, so an empty file will become just a new line (see od below). Thats working correctly AFAICT.
lex@fred5 ~ $ od untitled 0000000 000012 0000001
Cheers Lex
Hi.
Yes, of course it's logical that newline is always added, even for empty files. But it becomes that for non-empty files you get one empty line at the end, for empty files -- two empty lines. It's not quite useful and (IMHO) bad.
Well, if the file ends in a newline it will always appear as an empty line at the end even though there is nothing after the newline, the only way to avoid it is to not end in newline. If you don't like the blank line, delete the newline ... and turn off the preference so Geany won't add it back again ;-)
But there are some things that REQUIRE the file to end in newline, and IIUC that is what the "ensure newline at file end" preference is for, it has to add the newline. So it isn't a bug if the preference is selected.
Cheers Lex
Best regards, Eugene. _______________________________________________ Geany-devel mailing list Geany-devel@uvena.de http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel
On Sat, 16 Oct 2010 21:06:12 +1100% Lex Trotman elextr@gmail.com wrote:
On 16 October 2010 19:52, Eugene Arshinov earshinov@gmail.com wrote:
On Sat, 16 Oct 2010 17:49:27 +1100% Lex Trotman elextr@gmail.com wrote:
Hi Eugene,
I'm not sure it is a bug, the pref setting is there is to ensure that the file ends in a newline, so an empty file will become just a new line (see od below). Thats working correctly AFAICT.
lex@fred5 ~ $ od untitled 0000000 000012 0000001
Cheers Lex
Hi.
Yes, of course it's logical that newline is always added, even for empty files. But it becomes that for non-empty files you get one empty line at the end, for empty files -- two empty lines. It's not quite useful and (IMHO) bad.
Well, if the file ends in a newline it will always appear as an empty line at the end even though there is nothing after the newline, the only way to avoid it is to not end in newline. If you don't like the blank line, delete the newline ... and turn off the preference so Geany won't add it back again ;-)
No, I like a new line, but not two of them :D
But there are some things that REQUIRE the file to end in newline, and IIUC that is what the "ensure newline at file end" preference is for, it has to add the newline. So it isn't a bug if the preference is selected.
We may consider `wc -l' as an example. It (at least, the version I have) accounts the last line only if it ends with \n. With the option turned on, if a user creates an empty file with Geany and saves it, wc of course says it contains 1 line. I would prefer the file staying really empty and wc returning 0 lines. Note that I have to keep the option turned on to keep wc working properly in "usual" cases.
Best regards, Eugene.
On 16 October 2010 21:39, Eugene Arshinov earshinov@gmail.com wrote:
On Sat, 16 Oct 2010 21:06:12 +1100% Lex Trotman elextr@gmail.com wrote:
On 16 October 2010 19:52, Eugene Arshinov earshinov@gmail.com wrote:
On Sat, 16 Oct 2010 17:49:27 +1100% Lex Trotman elextr@gmail.com wrote:
Hi Eugene,
I'm not sure it is a bug, the pref setting is there is to ensure that the file ends in a newline, so an empty file will become just a new line (see od below). Thats working correctly AFAICT.
lex@fred5 ~ $ od untitled 0000000 000012 0000001
Cheers Lex
Hi.
Yes, of course it's logical that newline is always added, even for empty files. But it becomes that for non-empty files you get one empty line at the end, for empty files -- two empty lines. It's not quite useful and (IMHO) bad.
Well, if the file ends in a newline it will always appear as an empty line at the end even though there is nothing after the newline, the only way to avoid it is to not end in newline. If you don't like the blank line, delete the newline ... and turn off the preference so Geany won't add it back again ;-)
No, I like a new line, but not two of them :D
But there are some things that REQUIRE the file to end in newline, and IIUC that is what the "ensure newline at file end" preference is for, it has to add the newline. So it isn't a bug if the preference is selected.
We may consider `wc -l' as an example. It (at least, the version I have) accounts the last line only if it ends with \n. With the option turned on, if a user creates an empty file with Geany and saves it, wc of course says it contains 1 line. I would prefer the file staying really empty and wc returning 0 lines. Note that I have to keep the option turned on to keep wc working properly in "usual" cases.
I'm a bit confused, why turn on the preference in that case? What I don't see is your patch checking the preference?
Cheers Lex
Best regards, Eugene. _______________________________________________ Geany-devel mailing list Geany-devel@uvena.de http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel
On Sat, 16 Oct 2010 22:04:33 +1100% Lex Trotman elextr@gmail.com wrote:
On 16 October 2010 21:39, Eugene Arshinov earshinov@gmail.com wrote:
On Sat, 16 Oct 2010 21:06:12 +1100% Lex Trotman elextr@gmail.com wrote:
On 16 October 2010 19:52, Eugene Arshinov earshinov@gmail.com wrote:
On Sat, 16 Oct 2010 17:49:27 +1100% Lex Trotman elextr@gmail.com wrote:
Hi Eugene,
I'm not sure it is a bug, the pref setting is there is to ensure that the file ends in a newline, so an empty file will become just a new line (see od below). Thats working correctly AFAICT.
lex@fred5 ~ $ od untitled 0000000 000012 0000001
Cheers Lex
Hi.
Yes, of course it's logical that newline is always added, even for empty files. But it becomes that for non-empty files you get one empty line at the end, for empty files -- two empty lines. It's not quite useful and (IMHO) bad.
Well, if the file ends in a newline it will always appear as an empty line at the end even though there is nothing after the newline, the only way to avoid it is to not end in newline. If you don't like the blank line, delete the newline ... and turn off the preference so Geany won't add it back again ;-)
No, I like a new line, but not two of them :D
But there are some things that REQUIRE the file to end in newline, and IIUC that is what the "ensure newline at file end" preference is for, it has to add the newline. So it isn't a bug if the preference is selected.
We may consider `wc -l' as an example. It (at least, the version I have) accounts the last line only if it ends with \n. With the option turned on, if a user creates an empty file with Geany and saves it, wc of course says it contains 1 line. I would prefer the file staying really empty and wc returning 0 lines. Note that I have to keep the option turned on to keep wc working properly in "usual" cases.
I'm a bit confused, why turn on the preference in that case?
If I turn it off and write some text, for example
int main(int argc, char **argv){ return 0; }
, and do not manually insert a newline, wc -l will return 2 which (I believe) would be incorrect as there are 3 lines of code here.
What I don't see is your patch checking the preference?
The function is called only when the preference is turned on. See document_save_file() where editor_ensure_final_newline() is called.
Best regards, Eugene.
On 16 October 2010 22:11, Eugene Arshinov earshinov@gmail.com wrote:
On Sat, 16 Oct 2010 22:04:33 +1100% Lex Trotman elextr@gmail.com wrote:
On 16 October 2010 21:39, Eugene Arshinov earshinov@gmail.com wrote:
On Sat, 16 Oct 2010 21:06:12 +1100% Lex Trotman elextr@gmail.com wrote:
On 16 October 2010 19:52, Eugene Arshinov earshinov@gmail.com wrote:
On Sat, 16 Oct 2010 17:49:27 +1100% Lex Trotman elextr@gmail.com wrote:
Hi Eugene,
I'm not sure it is a bug, the pref setting is there is to ensure that the file ends in a newline, so an empty file will become just a new line (see od below). Thats working correctly AFAICT.
lex@fred5 ~ $ od untitled 0000000 000012 0000001
Cheers Lex
Hi.
Yes, of course it's logical that newline is always added, even for empty files. But it becomes that for non-empty files you get one empty line at the end, for empty files -- two empty lines. It's not quite useful and (IMHO) bad.
Well, if the file ends in a newline it will always appear as an empty line at the end even though there is nothing after the newline, the only way to avoid it is to not end in newline. If you don't like the blank line, delete the newline ... and turn off the preference so Geany won't add it back again ;-)
No, I like a new line, but not two of them :D
But there are some things that REQUIRE the file to end in newline, and IIUC that is what the "ensure newline at file end" preference is for, it has to add the newline. So it isn't a bug if the preference is selected.
We may consider `wc -l' as an example. It (at least, the version I have) accounts the last line only if it ends with \n. With the option turned on, if a user creates an empty file with Geany and saves it, wc of course says it contains 1 line. I would prefer the file staying really empty and wc returning 0 lines. Note that I have to keep the option turned on to keep wc working properly in "usual" cases.
I'm a bit confused, why turn on the preference in that case?
If I turn it off and write some text, for example
int main(int argc, char **argv){ return 0; }
, and do not manually insert a newline, wc -l will return 2 which (I believe) would be incorrect as there are 3 lines of code here.
Ok, so wc counts newlines, not lines, I can't say I've looked that closely at it (or its documentation :-). But this argues that if the option is set then Geany is correct in adding a newline, then it would count right. But that is just one tool.
I think we are, as we say here, getting our wires a bit crossed.
What I'm expressing badly is that if a file ends in a newline you can consider that there is nothing after that, or you can consider that it has an empty unterminated line after the newline. Similarly an empty file has no lines or it has one unterminated empty line. Geany takes the empty unterminated line view, since a new "untitled" shows one line on screen. But neither interpretation is "right", it depends on what you are using the file for and what the tools expect.
My argument is that, if someone (eg me) selects that I want my file to end in newline (which is what the preference says) then thats what it should do, irrespective of any interpretation or the length of the file.
What I don't see is your patch checking the preference?
The function is called only when the preference is turned on. See document_save_file() where editor_ensure_final_newline() is called.
Oh Ok fine, I'm not at my development machine with all Geany source.
Cheers Lex
Best regards, Eugene. _______________________________________________ Geany-devel mailing list Geany-devel@uvena.de http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel
On Sat, 16 Oct 2010 22:37:29 +1100% Lex Trotman elextr@gmail.com wrote:
On 16 October 2010 22:11, Eugene Arshinov earshinov@gmail.com wrote:
On Sat, 16 Oct 2010 22:04:33 +1100% Lex Trotman elextr@gmail.com wrote:
On 16 October 2010 21:39, Eugene Arshinov earshinov@gmail.com wrote:
On Sat, 16 Oct 2010 21:06:12 +1100% Lex Trotman elextr@gmail.com wrote:
On 16 October 2010 19:52, Eugene Arshinov earshinov@gmail.com wrote:
On Sat, 16 Oct 2010 17:49:27 +1100% Lex Trotman elextr@gmail.com wrote:
> Hi Eugene, > > I'm not sure it is a bug, the pref setting is there is to > ensure that the file ends in a newline, so an empty file > will become just a new line (see od below). Thats working > correctly AFAICT. > > lex@fred5 ~ $ od untitled > 0000000 000012 > 0000001 > > Cheers > Lex >
Hi.
Yes, of course it's logical that newline is always added, even for empty files. But it becomes that for non-empty files you get one empty line at the end, for empty files -- two empty lines. It's not quite useful and (IMHO) bad.
Well, if the file ends in a newline it will always appear as an empty line at the end even though there is nothing after the newline, the only way to avoid it is to not end in newline. If you don't like the blank line, delete the newline ... and turn off the preference so Geany won't add it back again ;-)
No, I like a new line, but not two of them :D
But there are some things that REQUIRE the file to end in newline, and IIUC that is what the "ensure newline at file end" preference is for, it has to add the newline. So it isn't a bug if the preference is selected.
We may consider `wc -l' as an example. It (at least, the version I have) accounts the last line only if it ends with \n. With the option turned on, if a user creates an empty file with Geany and saves it, wc of course says it contains 1 line. I would prefer the file staying really empty and wc returning 0 lines. Note that I have to keep the option turned on to keep wc working properly in "usual" cases.
I'm a bit confused, why turn on the preference in that case?
If I turn it off and write some text, for example
int main(int argc, char **argv){ return 0; }
, and do not manually insert a newline, wc -l will return 2 which (I believe) would be incorrect as there are 3 lines of code here.
Ok, so wc counts newlines, not lines, I can't say I've looked that closely at it (or its documentation :-). But this argues that if the option is set then Geany is correct in adding a newline, then it would count right. But that is just one tool.
I think we are, as we say here, getting our wires a bit crossed.
What I'm expressing badly is that if a file ends in a newline you can consider that there is nothing after that, or you can consider that it has an empty unterminated line after the newline. Similarly an empty file has no lines or it has one unterminated empty line. Geany takes the empty unterminated line view, since a new "untitled" shows one line on screen. But neither interpretation is "right", it depends on what you are using the file for and what the tools expect.
This is absolutely correct.
My argument is that, if someone (eg me) selects that I want my file to end in newline (which is what the preference says) then thats what it should do, irrespective of any interpretation or the length of the file.
I understand what you mean and agree that this point of view is meaningful.
My argument for unterminated lines view is that 1) Geany already uses this view in one aspect, as you wrote (and I agree) 2) and so, to my knowledge, do most text utilities like wc (they do not process last line if it is unterminated)
From this point of view, it's logical that Geany should never insert unterminated empty lines, either if file is empty or when it already contains trailing newline.
By the way, there is another argument for your point of view and current behaviour. The code of editor_ensure_final_newline() is quite old (it was inserted to utils.c in "Initial import" commit, rev 4) and may be already considered a feature :-)
What I don't see is your patch checking the preference?
The function is called only when the preference is turned on. See document_save_file() where editor_ensure_final_newline() is called.
Oh Ok fine, I'm not at my development machine with all Geany source.
No problem.
Best regards, Eugene.
On Sat, 16 Oct 2010 16:21:02 +0400% Eugene Arshinov earshinov@gmail.com wrote:
[...]
- and so, to my knowledge, do most text utilities like wc (they do
not process last line if it is unterminated)
[...]
I'm wrong here. For example, 'sort' and 'grep' work fine when the last line does not end with \n. So there's rather "just one tool", wc…
On Sat, 16 Oct 2010 22:37:29 +1100 Lex Trotman elextr@gmail.com wrote:
What I'm expressing badly is that if a file ends in a newline you can consider that there is nothing after that, or you can consider that it has an empty unterminated line after the newline. Similarly an empty file has no lines or it has one unterminated empty line. Geany takes the empty unterminated line view, since a new "untitled" shows one line on screen. But neither interpretation is "right", it depends on what you are using the file for and what the tools expect.
My argument is that, if someone (eg me) selects that I want my file to end in newline (which is what the preference says) then thats what it should do, irrespective of any interpretation or the length of the file.
I agree.
Nick
On Wed, 20 Oct 2010 12:42:52 +0100% Nick Treleaven nick.treleaven@btinternet.com wrote:
On Sat, 16 Oct 2010 22:37:29 +1100 Lex Trotman elextr@gmail.com wrote:
What I'm expressing badly is that if a file ends in a newline you can consider that there is nothing after that, or you can consider that it has an empty unterminated line after the newline. Similarly an empty file has no lines or it has one unterminated empty line. Geany takes the empty unterminated line view, since a new "untitled" shows one line on screen. But neither interpretation is "right", it depends on what you are using the file for and what the tools expect.
My argument is that, if someone (eg me) selects that I want my file to end in newline (which is what the preference says) then thats what it should do, irrespective of any interpretation or the length of the file.
I agree.
Okay, let's forget this issue. Anyway, how often do you edit empty files? :)
Is it then acceptable that the part of the addons plugin that removes trailing blank lines (written by me, btw) currently also removes the newline Geany adds to empty file? It may be a bit confusing (for a hypothetical user who edits empty files). Should it not remove the newline, or provide a checkbox for that, or should we leave everything as is? I'd prefer the latter :)
Best regards, Eugene.
On 22 October 2010 19:20, Eugene Arshinov earshinov@gmail.com wrote:
On Wed, 20 Oct 2010 12:42:52 +0100% Nick Treleaven nick.treleaven@btinternet.com wrote:
On Sat, 16 Oct 2010 22:37:29 +1100 Lex Trotman elextr@gmail.com wrote:
What I'm expressing badly is that if a file ends in a newline you can consider that there is nothing after that, or you can consider that it has an empty unterminated line after the newline. Similarly an empty file has no lines or it has one unterminated empty line. Geany takes the empty unterminated line view, since a new "untitled" shows one line on screen. But neither interpretation is "right", it depends on what you are using the file for and what the tools expect.
My argument is that, if someone (eg me) selects that I want my file to end in newline (which is what the preference says) then thats what it should do, irrespective of any interpretation or the length of the file.
I agree.
Okay, let's forget this issue. Anyway, how often do you edit empty files? :)
Is it then acceptable that the part of the addons plugin that removes trailing blank lines (written by me, btw) currently also removes the newline Geany adds to empty file? It may be a bit confusing (for a hypothetical user who edits empty files). Should it not remove the newline, or provide a checkbox for that, or should we leave everything as is? I'd prefer the latter :)
I'd leave everything as is. There is already a checkbox to turn on/off the "strip trailing blank lines" addon and one to turn on/off the "end in EOL' option. If a user turns on two options that do opposite things well ... the only real confusion is that the options are so far apart, but changing that is IMO too much work for the benefit.
Cheers Lex
Best regards, Eugene. _______________________________________________ Geany-devel mailing list Geany-devel@uvena.de http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel
Oh God, I left an erroneous check in the code. Updated patch attacked.
On Sat, 16 Oct 2010 15:05:01 +0400 Eugene Arshinov earshinov@gmail.com wrote:
Oh God, I left an erroneous check in the code. Updated patch attacked.
I meant attached...