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

Highlighting Folded #12649

Closed
TimUntersberger opened this issue Jul 16, 2020 · 17 comments · Fixed by #20750
Closed

Highlighting Folded #12649

TimUntersberger opened this issue Jul 16, 2020 · 17 comments · Fixed by #20750
Labels
Milestone

Comments

@TimUntersberger
Copy link

  • nvim --version:
NVIM v0.5.0-539-g91e41c857
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/gcc-5 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/travis/build/neovim/bot-ci/build/neovim/build/config -I/home/travis/build/neovim/bot-ci/build/neovim/src -I/home/travis/build/neovim/bot-ci/build/neovim/.deps/usr/include -I/usr/include -I/home/travis/build/neovim/bot-ci/build/neovim/build/src/nvim/auto -I/home/travis/build/neovim/bot-ci/build/neovim/build/include
Compiled by travis@travis-job-0d051a7f-9248-40f4-b926-4d32708ab9a1

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "
/home/travis/build/neovim/bot-ci/build/neovim/build/nvim.AppDir/usr/share/nvim
"
  • vim -u DEFAULTS (version: ) behaves differently? no
  • Operating system/version: wsl2 ubuntu 20.04
  • Terminal name/version: Windows Terminal
  • $TERM: xterm-256color

Is there a way to highlight Folded text?

I'm currently writing a plugin in lua that adds highlighting the following way:

vim.fn.matchadd("Function", "^Staged changes\\ze (")

I modify the fold settings in the following way:

  vim.api.nvim_command("setlocal foldmethod=manual")
  vim.api.nvim_command([[
     function! FoldFunction()
       return getline(v:foldstart)
       endfunction
     ]])   
  vim.api.nvim_command("setlocal fillchars=fold:\\ ")
  vim.api.nvim_command("setlocal foldtext=FoldFunction()")
  vim.api.nvim_command("hi Folded guibg=None guifg=None")

This is how it looks with an open fold

image

This is how it looks with a closed fold

image

Is there a way to make the second image look like the first and if there is none is there a plan to make this happen (or is it easy to implement then I might do it myself)?

@TimUntersberger TimUntersberger added the enhancement feature request label Jul 16, 2020
@teto
Copy link
Member

teto commented Jul 16, 2020

I've been working towards this in #12515.

@TimUntersberger
Copy link
Author

@teto nice!

What would you say is the current progress on this (percent wise)?

Do you need any help?

@teto
Copy link
Member

teto commented Jul 16, 2020

the tests fail because win_line has 2 distinct paths to display characters

if (n_extra > 0) {

I need the foldtext to follow the (more comprehensive) second path rather than the first one but that's quite tricky. I was hoping to take the opportunity to make the win_line function simpler but that's no easy task.

@TimUntersberger
Copy link
Author

If you fix this problem then all of the tests pass?

I saw that you currently have no time to work on this, is this still the case? I could help you, but I have never worked with the neovim source code before so I might take some time to get to know the codebase.

I was hoping to take the opportunity to make the win_line function simpler but that's no easy task.

Is it required to simplify the function?

I need the foldtext to follow the (more comprehensive) second path rather than the first one

Why does it need to follow the second path and what exactly do you mean by more comprehensive?

Are there only edge cases left or is the functionality missing something?

@teto
Copy link
Member

teto commented Jul 16, 2020

let's say it's rather complex. If you dont use Hebrew or Arabic characters ,you could aready use the patch.

@TimUntersberger
Copy link
Author

Would your pr also include conceal support in closed folds?

example:

source

# header

conceal # with -

conceal

- header

define a foldtext function that just returns the same line and set the fillchar for fold to \

fold + conceal (without pr)

# header

fold + conceal (hopefully with pr)

- header

Thanks for your work!

Looks like you don't need my help, so I can only wish you good luck with your bug hunt :)

@stsewd
Copy link
Contributor

stsewd commented Sep 20, 2020

Looks like this is the same as #2197

@teto
Copy link
Member

teto commented Sep 25, 2020

sorry I misunderstood your request.
There is no conceal yet for foldtext (but should be possible in a not so distant future, now that the previous PR is merged, we can build upon it), nor the level of customization described in #2197.

@pinusc
Copy link

pinusc commented Feb 16, 2021

I'm not sure if I'm doing anything wrong, but even after #12515 was merged I still get no syntax highlighting on folded lines, following the specific example in the first post from @TimUntersberger. Should I? Is there anything specific I should enable/disable to ensure that my folded lines are highlited as if they weren't folded?
Or is #12515 just a necessary step to later achieve this functionality in another PR? If so, is anyone working on this?
Sorry for the many questions, this feature is super important to me and I'm really confused.

@teto
Copy link
Member

teto commented Feb 16, 2021

I still get no syntax highlighting on folded lines,

its normal. I dont think it is possible yet (maybe with lua themas ?). What would be your scenario ?

@vatosarmat
Copy link

Will it ever be possible to have normal syntax highlighting of folded function or block? This seems so natural and straightforward but for whatever reason Vim paints all Folded and draws these strange dots.....................

set foldmethod=expr
set foldexpr=nvim_treesitter#foldexpr()
set foldtext=MyFoldTextSimple()

function! MyFoldTextSimple()
  return getline(v:foldstart)
endfunction

fold

@TimUntersberger
Copy link
Author

TimUntersberger commented Mar 22, 2021

I really need this for Neogit too.

@chuwy
Copy link
Contributor

chuwy commented Oct 5, 2021

One more use case for it comes from orgmode.nvim.

Here's comparison of the same file in Emacs and NeoVim.

Screenshot 2021-10-05 at 23 32 16

Screenshot 2021-10-05 at 23 31 53

You can see than in NeoVim (2nd screenshot) the color is defined by folding. If it's folded - you cannot highlight it depending on whether it's DONE or TODO. In Emacs however, folding is an invisible detail (as it should be) and doesn't affect the highlighting.

Also really looking forward to this feature as #12515 doesn't seem to be addressing this.

I'm also wondering, what this feature would look like UX-wise. It might be:

  1. A global flag to ignore ctermfg and guifg in Folded group
  2. Adding a special group beside of Folded (something like FoldedHightlighted) with ctermfg and guifg ignored
  3. Somehow allowed creation of custom Folded-based groups with diffent highlighting rules

@dhruvasagar
Copy link

The main idea should be that syntax definitions should apply the same way to the content of the fold like as they would to other non folded lines, so color authors can choose to differentiate based on fold state if they want (DONE in dim folding... example) or regular (TODO with folding... example).

@rebelot
Copy link

rebelot commented Mar 23, 2022

Couldn't Folded hl be applied just as Diff highlights? Ie without changing foreground hl unless explicitly defined

@kristijanhusak
Copy link
Contributor

kristijanhusak commented Nov 26, 2022

One more use case for it comes from orgmode.nvim.

This is a solid alternative until we get built-in support: https://github.com/kevinhwang91/nvim-ufo

@clason
Copy link
Member

clason commented Nov 26, 2022

#20750

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet