neovim / neovim

Vim-fork focused on extensibility and usability
https://neovim.io
Other
82.27k stars 5.62k forks source link

Fold improvements discussion #5931

Open teto opened 7 years ago

teto commented 7 years ago

I've been working to improve the terminal folding display and some things I think are LGTM:

But some aspects I am less confident with and would like some input:

Nb: as a reminder for myself: lines displayed on screen are generated by win_line and fold_line. Both functions write their result in current_ScreenLine which is copied later at the right offset. fold_line fills current_ScreenLine via copy_text_attr calls but this function doesn't support multibytes characters. screen_puts_len is a powered up version of copy_text_attr that support multibytes characters BUT it can't write to 'current_ScreenLine' because it can't compute its offset.

justinmk commented 7 years ago

with the current code it should be easy to adjust dynamically the foldcolumn width depending on the nesting fold depth

Won't that make the screen "bounce around" when opening/closing a fold? Allowing the foldcolumn width to be configurable should be enough. Any deeper folds should just show the fold symbol in the rightmost column of the foldcolumn (leftmost when 'rtl' is set).

multicell display ? I wonder if some multicell character can improve the foldcolumn look enough to justify the addition. Which character would you like (I could only find that one '+') ?

I wouldn't bother with that. If the fold display is "externalized" later, even a TUI could show a custom layout.

character customization ? it's easy to change foldcolumn characters in the source but that might be a nice setting to have ? In fillchars ?

Given that "stl:" is part of fillchars, adding "foldcolumn:" or something like that, makes sense.

add nvim_create_fold() to API ?

👍 Definitely in favor.

help with folds UI externalization ? GUIs could draw better folds for sure

I suggest waiting until #5686 is finished.

teto commented 7 years ago

Won't that make the screen "bounce around" when opening/closing a fold? Allowing the foldcolumn width to be configurable should be enough. Any deeper folds should just show the fold symbol in the rightmost column of the foldcolumn (leftmost when 'rtl' is set).

What I was thinking of is: -Opening/closing a fold doesn't change the fdc width -Creation/fold can change fdc width and "bounce". If neovim looks at the buffer-wide maximum nesting depth, the bouncing should be relatively infrequent For instance, in my config I have :set fdc=3 and when my buffer has no folds, nvim displays 3 empty columns (=lost).

I wouldn't bother with that. If the fold display is "externalized" later, even a TUI could show a custom layout.

guess you are right, it adds too much complexity and limits the number of folds that can be displayed.

teto commented 7 years ago

I got fillchars working. My problem with adaptive fdc is that is changes the meaning of the variable, i.e. it becomes the maximum width. As it might be controversial I will focus on improving tests first.

Btw, if anyone knows how to know if the current screen line is a wrapped line or not, it could spare me some analysis (seems that LineWraps is the key but does it accepted a "screenline" or "file line" ?).

teto commented 7 years ago

I am very tempted to change the current behavior when current line foldlevel > fdc, i.e., vim prints somehow the fold levels. It does not make much sense to me but I am curious if others feel different, if they like it and how they use it:

   aa
-  {
|- {
2- {
23 bb
23 }
|| cc
|| }
|  dd
|  ee
|+ +---  3 lignes : --------------------------------------------------------------------------------------------------------------------
|  }
   gg

I would like to convey the information there are hidden folds in another way.Highlights are too distracting. I thought of some alternatives:

justinmk commented 7 years ago

Neat idea, but might be overwrought. Users should already know what to expect based on their 'foldnestmax', for example.

teto commented 7 years ago

Users should already know what to expect based on their 'foldnestmax

Agreed that's why I find the vim numbers more confusing than anything, makes current folds hard to read. Am I right in understanding you would be ok with another behavior ? In fact I finally found a behavior I am comfortable with, ie., on the last column, just do as in all other editors and put fold open/closed on the same line. Here is a preview with a max nesting of 3.

With enough fdc, there are no problems: 2017-01-27-214323_956x487_scrot

But when the number of columns is not enough to display each fold on its own column, nvim merges all the folds with a level >= fdc on the same column; example with fdc=2: 2017-01-27-214315_956x487_scrot

...and fdc=1: 2017-01-27-214307_956x487_scrot

If you are ok with it I can proceed with cleaning the code and writing tests.

justinmk commented 7 years ago

Can you annotate the pictures? I'm not seeing how that's different from the OP or existing behavior.