It is currently Wed Apr 24, 2019 5:28 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Code Beautyfier for the IDE (also useful for jaPBe)
PostPosted: Sun Jan 06, 2008 5:17 am 
Offline
Enthusiast
Enthusiast

Joined: Thu May 06, 2004 4:28 pm
Posts: 406
Location: Cologne/GER
While working on the OOP parser which outputs the converted code also in a beautyfied way, I thought this also would be nice as a standalone plugin.

Its a Plugin primary build for the IDE but it also does it's job with jaPBe properly.

The beautyfing will be performed on the selected code area.

It also does handle code to be indented within Macros properly like ...
Code:
Macro TestCode()
  If x < 0
    If r = j
      z = x
EndMacro


And ... it does re-arrange the tokens of the selected code.
Like:
Code:
Procedure.l Functions (a,b,c, e.l, string="default" )
  Protected j.l =0
  if a+b /c= gVar
   string="hello"
  Endif
EndProcedure:FreeMemory( *mem)

#CONSTANT_A = $FF
#ERROR = 0
#DELETE_KEYWORD = "del"

gets polished to ...
Code:
Procedure.l Functions(a, b, c, e.l, string = "default")
  Protected j.l = 0
  if a + b / c = gVar
   string = "hello"
  Endif
EndProcedure : FreeMemory(*mem)


#CONSTANT_A     = $FF
#ERROR          = 0
#DELETE_KEYWORD = "del"

Also all unneeded white spaces at the end of codelines will be deleted.

To apply this function

The code is a simple merge of two modules: The code from Remi meiers lexer in combination with a Tokenarray and the Indentation tool of HeX0R.
http://www.purebasic.fr/german/viewtopic.php?t=8691
http://www.purebasic.fr/german/viewtopic.php?t=10418

In case of jaPBe Im forced to use "%FILE" instead of the argument "%TEMPFILE" as used in the IDE. This makes jaPBe overwriting the existing original code, so you can decide by altering the setup of the tool if you first want to try by letting the plugin writing the cleaned up code into a new file instead of overwriting the existing one.

Here's a howTo install of the pluigin for the IDE:

Image

Now there is a new syntax for the arguments used.
When using this plugin with the IDE the argument "%TEMPFILE" is still obligatory. Beside Indentation there can be done a codebeautifying as well, just add the argument -b and for a proper alignment of PB contants Lines just add -c.
You also can set up individual entries in the tools section where only the indentation will be applied, or combined with -b, or even combined with -b and -c.

The argument syntax "%TEMPFILE" "%SELECTION" "%BEAUTIFY" will be no longer supported.


And for jaPBe:

Image

In case of jaPBe instead of just "%TEMPFILE" you HAVE TO use "%FILE" "%SCI and if wanted followed by -b and -c (see above). Also here you can setup individual entries in the jaPBe's tools section using individual arguments.
As said, be aware the in the example above jaPBe does reload the cleaned up code into the current source. As this state actually is beta, you should work with copies for testing purposes or let the tool reload the code into a new source.
Means: This is beta, so no warranty.

Update: http://www.file-upload.net/download-600 ... y.exe.html
Here still a link to the old version - just in case.




An alternate version where the operators wont be separated by whitespaces:
http://www.file-upload.net/download-600 ... s.exe.html
Here as well a link to the old version.

Code:
Procedure.l Functions (a,b,c, e.l, string="default" )
  Protected j.l =0
  if a+ b /c= gVar
   string= #PB_Compiler_Home + "File.pbi"
  Endif
EndProcedure:FreeMemory( *mem)

... becomes ...
Code:
Procedure.l Functions(a, b, c, e.l, string="default")
  Protected j.l=0
  if a+b/c=gVar
   string=#PB_Compiler_Home+"File.pbi"
  Endif
EndProcedure : FreeMemory(*mem)




Changelog:

09.01.2007:
- New Syntax of arguments
- Selection now also supported for jaPBe
- Constand assignments now can be aligned horizontally to "=" (like in jaPBe's Select+ALT+STR+TAB)

06.01.2007:
-Bugfix if "If \number" was used, no whitespace Separator has been applied.

_________________
Check out OOP support for PB here!


Last edited by inc. on Mon Jan 21, 2008 12:12 pm, edited 6 times in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jan 06, 2008 5:26 am 
Offline
Addict
Addict
User avatar

Joined: Sat Jun 30, 2007 8:04 pm
Posts: 3237
I prefer to remove white space from between my operators in the exact opposite way of your beautifier. :roll:

Thanks for making this tool though. I know that a lot of people here do like that style.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jan 06, 2008 5:27 am 
Offline
Enthusiast
Enthusiast

Joined: Thu May 06, 2004 4:28 pm
Posts: 406
Location: Cologne/GER
Then, just deactivate the beautfy function.

EDIT: If other beautifying styles are wanted, maybe give me an example where finally individual styles can be archived by using a prefernce file.

_________________
Check out OOP support for PB here!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jan 06, 2008 1:14 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu May 06, 2004 4:28 pm
Posts: 406
Location: Cologne/GER
Added a version to the first post where Operators won't be whitespace-separated.

_________________
Check out OOP support for PB here!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jan 08, 2008 4:07 am 
Offline
Enthusiast
Enthusiast

Joined: Tue Oct 31, 2006 4:34 am
Posts: 527
Thanks inc.

Nice programs.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jan 08, 2008 10:27 pm 
Offline
Enthusiast
Enthusiast

Joined: Sat Apr 26, 2003 5:08 pm
Posts: 404
Location: Denmark
Many Thanks inc. 8) :D

