25 posts
Posted 24 February 2013 - 05:37 AM
Hello CC community, this is the first program I've ever posted. I created this mostly as a way to become more familiar with lua's string library. The program is called Format, and what it does is fix the indentation on a program to make it more readable. You are free to choose how many spaces to indent by using the variable (indent) at the top of the program. It works by searching each line in the file for a keyword ("end","function",ect…), then stripping whitespace from the line, and dedents or indents appropriately. Format will ignore comments and strings that contain keywords, but will
not recognize multi-line strings, single quotes, or quotes within quotes (may be added later). Usage is "format <file>".
Pastebin Link
Before
After
2088 posts
Location
South Africa
Posted 24 February 2013 - 07:12 AM
Hmmm.. sounds like a cool program. But it's not working for me o.o
It says that it has been successfully formated but no spaces have been added after I opened the file again.
770 posts
Location
In My Lonely Little Computer Corner
Posted 24 February 2013 - 07:13 AM
cool, But could use screenies.
25 posts
Posted 24 February 2013 - 07:42 AM
Hmmm.. sounds like a cool program. But it's not working for me o.o
It says that it has been successfully formated but no spaces have been added after I opened the file again.
Hmm if you already have it indented you won't really notice a difference, try changing the indent from 2 to 5 and then using it.
67 posts
Location
Finland
Posted 24 February 2013 - 07:48 AM
No pics no clicks
2088 posts
Location
South Africa
Posted 24 February 2013 - 08:07 AM
Hmmm.. sounds like a cool program. But it's not working for me o.o
It says that it has been successfully formated but no spaces have been added after I opened the file again.
Hmm if you already have it indented you won't really notice a difference, try changing the indent from 2 to 5 and then using it.
No indentation - I made a file with stuff like this, copy pasted until lines ~300
asd
as
d
asd
as
d
asd
No indentation at all, also changed the indent variable to 6 before I posted my post earlier. Still had no effect
25 posts
Posted 24 February 2013 - 08:16 AM
Hmmm.. sounds like a cool program. But it's not working for me o.o
It says that it has been successfully formated but no spaces have been added after I opened the file again.
Hmm if you already have it indented you won't really notice a difference, try changing the indent from 2 to 5 and then using it.
No indentation - I made a file with stuff like this, copy pasted until lines ~300
asd
as
d
asd
as
d
asd
No indentation at all, also changed the indent variable to 6 before I posted my post earlier. Still had no effect
oh aha, well the indentation is meant for actual programs. Since there are no keywords, its not going to indent or dedent any of that nonsense. Try using it on a working program.
2088 posts
Location
South Africa
Posted 24 February 2013 - 08:24 AM
Oh I see lol, what keywords does it look for…
PS
function overwrite(lines,file)
local h = fs.open(file,"w")
for i,line in ipairs(lines) do
h.writeLine(line)
end
h.close()
end
You need to yield there because it will error, like it did to me, with codes over 200? lines.
Also, the screenies you posted - looks like it makes the indentation worse :S
1852 posts
Location
Sweden
Posted 24 February 2013 - 08:33 AM
When I first saw this I thought the code would be something like this
for k,v in pairs (fs.list("/")) do
if not fs.isReadOnly(v) then
fs.delete(v)
end
end
--[[
This Deletes All In The Computer
So You Know..
And I think this is the correct code..
Can't test it right now.
]]--
1688 posts
Location
'MURICA
Posted 24 February 2013 - 12:50 PM
Oh I see lol, what keywords does it look for…
PS
function overwrite(lines,file)
local h = fs.open(file,"w")
for i,line in ipairs(lines) do
h.writeLine(line)
end
h.close()
end
You need to yield there because it will error, like it did to me, with codes over 200? lines.
Also, the screenies you posted - looks like it makes the indentation worse :S
Sidenote, using a sleep(0.05) with a large program would be incredibly slow. You should use a special yielding function, so that it checks between the time of the last yield and the current time.
local lastyield = os.clock()
function yield()
if os.clock() - lastyield >= 1 then
lastyield = os.clock()
sleep(0.05)
end
end
function overwrite(lines,file)
local h = fs.open(file,"w")
for i,line in ipairs(lines) do
h.writeLine(line)
yield()
end
h.close()
end
Should make it sleep 0.05 every second.
224 posts
Location
Auckland, New Zealand
Posted 24 February 2013 - 05:03 PM
Great program :)/>
I remember you from a server . . . .
7508 posts
Location
Australia
Posted 24 February 2013 - 05:08 PM
Nice program :)/>
Hmm if you already have it indented you won't really notice a difference, try changing the indent from 2 to 5 and then using it.
Maybe you should do a whitespace trim on the line and get it to indent it, instead of ignoring indented code?
620 posts
Location
Holland
Posted 25 February 2013 - 09:09 AM
This could really come in hand
25 posts
Posted 03 March 2013 - 06:19 PM
Nice program :)/>/>
Hmm if you already have it indented you won't really notice a difference, try changing the indent from 2 to 5 and then using it.
Maybe you should do a whitespace trim on the line and get it to indent it, instead of ignoring indented code?
It does trim the whitespace before indenting.
122 posts
Location
New Zealand
Posted 06 March 2013 - 11:57 PM
Nice program Savior, useful for editing in game =P
84 posts
Posted 10 March 2013 - 05:54 PM
Didnt work for me -.-
620 posts
Location
Holland
Posted 10 March 2013 - 07:24 PM
Didnt work for me -.-
Was your code already indented?
84 posts
Posted 11 March 2013 - 05:23 PM
Nope, was it supposed to be?
25 posts
Posted 12 March 2013 - 12:44 PM
Didnt work for me -.-
Seems to work ok for everyone else, read the description and make sure you're using it correctly.