Auto indent in the Editor v4.50

Working on new editor enhancements?
marc_256
Addict
Addict
Posts: 842
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Auto indent in the Editor v4.50

Post by marc_256 »

I was looking to change (set off) the "AUTO INDENT" in the editor of pb4.50.
I did not find a way to do this,
even in the preference/editor I did not find a way to do this.

I like to work without 'auto indent'.

Q: How must I do this.

Thanks, Marc.
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
Mr Coder
User
User
Posts: 54
Joined: Tue Apr 13, 2010 8:02 am

Re: Auto indent in the Editor v4.50

Post by Mr Coder »

Preferences -> Editor -> Indentation -> No indentation.
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Auto indent in the Editor v4.50

Post by Vera »

Congratulations Mr Coder ~ you've been some seconds quicker :wink:

on Linux: Preferences\General\Indentation\
Last edited by Vera on Fri Jun 25, 2010 10:01 am, edited 1 time in total.
marc_256
Addict
Addict
Posts: 842
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: Auto indent in the Editor v4.50

Post by marc_256 »

Thanks,

I didn't see it :oops:

Marc
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
MyTrial
Enthusiast
Enthusiast
Posts: 165
Joined: Thu Nov 30, 2006 11:47 am

Re: Auto indent in the Editor v4.50

Post by MyTrial »

Hi

I use the "block mode" because I don't like that a IDE changes lines by himself. Hope this "block mode" is the same as on the old IDE und no more auto changes are done. ;)

Sigi
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Auto indent in the Editor v4.50

Post by netmaestro »

I think it's fantastic, it saves me a lot of fiddling. But of course you can turn it off if you prefer not to use it.
BERESHEIT
User avatar
Michael Vogel
Addict
Addict
Posts: 2807
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Auto indent in the Editor v4.50

Post by Michael Vogel »

AutoIndent does some interesting things, e.g. Enter after "Endif" jumps to the next line but not after "Else" and some irritating things may happen when using Ctrl+D...

That's why I still use my old program, which gets started from the IDE, when pressing Alt+I:

Code: Select all

; <<< im Verzeichnis Purbasic\Catalogs >>>

;	%COMPILEFILE\..\Catalogs\Tool AutoIndent.exe
;	"%TEMPFILE" %SELECTION
;	%COMPILEFILE\..

;	Auto &Indent
;	Menu Or Shortcut

; x Wait until tool quits
; x Reload Source after tool has quit
; x into the current source

;{ AutoIndent by Michael Vogel V2.o1}

	; With pressed shift key:		eliminates tabs And spaces
	; without shift key:			indents source code
	; no selection:				complete source code is affected
	; selection of lines:			only selected lines are changed

	; known problems:			when cursor is in line 1, the Procedure folds up (editor bug?)
	;								":" in remark, like in "Until x>1;   x : 0...5"

