1

57 lines
1.6 KiB
Lua
Raw Normal View History

2024-12-30 20:31:50 -08:00
local Builder = require('argonaut.builder')
local Cursor = require('argonaut.cursor')
local Options = require('argonaut.options')
local Range = require('argonaut.range')
2022-12-30 15:10:22 -08:00
2024-04-24 20:02:10 -07:00
local function reflow()
2024-12-30 20:31:50 -08:00
local range = Range.find_closest()
if not range then
return false
2024-04-24 20:02:10 -07:00
end
2024-12-30 20:31:50 -08:00
local trace = range:hit_test(Cursor.get_current())
assert(trace)
local line_first = vim.fn.getline(range.start_cursor.row)
local line_last = vim.fn.getline(range.stop_cursor.row)
local indent_level = #line_first:match('^(%s*)')
local indent_block = '\t'
if vim.o.expandtab then
indent_level = math.floor(indent_level / vim.o.shiftwidth)
indent_block = string.rep(' ', vim.o.shiftwidth)
end
local range_prefix = line_first:sub(indent_level * #indent_block + 1, range.start_cursor.col - 1)
local range_suffix = line_last:sub(range.stop_cursor.col + 1)
local builder = Builder.new(indent_level, indent_block)
builder:write(range_prefix)
range:write(builder, not range:is_wrapped())
builder:write(range_suffix)
builder:endline()
builder:output(range.start_cursor.row, range.stop_cursor.row)
local new_range = Range.find_at_cursor(range.start_cursor)
2025-01-18 20:36:32 -08:00
assert(new_range)
2024-12-30 20:31:50 -08:00
new_range:hit_search(trace, 1):set_current()
return true
2022-12-30 15:10:22 -08:00
end
2025-01-18 18:24:01 -08:00
local function inspect()
local range = Range.find_closest()
if range then
local trace = range:hit_test(Cursor.get_current())
assert(trace)
dump(trace)
end
end
2022-12-30 10:40:23 -08:00
return {
2025-01-18 18:24:01 -08:00
inspect = inspect,
2024-04-24 20:02:10 -07:00
reflow = reflow,
2025-01-18 20:36:32 -08:00
setup = Options.setup,
query = Options.query,
2022-12-30 10:40:23 -08:00
}