Auto indenter - again

Share your advanced PureBasic knowledge/code with the community.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

eJan wrote:Thanks Derek!
I have commenteted indenter line:

Code: Select all

;RenameFile(pps,pps+".bak")
Is there a solution to make indentation only (without modifying the source), closing it without msgbox to save changes?
The file that the above line makes is a backup of the original source, unmodified, once you run a tool on a file and reload the file back in (which is what the indenter is doing) then that source is flagged by the IDE as being unsaved and so it will always ask if you want to save.

If you don't rename the source as a backup and save a modified source as the backup instead then it won't get reloaded as the names won't match so I don't really see any other way of doing this, sorry. :(
eJan
Enthusiast
Enthusiast
Posts: 366
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Post by eJan »

O.K., thanks!
eJan
Enthusiast
Enthusiast
Posts: 366
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Post by eJan »

Me again. :oops:
How to make it to work with structures?

Code: Select all

  Structure Person
    Name.s
    ForName.s 
    Age.w 
  EndStructure

Code: Select all

Structure Person
Name.s
ForName.s
Age.w
EndStructure
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

It should already be working, it does on mine. Just cut and pasted your bit of code above and it worked on that. :?
eJan
Enthusiast
Enthusiast
Posts: 366
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Post by eJan »

Derek wrote:It should already be working, it does on mine. Just cut and pasted your bit of code above and it worked on that. :?
Unfortunately not, I have added "procedure." to recognize Procedure types but then Structure is not recognized. This is My output:

Code: Select all

Procedure a(a, b, c=2)
  Debug c
EndProcedure

Procedure.s Attach(String1$, String2$)
  ProcedureReturn String1$+" "+String2$
EndProcedure

Structure Window
*NextWindow.Window  ; Points to another window object
x.w
y.w
Name.s[10]  ; 10 Names available (from 0 to 9)
EndStructure
Indenter changes:

Code: Select all

  Data.s "if ","for ","while ","repeat ","procedure ","procedure.","select ","datasection " 
  Data.s "macro ","compilerif ","compilerselect ","structure "
:(
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Code: Select all

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 
By adding 'Procedure.' you have increased the number of '#plus' finds by one and so 'structure' has fallen off the end, as it were.

If you increase the number in the line above that reads '#plus=11' to 12 that should work.

Basically, count how many keywords you have in each section of data and put it in the variable before each section.

Hope this helps. :)
eJan
Enthusiast
Enthusiast
Posts: 366
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Post by eJan »

Derek wrote: By adding 'Procedure.' you have increased the number of '#plus' finds by one and so 'structure' has fallen off the end, as it were.

If you increase the number in the line above that reads '#plus=11' to 12 that should work.

Basically, count how many keywords you have in each section of data and put it in the variable before each section.

Hope this helps. :)
Great, that do the trick.
Thanks a lot! :D
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

I use this, works in all situations correct for me, also in linux:
http://www.purebasic.fr/german/viewtopi ... r&start=10
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply