Skip to content

Instantly share code, notes, and snippets.

@zeen
Last active December 23, 2015 00:39
Show Gist options
  • Save zeen/6555506 to your computer and use it in GitHub Desktop.
Save zeen/6555506 to your computer and use it in GitHub Desktop.
Convert tabs to spaces while aligning with columns
local tabsize = 4;
function tabber(s)
local t = {};
for part in s:gmatch("[^\t]*") do
t[#t+1] = part;
t[#t+1] = "\t";
end
t[#t] = nil;
local n = 0;
for i=1,#t do
if i%2 == 0 then -- got a tab
t[i] = (" "):rep(tabsize - (n + tabsize) % tabsize + 1);
end
n = n + #t[i];
end
return table.concat(t);
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment