Page 1 of 3
Place spaces around operators (?)
Posted: Mon Feb 21, 2022 2:46 pm
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
Re: Place spaces around operators (?)
Posted: Mon Feb 21, 2022 3:16 pm
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 "
Re: Place spaces around operators (?)
Posted: Mon Feb 21, 2022 3:19 pm
by HeX0R
This PB-tool can do that also.
Re: Place spaces around operators (?)
Posted: Mon Feb 21, 2022 3:48 pm
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.
Re: Place spaces around operators (?)
Posted: Mon Feb 21, 2022 8:16 pm
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.
Re: Place spaces around operators (?)
Posted: Mon Feb 21, 2022 8:19 pm
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.
Re: Place spaces around operators (?)
Posted: Tue Feb 22, 2022 9:34 am
by AZJIO
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.
Re: Place spaces around operators (?)
Posted: Tue Feb 22, 2022 3:15 pm
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
Re: Place spaces around operators (?)
Posted: Tue Feb 22, 2022 5:24 pm
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.

Re: Place spaces around operators (?)
Posted: Tue Feb 22, 2022 6:01 pm
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.

Re: Place spaces around operators (?)
Posted: Tue Feb 22, 2022 11:28 pm
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

Re: Place spaces around operators (?)
Posted: Wed Feb 23, 2022 1:24 am
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
Re: Place spaces around operators (?)
Posted: Wed Feb 23, 2022 8:51 am
by HeX0R
Fixed
Re: Place spaces around operators (?)
Posted: Wed Feb 23, 2022 11:25 am
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
Re: Place spaces around operators (?)
Posted: Wed Feb 23, 2022 1:10 pm
by AZJIO
How about the English name e.g. TidyPB?