User Tools

Site Tools


script_autoformat

**This is an old revision of the document!** ----

A PCRE internal error occured. This might be caused by a faulty plugin

====== 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 : 1.1 * 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 ====== How to use the script ====== * Run from anywhere * type in the exact name of the script you want to format * copy/paste the output * test it, before replacing the old! //please report all bugs in the g+ community!// ====== Script ====== <sxh javascript;>var s=LL.getScriptByName(prompt("Which script?","")); try { var t=s.getText(); } catch(NullPointerException) { alert("script not found"); return; } var out=""; var i=0; var noCode=false; var starter; var newLine=true; for(a=0;a<t.length;a++) { if(!noCode&&((t[a]==" "&&(out[out.length-1].toLowerCase()==out[out.length-1].toUpperCase()||t[a+1].toLowerCase()==t[a+1].toUpperCase()))||(t[a]=="\t")))continue; if((t[a]=="\""||t[a]=="\'")&&!noCode) { noCode=true; starter=t[a]; } else if(!noCode&&t[a]=="/"&&(t[a+1]=="/"||t[a+1]=="*")) { noCode=true; starter=t.slice(a,a+2); } else if(noCode&&(t[a]==starter||(starter=="/*"&&t.slice(a,a+2)=="*/")||(starter=="//"&&t[a]=="\n"))&&(t[a-1]!="\\"||t.slice(a-2,a)=="\\\\")) { noCode=false; } if(!noCode) { if(t[a]=="\n") { newLine=true; out=out.concat(t[a]); continue; } if(t[a]=="}")i--; if(newLine&&t[a]!="\n") { for(b=0;b<i;b++) out=out.concat("\t"); newLine=false; } if(t[a]=="{")i++; } out=out.concat(t[a]); } while(out[out.length-1]=="\n")out=out.slice(0,out.length-1); prompt("",out); </sxh>

script_autoformat.1406232091.txt.gz · Last modified: 2014/07/24 20:01 by lm13