Lazarus

Using the Lazarus IDE => Editor => Topic started by: 440bx on March 17, 2020, 11:50:42 pm

Title: Unexpected CR/LF in source file due to editor
Post by: 440bx on March 17, 2020, 11:50:42 pm
Hello,

This is a very minor thing that doesn't usually affect anything.  Whenever a source file is edited in the Lazarus editor, the editor automatically adds an unnecessary "CR/LF" at the end of file (in Windows, I don't know what it does in other O/Ss.)

Ideally, there shouldn't be anything after the "end." not even a line ending.

Title: Re: Unexpected CR/LF in source file due to editor
Post by: winni on March 18, 2020, 12:08:10 am
@440bx

NO, no, no.

What you want is a file where the last readln fails.
It is a good standard that the last line ends with a lineEnding.

Because I now know that a missing LineEnding after the last line there is always an empty line after the last end in my units. Better take care ....

Btw.: There are so many failing config files in Linux that fail because of the last missing LF.

Winni
Title: Re: Unexpected CR/LF in source file due to editor
Post by: 440bx on March 18, 2020, 12:21:58 am
What you want is a file where the last readln fails.
I fully expect readln to be smart enough to realize that the end of file implies end of line.
Title: Re: Unexpected CR/LF in source file due to editor
Post by: Thaddy on March 18, 2020, 07:45:30 am
https://www.freepascal.org/docs-html/rtl/classes/tstrings.skiplastlinebreak.html

As the editor's content is a Tstrings descendant this should be configurable or easy to fix.
Title: Re: Unexpected CR/LF in source file due to editor
Post by: 440bx on March 18, 2020, 08:00:23 am
https://www.freepascal.org/docs-html/rtl/classes/tstrings.skiplastlinebreak.html

As the editor's content is a Tstrings descendant this should be configurable or easy to fix.
That sounds like the perfect solution. 

It's a very minor thing but, in some rare cases, that extra line ending can be a nuisance.
Title: Re: Unexpected CR/LF in source file due to editor
Post by: af0815 on March 18, 2020, 08:59:47 am
What you want is a file where the last readln fails.
I fully expect readln to be smart enough to realize that the end of file implies end of line.

Why should readln be smart and do unwanted things? It should only read until end of line not guess. If it is configurable, it will be ok.
Title: Re: Unexpected CR/LF in source file due to editor
Post by: PascalDragon on March 18, 2020, 09:29:03 am
What you want is a file where the last readln fails.
I fully expect readln to be smart enough to realize that the end of file implies end of line.

Why should readln be smart and do unwanted things? It should only read until end of line not guess. If it is configurable, it will be ok.

Because if it wouldn't detect the end of the file then the ReadLn would hang forever (like it does with StdIn if no line ending is read). And you can just as easily test it:

Code: Pascal  [Select][+][-]
  1. program tread;
  2.  
  3. var
  4.   t: Text;
  5.   s: AnsiString;
  6. begin
  7.   Assign(t, ParamStr(1));
  8.   Reset(t);
  9.   while not Eof(t) do begin
  10.     Readln(t, s);
  11.     Writeln(s);
  12.   end;
  13. end.

The test file:

Code: [Select]
test
another
end.

(no line ending after end.)

Output:

Code: [Select]
PS E:\fpc\git> .\testoutput\tread.exe .\fpctests\test.txt
test
another
end.
TinyPortal © 2005-2018