noice.nvim icon indicating copy to clipboard operation
noice.nvim copied to clipboard

feature: Custom format functions

Open lmcnulty4 opened this issue 1 month ago • 0 comments

Did you check the docs?

  • [X] 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.

image

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:

image

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

lmcnulty4 avatar May 06 '24 14:05 lmcnulty4