1
argonaut.nvim/lua/argonaut/init.lua

45 lines
1.3 KiB
Lua
Raw Normal View History

2024-12-31 04:31:50 +00:00
local Builder = require('argonaut.builder')
local Cursor = require('argonaut.cursor')
local Options = require('argonaut.options')
local Range = require('argonaut.range')
2022-12-30 23:10:22 +00:00
2024-04-25 03:02:10 +00:00
local function reflow()
2024-12-31 04:31:50 +00:00
local range = Range.find_closest()
if not range then
return false
2024-04-25 03:02:10 +00:00
end
2024-12-31 04:31:50 +00: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)
new_range:hit_search(trace, 1):set_current()
return true
2022-12-30 23:10:22 +00:00
end
2022-12-30 18:40:23 +00:00
return {
2024-04-25 03:02:10 +00:00
reflow = reflow,
2024-12-31 04:31:50 +00:00
setup = Options.setup,
2022-12-30 18:40:23 +00:00
}