Skip to content

Instantly share code, notes, and snippets.

@TehFlaminTaco
Created February 13, 2017 23:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TehFlaminTaco/bedb9e777933340dc0f5fc8327a8d653 to your computer and use it in GitHub Desktop.
Save TehFlaminTaco/bedb9e777933340dc0f5fc8327a8d653 to your computer and use it in GitHub Desktop.
local f = io.open("codetomakesad.txt")
s = f:read("*a")
s = s:gsub("/%*.-%*/","")
:gsub("//[^\n]+","")
repeat
local os=s
s=s:gsub("([{};])(%s+)([{};])","%1%3%2")
until s==os
repeat
local os=s
s = s:gsub("\n[\t ]-\n","\n")
until s==os
s = s:gsub("([{};])%s-(\n)","%1%2")
width = 0
for line in s:gmatch"[^\n]+" do
width = math.max(#line:gsub("\t"," "),width)
end
width = math.ceil((width+1)/4)*4
local Out = ""
for line in s:gmatch"[^\n]+" do
local chunk,brace = line:gsub("\t"," "):match("^(.-)([{};]*)$")
Out = Out .. chunk .. (" "):rep(width-#chunk)..brace.."\n"
end
print(Out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment