Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restoring a User{N} highlight inside an item group causes the whole item group to disappear #29306

Closed
antoineco opened this issue Jun 12, 2024 · 5 comments
Labels
bug-vim wrong behavior inherited from vim statusline tabline, winbar, statuscolumn

Comments

@antoineco
Copy link
Sponsor Contributor

Problem

Given:

  • a Lua function that returns a string which can be expanded inside statusline (e.g. return '%1*hello%*')
  • a statusline item group that expands the value returned by this function (e.g. %([%{%v:lua.myfunc()%}]%))

The entire item group disappears if the expansion contains a highlight restore item: either %* or %0*.

It does get rendered if a %N* item is positioned before the item group.

Steps to reproduce

nvim --clean
:hi User1 guifg=Red
:hi User2 guifg=Blue
:lua MyFunc = function() return "%1*MyFunc%*" end
  1. Simple expansion, no other user highlight in the statusline:

    :set statusline=--%(x%{%v:lua.MyFunc()%}x%)--

    statusline is rendered without the item group, neither the colored text nor the inner 'x's are printed:
    image

  2. Item group prefixed with another user highlight (it doesn't matter which one):

    :set statusline=--%2*%(x%{%v:lua.MyFunc()%}x%)--

    statusline is rendered with the item group, but not with the desired appearance due to workarounds:
    image

    Here the item group no longer disappears, but having to prefix it with a User{N} highlight is a hack that results in visual glitches, and possibly other side effects.

Expected behavior

In the first case above, the statusline should have been rendered with the text "MyFunc" highlighted in red, with all surrounding characters highlighted according to the built-in StatusLine highlight group:
image

Neovim version (nvim -v)

v0.11.0-dev-219+gc37695a5d

Vim (not Nvim) behaves the same?

N/A (no Lua)

Operating system/version

Debian 12

Terminal name/version

WezTerm

$TERM environment variable

wezterm

Installation

Build from repo

@antoineco antoineco added the bug issues reporting wrong behavior label Jun 12, 2024
@antoineco
Copy link
Sponsor Contributor Author

antoineco commented Jun 12, 2024

Interestingly, it works as expected if the Lua function returns any expandable item between %1* and %*, as opposed to just the "MyFunc" text.

:lua MyFunc = function() return "%1*MyFunc%t%*" end
:set statusline=--%(x%{%v:lua.MyFunc()%}x%)--

image

@zeertzjq zeertzjq added bug-vim wrong behavior inherited from vim statusline tabline, winbar, statuscolumn and removed bug issues reporting wrong behavior labels Jun 13, 2024
@zeertzjq
Copy link
Member

You don't need a Lua function to reproduce this. It also happens when putting it inside a string literal:

:set statusline=--%(x%{%'%1*MyFunc%*'%}x%)--

@zeertzjq
Copy link
Member

Actually you don't need a expression either:

:set statusline=--%(x%1*MyFunc%*x%)--

@antoineco
Copy link
Sponsor Contributor Author

Thanks for pointing this out, I didn't even consider putting a string literal inside a %{% item.

I should report this in vim/vim. I'm closing this issue for now.

@antoineco antoineco closed this as not planned Won't fix, can't repro, duplicate, stale Jun 13, 2024
@antoineco antoineco changed the title statusline: Restoring a User{N} highlight inside a v:lua expansion causes the whole item group to disappear Restoring a User{N} highlight inside an item group causes the whole item group to disappear Jun 13, 2024
@antoineco
Copy link
Sponsor Contributor Author

This is indeed an upstream bug.
It was decided upstream that the bug wouldn't be fixed to avoid breaking people who rely on the behavior (see reference above.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-vim wrong behavior inherited from vim statusline tabline, winbar, statuscolumn
Projects
None yet
Development

No branches or pull requests

2 participants