Feature Request: Remove empty lines
Feature Request: Remove empty lines
Feature Request: Remove empty lines
Or is there an menu entry which I have not seen?
Thanks
Icesoft
Or is there an menu entry which I have not seen?
Thanks
Icesoft
Belive! C++ version of Puzzle of Mystralia
Bug Planet
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
Bug Planet
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
- Rook Zimbabwe
- Addict
- Posts: 4322
- Joined: Tue Jan 02, 2007 8:16 pm
- Location: Cypress TX
- Contact:
Re: Feature Request: Remove empty lines
and REM lines... if possible... that would be good...
Re: Feature Request: Remove empty lines
Wait.. what? 
You want your code to be sandwiched into a wall of text?

You want your code to be sandwiched into a wall of text?
Re: Feature Request: Remove empty lines
They could have commented lines as the separators. 

I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
- utopiomania
- Addict
- Posts: 1655
- Joined: Tue May 10, 2005 10:00 pm
- Location: Norway
Re: Feature Request: Remove empty lines
I use empty lines to make my sourcecode more readable. If the compiler or the exe don't
mind why remove them?
mind why remove them?
- Michael Vogel
- Addict
- Posts: 2807
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: Feature Request: Remove empty lines
Hm, maybe there are different opinions about readable code, I love some empty lines within procedures, but don't like them seperating procedures, because a typical program will need a lot of scrolling even when all procedures are collapsed.
Therefore I personally like to have all comments for a procedure right/below the the first procedure line, so it will also be collapsable.
However, here's a fast possibility to get rid of empty lines - it's a quick and dirty code for now, but if it is useful, I could optimize it for recognizing "Procedure " and "Procedure." but not lines like "ProcedureVar=1". The same should work for "Macros" also...
But one after the other, here's the simple code which should be compiled as "Auto Compactor.exe" and copied into the "Catalog" directory of PureBasic. After that, just add is as a tool, using [%COMPILEFILE\..\Catalogs\Tool AutoCompactor.exe] for the command line, ["%TEMPFILE" %SELECTION] as arguments and [%COMPILEFILE\..] as the working directory (don't add the brackets).
Just activate also the options "wait until tool quits" and "reload source after tool has quit", that's it.
Therefore I personally like to have all comments for a procedure right/below the the first procedure line, so it will also be collapsable.
However, here's a fast possibility to get rid of empty lines - it's a quick and dirty code for now, but if it is useful, I could optimize it for recognizing "Procedure " and "Procedure." but not lines like "ProcedureVar=1". The same should work for "Macros" also...
But one after the other, here's the simple code which should be compiled as "Auto Compactor.exe" and copied into the "Catalog" directory of PureBasic. After that, just add is as a tool, using [%COMPILEFILE\..\Catalogs\Tool AutoCompactor.exe] for the command line, ["%TEMPFILE" %SELECTION] as arguments and [%COMPILEFILE\..] as the working directory (don't add the brackets).
Just activate also the options "wait until tool quits" and "reload source after tool has quit", that's it.
Code: Select all
;{ AutoCompactor by Michael Vogel Vo.o1}
; INSTALLATION:
; copy compiled exe into the directory "...\Purbasic\Catalogs"
; install the tool using the parameter "%TEMPFILE" %SELECTION
; use the PureBasic as the working directory (or adapt the OpenPreferences path below)
; Select 'Wait until tool quits' And 'Reload source after tool has quit'
; %COMPILEFILE\..\Catalogs\Tool AutoIndent.exe
; "%TEMPFILE" %SELECTION
; %COMPILEFILE\..
; Auto &Indent
; Menu Or Shortcut
; × Wait until tool quits
; × Reload Source after tool has quit
; × into the current source
; DESCRIPTION:
; With pressed shift key: remove all empty lines
; without shift key: just remove lines between endprocedure/procedure
; no selection: complete source code is affected
; selection of lines: only selected lines are changed
; HISTORY & ISSUES:
; first beta
;}
; Define
; EndDefine
Procedure.s RightTrim(s.s)
l.l=Len(s)
While l
l-1
b.l=PeekB(@s+l)
If b<>9 And b<>32
Break
EndIf
Wend
ProcedureReturn Left(s,l+1)
EndProcedure
Procedure.s LeftTrim(s.s)
l.l=Len(s)
c.l=0
While c<l
b.l=PeekB(@s+c)
If b<>9 And b<>32 ; Space & Tab
Break
EndIf
c+1
Wend
ProcedureReturn Mid(s,c+1,l-c)
EndProcedure
Procedure Init()
; Dateinamen holen...
CompilerIf 1
If CountProgramParameters()<>2
MessageBox_(0,"'AutoCompactor' benötigt Parameter!"+#CR$+"(%TEMPFILE und %SELECTION)","Fehler",#MB_ICONERROR| #MB_OK)
End
EndIf
Global OutputFile.s=ProgramParameter()
CompilerElse
Global OutputFile.s="Test.pb"
CompilerEndIf
Global InputFile.s=OutputFile+"~"
DeleteFile(InputFile)
If RenameFile(OutputFile,InputFile)=0
MessageBox_(0,"'AutoCompactor' konnte keine Temporärdatei erstellen","Fehler",#MB_ICONERROR| #MB_OK)
End
EndIf
; Selektion abfragen...
Global zeile.l=0
selektion.s=ProgramParameter()
Global Startzeile.l=Val(StringField(selektion, 1, "x"))
Global Endzeile.l=Val(StringField(selektion, 3, "x"))
;CreateFile(3,"c:\debug.log")
;WriteStringN(3,Str(Startzeile))
;WriteStringN(3,Str(Endzeile))
;CloseFile(3)
If Startzeile>=Endzeile
Startzeile=1
Endzeile=#MAXSHORT
EndIf
EndProcedure
Procedure Doit(mode.l)
; Doit(0) standard compacting
; Doit(1) complete compacting
;CreateFile(3,"c:\debug.log")
;WriteStringN(3,"s "+FormatDate("%hh:%ii:%ss", Date())+#TAB$+Str(GetTickCount_()))
Init()
ReadFile(1,InputFile)
CreateFile(2,OutputFile)
Protected RemoveFlag=mode
Protected Content.s
While Not(Eof(1))
z.s=ReadString(1)
zeile.l+1
z=righttrim(z) ; rechts kann man immer säubern
If zeile>=Startzeile And zeile<=Endzeile
Content=LCase(lefttrim(z))
If mode
RemoveFlag=#True
ElseIf Left(Content,9)="procedure"
RemoveFlag=#False
ElseIf Left(Content,12)="endprocedure"
RemoveFlag=#True
EndIf
If (RemoveFlag=#False) Or Len(Content)
WriteStringN(2,z)
EndIf
Else
WriteStringN(2,z)
EndIf ;
Wend
CloseFile(1)
CloseFile(2)
;WriteStringN(3,"e "+FormatDate("%hh:%ii:%ss", Date())+#TAB$+Str(GetTickCount_()))
;CloseFile(3)
EndProcedure
Doit((GetKeyState_(#VK_SHIFT)&$80))
Re: Feature Request: Remove empty lines
I am a supporter of generous white space usage, even more so than in the past, as can be seen by my contribution history on the Tips 'n' Tricks board:
http://www.purebasic.fr/english/viewtop ... 12&t=43994
It's all part of the "Mistrel Manual of Style".
http://www.purebasic.fr/english/viewtop ... 12&t=43994
It's all part of the "Mistrel Manual of Style".

- Michael Vogel
- Addict
- Posts: 2807
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: Feature Request: Remove empty lines
Now procedures are detected as promised...
Code: Select all
;{ AutoCompactor by Michael Vogel Vo.o2}
; INSTALLATION:
; copy compiled exe into the directory "...\Purbasic\Catalogs"
; install the tool using the parameter "%TEMPFILE" %SELECTION
; use the PureBasic as the working directory (or adapt the OpenPreferences path below)
; Select 'Wait until tool quits' And 'Reload source after tool has quit'
; %COMPILEFILE\..\Catalogs\Tool AutoIndent.exe
; "%TEMPFILE" %SELECTION
; %COMPILEFILE\..
; Auto &Indent
; Menu Or Shortcut
; × Wait until tool quits
; × Reload Source after tool has quit
; × into the current source
; DESCRIPTION:
; With pressed shift key: remove ALL empty lines
; without shift key: just remove lines between endprocedure/procedure
; no selection: complete source code is affected
; selection of lines: only selected lines are changed
; HISTORY & ISSUES:
; n/a
;}
; Define
#SpecialChar=Chr(1)
; EndDefine
Procedure Init()
; Dateinamen holen...
CompilerIf 1
If CountProgramParameters()<>2
MessageBox_(0,"'AutoCompactor' benötigt Parameter!"+#CR$+"(%TEMPFILE und %SELECTION)","Fehler",#MB_ICONERROR| #MB_OK)
End
EndIf
Global OutputFile.s=ProgramParameter()
CompilerElse
Global OutputFile.s="Test.pb"
CompilerEndIf
Global InputFile.s=OutputFile+"~"
DeleteFile(InputFile)
If RenameFile(OutputFile,InputFile)=0
MessageBox_(0,"'AutoCompactor' konnte keine Temporärdatei erstellen","Fehler",#MB_ICONERROR| #MB_OK)
End
EndIf
; Selektion abfragen...
Global zeile.l=0
selektion.s=ProgramParameter()
Global Startzeile.l=Val(StringField(selektion, 1, "x"))
Global Endzeile.l=Val(StringField(selektion, 3, "x"))
If Startzeile>=Endzeile
Startzeile=1
Endzeile=#MAXSHORT
EndIf
EndProcedure
Procedure.s RightTrim(s.s)
l.l=Len(s)
While l
l-1
b.l=PeekB(@s+l)
If b<>9 And b<>32
Break
EndIf
Wend
ProcedureReturn Left(s,l+1)
EndProcedure
Procedure.s LeftTrim(s.s)
l.l=Len(s)
c.l=0
While c<l
b.l=PeekB(@s+c)
If b<>9 And b<>32 ; Space & Tab
Break
EndIf
c+1
Wend
ProcedureReturn Mid(s,c+1,l-c)
EndProcedure
Procedure Doit(mode.l)
Init()
ReadFile(1,InputFile)
CreateFile(2,OutputFile)
Protected RemoveFlag=#True
Protected Content.s
While Not(Eof(1))
z.s=ReadString(1)
zeile.l+1
z=righttrim(z) ; rechts kann man immer säubern
If zeile>=Startzeile And zeile<=Endzeile
Content=LCase(LeftTrim(z))
ReplaceString(Content," ",#SpecialChar,#PB_String_InPlace)
ReplaceString(Content,";",#SpecialChar,#PB_String_InPlace)
ReplaceString(Content,":",#SpecialChar,#PB_String_InPlace)
ReplaceString(Content,#TAB$,#SpecialChar,#PB_String_InPlace)
Content+#SpecialChar
If mode
RemoveFlag=#True
ElseIf Left(Content,9)="procedure"
If FindString("."+#SpecialChar,Mid(Content,10,1),1)
RemoveFlag=#False
EndIf
ElseIf (Left(Content,6)="macro"+#SpecialChar) Or (Left(Content,3)=#SpecialChar+"{"+#SpecialChar) Or (Left(Content,9)=#SpecialChar+#SpecialChar+"define"+#SpecialChar)
RemoveFlag=#False
ElseIf (Left(Content,13)="endprocedure"+#SpecialChar) Or (Left(Content,9)="endmacro"+#SpecialChar) Or (Left(Content,3)=#SpecialChar+"}"+#SpecialChar) Or (Left(Content,12)=#SpecialChar+#SpecialChar+"enddefine"+#SpecialChar)
RemoveFlag=#True
;Else
; MessageRequester(content,z)
EndIf
If (RemoveFlag=#False) Or Len(Content)>1
WriteStringN(2,z)
EndIf
Else
WriteStringN(2,z)
EndIf ;
Wend
CloseFile(1)
CloseFile(2)
EndProcedure
Doit((GetKeyState_(#VK_SHIFT)&$80))
-
- Addict
- Posts: 2345
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: Feature Request: Remove empty lines
Rightclick: Add block comment and remove block comment? [Ctrl + B] and [Alt + B]Rook Zimbabwe wrote:and REM lines... if possible... that would be good...
bye,
Daniel
Daniel
Re: Feature Request: Remove empty lines
Couldn't you just load the file into a string array and then re-save it without the empty lines (or Rems)? That would make it cross-platform. I suppose you could have a little list of options to process the code before re-saving (like empty lines/rems/only delete empty lines between procedures/etc).
Sorry, this isn't a feature request... just a thought.
Sorry, this isn't a feature request... just a thought.
MacBook Pro-M1 (2021), Sequoia 15.4, PB 6.20