It is currently Wed Jan 27, 2021 5:29 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 28 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Format Indentation
PostPosted: Fri Jul 22, 2016 6:25 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Dec 21, 2015 8:12 pm
Posts: 179
The IDE's Format Indentation doesn't work well with CompilerIf and If statements

Code:
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
If SizeOf(Character) = 1
CompilerElse
If SizeOf(Character) = 2
CompilerElseIf
EndIf


Same Problem for Import/EndImport


Top
 Profile  
Reply with quote  
 Post subject: Re: Format Indentation
PostPosted: Fri Jul 22, 2016 7:26 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3382
Location: Boston, MA
It is expected behavior.

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: Format Indentation
PostPosted: Fri Jul 22, 2016 9:17 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Nov 09, 2010 10:15 pm
Posts: 1719
fryquez wrote:
The IDE's Format Indentation doesn't work well with CompilerIf and If statements

Code:
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
If SizeOf(Character) = 1
CompilerElse
If SizeOf(Character) = 2
CompilerElseIf
EndIf


Same Problem for Import/EndImport


I do not know if your are just trying to show a simple example or not, but what you have is much better to be changed so you have constant assignment values in the conditional compilation, so the IF statement is the same line regardless of any conditional compilation. For instance:
Code:
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
#Value = 1
CompilerElse
#Value = 2
CompilerEndif

If SizeOf(Character) = #Value
Endif


Top
 Profile  
Reply with quote  
 Post subject: Re: Format Indentation
PostPosted: Fri Jul 22, 2016 9:46 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Mar 21, 2006 12:31 am
Posts: 1773
Location: Canada
PB IDE Format Indentation system really messy in some ways.

Here's how it's shown under PB 5.42

Code:
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
**If SizeOf(Character) = 1
**CompilerElse
****If SizeOf(Character) = 2
****CompilerElseIf
****EndIf


I rather see it shown like;
Code:
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
**If SizeOf(Character) = 1
CompilerElse
**If SizeOf(Character) = 2
CompilerElseIf
...

_________________
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley


Top
 Profile  
Reply with quote  
 Post subject: Re: Format Indentation
PostPosted: Fri Jul 22, 2016 10:12 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Nov 09, 2010 10:15 pm
Posts: 1719
You are basically asking the IDE to compile code, to determine which code is used. That's a lot of work to make a real-time compiler.

Do not expect this to get changed.


Top
 Profile  
Reply with quote  
 Post subject: Re: Format Indentation
PostPosted: Fri Jul 22, 2016 10:51 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Mar 21, 2006 12:31 am
Posts: 1773
Location: Canada
I'm not living in no bubble, I personally know what to expect. :wink:

_________________
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley


Top
 Profile  
Reply with quote  
 Post subject: Re: Format Indentation
PostPosted: Sat Jul 23, 2016 12:17 am 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1907
Tenaja wrote:
You are basically asking the IDE to compile code

Wait... if the editor can correctly format If/Else/EndIf, then why can't it also do it for CompilerIf/CompilerElse/CompilerEndIf? There's literally zero difference except for the keywords. I don't get it.


Top
 Profile  
Reply with quote  
 Post subject: Re: Format Indentation
PostPosted: Sat Jul 23, 2016 12:58 am 
Offline
Addict
Addict
User avatar

Joined: Tue Mar 21, 2006 12:31 am
Posts: 1773
Location: Canada
Doesn't matter what code is used from CompilerIf.

If CompilerIf started 7 spaces over, the other Compiler* entries should also follow that rule. Therefore the other Compiler* entries should also be 7 spaces over. The following Compiler* entries should not be influenced by what has been placed in side the CompilerIf block.

If PB IDE is only going by what was on the previous line, then maybe some more thought should be put into this PB Indentation system.

_________________
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley


Top
 Profile  
Reply with quote  
 Post subject: Re: Format Indentation
PostPosted: Sat Jul 23, 2016 1:43 am 
Offline
Addict
Addict
User avatar

Joined: Tue Nov 09, 2010 10:15 pm
Posts: 1719
Thunder93 wrote:
Doesn't matter what code is used from CompilerIf.

If CompilerIf started 7 spaces over, the other Compiler* entries should also follow that rule. Therefore the other Compiler* entries should also be 7 spaces over. The following Compiler* entries should not be influenced by what has been placed in side the CompilerIf block.

If PB IDE is only going by what was on the previous line, then maybe some more thought should be put into this PB Indentation system.


Speaking from experience, it is not too difficult to indent after every IF, and unindent at every EndIf.

It is exponentially more difficult to have conditional indentation.


Top
 Profile  
