diff --git a/lua/u/buffer.lua b/lua/u/buffer.lua index 238249f..4e83d7e 100644 --- a/lua/u/buffer.lua +++ b/lua/u/buffer.lua @@ -24,7 +24,9 @@ function Buffer.current() return Buffer.from_nr(0) end --- @param listed boolean --- @param scratch boolean --- @return u.Buffer -function Buffer.create(listed, scratch) return Buffer.from_nr(vim.api.nvim_create_buf(listed, scratch)) end +function Buffer.create(listed, scratch) + return Buffer.from_nr(vim.api.nvim_create_buf(listed, scratch)) +end function Buffer:set_tmp_options() self:set_option('bufhidden', 'delete') @@ -36,7 +38,9 @@ end function Buffer:get_option(nm) return vim.api.nvim_get_option_value(nm, { buf = self.bufnr }) end --- @param nm string -function Buffer:set_option(nm, val) return vim.api.nvim_set_option_value(nm, val, { buf = self.bufnr }) end +function Buffer:set_option(nm, val) + return vim.api.nvim_set_option_value(nm, val, { buf = self.bufnr }) +end --- @param nm string function Buffer:get_var(nm) return vim.api.nvim_buf_get_var(self.bufnr, nm) end diff --git a/lua/u/logger.lua b/lua/u/logger.lua index 22e97a6..07fdf04 100644 --- a/lua/u/logger.lua +++ b/lua/u/logger.lua @@ -1,7 +1,9 @@ local M = {} --- @params name string -function M.file_for_name(name) return vim.fs.joinpath(vim.fn.stdpath 'cache', 'u.log', name .. '.log.jsonl') end +function M.file_for_name(name) + return vim.fs.joinpath(vim.fn.stdpath 'cache', 'u.log', name .. '.log.jsonl') +end -------------------------------------------------------------------------------- -- Logger class @@ -30,7 +32,10 @@ end function Logger:write(level, ...) local data = { ... } if #data == 1 then data = data[1] end - (vim.uv or vim.loop).fs_write(self.fd, vim.json.encode { ts = os.date(), level = level, data = data } .. '\n') + (vim.uv or vim.loop).fs_write( + self.fd, + vim.json.encode { ts = os.date(), level = level, data = data } .. '\n' + ) end function Logger:trace(...) self:write('INFO', ...) end diff --git a/lua/u/pos.lua b/lua/u/pos.lua index adc0c89..0331308 100644 --- a/lua/u/pos.lua +++ b/lua/u/pos.lua @@ -2,7 +2,9 @@ local MAX_COL = vim.v.maxcol --- @param bufnr number --- @param lnum number 1-based -local function line_text(bufnr, lnum) return vim.api.nvim_buf_get_lines(bufnr, lnum - 1, lnum, false)[1] end +local function line_text(bufnr, lnum) + return vim.api.nvim_buf_get_lines(bufnr, lnum - 1, lnum, false)[1] +end --- @class u.Pos --- @field bufnr number buffer number @@ -54,7 +56,9 @@ end function Pos.__lt(a, b) return a.lnum < b.lnum or (a.lnum == b.lnum and a.col < b.col) end function Pos.__le(a, b) return a < b or a == b end -function Pos.__eq(a, b) return Pos.is(a) and Pos.is(b) and a.bufnr == b.bufnr and a.lnum == b.lnum and a.col == b.col end +function Pos.__eq(a, b) + return Pos.is(a) and Pos.is(b) and a.bufnr == b.bufnr and a.lnum == b.lnum and a.col == b.col +end function Pos.__add(x, y) if type(x) == 'number' then x, y = y, x @@ -202,7 +206,9 @@ end --- @return u.Pos|nil function Pos:find_match(max_chars, invocations) if invocations == nil then invocations = {} end - if vim.tbl_contains(invocations, function(p) return self == p end, { predicate = true }) then return nil end + if vim.tbl_contains(invocations, function(p) return self == p end, { predicate = true }) then + return nil + end table.insert(invocations, self) local openers = { '{', '[', '(', '<' } @@ -212,7 +218,10 @@ function Pos:find_match(max_chars, invocations) local is_closer = vim.tbl_contains(closers, c) if not is_opener and not is_closer then return nil end - local i, _ = vim.iter(is_opener and openers or closers):enumerate():find(function(_, c2) return c == c2 end) + local i, _ = vim + .iter(is_opener and openers or closers) + :enumerate() + :find(function(_, c2) return c == c2 end) -- Store the character we will be looking for: local c_match = (is_opener and closers or openers)[i] @@ -255,7 +264,14 @@ end --- @param lines string|string[] function Pos:insert_before(lines) if type(lines) == 'string' then lines = vim.split(lines, '\n') end - vim.api.nvim_buf_set_text(self.bufnr, self.lnum - 1, self.col - 1, self.lnum - 1, self.col - 1, lines) + vim.api.nvim_buf_set_text( + self.bufnr, + self.lnum - 1, + self.col - 1, + self.lnum - 1, + self.col - 1, + lines + ) end return Pos diff --git a/lua/u/range.lua b/lua/u/range.lua index 03d195b..337f613 100644 --- a/lua/u/range.lua +++ b/lua/u/range.lua @@ -37,7 +37,13 @@ function Range.new(start, stop, mode) local _1 = posstr(r.start) local _2 = posstr(r.stop) - return string.format('Range{bufnr=%d, mode=%s, start=%s, stop=%s}', r.start.bufnr, r.mode, _1, _2) + return string.format( + 'Range{bufnr=%d, mode=%s, start=%s, stop=%s}', + r.start.bufnr, + r.mode, + _1, + _2 + ) end setmetatable(r, { __index = Range, __tostring = str }) return r @@ -164,7 +170,10 @@ function Range.from_motion(motion, opts) stop = stop:find_next(-1, motion_rest) or stop end - if opts.contains_cursor and not Range.new(start, stop):contains(Pos.new(unpack(original_state.cursor))) then + if + opts.contains_cursor + and not Range.new(start, stop):contains(Pos.new(unpack(original_state.cursor))) + then return nil end @@ -246,7 +255,9 @@ function Range.smallest(ranges) return smallest end -function Range:clone() return Range.new(self.start:clone(), self.stop ~= nil and self.stop:clone() or nil, self.mode) end +function Range:clone() + return Range.new(self.start:clone(), self.stop ~= nil and self.stop:clone() or nil, self.mode) +end function Range:line_count() if self:is_empty() then return 0 end return self.stop.lnum - self.start.lnum + 1 @@ -310,7 +321,8 @@ function Range:line(l) if l < 0 then l = self:line_count() + l + 1 end if l > self:line_count() then return end - local line_indices = vim.fn.getregionpos(self.start:as_vim(), self.stop:as_vim(), { type = self.mode }) + local line_indices = + vim.fn.getregionpos(self.start:as_vim(), self.stop:as_vim(), { type = self.mode }) local line_bounds = line_indices[l] local start = Pos.new(unpack(line_bounds[1])) @@ -329,7 +341,9 @@ function Range:replace(replacement) local function update_stop_non_linewise() local new_last_line_num = self.start.lnum + #replacement - 1 local new_last_col = #(replacement[#replacement] or '') - if new_last_line_num == self.start.lnum then new_last_col = new_last_col + self.start.col - 1 end + if new_last_line_num == self.start.lnum then + new_last_col = new_last_col + self.start.col - 1 + end self.stop = Pos.new(bufnr, new_last_line_num, new_last_col) end local function update_stop_linewise() @@ -399,7 +413,9 @@ end --- @param amount number function Range:must_shrink(amount) local shrunk = self:shrink(amount) - if shrunk == nil or shrunk:is_empty() then error 'error in Range:must_shrink: Range:shrink() returned nil' end + if shrunk == nil or shrunk:is_empty() then + error 'error in Range:must_shrink: Range:shrink() returned nil' + end return shrunk end diff --git a/lua/u/renderer.lua b/lua/u/renderer.lua index 36c4980..4617372 100644 --- a/lua/u/renderer.lua +++ b/lua/u/renderer.lua @@ -218,7 +218,8 @@ function Renderer:_reconcile() -- {{{ self:_set_lines(lnum0, lnum0, true, { line_change.item }) elseif line_change.kind == 'change' then -- Compute inter-line diff, and apply: - local col_changes = H.levenshtein(vim.split(line_change.from, ''), vim.split(line_change.to, '')) + local col_changes = + H.levenshtein(vim.split(line_change.from, ''), vim.split(line_change.to, '')) for _, col_change in ipairs(col_changes) do local cnum0 = col_change.index - 1 @@ -310,7 +311,15 @@ function Renderer:get_pos_infos(pos0) -- {{{ -- because the NeoVim API is over-inclusive in what it returns: --- @type RendererExtmark[] local intersecting_extmarks = vim - .iter(vim.api.nvim_buf_get_extmarks(self.bufnr, self.ns, pos0, pos0, { details = true, overlap = true })) + .iter( + vim.api.nvim_buf_get_extmarks( + self.bufnr, + self.ns, + pos0, + pos0, + { details = true, overlap = true } + ) + ) --- @return RendererExtmark :map(function(ext) --- @type number, number, number, { end_row?: number; end_col?: number }|nil diff --git a/lua/u/tracker.lua b/lua/u/tracker.lua index f4c3563..b3f43ef 100644 --- a/lua/u/tracker.lua +++ b/lua/u/tracker.lua @@ -37,7 +37,10 @@ function Signal:set(value) -- We don't handle cyclic updates: if self.changing then if M.debug then - vim.notify('circular dependency detected' .. (self.name and (' in ' .. self.name) or ''), vim.log.levels.WARN) + vim.notify( + 'circular dependency detected' .. (self.name and (' in ' .. self.name) or ''), + vim.log.levels.WARN + ) end return end @@ -143,7 +146,10 @@ function Signal:debounce(ms) local now_ms = (vim.uv or vim.loop).hrtime() / 1e6 -- If there is anything older than `ms` in our queue, emit it: - local older_than_ms = vim.iter(state.queued):filter(function(item) return now_ms - item.ts > ms end):totable() + local older_than_ms = vim + .iter(state.queued) + :filter(function(item) return now_ms - item.ts > ms end) + :totable() local last_older_than_ms = older_than_ms[#older_than_ms] if last_older_than_ms then filtered:set(last_older_than_ms.value) diff --git a/stylua.toml b/stylua.toml index 6ee49d6..6bfe2c0 100644 --- a/stylua.toml +++ b/stylua.toml @@ -1,6 +1,6 @@ call_parentheses = "None" collapse_simple_statement = "Always" -column_width = 120 +column_width = 100 indent_type = "Spaces" indent_width = 2 quote_style = "AutoPreferSingle"