Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lua/tirenvi/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ local defaults = {
probe = false,
},
textobj = {
column = "l"
column = "l",
},
}

Expand Down
24 changes: 21 additions & 3 deletions lua/tirenvi/core/block.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ function M:add(record)
end

---@self Block
---@param attr Attr
function M:set_attr(attr)
self.attr = attr
function M:reset_attr()
self.attr = Attr.new()
end

function M.plain.new()
Expand All @@ -136,6 +135,8 @@ M.plain.normalize = nop
M.plain.to_vim = nop
M.plain.apply_replacements = nop
M.plain.remove_padding = nop
M.plain.set_attr = nop
M.plain.set_attr_from_vi = nop

---@self Block_plain
---@return Block_grid
Expand Down Expand Up @@ -205,4 +206,21 @@ function M.grid:to_grid()
return self
end

---@self Block
---@param attr Attr|nil
function M.grid:set_attr(attr)
if not attr or Attr.is_plain(attr) then
return
end
self.attr = attr
end

---@self Block
function M.grid:set_attr_from_vi()
if #self.records == 0 then
return
end
self.attr = Attr.grid.new_from_record(self.records[1])
end

return M
31 changes: 18 additions & 13 deletions lua/tirenvi/core/blocks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ local function apply_replacements(self, replace)
end
end

---@self Blocks
local function set_attr(self)
for _, block in ipairs(self) do
Block[block.kind].set_attr_from_vi(block)
end
end

---@self Blocks
local function remove_padding(self)
for _, block in ipairs(self) do
Expand Down Expand Up @@ -122,7 +129,7 @@ local function apply_reference_attr_single(blocks, attr_prev, attr_next)
return false, "grid in plain"
end
end
Block.set_attr(block, attr)
Block[block.kind].set_attr(block, attr)
return true
end

Expand All @@ -142,25 +149,15 @@ local function insert_plain_block(self, attr_prev, attr_next)
self[#self + 1] = Block.plain.new()
end

---@param block Block
---@param attr Attr|nil
local function set_attr(block, attr)
if attr and not Attr.is_plain(attr) then
if block.kind == CONST.KIND.GRID then
Block.set_attr(block, attr)
end
end
end

---@param self Blocks
---@param attr_prev Attr|nil
---@param attr_next Attr|nil
local function attach_attr(self, attr_prev, attr_next)
if #self == 0 then
return
end
set_attr(self[1], attr_prev)
set_attr(self[#self], attr_next)
Block[self[1].kind].set_attr(self[1], attr_prev)
Block[self[#self].kind].set_attr(self[#self], attr_next)
end

---@param blocks Blocks
Expand Down Expand Up @@ -218,10 +215,18 @@ end
---@return Blocks
function M.new_from_vim(records)
local self = build_blocks(records)
set_attr(self)
remove_padding(self)
return self
end

---@self Blocks
function M:reset_attr()
for _, block in ipairs(self) do
Block.reset_attr(block)
end
end

---@self Blocks
---@return Ndjson[]
function M:serialize_to_flat()
Expand Down
2 changes: 1 addition & 1 deletion lua/tirenvi/core/flat_parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ local function ensure_command(parser)
if item.status == "error" then
return item.message
elseif item.status == "warn" then
-- vim.notify(item.message, vim.log.levels.WARN)
-- notify.warn(item.message)
end
end
return nil
Expand Down
8 changes: 4 additions & 4 deletions lua/tirenvi/core/tir_vim.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ end

---@param line string
---@return integer[]
local function get_pipe_byte_position(line)
function M.get_pipe_byte_position(line)
local indexes = {}
local index = 1
while index <= #line do
Expand Down Expand Up @@ -164,7 +164,7 @@ function M.get_block_range(lines, count, is_around, allow_plain)
local irow, icol0 = unpack(vim.api.nvim_win_get_cursor(0))
local icol = icol0 + 1
local cline = vim.api.nvim_get_current_line()
local cbyte_pos = get_pipe_byte_position(cline)
local cbyte_pos = M.get_pipe_byte_position(cline)
if #cbyte_pos == 0 then
return nil
end
Expand All @@ -181,8 +181,8 @@ function M.get_block_range(lines, count, is_around, allow_plain)
trow = 1
brow = #lines
end
local tbyte_pos = get_pipe_byte_position(lines[trow])
local bbyte_pos = get_pipe_byte_position(lines[brow])
local tbyte_pos = M.get_pipe_byte_position(lines[trow])
local bbyte_pos = M.get_pipe_byte_position(lines[brow])
local end_index = colIndex + count
end_index = math.min(end_index, #bbyte_pos)
return {
Expand Down
36 changes: 26 additions & 10 deletions lua/tirenvi/editor/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ local fn = vim.fn

-- Command / Keymap handlers (private)
---@param bufnr number
---@param opts {[string]:any}
---@return nil
local function cmd_redraw(bufnr)
log.debug("===+===+===+===+=== redraw %s ===+===+===+===+===", bufnr)
local function cmd_redraw(bufnr, opts)
if buf_state.should_skip(bufnr, {
ensure_tir_vim = true,
}) then
Expand All @@ -27,9 +27,9 @@ local function cmd_redraw(bufnr)
end

---@param bufnr number
---@param opts {[string]:any}
---@return nil
local function cmd_toggle(bufnr)
log.debug("===+===+===+===+=== toggle %s ===+===+===+===+===", bufnr)
local function cmd_toggle(bufnr, opts)
if buf_state.should_skip(bufnr, {
supported = true,
has_parser = true,
Expand All @@ -40,9 +40,9 @@ local function cmd_toggle(bufnr)
end

---@param bufnr number
---@param opts {[string]:any}
---@return nil
local function cmd_hbar(bufnr)
log.debug("===+===+===+===+=== hbar %s ===+===+===+===+===", bufnr)
local function cmd_hbar(bufnr, opts)
if buf_state.should_skip(bufnr, {
ensure_tir_vim = true,
}) then
Expand All @@ -51,6 +51,20 @@ local function cmd_hbar(bufnr)
init.hbar(bufnr)
end

---@param bufnr number
---@param opts {[string]:any}
---@return nil
local function cmd_width(bufnr, opts)
if buf_state.should_skip(bufnr, {
ensure_tir_vim = true,
}) then
return
end
local operator, num = opts.args:match("^width%s*([=+-]?)(%d*)")
num = tonumber(num) or 0
init.width(bufnr, operator, num)
end

----------------------------------------------------------------------
-- Registration (private)
----------------------------------------------------------------------
Expand All @@ -59,6 +73,7 @@ local commands = {
toggle = cmd_toggle,
redraw = cmd_redraw,
hbar = cmd_hbar,
width = cmd_width,
}

local function get_command_keys()
Expand All @@ -78,20 +93,21 @@ end
---@param opts any
local function on_tir(opts)
local sub = opts.fargs[1]
local command = sub:match("^[A-Za-z]+") or ""
if not sub then
notify.info(build_usage())
return
end

log.debug("===+===+===+===+=== Tir %s ===+===+===+===+===", opts.fargs[1])
local bufnr = vim.api.nvim_get_current_buf()
local fn = commands[sub]
if not fn then
log.debug("===+===+===+===+=== %s %s[%d] ===+===+===+===+===", opts.name, opts.fargs[1], bufnr)
local func = commands[command]
if not func then
notify.error(errors.err_unknown_command(sub))
return
end

fn(bufnr)
func(bufnr, opts)
end

local function register_user_command()
Expand Down
2 changes: 1 addition & 1 deletion lua/tirenvi/editor/motion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function M.block_top()
local top
local parser = util.get_parser(bufnr)
if not parser or not parser.allow_plain then
top = vim.api.nvim_buf_line_count(bufnr)
top = 1
else
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
top = tir_vim.get_block_top_nrow(lines, row)
Expand Down
4 changes: 4 additions & 0 deletions lua/tirenvi/editor/textobj.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ local log = require("tirenvi.util.log")

local M = {}

-- private helpers

---@param is_around boolean|nil
local function setup_vl(is_around)
is_around = is_around or false
Expand All @@ -22,6 +24,8 @@ local function setup_vl(is_around)
vim.api.nvim_win_set_cursor(0, { pos.end_row, pos.end_col - 1, })
end

-- public API

function M.setup_vil()
setup_vl()
end
Expand Down
6 changes: 6 additions & 0 deletions lua/tirenvi/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ end
function M.check()
health.start("tirenvi")
health.info("version: " .. version.VERSION)
pcall(vim.fn["repeat#set"], "")
if vim.fn.exists("*repeat#set") == 1 then
vim.health.ok("vim-repeat is available")
else
vim.health.warn("vim-repeat not found ('.' repeat disabled)")
end
if not config.parser_map or vim.tbl_isempty(config.parser_map) then
health.warn("No parsers configured.")
return
Expand Down
Loading
Loading