Closed tummetott closed 7 months ago
Hi there, An approach that should do what you want is to get the indentation level of the folded line, and prepend that amount of spaces to the content.
{
keep_indentation = false,
sections = {
left = {
function() return string.rep(' ', vim.fn.indent(vim.v.foldstart)) end, 'content',
},
},
}
@runarsf Thank you so much for providing such a straightforward solution. I can't believe I didn't think of that earlier.
For future reference, I made some alterations to the solution. It appears that the content module adds a whitespace character as a prefix if content
is not the first entry in the left
dictionary and the keep_indentation
flag is set to false
. This can result in a misalignment issue, causing the foldtext to be off by one character. See the source code:
So I strip away the leading whitespace like this:
{
keep_indentation = false,
sections = {
left = {
function(config)
local prefix = ''
local indent = vim.fn.indent(vim.v.foldstart)
if indent and indent > 0 then
prefix = string.rep(' ', indent)
end
local content = require('pretty-fold.components')['content'](config)
-- Cut the leading whitespace
content = content:gsub('^%s*', '')
return prefix .. content
end,
},
},
}
Hello there,
Let's assume the following code snippet:
When i fold the function, the code looks like this
I would like to get rid of the red circled
fill_char
sAs far as I can tell, the way to go about this is by configuring
fill_char = ' '
within the pretty-foldssetup()
function and then creating a right-side section which also generates the dots in between. Something like this:I'm aware I could skip using the
content
generated by the plugin and grab the text of the first line of the fold usingvim.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!