pretty-fold.nvim icon indicating copy to clipboard operation
pretty-fold.nvim copied to clipboard

How to get rid of the `fill_char`s in the foldtext before the `content`

Open tummetott opened this issue 2 years ago • 0 comments

Hello there,

Let's assume the following code snippet: image

When i fold the function, the code looks like this image

I would like to get rid of the red circled fill_chars

As far as I can tell, the way to go about this is by configuring fill_char = ' ' within the pretty-folds setup() function and then creating a right-side section which also generates the dots in between. Something like this:

local fold_text = function()
    local lines = vim.v.foldend - vim.v.foldstart + 1
    local padding = has_scrollbar() and ' ' or ''
    local n = vim.api.nvim_win_get_width(0)
         - vim.fn.strdisplaywidth(lines)
         - vim.fn.strdisplaywidth(padding)
         - vim.fn.strdiplaywidth(content) -- How do i get content???
         + 8) -- plus 8 because I have 8 fixed characters in my final string
    local fill_chars = string.rep('⋅', n)
    return string.format('%s %d LINES %s', fill_chars, lines, padding)
end

require('pretty-fold').setup {
    sections = {
        left = { 'content' }, -- I want to have the length of this content in my custom function before
        right = { fold_text }, -- use my custom function
    },
    fill_char = ' ',
    add_close_pattern = true,
}

I'm aware I could skip using the content generated by the plugin and grab the text of the first line of the fold using vim.api.nvim_buf_get_lines(...). However, that would mean missing out on the cool substitutions like the close_pattern, etc.

Is there a way to determine the length of the content? Or perhaps a simpler approach to achieve my goal?

Thanks a lot!

tummetott avatar Oct 09 '23 19:10 tummetott