Best Regards Henrik.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Jan 09, 2008 10:35 am 
Offline
Enthusiast
Enthusiast

Joined: Thu May 06, 2004 4:28 pm
Posts: 406
Location: Cologne/GER
Update.
See changelog.

_________________
Check out OOP support for PB here!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Jan 11, 2008 9:36 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Feb 16, 2006 1:41 am
Posts: 179
Location: New Zealand
Very nice inc.! Beautify-full :D

Any chance of indenting StartDrawing/StopDrawing with optional assignment of the returned handle (e.g. hdc = StartDrawing())

The more whitespace, the better I say. While we're on the whitespace track - any chance of adding spaces after/before brackets "()"? Or the source code? Or an INI file with which options to enabledisable?

Cheers inc.!!!!


P.S.
Code:
   Define.d ang_div =(#PI / 45)

Brackets next to equals sign throws it off.

_________________
Win8.1, PB5.x, okayish CPU, onboard video card, fuzzy monitor (or is that my eyesight?)
"When the facts change, I change my mind" - John Maynard Keynes


Last edited by Amundo on Fri Jan 11, 2008 10:00 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Jan 11, 2008 9:55 am 
Offline
Enthusiast
Enthusiast

Joined: Thu May 06, 2004 4:28 pm
Posts: 406
Location: Cologne/GER
Hi Amundo,

as Startdrawing() isn't a Keyword but a command, so indentation is not planned on this.
But in future this Plugin will check the IDE's (and also jaPBe's, when providing EnVars while compiling will be officially supported by jaPBe) preferences for user folding keywords, where these also will be added to the indentation. So thats how you could add individual Tokens to the indentation list.

Whitespaces before and after brackets in general would mess up things like
Code:
Procedure TestFuntion ()

NewList LongTypeList ()
AddElement ( LongTypeList () )
LongTypeList () = 100

see the point? ;-)

_________________
Check out OOP support for PB here!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Jan 11, 2008 10:03 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Feb 16, 2006 1:41 am
Posts: 179
Location: New Zealand
I was just thinking about spaces after opening / before closing brackets, but that's okay.

Was editing my original post (about a bug) when you posted :)

_________________
Win8.1, PB5.x, okayish CPU, onboard video card, fuzzy monitor (or is that my eyesight?)
"When the facts change, I change my mind" - John Maynard Keynes


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jan 20, 2008 9:03 pm 
Offline
User
User

Joined: Wed Jan 24, 2007 12:15 pm
Posts: 27
I'm using this tool with the original PB IDE. Nice job, thank you!
While i was using it, i've noticed something strange:

Start with a "beautified" source, modify a line so that it will be modified by the tool, then select some lines which are already beautified (don't select the modified one) and execute the beautifier. Nothing will be modified and this is ok.

Then if you run the tool again with nothing selected, the "bad" line won't be modified, while this time it should be.

The arguments are: "%TEMPFILE" -b -c and actually i can't figure out whether the problem lies in your tool or in the ide itself, since i don't understand how the information about the selected lines is passed to codebeautifier.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jan 20, 2008 9:29 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu May 06, 2004 4:28 pm
Posts: 406
Location: Cologne/GER
Quote:
... Then if you run the tool again with nothing selected ...

Sorry Ive forgot to mention in here: You must select an area to be beautyfied, like in jaPBes's STRG+TAB where you also actually do indent the selected area.

_________________
Check out OOP support for PB here!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jan 20, 2008 9:55 pm 
Offline
User
User

Joined: Wed Jan 24, 2007 12:15 pm
Posts: 27
inc. wrote:
Quote:
... Then if you run the tool again with nothing selected ...

Sorry Ive forgot to mention in here: You must select an area to be beautyfied, like in jaPBes's STRG+TAB where you also actually do indent the selected area.


Ah, ok, i see.. i've looked into it further and i think i was misleaded by the fact that it indents the line where the cursor is, even if it's not selected. So i had wrongly assumed it was working also with nothing selected.

Very useful tool! thanks again.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Jul 12, 2008 5:26 pm 
Offline
User
User
User avatar

Joined: Wed Jan 16, 2008 11:28 am
Posts: 84
Location: china
"%TEMPFILE" "%SELECTION" "%BEAUTIFY"

The version from pureare.net downloaded, if that is the latest version ?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Jul 16, 2008 11:26 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Jul 03, 2008 10:13 pm
Posts: 504
Location: Kent, UK
This works pretty well, however one 'hitch' is that comments get indented to the level of any code, is there an easy way to stop this happening.
Thanks

<edit>
Also if '>=' and '<=' could not be spaced into '> =' & '< ='
</edit>

_________________
%101010 = $2A = 42


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye