luukvbaal / statuscol.nvim

Status column plugin that provides a configurable 'statuscolumn' and click handlers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Show foldcolumn only when one or more folds are closed

yoplat opened this issue · comments

Screen.Recording.2023-10-09.at.16.57.39.mov

This is what I've been able to do to make it happen but I don't know why but it adds spacing to the left instead of the right. I'm looking for a way to enable the foldcolumn only when there is at least one fold closed.

Not exactly sure what you want, this segment might be closer:

{
  text = {
    function() return "%=" end,
    " ",
    builtin.foldfunc
  },
  condition = {
    true, 
    function(args) return args.fold.width > 0 end,
    true,
  }
},

Also, is the condition for builtin.foldfunc even necessary?
If you set 'foldcolumn' to "auto" it should hide automatically when there are no folds in the current buffer.

I've added args.fold.width in 826aed3 which you might use as the condition for the whitespace in your config (still not exactly sure that that is what you want).

Also, is the condition for builtin.foldfunc even necessary? If you set 'foldcolumn' to "auto" it should hide automatically when there are no folds in the current buffer.

It's not that I want to disable it if there are no folds in the buffer (not specifically), I want to disable it even if there are folds available in the buffer but there isn't any closed. I want to show the foldcolumn only if there is at least one fold closed. This is because I normally don't use folds, but if I fold something I want to be able to see it in the statuscolumn.

Detecting whether the current window contains any closed folds is unfortunately not currently possible through the neovim API without looping over each buffer line(neovim/neovim#19226). Not something I would recommend to do inside the statuscolumn callback.

Hi @luukvbaal. I'm using the solution you posted. As it can be seen in the image below my fold currently looks like >291 class.... I have two questions:

  1. Is possible to get the > fold symbol in the current line to share the linenr (white) highlight? (only for the current line)
  2. I like the fact that there is minimal separation/padding between the fold symbol and the line number but for the current line I would like to add a whitespace such that I get > 291 instead of >291 (while keeping for the other lines the > 3). Dunno if this is possible.

Thanks in advance for the help!
image

  1. See :h hl-CursorLineFold. The builtin fold column segment should follow that highlight group when 'cursorline' is set.
  2. I'm not sure, the picture you posts shows a misaligned foldcolumn. The foldcolumn should be a single column no, it would look weird with a foldcolumn that has a background highlight defind.
    If that is what my snippet yields it is erroneous, perhaps adding a %= segment isn't a good idea. Simply adding padding (conditional on whether there is a foldcolumn) before the line number could be done like so:
{
  text = {
    builtin.foldfunc,
    " ",
  },
  condition = {
    true,
    function(args) return args.fold.width > 0 end,
  }
}

Closing this, original issue kind of necessitates an addition to the neovim API.

  1. Great. Worked perfectly
  2. What I meant was whether is possible to have a different padding behavior for the current/cursor line. I use relative numbers so relativeline numbers tend to be small (between 1-52) except for the current line (which shows the actual line number, in the image 291). I like the way fold + line numbers look in general (i.e minimal space between the fold and the line nr as in > 3 class RolCustomApp) but was wondering whether a condition could be added such that if we are on the current line an extra padding can be added between the fold and the line number: > 291 instead of >291.

@petobens I mean a conditional whitespace segment for the current line would be:

{
  text = { " " },
  condition = { function(args) return args.relnum == 0 end }
},

But IDK if you can make that work properly with alignment.

Mmm doing:

        {
            text = {
                function()
                    return '%='
                end,
                builtin.foldfunc,
            },
            auto = true,
        },
        {
            text = {
                function(args)
                    return (args.relnum == 0) and ' ' or ''
                end,
            },
        },

is basically equivalent to simply adding a whitespace characters after the foldfunc as far as I can tell:

        {
            text = {
                function()
                    return '%='
                end,
                builtin.foldfunc,
                ' ',
            },
            auto = true,
        },

If this is true then I have no further options right?

is basically equivalent to simply adding a whitespace characters after the foldfunc as far as I can tell:

Yeah probably because the builtin line number segment starts with a %=, any preceding whitespace is aligned also on non-cursor lines.

If this is true then I have no further options right?

Yeah unfortunately I don't think any non-trivial segment/option this plugin provides can do what you're looking for. Probably doable if you resort to custom segments that add their own padding rather than relying on the %= separator item...