Reply with quote  
 Post subject: Re: Format Indentation
PostPosted: Sat Jul 23, 2016 1:55 am 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1907
Tenaja wrote:
It is exponentially more difficult to have conditional indentation.

But why? That's why I don't get. Assuming "indent" is a variable that keeps track and starts at 0:

See a line with CompilerIf: "indent+2", which is applied to all following lines.
See a line with CompilerElse: use "indent-2" for this line only, so no indent occurs.
See a line with CompilerEndIf: "indent-2", which is applied to all following lines.

What's the big deal? I could write a pre-processor in 10 seconds to do this.


Top
 Profile  
Reply with quote  
 Post subject: Re: Format Indentation
PostPosted: Sat Jul 23, 2016 3:08 am 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 3767
Location: Utah, USA
Dude wrote:
Tenaja wrote:
It is exponentially more difficult to have conditional indentation.

But why? That's why I don't get. Assuming "indent" is a variable that keeps track and starts at 0:

See a line with CompilerIf: "indent+2", which is applied to all following lines.
See a line with CompilerElse: use "indent-2" for this line only, so no indent occurs.
See a line with CompilerEndIf: "indent-2", which is applied to all following lines.

What's the big deal? I could write a pre-processor in 10 seconds to do this.

Currently the IDE only has to look at the line before to see if the indent needs to be increased or decreased.

You are suggesting to keep track of the indenting for CompilerIf/CompilerElse/CompilerEndif statements separately by resetting the indent level to whatever it was at the starting CompilerIf each time a CompilerElse, or CompilerEndif is reached. It seems like that may be doable.

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Format Indentation
PostPosted: Mon Jul 25, 2016 7:38 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Nov 09, 2010 10:15 pm
Posts: 1719
Dude wrote:
Tenaja wrote:
It is exponentially more difficult to have conditional indentation.

But why? That's why I don't get. Assuming "indent" is a variable that keeps track and starts at 0:

See a line with CompilerIf: "indent+2", which is applied to all following lines.
See a line with CompilerElse: use "indent-2" for this line only, so no indent occurs.
See a line with CompilerEndIf: "indent-2", which is applied to all following lines.

What's the big deal? I could write a pre-processor in 10 seconds to do this.


It is relatively easy to create a text formatter that only looks at existing text.

If you start adding conditional indentation, like "only indent the IF statement if it is not within a CompilerIf", then things are a lot more complicated.

Then, to add on top of that, do it "real time" as you are typing, and this is where the hassle begins. How far back do you look to see if your indentation is correct? If you look any more than the start of the line, then to be accurate and avoid screams of bugs, you must look back to the beginning of a file. And then you'll get screams because the ide is too slow when editing the end of a large file.

There is a balance everywhere.


Top
 Profile  
Reply with quote  
 Post subject: Re: Format Indentation
PostPosted: Mon Jul 25, 2016 8:05 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Mar 21, 2006 12:31 am
Posts: 1773
Location: Canada
I don't see an issue from indent tracking w/variable approach.

_________________
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley


Top
 Profile  
Reply with quote  
 Post subject: Re: Format Indentation
PostPosted: Mon Jul 25, 2016 8:38 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 5:21 pm
Posts: 5818
Location: Germany
viewtopic.php?p=431046#p431046

The offer still stands:

Quote:
Here is my suggestion: If somebody can define a good algorithm (in words, not code) how to handle the indentation of comments, i will try to implement it.

These are the conditions under which the indentation code must operate:
  • The IDE must decide based on the content of the previous line how to indent the next one.
  • It can scan a little further back (past an empty line or comment for example) to get more context, but the look-back must be short. I.e. the ident algorith cannot start from the beginning of the source. It must work with only limited context information around the current line.

Good ideas are welcome :)


Btw, I don't see whats wrong with putting a ";<" marker behind the IF line to correct the auto-indent in special cases like this. That is why the possibility to use such markers exist.

_________________
quidquid Latine dictum sit altum videtur


Top
 Profile  
Reply with quote  
 Post subject: Re: Format Indentation
PostPosted: Mon Jul 25, 2016 9:36 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Mar 21, 2006 12:31 am
Posts: 1773
Location: Canada
I've had too many beers and now stupid. I don't see how adding ";<" corrects auto-indent issues. I'm using PB 5.42 .. is there a feature I need to activate or is this something now available with the non-LTS release?

Code:
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
  If SizeOf(Character) = 1 ;<
  CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64 ;<
    If SizeOf(Character) = 2                                ;<
    CompilerElse     
      If SizeOf(Character) = 4 ;<
      CompilerEndIf

_________________
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 28 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye