Recent

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

glubbish

  • New Member
  • *
  • Posts: 44
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: 1836
    • 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.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

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

ASerge

  • Hero Member
  • *****
  • Posts: 1665
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: 44
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: 1836
    • 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.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

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

ASerge

  • Hero Member
  • *****
  • Posts: 1665
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: 44
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.

 

TinyPortal © 2005-2018