[mini.pick] alignment with grep_live? #1192
-
Now that we have alignment with buf_lines, I really want the same for local show_align_on_nul = function(buf_id, items, query, opts)
items = MiniAlign.align_strings(items, {
justify_side = { "left", "right", "right" },
merge_delimiter = { "", " ", "", " ", "" },
split_pattern = "%z",
})
MiniPick.default_show(buf_id, items, query, opts)
end
MiniPick.registry.grep_live_align = function()
MiniPick.builtin.grep_live({}, { source = { show = show_align_on_nul } })
end Alas, it doesn't work because of Anyone have any simple suggestions? Thanks! Updated solution with monkey patching based on this comment: local show_align_on_nul = function(buf_id, items, query, opts)
-- HACK: `items` is an array of strings with \0 byte separators, cannot use strdisplaywidth.
local original = vim.fn.strdisplaywidth
vim.fn.strdisplaywidth = string.len
items = MiniAlign.align_strings(items, {
justify_side = { "left", "right", "right" },
merge_delimiter = { "", " ", "", " ", "" },
split_pattern = "%z",
})
vim.fn.strdisplaywidth = original
MiniPick.default_show(buf_id, items, query, opts)
end
MiniPick.registry.grep_live_align = function()
MiniPick.builtin.grep_live({}, { source = { show = show_align_on_nul } })
end |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
The simplest (and the hackiest) suggestion is to temporarily monkey patch The more proper suggestion would be to replace Just a note: as |
Beta Was this translation helpful? Give feedback.
-
Very nice! |
Beta Was this translation helpful? Give feedback.
The simplest (and the hackiest) suggestion is to temporarily monkey patch
vim.fn.strdisplaywidth = string.len
.The more proper suggestion would be to replace
\0
with come rare character (or even'│'
right away), align using replaced character as split pattern, and then replace them back to be\0
.Just a note: as
grep_live
is a fairly performance critical function, I don't think it having alignment option similar toMiniExtra.pickers.buf_lines
is a good idea.