Please ignore comments for indentation

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Please ignore comments for indentation

Post by netmaestro »

When I key the following code:

Code: Select all

a = 5   ; a must be set to 5
        ; in order for the program
        ; to work correctly.
b = 6
After I type in this code, which is aligned as I want it, subsequent ctrl-a, ctrl-I results in this:

Code: Select all

a = 5   ; a must be set to 5
; in order for the program
; to work correctly.
b = 6
I think that for purposes of code indentation the IDE could and should ignore comments with the assumption that the coder has them aligned where he wants them. Just my opinion, don't want to make waves if everyone else is happy with the current.
BERESHEIT
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: Please ignore comments for indentation

Post by freak »

To be honest i am not so sure how to best deal with comments. I don't see a perfect solution.

For example, your suggestion also has a problem. Assume that you take your code as it is and paste
it to another place (inside an if/loop block for example). It then looks like:

Code: Select all

If X
  While Y
  
a = 5   ; a must be set to 5
        ; in order for the program
        ; to work correctly.
b = 6

  Wend
EndIf
Now you want to get it all aligned and do Ctrl+A, Ctrl+I. With your suggestion the result looks like this:

Code: Select all

If X
  While Y
  
    a = 5   ; a must be set to 5
        ; in order for the program
        ; to work correctly.
    b = 6

  Wend
EndIf
The code was moved, but the comments stayed in place. Is that what you want?

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 :)
quidquid Latine dictum sit altum videtur
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Please ignore comments for indentation

Post by skywalk »

My compromise has been to set the comment margin according to normal flow, but start actual comment text aligned to the previous line's comment.
If previous line does not have a comment, then no need for extra leading spaces.
This editing does not fail with the current indentation rules.

Code: Select all

If X
  While Y 
    a = 5   ; a must be set to 5
    ;         in order for the program
    ;         to work correctly.
    b = 6
  Wend
  ; this is a normally spaced comment
EndIf
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Please ignore comments for indentation

Post by netmaestro »

Here's a start:

Code: Select all

If prefs->comment_alignment is true
  If this line contains a semicolon
    If the line above this line contains a semicolon
      Move the comment portion of this line only such that the semicolons are aligned
    EndIf
  EndIf
EndIf
BERESHEIT
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Please ignore comments for indentation

Post by netmaestro »

Another interesting idea would be to leave comments as they are but implement a "special character" which, if found immediately following a semicolon, results in the comment portion of that line aligned with a similar pair found above it. In this scenario a ctrl-I would result in this:

Code: Select all

If X
  While Y
  
    a = 5   ; a must be set to 5
    ; in order for the program
    ; to work correctly.
    b = 6

  Wend
EndIf

If X

  While Y
  
    a = 5   ;\ a must be set to 5
            ;\ in order for the program
            ;\ to work correctly.
    b = 6

  Wend
EndIf
And both codeblocks are what I asked for.
Last edited by netmaestro on Mon Nov 18, 2013 10:37 pm, edited 3 times in total.
BERESHEIT
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Please ignore comments for indentation

Post by Fred »

Please, not another pref option ! :)
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Please ignore comments for indentation

Post by netmaestro »

Actually I like my second idea better and it needs no pref option.
BERESHEIT
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Please ignore comments for indentation

Post by davido »

Hi netmaestro,

I, too, like your second suggestion.
I presume that mean the line, one line above it. If no distance is specified it might align with those 20,000 lines above!?
DE AA EB
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Please ignore comments for indentation

Post by netmaestro »

Yes, just the line above. So this hastily typed code:

Code: Select all

If X
While Y
  
a = 5   ; a must be set to 5
; in order for the program
; to work correctly.
b = 6

Wend
EndIf

If X
;\ we come to an important loop:
;\ a and be must b set while  
;\ Y is true, otherwise chaos will ensue.
While Y
  
a = 5   ;\ a must be set to 5
;\ in order for the program
;\ to work correctly.
b = 6

Wend
EndIf
followed by ctrl-a ctrl-I would look like:

Code: Select all

If X
  While Y
  
    a = 5   ; a must be set to 5
; in order for the program
; to work correctly.
    b = 6

  Wend
EndIf

If X
  ;\ we come to an important loop:
  ;\ a and b must be set while  
  ;\ Y is true, otherwise chaos will ensue.
  While Y
  
    a = 5   ;\ a must be set to 5
            ;\ in order for the program
            ;\ to work correctly.
    b = 6

  Wend
EndIf
BERESHEIT
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Please ignore comments for indentation

Post by PB »

There's no problems at all if you just code with the comment above the line:

Code: Select all

; a must be set to 5
; in order for the program
; to work correctly.
a = 5

b = 6
Now you can indent, decrease, or Ctrl+I to your heart's content. ;)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Le Soldat Inconnu
Enthusiast
Enthusiast
Posts: 306
Joined: Wed Jul 09, 2003 11:33 am
Location: France

Re: Please ignore comments for indentation

Post by Le Soldat Inconnu »

when you comment ";" is placed on start line and not before indentation.
But when you reset indentation with Ctrl+I, ";" come back with good indentation

Example

Code: Select all

If Truc = 0
  Test + 1
EndIf
i comment

Code: Select all

If Truc = 0
;  Test + 1
EndIf
i set indent with ctrl + I

Code: Select all

If Truc = 0
  ;  Test + 1
EndIf
so i get indentation before and after !

The best solution for me :

Code: Select all

If Truc = 0
  Test + 1
  If Test > 2
    Toto = Test + 4
  EndIf
EndIf
i comment

Code: Select all

If Truc = 0
  ; Test + 1
  ; If Test > 2
  ;   Toto = Test + 4
  ; EndIf
EndIf
So, i keep indentation from fisrt commented line, and i keep indentation inside comment
if i do Ctrl + I, indentation don't change
if i remove comment, i don't lost indentation on line "Toto = Test + 4"

Thanks
LSI
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Please ignore comments for indentation

Post by Little John »

I am also rather unhappy with the way comments are currently handled by the IDE.
netmaestro wrote:[...] implement a "special character" which, if found immediately following a semicolon, results in the comment portion of that line aligned with a similar pair found above it.
I would appreciate it if that would happen with normal comments which start just with a semi-colon. Is actually an additional special character required to make it work?
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Please ignore comments for indentation

Post by davido »

Hi Little John,

I assumed that the extra character would force that comment to align with the comment on the line above.

Of course, the IDE could simply ignore the position of ;comments
Then they would stay where the Coder had placed them.
DE AA EB
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Please ignore comments for indentation

Post by Little John »

Hi Davido!
I assumed that the extra character would force that comment to align with the comment on the line above.
That's how I understood it, too. But why use an extra character in order to achieve that goal?
I would appreciate it if after pressing CTRL+A and CTRL+I, any normal comment would be aligned with the comment on the line above (if possible). Am I overlooking something?
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Please ignore comments for indentation

Post by skywalk »

Wow, I don't want another comment character unless it is to support block commenting. :!:
And ignoring comments during indentation does not work for me either. :cry:
What is the real problem here?

Code: Select all

If X
  While Y 
    a = 5   ; a must be set to 5
    ;         in order for the program
    ;         to work correctly.
    b = 6
  Wend
  ; this is a normally spaced comment
EndIf
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Post Reply