Format Indentation

Working on new editor enhancements?
fryquez
Enthusiast
Enthusiast
Posts: 362
Joined: Mon Dec 21, 2015 8:12 pm

Format Indentation

Post by fryquez »

The IDE's Format Indentation doesn't work well with CompilerIf and If statements

Code: Select all

CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
If SizeOf(Character) = 1
CompilerElse
If SizeOf(Character) = 2
CompilerElseIf
EndIf
Same Problem for Import/EndImport
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Format Indentation

Post by skywalk »

The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Tenaja
Addict
Addict
Posts: 1948
Joined: Tue Nov 09, 2010 10:15 pm

Re: Format Indentation

Post by Tenaja »

fryquez wrote:The IDE's Format Indentation doesn't work well with CompilerIf and If statements

Code: Select all

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: Select all

CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
#Value = 1
CompilerElse
#Value = 2
CompilerEndif

If SizeOf(Character) = #Value
Endif
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Format Indentation

Post by Thunder93 »

PB IDE Format Indentation system really messy in some ways.

Here's how it's shown under PB 5.42

Code: Select all

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: Select all

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
User avatar
Tenaja
Addict
Addict
Posts: 1948
Joined: Tue Nov 09, 2010 10:15 pm

Re: Format Indentation

Post by Tenaja »

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.
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Format Indentation

Post by Thunder93 »

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
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Format Indentation

Post by Dude »

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.
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Format Indentation

Post by Thunder93 »

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
User avatar
Tenaja
Addict
Addict
Posts: 1948
Joined: Tue Nov 09, 2010 10:15 pm

Re: Format Indentation

Post by Tenaja »

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.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Format Indentation

Post by Dude »

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.
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Format Indentation

Post by Demivec »

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.
User avatar
Tenaja
Addict
Addict
Posts: 1948
Joined: Tue Nov 09, 2010 10:15 pm

Re: Format Indentation

Post by Tenaja »

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.
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Format Indentation

Post by Thunder93 »

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
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: Format Indentation

Post by freak »

http://www.purebasic.fr/english/viewtop ... 46#p431046

The offer still stands:
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
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Format Indentation

Post by Thunder93 »

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: Select all

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
Post Reply