Cleanup
This commit is contained in:
parent
6b63f79b2d
commit
06113ccb2f
@ -3,14 +3,13 @@ local Cursor = require('argonaut.cursor')
|
|||||||
local Options = require('argonaut.options')
|
local Options = require('argonaut.options')
|
||||||
local Range = require('argonaut.range')
|
local Range = require('argonaut.range')
|
||||||
|
|
||||||
local function reflow()
|
local function reflow(toggle_wrapping)
|
||||||
local range = Range.find_closest()
|
local range = Range.find_closest()
|
||||||
if not range then
|
if not range then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local trace = range:hit_test(Cursor.get_current())
|
local trace = range:hit_test(Cursor.get_current())
|
||||||
assert(trace)
|
|
||||||
|
|
||||||
local line_first = vim.fn.getline(range.start_cursor.row)
|
local line_first = vim.fn.getline(range.start_cursor.row)
|
||||||
local line_last = vim.fn.getline(range.stop_cursor.row)
|
local line_last = vim.fn.getline(range.stop_cursor.row)
|
||||||
@ -27,14 +26,22 @@ local function reflow()
|
|||||||
|
|
||||||
local builder = Builder.new(indent_level, indent_block)
|
local builder = Builder.new(indent_level, indent_block)
|
||||||
builder:write(range_prefix)
|
builder:write(range_prefix)
|
||||||
|
if toggle_wrapping then
|
||||||
range:write(builder, not range:is_wrapped())
|
range:write(builder, not range:is_wrapped())
|
||||||
|
else
|
||||||
|
range:write(builder, range:is_wrapped())
|
||||||
|
end
|
||||||
builder:write(range_suffix)
|
builder:write(range_suffix)
|
||||||
builder:endline()
|
builder:endline()
|
||||||
builder:output(range.start_cursor.row, range.stop_cursor.row)
|
builder:output(range.start_cursor.row, range.stop_cursor.row)
|
||||||
|
|
||||||
local new_range = Range.find_at_cursor(range.start_cursor)
|
local new_range = Range.find_at_cursor(range.start_cursor)
|
||||||
assert(new_range)
|
assert(new_range)
|
||||||
|
if trace then
|
||||||
new_range:hit_search(trace, 1).cursor:set_current()
|
new_range:hit_search(trace, 1).cursor:set_current()
|
||||||
|
else
|
||||||
|
new_range.start_cursor:set_current()
|
||||||
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -43,8 +50,13 @@ local function inspect()
|
|||||||
local range = Range.find_closest()
|
local range = Range.find_closest()
|
||||||
if range then
|
if range then
|
||||||
local trace = range:hit_test(Cursor.get_current())
|
local trace = range:hit_test(Cursor.get_current())
|
||||||
assert(trace)
|
if trace then
|
||||||
dump(trace)
|
dump(trace)
|
||||||
|
else
|
||||||
|
print('No range trace!')
|
||||||
|
end
|
||||||
|
else
|
||||||
|
print('No range found!')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -52,5 +64,4 @@ return {
|
|||||||
inspect = inspect,
|
inspect = inspect,
|
||||||
reflow = reflow,
|
reflow = reflow,
|
||||||
setup = Options.setup,
|
setup = Options.setup,
|
||||||
query = Options.query,
|
|
||||||
}
|
}
|
||||||
|
@ -54,8 +54,9 @@ local function find_closest()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function find_at_cursor(start_cursor, parent_range)
|
local function find_at_cursor(start_cursor, parent_range)
|
||||||
local pairing = Pairing.from_brace(start_cursor:get_value())
|
local value = start_cursor:get_value()
|
||||||
if pairing then
|
local pairing = Pairing.from_brace(value)
|
||||||
|
if pairing and value == pairing.open then
|
||||||
local cursor_current = Cursor:get_current()
|
local cursor_current = Cursor:get_current()
|
||||||
start_cursor:set_current()
|
start_cursor:set_current()
|
||||||
|
|
||||||
@ -75,6 +76,10 @@ local function find_at_cursor(start_cursor, parent_range)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Range.new(start_cursor, stop_cursor, pairing)
|
function Range.new(start_cursor, stop_cursor, pairing)
|
||||||
|
assert(start_cursor < stop_cursor)
|
||||||
|
assert(start_cursor:get_value() == pairing.open)
|
||||||
|
assert(stop_cursor:get_value() == pairing.close)
|
||||||
|
|
||||||
local range = {
|
local range = {
|
||||||
start_cursor = start_cursor,
|
start_cursor = start_cursor,
|
||||||
stop_cursor = stop_cursor,
|
stop_cursor = stop_cursor,
|
||||||
@ -133,7 +138,10 @@ function Range:parse()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Range:hit_test(cursor)
|
function Range:hit_test(cursor)
|
||||||
if self:contains_cursor(cursor) then
|
if not self:contains_cursor(cursor) or #self.params == 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local frame = {
|
local frame = {
|
||||||
type = 'range',
|
type = 'range',
|
||||||
pairing = self.pairing.open .. self.pairing.close,
|
pairing = self.pairing.open .. self.pairing.close,
|
||||||
@ -166,7 +174,6 @@ function Range:hit_test(cursor)
|
|||||||
return trace
|
return trace
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Range:hit_search(trace, depth)
|
function Range:hit_search(trace, depth)
|
||||||
|
@ -7,25 +7,22 @@ if not vim.g.argonaut_loaded then
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function argonaut_auto_reload()
|
|
||||||
if require('argonaut').query('auto_reload') then
|
|
||||||
argonaut_reload()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function argonaut_reflow()
|
|
||||||
argonaut_auto_reload()
|
|
||||||
require('argonaut').reflow()
|
|
||||||
end
|
|
||||||
|
|
||||||
local function argonaut_inspect()
|
local function argonaut_inspect()
|
||||||
argonaut_auto_reload()
|
|
||||||
require('argonaut').inspect()
|
require('argonaut').inspect()
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_create_user_command('ArgonautReload', argonaut_reload, {})
|
local function argonaut_reflow()
|
||||||
vim.api.nvim_create_user_command('ArgonautReflow', argonaut_reflow, {})
|
require('argonaut').reflow(false)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function argonaut_toggle()
|
||||||
|
require('argonaut').reflow(true)
|
||||||
|
end
|
||||||
|
|
||||||
vim.api.nvim_create_user_command('ArgonautInspect', argonaut_inspect, {})
|
vim.api.nvim_create_user_command('ArgonautInspect', argonaut_inspect, {})
|
||||||
|
vim.api.nvim_create_user_command('ArgonautReflow', argonaut_reflow, {})
|
||||||
|
vim.api.nvim_create_user_command('ArgonautReload', argonaut_reload, {})
|
||||||
|
vim.api.nvim_create_user_command('ArgonautToggle', argonaut_toggle, {})
|
||||||
|
|
||||||
vim.g.argonaut_loaded = true
|
vim.g.argonaut_loaded = true
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user