LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

`A`u`t`o`m`a`t`i`c` `I`n`d`e`n`t`e`r`

Root / Submissions / [.]

12Me21Created:
Version:1.1Size:2.39KB
A big problem with SmileBasic is that it doesn't automatically indent your code. I made a program that adds proper indenting (based on TABSTEP) to another program.

Instructions:

Make sure AUTO_INDENT is in the same folder as the program you want to modify (Also make sure you have nothing important in slot 3) Open AUTO_INDENT and enter the other program's name. Press [Yes]/[OK]/whatever to load and save the file

Notes:

Doing things like IF X=1 THEN BEEP ' THEN IF X=1 THEN 'comment BEEP ENDIF NEXT:NEXT will mess up the indenting (It shouldn't harm the program though)

This is probably one of the most useless programs here. You know that you could just press space and it will automatically keep that indention for future lines. Still don't know how this would be useful.... sorry.

Replying to:Defaultio
This is probably one of the most useless programs here. You know that you could just press space and it will automatically keep that indention for future lines. Still don't know how this would be useful.... sorry.
It indents an otherwise non-indented code file. It can fix the indenting on a file which has broken indenting (if it works correctly).

Replying to:Defaultio
This is probably one of the most useless programs here. You know that you could just press space and it will automatically keep that indention for future lines. Still don't know how this would be useful.... sorry.
Yes, it converts any code into code with proper indenting. For example: WHILE 1 BEEP WEND would be converted to WHILE 1 BEEP WEND Etc.

I like this idea! I don't know yet if it works correctly but I don't see why not :) Here's a tip for fixing the problem you described: 1. Find where a comment starts in a line. Comments start with the first ' character that isn't inside a string 2. Remove the comment entirely (for your internal processing only) 3. Remove any trailing whitespace. 4. At this point you can just use the code you already have, maybe with a few tweaks (for example, you need to put the comment back in) 5. Hopefully, bug-free automatic indentation!

Replying to:NeatNit
I like this idea! I don't know yet if it works correctly but I don't see why not :) Here's a tip for fixing the problem you described: 1. Find where a comment starts in a line. Comments start with the first ' character that isn't inside a string 2. Remove the comment entirely (for your internal processing only) 3. Remove any trailing whitespace. 4. At this point you can just use the code you already have, maybe with a few tweaks (for example, you need to put the comment back in) 5. Hopefully, bug-free automatic indentation!
I will try to add this eventuallly. Luckily, the comment problem only affects IF ... THEN 'COMMENT ... ENDIF and (this is rare) IF ... THEN ... ' THEN . The main issue is things like: NEXT:NEXT. That will me much harder to solve.

Replying to:NeatNit
I like this idea! I don't know yet if it works correctly but I don't see why not :) Here's a tip for fixing the problem you described: 1. Find where a comment starts in a line. Comments start with the first ' character that isn't inside a string 2. Remove the comment entirely (for your internal processing only) 3. Remove any trailing whitespace. 4. At this point you can just use the code you already have, maybe with a few tweaks (for example, you need to put the comment back in) 5. Hopefully, bug-free automatic indentation!
Oh, and also there's the problem of ' inside of strings, where it doesn't make a comment.

I finally have a solution! Originally I was lazy (and efficient), and only checked the first "word" (text with a space after it) in each line, except when the first word was "IF", where I had to check if the final 4 characters were "THEN" This causes problems when people do stuff like NEXT:NEXT (even the first one isn't detected because there's no space) REPEAT:UNTIL BUTTON() etc. So now I have a new solution!

Replying to:12Me21
I finally have a solution! Originally I was lazy (and efficient), and only checked the first "word" (text with a space after it) in each line, except when the first word was "IF", where I had to check if the final 4 characters were "THEN" This causes problems when people do stuff like NEXT:NEXT (even the first one isn't detected because there's no space) REPEAT:UNTIL BUTTON() etc. So now I have a new solution!
I made a function to check a line for valid occurances of a keyword. The rules it uses are: -It can't be inside a string -It can't be in a comment (comments start with ' outside a string)* -It can't have a LETTER, @, or _ directly in front of it -It can't have a NUMBER, LETTER, $, #, %, or _ directly after it I think this covers every possible scenario. So now, I can just do INLIN(LINE$, IF,0), for example, and find out if that line has the keyword IF in it (and not something like ENDIF) Now, I just need to make it find multiple keywords... And... Detect non-block IF statements. I think that could be detected if I checked if there was anything besides : , ' , or spaces after THEN... UGH... *REM is not technically a comment marker, it is just a statement that does nothing. And no one uses it.

Replying to:12Me21
I finally have a solution! Originally I was lazy (and efficient), and only checked the first "word" (text with a space after it) in each line, except when the first word was "IF", where I had to check if the final 4 characters were "THEN" This causes problems when people do stuff like NEXT:NEXT (even the first one isn't detected because there's no space) REPEAT:UNTIL BUTTON() etc. So now I have a new solution!
I'm just trying to think what how smileBASIC determines this, and not how I would do it, since I might miss something.. So, It seems that if there is anything after the THEN, except space and CR, (and comments,) it will be considered a single-line IF statement. So then I do something like IF {the line has IF in it} THEN IF {the line has THEN in it, and nothing is after THEN (except comments...)} THEN INC I, TAB ENDIF ENDIF comment detection... hmm...

I'll have a vastly improved version in a day or two.

Currently testing the final version. Seems to be 100% perfect. It's currently not optimized, and taking probably a hour to edit GIVERS_APP (very big program)

DONT USE THIS ONE!!! I have a new version coming VERY SOON!

Replying to:12Me21
DONT USE THIS ONE!!! I have a new version coming VERY SOON!
1 year ago Can you post the original source code on Pastebin, I actually enjoyed this very much and deleted it by accident