AutoHotkey Community

It is currently May 25th, 2012, 9:29 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 55 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
PostPosted: February 25th, 2005, 1:04 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
This is an old thread. The new thread with a newer version can be found here:
www.autohotkey.com/forum/viewtopic.php?p=46338


Dear all,
This is version 6 of a script for all those people like me and Hajos who get lazy with adjusting the indentation manually as it should be (for readability of the script). Until now it works ok for our scripts. Have a try and test it. (To work correctly for hotstrings or hotkeys a space or comma has to be between the colon ":" and the action to be performed). We are open for suggestions. Please see also notes in the scripts header.

Image

Happy scripting

Code:
Code removed, because it is out of date


Edit: 2005-02-26: (Fixed) If a rememberstring was last command in file without a newline, it wasn't put into the new file. (thanks ChrisM)

Edit: 2005-02-26: New: Changed the whole script. New Functionality, new Options, new Gui, two style options, option to use tabs or spaces, fixed some indentation for complex block structures.

Edit: 2005-03-03: Script now supports one-line if-statements.

Edit: 2005-03-07:
- Added new functionality: a)Case Correction, b) Gui remembers Position on screen
- Script name has changed to reflect these changes

Edit: 2005-03-09:
- Added new functionality: Gui remembers settings between sessions
- Hotkey has changed to F2
- Fixed: Indentation within a editor was damaged, due to `r`n at end of line (thanks AGU)
- Fixed: Indentation within a editor added additional ´n each time
- Improved speed (setbatchline)

Edit: 2005-06-06:
- Added indentation and casecorrection for functions (thanks to HJS)

Edit: 2005-06-09:
- Added indentation for continuation lines (thanks to HJS)
- Made Hajos a co-author

_________________
Ciao
toralf
Image


Last edited by toralf on February 3rd, 2006, 7:28 am, edited 12 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2005, 1:45 pm 
Und, was sagt Deine Frau zu dem Script ? :twisted:
OK, OK - war nicht so gemeint. :wink:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2005, 2:14 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
Woah, great stuff !

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2005, 3:16 pm 
Offline

Joined: March 28th, 2004, 3:53 pm
Posts: 1870
great start toralf! just don't stop here!!

next is applying proper case to commands and keywords... and the indentation needs some optional settings... like u use the first one here, and i use the second:

Code:
loop
  {
     some function
  }


Code:
loop
{
   some function
}


by the way mine has a real tab there..

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2005, 3:23 am 
Offline

Joined: November 28th, 2004, 10:26 pm
Posts: 58
Great script!



One problem I found:
If a script ends with 'return' and no newline after it - the 'return' never gets copied to the new file.

I tracked it down to the 'RememberString' variable. The last 'return' is stored in it but since there is no newline the Loop ends and that 'return' never gets added to the 'String' varialble.

To solve it I moved this section of code to the bottom of the Loop:

Code:
    ;Create current indentation depending on indentation levels
    Indent =
    ;turn AutoTrim off, to be able to process tabs and spaces
    AutoTrim, Off
    Loop, %IndentCount%
        Indent = %Indent%%IndentSize%

    ;If a line had to been remembered from previous loop, add it to string and set it to nothing
    If RememberString
        String = %String%%Indent%%RememberString%

    ;turn AutoTrim on, to remove leading and trailing tabs and spaces
    AutoTrim, On

    ;Clear Rememberstring
    RememberString =


I believe this is safe because the first line in any script should always have
no indentation, so 'Indent' variable need only be set after the first line is read.

_________________
ChrisM


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2005, 12:12 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
Thank you ChrisM,
You are right. I will update the fist post.

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2005, 10:26 pm 
Offline

Joined: November 28th, 2004, 10:26 pm
Posts: 58
Here's a version that indents all text in an active editor window by hotstring Ctl-i
Braces may or maynot be indented as Rajat requested.
Works with hotkeys and hotstrings.

Problems:
- after all text is highlighted(ctl-a) sometimes the script takes a long time to return, the text in the window is left highlighted and vulnerable to deletion.
- with Wordpad every time the hotkey is pressed an empty newline is added to the end of the file. PSPad and Notepad do not have this problem.
- after indentation the cursor is always put to the end of the file. Would be better to put cursor back to the line number it was on when the hotkey was pressed, but this will probably be editor dependant.

Comment from moderator: For the lateset version, see http://www.autohotkey.com/forum/viewtopic.php?t=7810

_________________
ChrisM


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 27th, 2005, 1:29 am 
I found two problems with my script. And it will most propably also happen with ChrisM Script, since it looks like he hasn't changed the indentation part.

Problem 1)
Indentation will be incorrect if there is a one-line if-statement in the code like
Code:
IfEqual, x, 1, Sleep, 1


Problem 2)
There will be problems if the code doesn't use brackets with multiple inclded if-statements, e.g.
Code:
if x = 1
if y =2
if z = 3
MsgBox, toralf doens't do the indentation correct for next line.
MsgBox, this line is indented too much


3)
And what is the correct indentaion of the following example? Chris can you please respond to this, it gives me some trouble:
Code:
if x = 1
if y =2
if z = 3
MsgBox, toralf tried to do the indentation correct.
Else if w =4
if v = 5
MsgBox, I do not were I am
else
MsgBox, I'm totally lost


Thanks.

I will not fix Problem 1. On problem two I'm working. And I hope to fix it when I understand 3. The current workaround is to use {} for every block (loops, ifs, etc.) even if they only have one line in the block.

Though, the code will work fine with
Code:
MsgBox, No indent
if z = 3
MsgBox, indentation
MsgBox, No indentation


Ciao
toralf


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 27th, 2005, 7:10 am 
Offline

Joined: March 28th, 2004, 3:53 pm
Posts: 1870
Nice work ChrisM !
keep going guyz!

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 27th, 2005, 10:53 am 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
Please help/correct me:
Ok, I have played around with 3). Which was

toralf as guest wrote:
And what is the correct indentaion of the following example? Chris can you please respond to this, it gives me some trouble:
Code:
if x = 1
if y =2
if z = 3
MsgBox, toralf tried to do the indentation correct.
Else if w =4
if v = 5
MsgBox, I do not were I am
else
MsgBox, I'm totally lost



Here is what I think is the correct indentation. Please let me know if I'm correct or give help where the error is. Thanks

Code:
if x = 1
    if y = 2
        if z = 3
            MsgBox,up to here indentation should be correct.
        Else if w = 4
            if v = 5
                MsgBox, don't know if correct
            else
                MsgBox, please help
MsgBox, This line should be without indentation,correct?

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 27th, 2005, 11:08 am 
Offline

Joined: March 28th, 2004, 3:53 pm
Posts: 1870
i think that the above is the optimum way.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 27th, 2005, 11:15 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Yes, I think that's the standard way to indent such an extreme example :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2005, 9:19 am 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
I re-wrote the whole script, please see first post. Lot's of requests have been added and bugs fixed.

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2005, 12:51 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
It looks great. Thanks for posting it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2005, 2:21 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
I wonder what Rajat thinks of it?

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 55 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 21 guests


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

Search for:
Powered by phpBB® Forum Software © phpBB Group