Jump to content

Tidy Your Script File


Jos
 Share

Recommended Posts

  • Developers

Been working on a script that cleans up the indentation of au3 scripts and though i would share it with you...

It will replace the leading Spaces/Tabs with the correct number of spaces/tabs to make the script more reable.

comments/suggestions are welcome :whistle:

EDIT: Updated with Continuation lines support....

EDIT: source now in a later post

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

nope... will look at that... tnx

EDIT: Removed the remark.... don't know what happend but downloaded the original and that looks ok..

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

One suggestion. Often if I have a very complicated line of code then I hand format it (in AutoIt, using the line continuation character). It would be nice to be able to turn the formatting off and on again using keywords - these would have to contained in comments so as to avoid messing up the script. Perhaps

;;;Tidy-Off
  MsgBox(0, "", "Contrived example that will come out as a sort of table" & @LF &_
                "   1       One" & @LF &_
                "   2       Two")
;;;Tidy-On

As for the script - great.

When I'm reading other peoples scripts that don't indent then the first thing I do is go through and add spaces! Now I can do this automatically.

Perhaps we can find a way to run all code samples sent to the forum through this script prior to being displayed :whistle:

GrahamS

Link to comment
Share on other sites

  • Developers

Perhaps we can find a way to run all code samples sent to the forum through this script prior to being displayed  :whistle:

Must be possible... right Jon ??? B)

Seriously... just update the above script to cope with continuations..

It does 2 extra tabbings for the continued lines...

Would that solve your issue ??

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Seriously... just update the above script to cope with continuations..

It does 2 extra tabbings for the continued lines...

Would that solve your issue ??

Was about to say no, but then thought a bit more :whistle:

A little bit of reformatting on my part will achieve the effect I'm looking for and still be compatible with your modified script, i.e.

MsgBox(0, "", _
   "Contrived example that will come out as a sort of table" & @LF &_
   "   1       One" & @LF &_
   "   2       Two")

should not be modified by your script

Thanks

GrahamS

Link to comment
Share on other sites

  • Developers

A little bit of reformatting on my part will achieve the effect I'm looking for and still be compatible with your modified script, i.e.

Not sure if i understand this... the script removes ALL leading spaces and TAB characters and then start formatting.

In case of a continuation the script will do the following:

(assume you specified 3 spaces as the indent characters and i replaced a space by a dot just to show what it does)

...MsgBox(0, "", "Contrived example that will come out as a sort of table" & @LF &_
........."   1       One" & @LF &_
........."   2       Two")

as Larry would say: Trust me...just run it and see what it does.... :whistle:

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Let me see if I can explain. What I want to do, say, is to have all three lines in the message box text line up (I do this a lot using message box when I have multiple lines so that I can see how it will appear when the program is run). So, replacing spaces by dots, my original was

.MsgBox(0, "", "Contrived example that will come out as a sort of table" & @LF &_
..............."   1       One" & @LF &_
..............."   2       Two")

As you pointed out, when using an ident of 3 spaces it is tidied to look like

...MsgBox(0, "", "Contrived example that will come out as a sort of table" & @LF &_
........."   1       One" & @LF &_
........."   2       Two")

Not what I want, since the quotes on line 2 are not lined up with the quote at the start of "Contrived...

But what I realised was that I could reformat my original a bit to look like

...MsgBox(0, "", _
........."Contrived example that will come out as a sort of table" & @LF &_
........."   1       One" & @LF &_
........."   2       Two")

Has everything lined up like I want, plus when the tidy script is run on this it will basically leave it alone.

So I'm happy. You can forget about my request for keywords to turn tidying off and on - I don't need it.

So to paraphrase Larry - I trust you, I've seen what it does and I like it

GrahamS

Link to comment
Share on other sites

  • Administrators

When I'm reading other peoples scripts that don't indent then the first thing I do is go through and add spaces!

David mocks me when I say that I have to do this to read his and C code. :whistle:

I'm completely code blind unless something is perfectly indented at tab size 2/4. If I can't see the obvious block structure from the other side of the room then it's just gibberish.

Link to comment
Share on other sites

  • Developers

Added functionality to the Tidy Script that will change all Keyword/function/macros to proper case.

EDIT 2/26:

- update to be able to cope with Select inside Select.

- created the possibility to run it agains the script you edit:

Just compile the script to tidy.exe. create an userfunction in your editor to call tidy.exe "yourscripfilename" ....

It will in this case create an backup called scriptname.old?.au3 where ? is an sequence number.

EDIT: its available on Yahoo called "tidy.zip" ... it contains the script and needed tables. http://groups.yahoo.com/group/AutoItList/files/AU3/UTIL/

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Where can we get hold of this script - I had a quick look in the usual places - couldn't find it.

The script that you see listed is "it" ..... :whistle:

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Script won't run because functions.txt isn't present.

Any thoughts?

ok ...understand now. :whistle:

I made the whole thing available on yahoo called "tidy.zip" ... it contains the script and needed tables. http://groups.yahoo.com/group/AutoItList/files/AU3/UTIL/

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Gave this tidy up script an outing - it looks really good - my smaller scripts were tidied up nicely..but..

my big script (2500 lines... don't ask!!) didn't get tidied. All the leading spaces were removed and that was that.

its not the end of the world but.. I thought I'd let you know. :whistle:

Keep up this great work.

Link to comment
Share on other sites

  • Developers

Added/changed the following in this version:

- write warning comment line into the script when indentation fails like on old v3 scripts that don't have a Then at the end of a If statement.

- Added the userfunctions and internal functions to the set to proper case.

- Added Binary array search to speed it up a bit

- Added Sort function to sort the input files

- Changed the backup name from:XYZ.AU3.old1 to XYZ.old1.AU3

- bug fixes in indentation logic

To download: http://www.hiddensoft.com/fileman/users/jdeb/tidy.zip

Description from the script:

; Script Function: Tidy au3 scripts
; What does it do:
; 1. $TABCHAR -> Cleans up the indentation of au3 scripts with spaces or Tabs.
; 2. $PROPER -> When Set to 1:
;    The script will also change all Functions/Keywords/Macros to proper case as defined in the
;    files made available by Jon.
;    $UserFunc -> When set to 1
;    Also All userfunctions from Userfunctions.txt and all FUNC in the script are loaded into
;    the Functions table. Only works when $PROPER=1
; 3. $VARS -> Script can chance all Variables to Uppercase or Lowercase.
;
; This script will prompt for an AutoItscript file lets say XYZ.AU3
; It will create a new file called XYZ_N.AU3 that is properly indented with spaces or Tabs
;
; IT also has the possibility to run it agains the script you edit:
;    1. Just compile the script to tidy.exe.
;    2. create an userfunction in your editor to call tidy.exe "yourscripfilename" ....
;    It will in this case create an backup called scriptname.old?.au3 where ? is an sequence number.
;    When finished the original file is copied to XYZ.AU3.old1 and the original is replaced.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Found some more "special situation" the script didn't coupe with correctly.

Changed and uploaded the script (ver 0.2.10)

If you find any more issue, please let me know...

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

uploaded a new version (0.2.11) with some added functionality:

$ENDFUNC_COMMENT-> Add a comment after EndFunc like : "EndFunc;==> FunctionName"
$GEN_DOC->   0=no 1=yes 2=prompt
                Generates documentation file with program logic and Xref reports for Variables and UDF's.

Example Documentation:

--snip--
0067  ; ===============================
0068  ; Get input and check output file
0069  ; ===============================
0070    $FILE = ""
0071  +-If $CMDLINE[0] = 1 Then
0072  |    $FILE = $CMDLINE[1]
0073  |    $OFILE = StringReplace($FILE,'.au3','_x.au3')
0074  |    FileRecycle($OFILE)
0075  +-Else
0076  |  +-While Not FileExists($FILE) Or StringRight($FILE,4) <> '.au3'
0077  |  |    $FILE = FileOpenDialog( "...to Tidy?","", "AutoIt3(*.AU3)", 1 )
0078  |  |  +-If @error = 1 Then
0079  |  |  |    $RC = MsgBox(4100, "AutoIt3 Tidy", "Do you want to ....?" )
0080  |  |  |    If $RC = 6 Then Exit
0081  |  |  +-EndIf
0082  |  +-Wend
0083  |    $OFILE = StringReplace($FILE,'.au3','_n.au3')
--snip--
======================
=== Xref reports =====
======================
Function/Variable name ==> Row(col)  col = char. position after the first non space/tab character

== UserFunctions=====================
_Doc_Functions => 568(31),725(6)
_Doc_Variables => 592(20),709(6)
_FileRead2Array => 154(1),161(1),168(1),687(6)
BinarySearch => 566(8),595(7),597(7),624(6)

== Variables ================================
$A_SIZE => 653(1),654(12),658(19)
$ALL_REC => 693(1),698(4),699(1),701(1),701(13),704(24)
$BS_RC => 54(8),566(36),568(19),595(32),597(34),624(54),640(1),643(1)
$C_DIM => 668(5),669(26),670(18),670(50),671(25)

Comments/Suggestions/Problems ? let me know... tnx

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...