Just two simple routines to indent or un-indent source code.
Did a search and couldn't find any recent ones.
Code: Select all
;INDENTER
;
;Configure as tool with Arguments set as "%FILE" "%TEMPFILE"
;Set shortcut to 'ctrl' 'shift' and 'I'
;Tick 'Wait until tool quits', 'Reload Source' and 'into current source'
;
;
cpp.b=CountProgramParameters()
If cpp<>2
MessageRequester("Error","Wrong number of parameters.")
End
EndIf
pps.s=ProgramParameter()
ppt.s=ProgramParameter()
If pps=""
MessageRequester("Error","Source file has to be saved first.")
End
EndIf
DataSection
#plus=11
Data.s "if ","for ","while ","repeat ","procedure ","select ","datasection "
Data.s "macro ","compilerif ","compilerselect ","structure "
#minus=12
Data.s "endif ","next ","wend ","until ","endprocedure ","endselect ","enddatasection "
Data.s "endmacro ","forever ","compilerendif ","compilerendselect ","endstructure "
#temp=7
Data.s "else ","elseif ","case ","compilerelse ","default ","compilercase ","compilerdefault "
EndDataSection
Dim indent_plus.s(#plus)
Dim indent_minus.s(#minus)
Dim indent_temp.s(#temp)
For n=1 To #plus
Read.s indent_plus(n)
Next
For n=1 To #minus
Read.s indent_minus(n)
Next
For n=1 To #temp
Read.s indent_temp(n)
Next
addspaces=0
#ind=2
RenameFile(pps,pps+".bak")
OpenFile(0,ppt)
CreateFile(1,pps)
While Not Eof(0)
getline.s=ReadString(0)
getline=Trim(getline)+" "
toadd.s=Space(addspaces)
flag=0
For n=1 To #plus
compare.s=indent_plus(n)
If LCase(Left(getline,Len(compare)))=compare
flag=1
EndIf
Next
If flag
addspaces+#ind
EndIf
flag=0
For n=1 To #minus
compare.s=indent_minus(n)
If LCase(Left(getline,Len(compare)))=compare
flag=1
EndIf
Next
If flag
addspaces-#ind
If addspaces<0
addspaces=0
EndIf
toadd=Space(addspaces)
EndIf
flag=0
For n=1 To #temp
compare.s=indent_temp(n)
If LCase(Left(getline,Len(compare)))=compare
flag=1
EndIf
Next
If flag
If Len(toadd)>0
toadd=Left(toadd,Len(toadd)-#ind)
EndIf
EndIf
getline=RTrim(toadd+getline)
WriteStringN(1,getline)
Wend
CloseFile(0)
CloseFile(1)
CopyFile(pps,ppt)
Code: Select all
;UNINDENTER
;
;Configure as tool with Arguments set as "%FILE" "%TEMPFILE"
;Set shortcut to 'ctrl' 'shift' and 'U'
;Tick 'Wait until tool quits', 'Reload Source' and 'into current source'
;
cpp.b=CountProgramParameters()
If cpp<>2
MessageRequester("Error","Wrong number of parameters.")
End
EndIf
pps.s=ProgramParameter()
ppt.s=ProgramParameter()
If pps=""
MessageRequester("Error","Source file has to be saved first.")
End
EndIf
RenameFile(pps,pps+".bak")
OpenFile(0,ppt)
CreateFile(1,pps)
While Not Eof(0)
getline.s=ReadString(0)
getline=Trim(getline)
WriteStringN(1,getline)
Wend
CloseFile(0)
CloseFile(1)
CopyFile(pps,ppt)
If a=1 : b=1 : EndIf
will miss the endif, solution, split the line into 3!
Anyway, try them if you like.
