v3
Some checks failed
ci / ci (push) Has been cancelled

- range: extmarks/tsquery
- mise for dev env
- get rid of obsolete modules
- implement as single file module
This commit is contained in:
2025-06-11 20:04:46 -06:00
parent 12945a4cdf
commit e791dfb980
50 changed files with 3539 additions and 5362 deletions

View File

@@ -1,6 +1,10 @@
local vim_repeat = require 'u.repeat'
local CodeWriter = require 'u.codewriter'
local Range = require 'u.range'
--
-- Split/Join: toggles between single-line and multi-line forms for bracketed expressions.
-- Example: { a, b, c } <-> {\n a,\n b,\n c\n}
-- Maps to gS in normal mode.
--
local Range = require('u').Range
local vim_repeat = require('u').repeat_
local M = {}
@@ -8,8 +12,27 @@ local M = {}
--- @param left string
--- @param right string
local function split(bracket_range, left, right)
local code = CodeWriter.from_pos(bracket_range.start)
code:write_raw(left)
local bufnr = bracket_range.start.bufnr
local first_line = Range.from_line(bufnr, bracket_range.start.lnum):text()
local ws = first_line:match '^%s*'
local expandtab = vim.bo[bufnr].expandtab
local shiftwidth = vim.bo[bufnr].shiftwidth
local indent_str, base_indent
if expandtab then
indent_str = string.rep(' ', shiftwidth)
base_indent = math.floor(#ws / shiftwidth)
else
indent_str = '\t'
base_indent = #ws
end
local lines = {}
local function write(line, indent_offset)
table.insert(lines, indent_str:rep(base_indent + (indent_offset or 0)) .. line)
end
table.insert(lines, left)
local curr = bracket_range.start:next()
if curr == nil then return end
@@ -27,7 +50,7 @@ local function split(bracket_range, left, right)
if vim.tbl_contains({ ',', ';' }, curr:char()) then
-- accumulate item:
local item = vim.trim(Range.new(last_start, curr):text())
if item ~= '' then code:indent():write(item) end
if item ~= '' then write(item, 1) end
local next_last_start = curr:next()
if next_last_start == nil then break end
@@ -45,11 +68,11 @@ local function split(bracket_range, left, right)
local pos_before_right = bracket_range.stop:must_next(-1)
if last_start < pos_before_right then
local item = vim.trim(Range.new(last_start, pos_before_right):text())
if item ~= '' then code:indent():write(item) end
if item ~= '' then write(item, 1) end
end
code:write(right)
bracket_range:replace(code.lines)
write(right)
bracket_range:replace(lines)
end
--- @param bracket_range u.Range