;}
; Define

	Global LeftC.l
	Global LeftD.l
	Global RightC.l
	Global RightD.l
	Global RightP.l

	#Words=51; has to be adapted manually

	Global Dim Word.s(#Words)
	Global Dim Exception.s(4)
	Global exceptions.l=0
	Global Dim Border(3)

	z.l=0
	i.l=0
	While i<#Words
		i+1
		Read.s Word(i)
		If Asc(word(i))=254	; "þ"
			exceptions+1
			exception(exceptions)=Mid(word(i),2,Len(word(i))-1)
		EndIf
		If Word(i)="!"
			i-1
			Border(z)=i
			;Debug Str(z)+": "+Str(i-1)+" = "+word(border(z))
			z+1
		EndIf
	Wend

	DataSection
		Data.s "þ Define"
		Data.s "þ{"
		Data.s "Procedure "
		Data.s "Procedure."
		Data.s "ProcedureC"
		Data.s "ProcedureDLL"
		Data.s "DataSection"
		Data.s "Macro "
		Data.s "If "
		Data.s "With "
		Data.s "Select "
		Data.s "While "
		Data.s "For "
		Data.s "ForEach "
		Data.s "Repeat"
		Data.s "Structure "
		Data.s "StructureUnion"
		Data.s "Interface "
		Data.s "Enumeration"
		Data.s "CompilerIf "
		Data.s "CompilerSelect "
		Data.s "ImportC "
		Data.s "Import "
		Data.s "!"							; border(0)

		; kurzzeitig ''ausrücken''
		Data.s "Case "
		Data.s "Else:"						; needed!
		Data.s "Else "						; needed!

		Data.s "ElseIf "
		Data.s "Default "					; ???
		Data.s "Default"
		Data.s "CompilerElse"
		Data.s "CompilerCase"
		Data.s "CompilerDefault"
		Data.s "!"							; border(1)

		Data.s "þ EndDefine"
		Data.s "þ}"
		Data.s "EndProcedure"
		Data.s "EndDataSection"
		Data.s "EndMacro"
		Data.s "EndIf"
		Data.s "EndWith"
		Data.s "EndSelect"
		Data.s "Wend"
		Data.s "ForEver"
		Data.s "EndStructure"
		Data.s "EndStructureUnion"
		Data.s "EndInterface"
		Data.s "EndEnumeration"
		;Data.s "CompilerEndIf"		; wird schon bei 'EndIf' entdeckt
		;Data.s "CompilerEndSelect"	; analog oben
		Data.s "EndImport"
		Data.s "!"						; border(2)

		Data.s "Next "					; viele Variablen beginnen mit Next...
		Data.s "Next:"					; blöd, da kann nach 'Until' noch Text kommen...
		Data.s "Until "					; detto
		Data.s "!",""					; border(3)

	EndDataSection
; 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 FindCommas(s.s)
	LeftC=0
	LeftD=0
	RightC=0
	RightD=0
	RightP=0
	l.l=Len(s)
	c.l=0
	While c<l
		b.l=PeekB(@s+c)
		c+1
		Select b
		Case 59		; Semicolon
			RightC=c
			If LeftC=0 : LeftC=c : EndIf
		Case 34		; DoubleQuote
			RightD=c
			If LeftD=0 : LeftD=c : EndIf
		Case 58		; Colon
			RightP=c
		Case 9,32
			If c=RightP+1 : RightP+1 : EndIf
		EndSelect

	Wend
EndProcedure
Procedure.s RightCut(s.s,x.l)
	ProcedureReturn RTrim(Left(s,x-1))
EndProcedure
Procedure.s StringS(n, chars.s)
	Protected s.s=""
	While n>0
		s+chars
		n-1
	Wend
	ProcedureReturn s
EndProcedure

;{ AutoIndent Installation }

	; > 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 aftzer tool has quit'

;}
Procedure Init()

	; Dateinamen holen...
	CompilerIf 1
		If CountProgramParameters()<>2
			MessageBox_(0,"'AutoIndent' 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,"'AutoIndent' 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

	OpenPreferences("PureBasic.prefs"); ok
	PreferenceGroup("Global")
	If Val(ReadPreferenceString("RealTab","0")) Or (GetKeyState_(#VK_CONTROL)&$80)
		Global indtxt.s=#TAB$
	Else
		Global indtxt.s=Space(Val(ReadPreferenceString("TabLength", "2")))
	EndIf
	ClosePreferences()

EndProcedure
Procedure Doit(mode.l)

	; Doit(0)	auto indent the source code
	; Doit(1)	trims source code from space And tab characters

	init()

	ReadFile(1,InputFile)
	CreateFile(2,OutputFile)

	indent.l=0


	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

			z=lefttrim(z)		; links nur, wenn gewünscht...

			afterburner.l=0

			If (mode=0) And (Len(z)>0)

				If Asc(z)=';'; ";"
					If Left(z,25)="; IDE Options = PureBasic"
						indent=0
					Else
						For i=1 To exceptions
							If Mid(z,2,Len(exception(i)))=exception(i)
								PokeB(@z,254) ; "þ"
								Break
							EndIf
						Next i
					EndIf
				EndIf

				s.s=z

				FindCommas(s)
				; [1]	If a=0		; remark
				; [2]	If a=''x''	; remark
				; [3]	If a=0		; ''remark''
				; [x]	If a=''x''	; ''remark''
				If LeftC
					If LeftD=0 Or LeftC<LeftD	; [1], [3]
						s=RightCut(s,LeftC)
					ElseIf RightC>RightD		; [2]
						s=RightCut(s,RightC)
					EndIf
				EndIf

				For i=1 To #Words
					l.l=Len(word(i))
					Select i
					Case 1 To border(1)
						p.l=1
					Case 1 To border(2)
						p.l=Len(s)-l+1
					Case 1 To border(3)
						p.l=RightP+1
					EndSelect

					If Mid(s+":",p,l)=word(i)

						Select i
						Case 1 To border(0)
							afterburner.l+1

						Case 1 To border(1)
							indent-1
							afterburner.l+1

						Case 1 To border(3)
							If afterburner
								afterburner-1
							Else
								indent-1
							EndIf

						EndSelect
					EndIf

				Next i

				If Asc(z)=254 ; "þ"
					PokeB(@z,';') ; ";"
				EndIf

				z=strings(indent,indtxt)+z

			EndIf ; mode

		EndIf ; Zeilenselektion

		WriteStringN(2,z)
		indent+afterburner
	Wend
	CloseFile(1)
	CloseFile(2)

EndProcedure

Doit((GetKeyState_(#VK_SHIFT)&$80))

MyTrial
Enthusiast
Enthusiast
Posts: 165
Joined: Thu Nov 30, 2006 11:47 am

Re: Auto indent in the Editor v4.50

Post by MyTrial »

Hi

thanks, netmaestro, that you allow me to shut this silly thing off. ;)

I don't like any editor or ide to handle parts of my code by himself. If i type [return] for a next line and it inserts spaces (i never use tabs!) to go to the same row as the line before, that is ok - and a help. No more should it do. I am working mostly with "vi" and so i have learned to do all by myself and i do it daily. So fiddling all extra parts of this autoindent back to "my design" is a very heavy work and stops my (!!!) workflow.

On the next i think this autoindent doesn't do a good work, like michael found out too. It changes although lines which are well formatted when i go back in the source or insert a "else" or a "endif" somewhere. Other lines are not well formatted. I did not a full test, because i don't want it. :)

I would not be happy with such a "help" - others would - no problem. So it's good, that it could be switched off.

A other "helper" would be better (for me): Cut all spaces at the end of a line if you change from that line. PSPad on windows os does this very fine (if you need a sample).

Sigi
User avatar
skywalk
Addict
Addict
Posts: 4218
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Auto indent in the Editor v4.50

Post by skywalk »

Hi,
Is there a way to assign a shortcut to toggle Auto-Indent?

Meaning...
I am making some repetitive edits and I want to temporarily turn OFF Auto-Indent.
So I hit [CTRL+whatever] and continue.
Then I hit [CTRL+whatever] and Auto-Indent is resumed to ON.

Going to the Preferences page is time consuming.
AlexGrits
New User
New User
Posts: 1
Joined: Tue Dec 25, 2012 8:55 am

Re: Auto indent in the Editor v4.50

Post by AlexGrits »

For win7 compatibility.:

Code: Select all

; <<< im Verzeichnis Purbasic\Catalogs >>>

;   %COMPILEFILE\..\Catalogs\Tool AutoIndent.exe
;   "%TEMPFILE" %SELECTION purebasic.prefs-file location ;"C:\Program Files\PureBasic 5\Catalogs\purebasic.prefs" Or "C:\Users\%USER%\AppData\Roaming\PureBasic\purebasic.prefs"
;   %COMPILEFILE\..

;   Auto &Indent
;   Menu Or Shortcut

; x Wait until tool quits
; x Reload Source after tool has quit
; x into the current source

;{ AutoIndent by Michael Vogel V2.o1}

   ; With pressed shift key:      eliminates tabs And spaces
   ; without shift key:         indents source code
   ; no selection:            complete source code is affected
   ; selection of lines:         only selected lines are changed

   ; known problems:         when cursor is in line 1, the Procedure folds up (editor bug?)
   ;                        ":" in remark, like in "Until x>1;   x : 0...5"

   ;}
   ;alexgrits + few lines for win7 compatibility
; Define

Global PureBasic_prefsFileLocation.s


   Global LeftC.l
   Global LeftD.l
   Global RightC.l
   Global RightD.l
   Global RightP.l
   
   
   #Words=51; has to be adapted manually

   Global Dim Word.s(#Words)
   Global Dim Exception.s(4)
   Global exceptions.l=0
   Global Dim Border(3)

   z.l=0
   i.l=0
   While i<#Words
      i+1
      Read.s Word(i)
      If Asc(word(i))=254   ; "?"
         exceptions+1
         exception(exceptions)=Mid(word(i),2,Len(word(i))-1)
      EndIf
      If Word(i)="!"
         i-1
         Border(z)=i
         ;Debug Str(z)+": "+Str(i-1)+" = "+word(border(z))
         z+1
      EndIf
   Wend

   DataSection
      Data.s "? Define"
      Data.s "?{"
      Data.s "Procedure "
      Data.s "Procedure."
      Data.s "ProcedureC"
      Data.s "ProcedureDLL"
      Data.s "DataSection"
      Data.s "Macro "
      Data.s "If "
      Data.s "With "
      Data.s "Select "
      Data.s "While "
      Data.s "For "
      Data.s "ForEach "
      Data.s "Repeat"
      Data.s "Structure "
      Data.s "StructureUnion"
      Data.s "Interface "
      Data.s "Enumeration"
      Data.s "CompilerIf "
      Data.s "CompilerSelect "
      Data.s "ImportC "
      Data.s "Import "
      Data.s "!"                     ; border(0)

      ; kurzzeitig ''ausrucken''
      Data.s "Case "
      Data.s "Else:"                  ; needed!
      Data.s "Else "                  ; needed!

      Data.s "ElseIf "
      Data.s "Default "               ; ???
      Data.s "Default"
      Data.s "CompilerElse"
      Data.s "CompilerCase"
      Data.s "CompilerDefault"
      Data.s "!"                     ; border(1)

      Data.s "? EndDefine"
      Data.s "?}"
      Data.s "EndProcedure"
      Data.s "EndDataSection"
      Data.s "EndMacro"
      Data.s "EndIf"
      Data.s "EndWith"
      Data.s "EndSelect"
      Data.s "Wend"
      Data.s "ForEver"
      Data.s "EndStructure"
      Data.s "EndStructureUnion"
      Data.s "EndInterface"
      Data.s "EndEnumeration"
      ;Data.s "CompilerEndIf"      ; wird schon bei 'EndIf' entdeckt
      ;Data.s "CompilerEndSelect"   ; analog oben
      Data.s "EndImport"
      Data.s "!"                  ; border(2)

      Data.s "Next "               ; viele Variablen beginnen mit Next...
      Data.s "Next:"               ; blod, da kann nach 'Until' noch Text kommen...
      Data.s "Until "               ; detto
      Data.s "!",""               ; border(3)

   EndDataSection
; 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 FindCommas(s.s)
   LeftC=0
   LeftD=0
   RightC=0
   RightD=0
   RightP=0
   l.l=Len(s)
   c.l=0
   While c<l
      b.l=PeekB(@s+c)
      c+1
      Select b
      Case 59      ; Semicolon
         RightC=c
         If LeftC=0 : LeftC=c : EndIf
      Case 34      ; DoubleQuote
         RightD=c
         If LeftD=0 : LeftD=c : EndIf
      Case 58      ; Colon
         RightP=c
      Case 9,32
         If c=RightP+1 : RightP+1 : EndIf
      EndSelect

   Wend
EndProcedure
Procedure.s RightCut(s.s,x.l)
   ProcedureReturn RTrim(Left(s,x-1))
EndProcedure
Procedure.s StringS(n, chars.s)
   Protected s.s=""
   While n>0
      s+chars
      n-1
   Wend
   ProcedureReturn s
EndProcedure

;{ AutoIndent Installation }

   ; > 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 aftzer tool has quit'

;}
Procedure Init()

   ; Dateinamen holen...
   CompilerIf 1
      If CountProgramParameters()<>3
         MessageBox_(0,"'AutoIndent' benotigt Parameter!"+#CR$+"(%TEMPFILE und %SELECTION und 'PureBasic.prefs' File Location "+")"+Chr(13)+"'C:\Program Files\PureBasic 5\Catalogs\purebasic.prefs' or"+Chr(13)+" 'C:\Users\%USER%\AppData\Roaming\PureBasic\PureBasic.prefs' - on Windows 7 ! ","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,"'AutoIndent' konnte keine Temporardatei 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"))
   PureBasic_prefsFileLocation=ProgramParameter()
   
   
   If Startzeile>=Endzeile
      Startzeile=1
      Endzeile=#MAXSHORT
   EndIf

   OpenPreferences(PureBasic_prefsFileLocation); ok
   PreferenceGroup("Global")
   If Val(ReadPreferenceString("RealTab","0")) Or (GetKeyState_(#VK_CONTROL)&$80)
      Global indtxt.s=#TAB$
   Else
      Global indtxt.s=Space(Val(ReadPreferenceString("TabLength", "2")))
   EndIf
   ClosePreferences()

EndProcedure
Procedure Doit(mode.l)

   ; Doit(0)   auto indent the source code
   ; Doit(1)   trims source code from space And tab characters

   init()

   ReadFile(1,InputFile)
   CreateFile(2,OutputFile)

   indent.l=0


   While Not(Eof(1))
      z.s=ReadString(1)
      zeile.l+1

      z=righttrim(z)      ; rechts kann man immer saubern

      If zeile>=Startzeile And zeile<=Endzeile

         z=lefttrim(z)      ; links nur, wenn gewunscht...

         afterburner.l=0

         If (mode=0) And (Len(z)>0)

            If Asc(z)=';'; ";"
               If Left(z,25)="; IDE Options = PureBasic"
                  indent=0
               Else
                  For i=1 To exceptions
                     If Mid(z,2,Len(exception(i)))=exception(i)
                        PokeB(@z,254) ; "?"
                        Break
                     EndIf
                  Next i
               EndIf
            EndIf

            s.s=z

            FindCommas(s)
            ; [1]   If a=0      ; remark
            ; [2]   If a=''x''   ; remark
            ; [3]   If a=0      ; ''remark''
            ; [x]   If a=''x''   ; ''remark''
            If LeftC
               If LeftD=0 Or LeftC<LeftD   ; [1], [3]
                  s=RightCut(s,LeftC)
               ElseIf RightC>RightD      ; [2]
                  s=RightCut(s,RightC)
               EndIf
            EndIf

            For i=1 To #Words
               l.l=Len(word(i))
               Select i
               Case 1 To border(1)
                  p.l=1
               Case 1 To border(2)
                  p.l=Len(s)-l+1
               Case 1 To border(3)
                  p.l=RightP+1
               EndSelect

               If Mid(s+":",p,l)=word(i)

                  Select i
                  Case 1 To border(0)
                     afterburner.l+1

                  Case 1 To border(1)
                     indent-1
                     afterburner.l+1

                  Case 1 To border(3)
                     If afterburner
                        afterburner-1
                     Else
                        indent-1
                     EndIf

                  EndSelect
               EndIf

            Next i

            If Asc(z)=254 ; "?"
               PokeB(@z,';') ; ";"
            EndIf

            z=strings(indent,indtxt)+z

         EndIf ; mode

      EndIf ; Zeilenselektion

      WriteStringN(2,z)
      indent+afterburner
   Wend
   CloseFile(1)
   CloseFile(2)

EndProcedure

Doit((GetKeyState_(#VK_SHIFT)&$80))
On win7 & PB5.00 works perfectly! :D
Post Reply