feature: Custom format functions
lmcnulty4 opened this issue · comments
Did you check the docs?
- I have read all the noice.nvim docs
Is your feature request related to a problem? Please describe.
I don't like the default text that nvim spits out for search_count events. I don't need to be told the text that I'm highlighting or searching for, all I want is a count. So I want to mutate the message text. Here's an example of searching for "DemoApplication" and the virtual text showing that same search term before the [1/2] count.
What would be nice is an API to alter the text in the message that is displayed, ultimately I want it to look like this:
Describe the solution you'd like
Well, I'm not sure the best way this would fit in to Noice but allowing more flexible formatters seems like it might be the best? If we could include functions in the formatter instead of just the built in formatters (or of tables which are compose of only the built in formatters), that would work I think.
So it could be like
require("noice").setup({
...,
format = {
my_formatter = function(message, opts, input)
message:append(map_message(input:content()))
end
},
})
Describe alternatives you've considered
I have worked around this issue for my own purposes but it relies on internals that I don't think you'd be happy to support people toying with:
require("noice").setup({ ... })
local Formatters = require("noice.text.format.formatters")
local FormatConfig = require("noice.config.format")
Formatters.trim_search_count = function(message, opts, input)
local content = utils.extract_search_nums(input:content()) -- this pulls out the [x/y] content I am interested in
if opts.hl_group then
message:append(content, opts.hl_group)
else
message:append(content)
end
end
FormatConfig.builtin.trim_search_count = { "{trim_search_count}" }
Additional context
No response
That would be nice to have. In general a way to modify a message on a route would be a good addition.