Page 1 of 1

code formatting

Posted: Sun May 26, 2024 8:02 am
by jassing
This is how "reformat code" formats this.
The "retval" is, indeed, declared as protected. but reformatting doesn't indent it.
It should be getting indented. (I pre-accept that I am wrong)

Code: Select all

EnableExplicit
Global retval=3
Procedure   winResultsCB( hWnd, iMessage, wParam, lParam ) 
  Protected col,
            *nmhdr.NMHDR,
            *nmitem.NMITEMACTIVATE, 
            ;*pnmv.NMLISTVIEW,
            
            
  retval = #PB_ProcessPureBasicEvents 
  Debug retval
EndProcedure

winResultsCB(1,1,1,1)
Debug retval

Re: code formatting

Posted: Sun May 26, 2024 8:08 am
by BarryG
The comment marks the end of the "Protected" multi-line block, so "retval=" correctly goes onto its own new line. It's like this:

Code: Select all

Procedure   winResultsCB( hWnd, iMessage, wParam, lParam ) 
  Protected col, *nmhdr.NMHDR, *nmitem.NMITEMACTIVATE, ;*pnmv.NMLISTVIEW,
  retval = #PB_ProcessPureBasicEvents 
  Debug retval
EndProcedure

Re: code formatting

Posted: Sun May 26, 2024 8:08 am
by jassing
BarryG wrote: Sun May 26, 2024 8:08 am The comment marks the end of the "Protected" multi-line block, so "retval=" correctly goes onto its own new line.
But it should get indented.

even w/o spaces.. it doesn't get indented

Code: Select all

Procedure   winResultsCB( hWnd, iMessage, wParam, lParam ) 
  Protected col,
            *nmhdr.NMHDR,
            *nmitem.NMITEMACTIVATE, 
            ;*pnmv.NMLISTVIEW,
  retval = #PB_ProcessPureBasicEvents 
  Debug retval
EndProcedure

Re: code formatting

Posted: Sun May 26, 2024 8:09 am
by BarryG
Why? See my edited comment above for how the IDE sees it. Why should it get indented? The comma at the end of the comment is rightfully ignored. There's no line continuation after the comment, so no indentation occurs. Remove the commented lined and it indents.

Re: code formatting

Posted: Sun May 26, 2024 8:12 am
by jassing
BarryG wrote: Sun May 26, 2024 8:09 am Why? See my edited comment above for how the IDE sees it. Why should it get indented? The comma at the end of the comment is rightfully ignored. There's no line continuation after the comment, so no indentation occurs.
Here's a different example

Code: Select all

Debug FormatDate("%yyyy",
                 ; acomment
Date())
Actually, I don't care enough anymore.
cheers.

Re: code formatting

Posted: Sun May 26, 2024 8:14 am
by BarryG
The IDE sees it as ths:

Code: Select all

Debug FormatDate("%yyyy", ; acomment
Date())
There's no line continuation at the end of the line due to the comment, so "Date()" rightfully doesn't get indented.
jassing wrote: Sun May 26, 2024 8:12 amActually, I don't care enough anymore.
I was just showing why you're misunderstanding how it works. :( It works only if the end of the line is not a comment, and your examples all end with a comment. You can't line continuation a comment.

Re: code formatting

Posted: Mon May 27, 2024 4:54 am
by jassing
BarryG wrote: Sun May 26, 2024 8:14 am
I was just showing why you're misunderstanding how it works. :( It works only if the end of the line is not a comment, and your examples all end with a comment. You can't line continuation a comment.
It's a bug.
if the IDE "sees" it as a non-continuation, then it shouldn't compile & run.
We just have differing views on what constitutes a bug.

Re: code formatting

Posted: Mon May 27, 2024 5:36 am
by Demivec
Garbage In = Garbage Out.

Re: code formatting

Posted: Mon May 27, 2024 11:33 am
by PBJim
The behaviour of indentation, where there is line-continuation, depends on whether the comment is a line-appended comment, or on a line of its own. I'd more or less agree with Barry's synopsis, but just to make that distinction, which I didn't see mentioned and apologies if anyone did.

End-of-Line (appended comments) are properly ignored and therefore the indentation remains (example 1) since there is a comma after NMITEMACTIVATE. A comment occupying a line of its own however, breaks that continuation, (as indeed does an empty line) hence the indentation being reset to level 2 (example 2).

(1)

Code: Select all

Procedure   winResultsCB( hWnd, iMessage, wParam, lParam ) 
  Protected col,
            *nmhdr.NMHDR,
            *nmitem.NMITEMACTIVATE,           ; Comment
            retval = #PB_ProcessPureBasicEvents 
  Debug retval
EndProcedure
(2)

Code: Select all

Procedure   winResultsCB( hWnd, iMessage, wParam, lParam ) 
  Protected col,
            *nmhdr.NMHDR,
            *nmitem.NMITEMACTIVATE,
            ; Comment
  retval = #PB_ProcessPureBasicEvents 
  Debug retval
EndProcedure
Likewise, as I mentioned, an empty line also resets :

Code: Select all

Procedure   winResultsCB( hWnd, iMessage, wParam, lParam ) 
  Protected col,
            *nmhdr.NMHDR,
            *nmitem.NMITEMACTIVATE,

  retval = #PB_ProcessPureBasicEvents 
  Debug retval
EndProcedure