echasnovski / mini.nvim

Library of 40+ independent Lua modules improving overall Neovim (version 0.8 and higher) experience with minimal effort
MIT License
4.45k stars 171 forks source link

Inconsistent spaces in mini.splitjoin #1002

Closed justus2510 closed 3 days ago

justus2510 commented 3 days ago

Contributing guidelines

Module(s)

splitjoin

Description

I like to format my function calls such that the arguments are all indented to the opening parenthesis. However, this style seems to introduce inconsistent spaces when joining.

I was able to easily fix this using a hook:

local function comma_fixup(split_positions)
    local line = vim.api.nvim_get_current_line()
    local new_line = {}
    for i = 1, #line do
        table.insert(new_line, line:sub(i, i))
        if line:sub(i, i+1):match(",[^%s]") then
            table.insert(new_line, " ")
        end
    end
    new_line = table.concat(new_line)
    vim.api.nvim_set_current_line(new_line)
end

require("mini.splitjoin").setup({
    join = { hooks_post = {comma_fixup} },
})

Neovim version

0.10.0

Steps to reproduce

  1. Format a function call like this (all arguments lined up):
    func(a,
     b,
     c,
     d)
  2. Join/Toggle the lines.

Expected behavior

func(a, b, c, d)

Actual behavior

func(a,b, c,d)

echasnovski commented 3 days ago

Thanks for the issue!

This is an intended and documented behavior. The idea is that it is consistent with common case of splitting function call (like f(a, b, c)) or an array without initial padding (like [a, b, c]).

The suggested way to account for that is indeed with custom hooks.

Closing as not planned.