code formatting

Working on new editor enhancements?
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

code formatting

Post 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
Last edited by jassing on Sun May 26, 2024 8:08 am, edited 1 time in total.
BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

Re: code formatting

Post 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
Last edited by BarryG on Sun May 26, 2024 8:08 am, edited 1 time in total.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: code formatting

Post 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
Last edited by jassing on Sun May 26, 2024 8:09 am, edited 1 time in total.
BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

Re: code formatting

Post 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.
Last edited by BarryG on Sun May 26, 2024 8:12 am, edited 2 times in total.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: code formatting

Post 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.
BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

Re: code formatting

Post 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.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: code formatting

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

Re: code formatting

Post by Demivec »

Garbage In = Garbage Out.
PBJim
Enthusiast
Enthusiast
Posts: 296
Joined: Fri Jan 19, 2024 11:56 pm

Re: code formatting

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