fix(splitjoin): handle empty positions in split#2485
Open
yilisharcs wants to merge 1 commit into
Open
Conversation
why is this a problem? well, i took your advice from nvim-mini#2470 to heart and implemented the fennel logic entirely with hooks. but one minor hiccup was revealed when i tried to do this: ```lua -- brackets stay close to the first and last elements local function lisp_split(positions) if #positions < 2 then return positions end -- here specifically, i am NOT splitting if a -- list only has 1 index or 1 key-value pair local res = {} for i = 2, #positions - 1 do res[i - 1] = positions[i] end return res end ``` where on line 354 it would attempt to index local 'last' (a nil value). i thought it'd be ugly if i allowed splits here and the rest is history. i figure that this patch is simple enough that it won't trouble you this time. keep up the good work! i love your plugins
Member
|
Thanks for the PR! Please provide a minimal reproduction steps that show the problem. This will help determining if the issue is on 'mini.splitjoin' side and potentially with writing tests. |
Author
|
like so?
-- minimal.lua
require("mini.splitjoin").setup()
vim.cmd("edit " .. vim.fn.tempname() .. ".lua")
vim.api.nvim_buf_set_lines(0, 0, -1, false, {
"[a]",
"{ b = 1 }",
})
local function dont_split_loners(positions)
if #positions < 2 then
return positions
end
local res = {}
for i = 2, #positions - 1 do
res[i - 1] = positions[i]
end
return res
end,
vim.b.minisplitjoin_config = {
split = {
hooks_pre = { dont_split_loners },
},
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
why is this a problem? well, i took your advice from #2470 to heart and
implemented the fennel logic entirely with hooks. but one minor hiccup
was revealed when i tried to do this:
where on line 354 it would attempt to index local 'last' (a nil value).
i thought it'd be ugly if i allowed splits here and the rest is history.
i figure that this patch is simple enough that it won't trouble you this
time. keep up the good work! i love your plugins