aboutsummaryrefslogtreecommitdiff
path: root/code_obj.lua
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-06-19 00:44:17 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-06-19 00:44:22 -0700
commitd7d86e026831f60aae8193f1cfda7f53bf26a61e (patch)
tree50e810d54a199eb86b751c1a1661ece401689fcf /code_obj.lua
parent6d8d617774b064dce4cc230f5e10027c58790c2d (diff)
Lots of cleanup.
Diffstat (limited to 'code_obj.lua')
-rw-r--r--code_obj.lua31
1 files changed, 20 insertions, 11 deletions
diff --git a/code_obj.lua b/code_obj.lua
index 6dbffca..de62c8f 100644
--- a/code_obj.lua
+++ b/code_obj.lua
@@ -98,26 +98,35 @@ do
end
self.__str = nil
end,
- concat_append = function(self, values, joiner)
+ concat_append = function(self, values, joiner, wrapping_joiner)
+ wrapping_joiner = wrapping_joiner or joiner
local bits, indents = self.bits, self.indents
local match = string.match
+ local line_len = 0
for i = 1, #values do
local b = values[i]
- assert(b)
if i > 1 then
- bits[#bits + 1] = joiner
+ if line_len > 80 then
+ bits[#bits + 1] = wrapping_joiner
+ line_len = 0
+ else
+ bits[#bits + 1] = joiner
+ end
end
bits[#bits + 1] = b
- if type(b) == 'string' then
- do
- local spaces = match(b, "\n([ ]*)[^\n]*$")
- if spaces then
- self.current_indent = #spaces
- end
- end
- elseif self.current_indent ~= 0 then
+ if type(b) ~= 'string' and self.current_indent ~= 0 then
indents[#bits] = self.current_indent
end
+ local b_str = tostring(b)
+ local line, spaces = match(b_str, "\n(([ ]*)[^\n]*)$")
+ if spaces then
+ if type(b) == 'string' then
+ self.current_indent = #spaces
+ end
+ line_len = #line
+ else
+ line_len = line_len + #b
+ end
end
self.__str = nil
end,