Recent

Author Topic: jedi issue with align and if..then..else  (Read 3684 times)

glubbish

  • New Member
  • *
  • Posts: 46
jedi issue with align and if..then..else
« on: August 13, 2020, 12:33:33 am »
To reproduce:
create new project
create onactivate for form1
I have not been able to find good documentation for the jcf settings. If anyone knows what to change to fix this, that would be great.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormActivate(Sender: TObject);
  2. var
  3.   s: string;
  4. begin
  5.   Top        := (screen.Height - Height) div 2;
  6.   Left := (screen.Width - Width) div 2;
  7.   if Top < 400 then s:= 'small' else s:='big';
  8.   Top  := (screen.Height - Height) div 2;
  9.   Left   := (screen.Width - Width) div 2;
  10. end;   ;
format with ctrl-d gives:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormActivate(Sender: TObject);
  2. var
  3.   s: string;
  4. begin
  5.   Top  := (screen.Height - Height) div 2;
  6.   Left := (screen.Width - Width) div 2;
  7.   if Top < 400 then s                   := 'small' else s := 'big';  //actual problem
  8.   Top := (screen.Height - Height) div 2;                             //this does not align like the same lines before the if.
  9.   Left := (screen.Width - Width) div 2;
  10. end;

jcfsettings attached.

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Re: jedi issue with align and if..then..else
« Reply #1 on: August 13, 2020, 12:39:48 am »
Hello.

There are some problems with jedi code beautifier.
You may try ptop, it is part of fpc project, I get better result with it.

Fre;D

I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

ASerge

  • Hero Member
  • *****
  • Posts: 2212
Re: jedi issue with align and if..then..else
« Reply #2 on: August 13, 2020, 09:30:20 pm »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormActivate(Sender: TObject);
  2. ...
  3. end;   ;
format with ctrl-d gives:
I have in case of the presence of that extra semicolon Jedi Code Format does not work at all. But if remove extra semicolon, it gives out:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormActivate(Sender: TObject);
  2. var
  3.   s: string;
  4. begin
  5.   Top := (screen.Height - Height) div 2;
  6.   Left := (screen.Width - Width) div 2;
  7.   if Top < 400 then
  8.     s := 'small'
  9.   else
  10.     s := 'big';
  11.   Top := (screen.Height - Height) div 2;
  12.   Left := (screen.Width - Width) div 2;
  13. end;

glubbish

  • New Member
  • *
  • Posts: 46
Re: jedi issue with align and if..then..else
« Reply #3 on: August 14, 2020, 12:25:21 am »
@Fred - I would prefer the in ide formatter. A command line one is very cumbersome.

@ASerge - The extra semicolon was a copy/paste error. My testcase does not have it either.
I want it to format simple if.then.else on a single line and only break when begin is used eg:
Code: Pascal  [Select][+][-]
  1.           if Result = 0 then
  2.           begin
  3.             prefix  := 'Updated';
  4.             prefix2 := 'Updating: ';
  5.           end
  6.           else
  7.           begin
  8.             prefix  := 'Copied';
  9.             prefix2 := 'Copying: ';
  10.           end;
If you use my settings.jcf (uploaded) you should get the same results.

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Re: jedi issue with align and if..then..else
« Reply #4 on: August 14, 2020, 01:03:29 am »
@Fred - I would prefer the in ide formatter. A command line one is very cumbersome.

Indeed strange that Lazarus did not integrate Ptop in his IDE.

Fre;D
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

ASerge

  • Hero Member
  • *****
  • Posts: 2212
Re: jedi issue with align and if..then..else
« Reply #5 on: August 14, 2020, 03:15:38 pm »
I want it to format simple if.then.else on a single line and only break when begin is used eg:
With your jcfsettings.cfg I have the same extra indent. But in my opinion, if.then.else on a single line is a very bad style.

glubbish

  • New Member
  • *
  • Posts: 46
Re: jedi issue with align and if..then..else
« Reply #6 on: August 15, 2020, 01:59:17 am »
Quote
if.then.else on a single line is a very bad style.

Horses for courses I guess.
I also like single line if.then.
Code: Pascal  [Select][+][-]
  1.  if Count = 2 then Result := True;

As to the problem. If you set align.max variance to 19, problem does not occur.
Setting to 20 or higher it does.

Paolo

  • Sr. Member
  • ****
  • Posts: 499
Re: jedi issue with align and if..then..else
« Reply #7 on: October 05, 2020, 03:55:40 pm »
Hi glubbish,

maube you already know, but if you like coincise code in just one line

if Count = 2 then Result := True;

you can do that

Result:=(Cont = 2);

bd4kc

  • New Member
  • *
  • Posts: 46
Re: jedi issue with align and if..then..else
« Reply #8 on: December 17, 2020, 10:22:53 pm »
jedi code formatting, I'm not used to writing multiple statements in a single line. Jedi separates them all, causing them to turn pages frequently while reading. I'm looking for a way to separate the extra-long code, I've debugged the confirmed parts, I don't want to see them anymore, but I don't want them to be folded up. How did you do that?

Zoran

  • Hero Member
  • *****
  • Posts: 1827
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: jedi issue with align and if..then..else
« Reply #9 on: December 18, 2020, 12:36:07 am »
Hi glubbish,

maube you already know, but if you like coincise code in just one line

if Count = 2 then Result := True;

you can do that

Result:=(Count = 2);

No, wrong. No!
This would get the same behaviour:
Code: Pascal  [Select][+][-]
  1. Result := Result or (Cont = 2)
Still, not really relevant to the question, which is about code formatting.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: jedi issue with align and if..then..else
« Reply #10 on: December 18, 2020, 07:36:49 am »
Hi glubbish,

maube you already know, but if you like coincise code in just one line

if Count = 2 then Result := True;

you can do that

Result:=(Count = 2);

No, wrong. No!
This would get the same behaviour:
Code: Pascal  [Select][+][-]
  1. Result := Result or (Cont = 2)
Still, not really relevant to the question, which is about code formatting.
Unfortunately you are incorrect.

    Result := Result or (count = 2);
does not always give the same outcome or behaviour as
    Result := count = 2;

If Result is initially True, then your OR expression yields True,

but the simple comparison yields False, when count <> 2.


rvk

  • Hero Member
  • *****
  • Posts: 6056
Re: jedi issue with align and if..then..else
« Reply #11 on: December 18, 2020, 09:26:21 am »
Hi glubbish,

maube you already know, but if you like coincise code in just one line

if Count = 2 then Result := True;

you can do that

Result:=(Count = 2);

No, wrong. No!
This would get the same behaviour:
Code: Pascal  [Select][+][-]
  1. Result := Result or (Cont = 2)
Still, not really relevant to the question, which is about code formatting.
Unfortunately you are incorrect.

    Result := Result or (count = 2);
does not always give the same outcome or behaviour as
    Result := count = 2;

If Result is initially True, then your OR expression yields True,

but the simple comparison yields False, when count <> 2.
That's not what he said.

He said
Result := Result or (count = 2);
Is the same as
if Count = 2 then Result := True;
Which is correct.

It was a reaction to the incorrect answer that
Result := count = 2;
is the same as
if Count = 2 then Result := True;


Zoran

  • Hero Member
  • *****
  • Posts: 1827
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: jedi issue with align and if..then..else
« Reply #12 on: December 18, 2020, 11:00:37 am »
Yes, thanks RVK. Howard, you missed my point.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: jedi issue with align and if..then..else
« Reply #13 on: December 18, 2020, 11:08:35 am »
Unfortunately you are incorrect.

    Result := Result or (count = 2);
does not always give the same outcome or behaviour as
    Result := count = 2;

If Result is initially True, then your OR expression yields True,

but the simple comparison yields False, when count <> 2.

The point is that to replace the "if", Result must not be changed unless Count = 2, so the OR expression is the way to go: when Count <> 2, Result keeps its value and when Count = 2 it changes to True whatever it previously was. ;)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: jedi issue with align and if..then..else
« Reply #14 on: December 18, 2020, 12:05:45 pm »
@Zoran
Apologies that I missed your (valid) point.

 

TinyPortal © 2005-2018