function Util.EmulateTabstops(G,h)local F=0 local e=#G local o=table.create(e)for e=1,e,1 do local m=string.sub(G,e,e)if m=="\t"then local G=h-F%h table.insert(o,string.rep(" ",G))F+=G else table.insert(o,m)if m=="\n"then F=0 elseif m~="\r"then F+=1 end end end return table.concat(o)end function Util.Mutex()local G={}local h=false return function()if h then table.insert(G,coroutine.running())coroutine.yield()else h=true end return function()if#G>0 then coroutine.resume(table.remove(G,1))else h=false end end end end return Util
--- Emulates tabstops with spaces
function Util.EmulateTabstops(text, tabWidth)
	local column = 0
	local textLength = #text
	local result = table.create(textLength)
	for i = 1, textLength do
		local char = string.sub(text, i, i)
		if char == "\t" then
			local spaces = tabWidth - column % tabWidth
			table.insert(result, string.rep(" ", spaces))
			column += spaces
		else
			table.insert(result, char)
			if char == "\n" then
				column = 0 -- Reset column counter on newlines
			elseif char ~= "\r" then
				column += 1
			end
		end
	end
	return table.concat(result)
end

function Util.Mutex()
	local queue = {}
	local locked = false

	return function()
		if locked then
			table.insert(queue, coroutine.running())
			coroutine.yield()
		else
			locked = true
		end

		return function()
			if #queue > 0 then
				coroutine.resume(table.remove(queue, 1))
			else
				locked = false
			end
		end
	end
end

return Util
