Format Indentation
Re: Format Indentation
You can add it as a keyword for indentation in the preferences (or any other kind of comment or custom keyword as long as it contains no space). I thought this was part of the default, but I guess I just added it myself in my setup.
quidquid Latine dictum sit altum videtur
Re: Format Indentation
That's a little better Freak. Thanks for the suggestion.
Code: Select all
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
If SizeOf(Character) = 1 ;<
CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64
If SizeOf(Character) = 2 ;<
CompilerElse
If SizeOf(Character) = 4 ;<
CompilerEndIf
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Re: Format Indentation
or just Write :
Code: Select all
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
If SizeOf(Character) = 1 :EndIf ;<
CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64
If SizeOf(Character) = 2 :EndIf ;<
CompilerElse
If SizeOf(Character) = 4 :EndIf ;<
CompilerEndIf
Re: Format Indentation
more seriously,
if I put this code in the official editor:
I get this tab:
but with my Tab procedure
( copy and paste this code,
and Shift + Tab to remove tabs
and Ctrl + tab to tabulate the code )
Tabulator in the editor
if I put this code in the official editor:
I get this tab:
Code: Select all
Macro si1 :If SizeOf(Character) = 1:EndMacro
Macro si2 :If SizeOf(Character) = 2:EndMacro
Macro si4 :If SizeOf(Character) = 4:EndMacro
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
si1
CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64
si2
CompilerElse
si4
CompilerEndIf
but with my Tab procedure
( copy and paste this code,
and Shift + Tab to remove tabs
and Ctrl + tab to tabulate the code )
Tabulator in the editor
Code: Select all
;{- Enumerations / DataSections
Global NewMap decrement.S()
Global Compteur_tab=0
decrement.S("endenumeration")="endenumeration"
decrement.S("endstructure")="endstructure"
decrement.S( "endprocedure")="endprocedure"
decrement.S( "enddatasection")="enddatasection"
decrement.S( "endselect")="endselect"
decrement.S( "stopdrawing")="stopdrawing"
decrement.S( "endinterface")="endinterface"
decrement.S( "endstructure")="endstructure"
decrement.S( "endimport")= "endimport"
decrement.S( "endmacro")= "endmacro"
decrement.S( "endwith")="endwith"
decrement.S( "endstructureunion")="endstructureunion"
decrement.S("stop3d")="stop3d"
decrement.S("compilerendif")="compilerendif"
decrement.S("compilerendselect")="compilerendselect"
decrement.S("endmodule")="endmodule"
decrement.S("enddeclaremodule")="enddeclaremodule"
decrement.S("closefile")="closefile"
decrement.S("next")="next"
decrement.S("until")="until"
decrement.S("forever")="forever"
decrement.S("wend")="wend"
decrement.S( "endif")="endif"
; *******************************************
; attention l'ordre des termes a son importance
Global NewMap increment.S()
increment.S( "enumeration")="enumeration"
increment.S( "datasection")="datasection"
increment.S( "startdrawing")= "startdrawing"
increment.S( "structure")= "structure"
increment.S( "proceduredll")= "proceduredll"
increment.S( "procedurecdll")= "procedurecdll"
increment.S( "procedurec")="procedurec"
increment.S( "procedure")= "procedure"
increment.S( "importc")= "importc"
increment.S( "import")= "import"
increment.S( "macro")="macro"
increment.S( "interface")= "interface"
increment.S( "structureunion")= "structureunion"
increment.S("start3d")="start3d"
increment.S("compilerif")="compilerif"
increment.S("compilerselect")="compilerselect"
increment.S("module")="module"
increment.S("declaremodule")="declaremodule"
increment.S( "with")= "with"
increment.S( "select")= "select"
increment.S("openfile")="openfile"
increment.S("readfile")="readfile"
increment.S("createfile")="createfile"
increment.S( "foreach")="foreach"
increment.S( "for")="for"
increment.S( "repeat")="repeat"
increment.S( "while")="while"
increment.S( "if")="if"
increment.S("case")="case"
;{ Windows
Enumeration
#Win
EndEnumeration
;}
;{ Gadgets
Enumeration
#Button_Load
#Text_titre
#Editor
#tabulation
#detabulation
EndEnumeration
;}
;{ Fonts
Enumeration
#Font_Text_titre
EndEnumeration
Declare openwindow_win()
Declare pos_com_max()
Declare.s tabulation(txt.s)
;}
Define.l Event
Global NewList code.S()
Global pos_max
;}
OpenWindow_Win()
;{- Event loop
Repeat
Event = WaitWindowEvent(12)
Select Event
; ///////////////////
Case #PB_Event_Menu ; Alt+Tab
Select EventMenu()
Case #tabulation
; ; cherche la position max d'un ";"
; pos_max=pos_com_max()
; ClearList(code.s())
; For i=0 to CountGadgetItems(#editor)
; line.S=GetGadgetItemText(#editor, i)
; a$=LTrim(line.S,Chr(9))
; a$=LTrim(a$)
; AddElement(code.S())
; code.S()=a$
; Next i
ClearGadgetItems(#editor)
ForEach code.S()
txt.S=code.S()
AddGadgetItem(#editor, -1, tabulation(txt.S) ) ; ajoute chaque ligne tabuléees
Next
Case #detabulation
ClearList(code.s())
For i=0 to CountGadgetItems(#editor)
line.S=GetGadgetItemText(#editor, i)
a$=LTrim(line.S,Chr(9))
a$=LTrim(a$)
AddElement(code.S())
code.S()=a$
Next i
ClearGadgetItems(#editor)
ForEach code.S()
txt.S=code.S()
AddGadgetItem(#editor, -1,txt.S ) ; ajoute chaque ligne tabuléees
Next
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #Button_Load
local.S=GetCurrentDirectory()
file.S=OpenFileRequester("ouvrir code",local.S,"*.pb",1)
OpenFile(0,file.S)
While Eof(0) = 0 ; Boucle tant que la fin du fichier n'est pas atteinte. (Eof = 'End Of File')
line.S=ReadString(0)
a$=LTrim(line.S,Chr(9))
a$=LTrim(a$)
AddElement(code.S())
code.S()=a$
Wend
CloseFile(0)
; Tabulation au chargement
ForEach code.S()
txt.S=code.S()
AddGadgetItem(#editor, -1, tabulation(txt.S) ) ; ajoute chaque ligne tabuléees
Next
Case #Text_titre
Case #Editor
EndSelect
; ////////////////////////
Case #PB_Event_CloseWindow
Select EventWindow()
Case #Win
CloseWindow(#Win)
Break
EndSelect
EndSelect
Forever
;-Zone Procedures
Procedure OpenWindow_Win()
If OpenWindow(#Win, 405, 47, 720, 597, "Exemple indentation", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
ButtonGadget(#Button_Load, 20, 20, 90, 35, "Load *.Pb")
TextGadget(#Text_titre, 205, 15, 255, 40, "Exemple Tabulation")
EditorGadget(#Editor, 25, 80, 680, 500)
; Gadget Fonts
SetGadgetFont(#Text_titre, LoadFont(#Font_Text_titre, "Microsoft Sans Serif", 20, #PB_Font_HighQuality))
; Raccourcis :
AddKeyboardShortcut(#win, #PB_Shortcut_Control | #PB_Shortcut_Tab, #tabulation)
AddKeyboardShortcut(#win, #PB_Shortcut_Shift | #PB_Shortcut_Tab, #detabulation)
EndIf
EndProcedure
Procedure pos_com_max()
; on recherche dans tout le code la possition max d'un commentaire (le plus a droite dans une ligne )
For i=0 to CountGadgetItems(#editor)
line.S=GetGadgetItemText(#editor, i)
a$=LTrim(line.S,Chr(9))
a$=LTrim(a$)
pos=FindString(a$,";") ; on recherche ";"
if pos>mem_pos ; si la position est plus grande
mem_pos=pos ; on garde
Endif
Next i
ProcedureReturn mem_pos ; voici la position maximum d'un ";" dans le code
EndProcedure
Procedure.S tabulation(txt.S)
; procedure de tabulation by Dobro (plus court tu meurts !! )
;
; pos= findstring(StringField(txt.S,1,chr(34)),";")
; if pos<pos_max and Pos>0
; txt.s=RemoveString(txt.s,chr(9))
;
; nbbn=pos_max-pos
;
; tt.s=""
; For z=1 to nbbn
; tt.s=tt.s+" "
; Next z
; txt.s=ReplaceString(txt.s,";",tt.s +";" )
; nbbn-(Compteur_tab*3)
; Endif
;
extrait.S=LCase(StringField(txt.S,1,":")) ; recup avant multipligne
; extrait.S=StringField(extrait.S,1,";"); recupe avant commentaire : ceci ne tabule pas les comentaires ... c'est un choix
extrait.S=StringField(extrait.S,1," "); recupe premier mot
extrait.S=StringField(extrait.S,1,"("); pour les fonctions
extrait.S=StringField(extrait.S,1,"."); pour les fonctions (typées)
extrait.S=LCase(Trim(extrait.S))
; If extrait.S="" :Goto su :EndIf ; saute les lignes vides
tab.S=LSet(tab.S,Compteur_tab,Chr(9)) ; pour l'increment se fait dans un deuxieme appel
; -- Else
If extrait.S="else" Or extrait.S="elseif" Or extrait.S="case"
mem_Compteur_tab=Compteur_tab
Compteur_tab=Compteur_tab-1
tab.S=LSet(tab.S,Compteur_tab,Chr(9)) ; pour un decrement, c'est tout de suite
Compteur_tab=mem_Compteur_tab
Goto su
EndIf
;++++ increment
If extrait.S= increment.S(extrait.S) And extrait.S<>""
; regarde si un decrement se trouve sur la meme ligne qu'un increment , dans ce cas on tabule en arriere puis on remet la valeur de tabulation
extrait2.S=StringField(txt.S,1,";")
ForEach decrement.S()
pooo=FindString(extrait2.S,decrement.S(),Len(extrait.S),#PB_String_NoCase)
If pooo>0
If Asc(Mid( extrait2.S,pooo+Len(decrement.S()),1))<33
Goto su
Else
Break
EndIf
EndIf
Next
; regarde si un decrement se trouve sur la meme ligne qu'un increment dans ce cas on ajoute une tabulation
extrait2.S=StringField(txt.S,1,"(") :extrait2.S=StringField(extrait2.S,1,"."):extrait2.S=StringField(extrait2.S,1,":")
ForEach increment.S()
;If FindString(extrait2.S,increment.S(),Len(extrait.S),#PB_String_NoCase)>0
pooo=FindString(extrait2.S,increment.S(),Len(extrait.S),#PB_String_NoCase) ; on a trouvée un semblant d'increment
If pooo>0
If Asc(Mid( extrait2.S,pooo+Len(increment.S()),1))<33; on regarde le caractere suivant, si inf a 33 c'est vrais c'est un increment
Compteur_tab=Compteur_tab+1
Break
EndIf
EndIf
Next
;
Compteur_tab=Compteur_tab+1
Goto su
EndIf
;----- decrement
If extrait.S= decrement.S(extrait.S) And extrait.S<>""
Compteur_tab=Compteur_tab-1
tab.S=LSet(tab.S,Compteur_tab,Chr(9)) ; pour un decrement, c'est tout de suite
Goto su
EndIf
su:
If Compteur_tab<=0:Compteur_tab=0
tab.S=""
EndIf
txt.S=tab.S+txt.S;+"("+str(compteur_tab)+")"
ProcedureReturn txt.S
EndProcedure
;
;}
Last edited by dobro on Tue Jul 26, 2016 10:43 pm, edited 2 times in total.
Re: Format Indentation
@dobro
No problem if you know when to use " ;< ", example for your Macros demo;
No problem if you know when to use " ;< ", example for your Macros demo;
Code: Select all
Macro si1 :If SizeOf(Character) = 1:EndMacro ;<
Macro si2 :If SizeOf(Character) = 2:EndMacro ;<
Macro si4 :If SizeOf(Character) = 4:EndMacro ;<
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
si1
CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64
si2
CompilerElse
si4
CompilerEndIf
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Re: Format Indentation
I guess ;< will do it. I Would never had thought about fixing the indentation with a comment.
Re: Format Indentation
Well freak uses this method, so we know it's of utmost quality
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Re: Format Indentation
I think you have not understood me !!
I do not speak comments "; <"
but the code alignment
try to put this code in the official editor
and tabulate it!
you will get this alignment:
with my procedure, it becomes:
alignment is correct !
I do not speak comments "; <"
but the code alignment
try to put this code in the official editor
and tabulate it!
you will get this alignment:
Code: Select all
Macro si1 :If SizeOf(Character) = 1:EndMacro
Macro si2 :If SizeOf(Character) = 2:EndMacro
Macro si4 :If SizeOf(Character) = 4:EndMacro
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
si1
CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64
si2
CompilerElse
si4
CompilerEndIf
Code: Select all
Macro si1 :If SizeOf(Character) = 1:EndMacro
Macro si2 :If SizeOf(Character) = 2:EndMacro
Macro si4 :If SizeOf(Character) = 4:EndMacro
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
si1
CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64
si2
CompilerElse
si4
CompilerEndIf
alignment is correct !
Re: Format Indentation
The special comment, when added and with the usage, corrects the alignment issues. Why do anything more special if I can use special comment to correct alignments as I'm typing. ?
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Re: Format Indentation
look here !!
https://youtu.be/Jpi2jxDBpG0
must only correct procedure tab, of the official editor ...
in French
mon code démontre qu'on peut obtenir un bon resultat avec une procedure de tabulation correcte !
il faut juste, corriger la procedure de tabulation , de l'éditeur officiel ....
https://youtu.be/Jpi2jxDBpG0
my code demonstrates that we can achieve good results with a procedure tab, correct!Thunder93 wrote:@dobro
No problem if you know when to use " ;< ", example for your Macros demo;
must only correct procedure tab, of the official editor ...
in French
mon code démontre qu'on peut obtenir un bon resultat avec une procedure de tabulation correcte !
il faut juste, corriger la procedure de tabulation , de l'éditeur officiel ....
Re: Format Indentation
dobro: Your code requires processing of the entire input source to get correct results. This simply takes too long when editing large files. The indentation algorithm must work with limited context only (see my post above).
quidquid Latine dictum sit altum videtur
Re: Format Indentation
not really !freak wrote:dobro: Your code requires processing of the entire input source to get correct results. This simply takes too long when editing large files. The indentation algorithm must work with limited context only (see my post above).
it is the variable: Global Compteur_tab=0
which has decided which tab you begin
if you know the tab before the current line
just put that value in the variable: Compteur_tab
before calling my procedure
and the tab will be correct!
I also used, this procedure on my IDE (EPB)
on pieces of Selected codes
my procedure does not contain a loop on the entire list
line by line I call it
Code: Select all
ForEach code.S()
txt.S=code.S()
AddGadgetItem(#editor, -1, tabulation(txt.S) ) ; ajoute chaque ligne tabuléees
Next
Compteur_tab=20 ;<<<< tab previous line
for number_line=xx to xx ;<<< pseudocode
setline(number_line,tabulation(txt.S) ;<<< pseudocode
Next number_line ;<<< pseudocode
the variable Compteur_tab will be equal to the new tab after the call
Re: Format Indentation
Your 'Exemple Tabulation' indentation algorithm can easily be fooled. Have a look at the included code at the bottom.
You have a ways to go to have it match PB IDE sophistication, .. regarding Its indentation algorithm.
You have to remember that people also customizes indentation settings via PB preferences, and such utility should respect that.
First thing I've noticed when I saw your example indentation correctness. You wasn't using PB default indentation values, which I am. The example I earlier provided is from PB default indentation values, before and after the special comment usage.
You have a ways to go to have it match PB IDE sophistication, .. regarding Its indentation algorithm.
You have to remember that people also customizes indentation settings via PB preferences, and such utility should respect that.
First thing I've noticed when I saw your example indentation correctness. You wasn't using PB default indentation values, which I am. The example I earlier provided is from PB default indentation values, before and after the special comment usage.
Code: Select all
Macro si1
If SizeOf(Character) = 1
EndMacro
Macro si2
If SizeOf(Character) = 2
EndMacro
Macro si4
If SizeOf(Character) = 4
EndMacro
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
si1
CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64
si2
CompilerElse
si4
CompilerEndIf
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley