Page 1 of 2

Please ignore comments for indentation

Posted: Mon Nov 18, 2013 8:10 pm
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.

Re: Please ignore comments for indentation

Posted: Mon Nov 18, 2013 8:40 pm
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 :)

Re: Please ignore comments for indentation

Posted: Mon Nov 18, 2013 8:52 pm
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

Re: Please ignore comments for indentation

Posted: Mon Nov 18, 2013 9:34 pm
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

Re: Please ignore comments for indentation

Posted: Mon Nov 18, 2013 9:41 pm
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.

Re: Please ignore comments for indentation

Posted: Mon Nov 18, 2013 9:42 pm
by Fred
Please, not another pref option ! :)

Re: Please ignore comments for indentation

Posted: Mon Nov 18, 2013 9:43 pm
by netmaestro
Actually I like my second idea better and it needs no pref option.

Re: Please ignore comments for indentation

Posted: Mon Nov 18, 2013 10:24 pm
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!?

Re: Please ignore comments for indentation

Posted: Mon Nov 18, 2013 10:30 pm
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

Re: Please ignore comments for indentation

Posted: Tue Nov 19, 2013 11:18 am
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. ;)

Re: Please ignore comments for indentation

Posted: Wed Nov 20, 2013 9:45 am
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

Re: Please ignore comments for indentation

Posted: Wed Nov 20, 2013 4:14 pm
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?

Re: Please ignore comments for indentation

Posted: Wed Nov 20, 2013 5:39 pm
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.

Re: Please ignore comments for indentation

Posted: Wed Nov 20, 2013 5:52 pm
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?

Re: Please ignore comments for indentation

Posted: Wed Nov 20, 2013 5:58 pm
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