Page 1 of 2
Format Indentation
Posted: Fri Jul 22, 2016 6:25 pm
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
Re: Format Indentation
Posted: Fri Jul 22, 2016 7:26 pm
by skywalk
Re: Format Indentation
Posted: Fri Jul 22, 2016 9:17 pm
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
Re: Format Indentation
Posted: Fri Jul 22, 2016 9:46 pm
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
...
Re: Format Indentation
Posted: Fri Jul 22, 2016 10:12 pm
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.
Re: Format Indentation
Posted: Fri Jul 22, 2016 10:51 pm
by Thunder93
I'm not living in no bubble, I personally know what to expect.

Re: Format Indentation
Posted: Sat Jul 23, 2016 12:17 am
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.
Re: Format Indentation
Posted: Sat Jul 23, 2016 12:58 am
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.
Re: Format Indentation
Posted: Sat Jul 23, 2016 1:43 am
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.
Re: Format Indentation
Posted: Sat Jul 23, 2016 1:55 am
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.
Re: Format Indentation
Posted: Sat Jul 23, 2016 3:08 am
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.
Re: Format Indentation
Posted: Mon Jul 25, 2016 7:38 pm
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.
Re: Format Indentation
Posted: Mon Jul 25, 2016 8:05 pm
by Thunder93
I don't see an issue from indent tracking w/variable approach.
Re: Format Indentation
Posted: Mon Jul 25, 2016 8:38 pm
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.
Re: Format Indentation
Posted: Mon Jul 25, 2016 9:36 pm
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