1

Smarter wrapping

This commit is contained in:
Alex Yatskov 2024-12-31 10:05:01 -08:00
parent 5fa76a6522
commit a64cac9be8
3 changed files with 43 additions and 1 deletions

View File

@ -11,6 +11,9 @@ local options_current = {
go = {
comma_last = true,
},
lua = {
comma_last = true,
},
}
local function setup(opt)

View File

@ -5,6 +5,24 @@ local function is_empty_cell(cell)
return cell.type == 'cursor' and not cell.value:get_value():match('%S')
end
local function get_param_start_row(param)
local cell = param.cells[1]
if cell.type == 'range' then
return cell.value.start_cursor.row
elseif cell.type == 'cursor' then
return cell.value.row
end
end
local function get_param_stop_row(param)
local cell = param.cells[#param.cells]
if cell.type == 'range' then
return cell.value.stop_cursor.row
elseif cell.type == 'cursor' then
return cell.value.row
end
end
function Param.new(range, index, cells)
local param = {
range = range,
@ -72,6 +90,22 @@ function Param:write(builder, wrapped)
end
end
function Param:is_wrapped()
local previous_param = self:get_previous()
if previous_param then
-- print(get_param_stop_row(previous_param), get_param_start_row(self))
return get_param_stop_row(previous_param) ~= get_param_start_row(self)
else
return false
end
end
function Param:get_previous()
if self.index > 1 then
return self.range.params[self.index-1]
end
end
function Param:find_index_begin()
for i = 1, #self.cells do
if not is_empty_cell(self.cells[i]) then

View File

@ -206,7 +206,12 @@ function Range:query_option(name)
end
function Range:is_wrapped()
return self.start_cursor.row ~= self.stop_cursor.row
for _, param in ipairs(self.params) do
if param:is_wrapped() then
return true
end
end
return false
end
function Range.__lt(range_1, range_2)