====== About the script ====== * Purpose : This script will autoindent and remove unneeded spaces and tabs in other scripts * Author : [[https://plus.google.com/+LukasMorawietz|LM13]] * Current Version : 2.0 * Link : https://plus.google.com/115366157037831519359/posts/RjizoNAYKsc ====== Changelog ====== * Version 1.0 (22/7/2014): initial release in wiki * Version 1.1 (23/7/2014): line breaks stay as they are, fix for strings and comments, double spaces and backslashes * Version 1.2 (25/7/2014): fix for backslashes, keywords, added switch support * Version 1.3 (29/8/2014): option to write directly to script files (default: on) * Version 2.0 (14/9/2014): new UI, option to format all Scripts ====== How to use the script ====== * Run from anywhere * choose something * copy/paste the output if not using directWrite ====== Issues and Hints ====== * When formatting all scripts it really may take some time! Don't click anywhere and when a Dialog pops up "LLX is not reacting" tap wait. **//This Standalone Version is discontinued! Use [[script_multitool|Multitool]] instead, it's included there.//** //please report all bugs in the g+ community!// ====== Script ====== //config var directWrite=true;//wether to show a prompt or write directly to the script //endconfig //Initialize List //import java classes LL.bindClass("android.app.AlertDialog"); LL.bindClass("android.content.DialogInterface"); //function to display a List in a Popup, where the user can select one item list=function(items,listener,title) { var builder=new AlertDialog.Builder(LL.getContext()); builder.setItems(items,listener); builder.setCancelable(true); builder.setTitle(title); builder.setNegativeButton("Cancel",new DialogInterface.OnClickListener(){onClick:function(dialog,id){dialog.cancel();}});//it has a Cancel Button builder.create().show(); } //create Strings to display var title="Which script?"; var items=[]; var scripts=LL.getAllScriptMatching(Script.FLAG_ALL); for(var z=0;z0)//special handling when in switch command { switchLevel=0; i--; } } if(newLine&&t[a]!="\n")//indent the next line { indentLine(); } if(t[a]=="{")i++;//function block start if(t.slice(a,a+7)=="switch(")switchLevel=++i;//start of switch command } out=out.concat(t[a]);//concat the char } while(out[out.length-1]=="\n")out=out.slice(0,out.length-1);//remove unnessecary line brakes at the end of the script if(directWrite)//set output to the script { s.setText(out); if(y==selected.length-1)Android.makeNewToast("Done!",true).show();//notify if finished } else prompt("",out);//show output } } } //show selection list list(items,listener,title); //creates tabs at the beginning of a line function indentLine() { for(b=(switchLevel!=0&&(t.slice(a,a+4)=="case"||t.slice(a,a+7)=="default")?1:0);bb.toLowerCase())return 1; if(a.toLowerCase()