Place spaces around operators (?)

Just starting out? Need help? Post your questions and find answers here.
AZJIO
Addict
Addict
Posts: 2143
Joined: Sun May 14, 2017 1:48 am

Place spaces around operators (?)

Post by AZJIO »

There is a lot of code in which everything is written together, and I'm used to having spaces around the operators. Are there any features to fix this situation?

Code: Select all

; bad
OpenWindow(0,0,0,220,100, "", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
x+1

; good
OpenWindow(0, 0, 0, 220, 100, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
x + 1
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Place spaces around operators (?)

Post by STARGÅTE »

You can open the file in Notepad++ and use the Search-Replace-Option with the regular-expression-mode.
Search: ",(?!\s)"
Replace: ", "

And for the oprators:
Search: "\s*([*/|&+-])\s*"
Replace: " $1 "
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
HeX0R
Addict
Addict
Posts: 1189
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: Place spaces around operators (?)

Post by HeX0R »

This PB-tool can do that also.
AZJIO
Addict
Addict
Posts: 2143
Joined: Sun May 14, 2017 1:48 am

Re: Place spaces around operators (?)

Post by AZJIO »

HeX0R
Can it be used on code of any complexity?
I checked that inside the quotes does not make changes.
Probably it is necessary to try the complex code and compare it in the Meld program.

Thanks.
Checked for 1500 lines of code, everything is fine.
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Place spaces around operators (?)

Post by Tenaja »

AZJIO wrote: Mon Feb 21, 2022 3:48 pm HeX0R
Can it be used on code of any complexity?
I checked that inside the quotes does not make changes.
Probably it is necessary to try the complex code and compare it in the Meld program.

Thanks.
Checked for 1500 lines of code, everything is fine.
I don't know about this one specifically, but in general, tools like this do not modify strings. They usually skip anything within quotes, because strings are usually not code and frequently must remain unaltered.
User avatar
HeX0R
Addict
Addict
Posts: 1189
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: Place spaces around operators (?)

Post by HeX0R »

Sure, strings keep untouched.
It might have difficulties with escaped strings, though, because it had been created at a time, where those were not possible.
AZJIO
Addict
Addict
Posts: 2143
Joined: Sun May 14, 2017 1:48 am

Re: Place spaces around operators (?)

Post by AZJIO »

Code: Select all

comstr$ = ~"-c \"find %s 2>&1\""
I checked the escaped strings and this is indeed the problem. At one time, I also encountered this problem when deleting comments.
Can you add code to ignore lines if a "~" character is found in a line? That is, if the symbol "~" is found, then look for the end-of-line character and continue analyzing the data from it.
User avatar
ChrisR
Addict
Addict
Posts: 1466
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Place spaces around operators (?)

Post by ChrisR »

I discover it, nice tool, thanks HeX0R :)
I also like the spaces between the operators and with the vertical alignment of variables, constants values, it really makes reading easier.
It would be nice to have some of it's features in the native IDE

I have an indentation problem, if I use multiple commands on the same line ":" and with the use of a module "::"

Code: Select all

If ToolBar::Gadget(#MainWindow, #ToolBar, 10, 10, 200, 40, ToolBar::#ImageAndText)
  If IsFont(ToolBarFont) : ToolBar::SetFont(#ToolBar, FontID(ToolBarFont)) : EndIf
    CatchImage(#TBImage1,   ?TBImage1)
  EndIf
User avatar
HeX0R
Addict
Addict
Posts: 1189
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: Place spaces around operators (?)

Post by HeX0R »

Damn... I didn't want to start now a discussion about improving that tool.
It's pretty old and I knew there were some things wrong.
Let's see when I find the time to reanimate that corpse. :mrgreen:
User avatar
ChrisR
Addict
Addict
Posts: 1466
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Place spaces around operators (?)

Post by ChrisR »

:)
It is already very good, I adopted it.
If you reanimate it a little, it will be like good wine, it will get better with age.

Image
User avatar
HeX0R
Addict
Addict
Posts: 1189
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: Place spaces around operators (?)

Post by HeX0R »

I've updated the code.
Now I'm using the Indentation settings of the PB IDE also.

I've added quite some comments, because it was pretty hard for me to understand my old code :lol:
User avatar
ChrisR
Addict
Addict
Posts: 1466
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Place spaces around operators (?)

Post by ChrisR »

Thanks HeX0R for its reanimation and great to have used PB IDE's indentation settings :)
It's all good for my previous example.
A minor change, for the tab length if we use a number of chars (eg: 2) rather than using the real tab (ASCII 9)

Code: Select all

Procedure.s AddTabs(Tabs, Tab.s)
  ProcedureReturn RSet("", Tabs * Len(Tab), Tab)
EndProcedure

# Edit
I have another little problem with this example and the Select_All() procedure, Not Select

Code: Select all

Select EventMenu()
  Case #Shortcut_Ctrl_A
    Select_All()
      Case #Shortcut_Ctrl_U
        Unselect_All()
    EndSelect
User avatar
HeX0R
Addict
Addict
Posts: 1189
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: Place spaces around operators (?)

Post by HeX0R »

Fixed
User avatar
ChrisR
Addict
Addict
Posts: 1466
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Place spaces around operators (?)

Post by ChrisR »

Thanks HeX0R, I tested several sources, it seems all good.

The only thing seen is for the great vertival alignment of = Values, is it possible to also include it in the Enumerations or inside If-Endif,...

Code: Select all

Enumeration DWMWINDOWATTRIBUTE
  #DWMWA_USE_IMMERSIVE_DARK_MODE = 20
  #DWMWA_BORDER_COLOR = 34
  #DWMWA_CAPTION_COLOR = 35
  #DWMWA_TEXT_COLOR  = 36
EndEnumeration

#DWMWA_USE_IMMERSIVE_DARK_MODE = 20
#DWMWA_BORDER_COLOR            = 34
#DWMWA_CAPTION_COLOR           = 35
#DWMWA_TEXT_COLOR              = 36
AZJIO
Addict
Addict
Posts: 2143
Joined: Sun May 14, 2017 1:48 am

Re: Place spaces around operators (?)

Post by AZJIO »

How about the English name e.g. TidyPB?
Post Reply