Jump to content
Sign in to follow this  
Kaotar

Auto-Tabulação

Recommended Posts

Kaotar    5
Kaotar

Estava ficando cansado do Etherpad que muda toda a tabulação do script, então fiz esse coisinha ai.

Pra quem quiser esta ae.

 

function AjustEscop(file)
newFile = ""
script = io.open(file, "r")
tab = 0
if (script) then
	for line in script:lines() do
		line = removeEspaces(tostring(line))
		if (line:match("{.-}")) then
			newFile = newFile .. stringTab(tab) .. line .. "\n"
		elseif (line:match("function") or line:match("if .- then") or line:match("for .- do") or line:match("while .- do") or line:match("{")) or line:match("repeat") then
			newFile = newFile .. stringTab(tab) .. line .. "\n"
			tab = tab + 1
		elseif (line:match("end") or line:match("}") or line:match("until")) then
			tab = tab - 1
			newFile = newFile .. stringTab(tab) .. line .. "\n"
		else
			newFile = newFile .. stringTab(tab) .. line .. "\n"
		end
	end
	local script = io.open(file, "w+")
	script:write(newFile)
	script:close()
else
	error("ERROR: File not found")
end
script:close()
end

function removeEspaces(s)
_, v = s:find("%s*")
return string.sub(s, v+1)
end

function stringTab(num)
s = ""
while (num > 0) do
	s = s .. "	"
	num = num - 1
end
return s
end

Edited by Kaotar

Share this post


Link to post
Share on other sites
Mock    32
Mock

Boa cara, alem do etherpad o proprio otscript live q muita gente usa nao tabula direito, eu uso o scite.

agora que vi, você usou line:match("{.-}")

{ } como pattern, eu nunca tinha visto alguem usar eu estava acostumado a (.-) :P

Share this post


Link to post
Share on other sites
Kaotar    5
Kaotar

Isso nao é pattern UAHuaHauha

Isso é a tabela mesmo, é que se for uma tabela de uma linha so entende

AUhauhAUhauah

Share this post


Link to post
Share on other sites
pejuge2    1
pejuge2

Primeira vez também, uhauhahuuh!

 

P.S.: Claro que isso é pattern O.o.

 

yessir.gifAprovado

Edited by pejuge2

Share this post


Link to post
Share on other sites
dragonlorde    0
dragonlorde

Muito bom cara...

Mas voce boto como 1 tabela e não como padrão?

>> line:match("{.-}")

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×