Skip to content

better breakindent for numbered/bulleted lists#8564

Closed
chrisbra wants to merge 3 commits intovim:masterfrom
chrisbra:vim_1661
Closed

better breakindent for numbered/bulleted lists#8564
chrisbra wants to merge 3 commits intovim:masterfrom
chrisbra:vim_1661

Conversation

@chrisbra
Copy link
Member

Detecting bulleted or numbered lists and applying an additional indentation for soft-wrapping is a bit of a popular request (see #1661). So here is a PR, that implements this. It makes use of the 'formatlistpat' option setting to detect such lines and if they match, Vim applies an additional indent, that can be specified using :set breakindentopt+=list:{n}. By default this is not set. This works currently best in combination with the 'linebreak' setting.

It also adds some tests to make sure it works correctly and also adds some documentation.

@codecov
Copy link

codecov bot commented Jul 13, 2021

Codecov Report

Merging #8564 (391e8a6) into master (841e498) will decrease coverage by 0.34%.
The diff coverage is 100.00%.

❗ Current head 391e8a6 differs from pull request most recent head 00a49af. Consider uploading reports for the commit 00a49af to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8564      +/-   ##
==========================================
- Coverage   90.03%   89.68%   -0.35%     
==========================================
  Files         150      150              
  Lines      168219   167582     -637     
==========================================
- Hits       151462   150302    -1160     
- Misses      16757    17280     +523     
Flag Coverage Δ
huge-clang-none 89.18% <100.00%> (+0.10%) ⬆️
huge-gcc-none 89.53% <100.00%> (+<0.01%) ⬆️
huge-gcc-testgui ?
huge-gcc-unittests 2.49% <18.18%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/version.c 92.34% <ø> (ø)
src/evalfunc.c 95.61% <100.00%> (-0.56%) ⬇️
src/indent.c 93.82% <100.00%> (+0.07%) ⬆️
src/gui_gtk_x11.c 58.44% <0.00%> (-4.87%) ⬇️
src/highlight.c 86.63% <0.00%> (-3.83%) ⬇️
src/gui_gtk.c 28.05% <0.00%> (-3.23%) ⬇️
src/gui.c 69.48% <0.00%> (-2.92%) ⬇️
src/buffer.c 90.12% <0.00%> (-2.33%) ⬇️
src/os_unix.c 69.92% <0.00%> (-2.30%) ⬇️
src/hardcopy.c 85.78% <0.00%> (-1.99%) ⬇️
... and 51 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 841e498...00a49af. Read the comment docs.

@brammool brammool closed this in 4a0b85a Jul 14, 2021
@chrisbra chrisbra deleted the vim_1661 branch July 14, 2021 19:12
@habamax
Copy link
Contributor

habamax commented Jul 16, 2021

Thx for the patch, Christian!

I wonder if it is possible to have "dynamic" list:{n} ?

There are lists that are common in asciidoc format where sublilst level could be defined as a sequence of *:
image

With current implementation it is only possible to define a single indent for all list items but not per "level".

I am not sure if it is possible to capture what was in formatlistpat and count the length and use it somehow?

Anyway even with current impl it is better than it was before, thank you again!

PS, formatlistpat I use for asciidoc:

set wrap breakindent briopt+=list:2
let &formatlistpat = '^\s*[\[({]\?\([0-9]\+\|[a-zA-Z]\)[\]:.)}]\s\+\|^\s*-\s\+\|^\s*[*]\+\s\+\|^\s*[.]\+\s\+'

@chrisbra
Copy link
Member Author

Hm, it might be possible. If you use the formatlistpat on such a line using len(matchstr(&formatlistpat, line)) does that return the length of the indent you need?

@habamax
Copy link
Contributor

habamax commented Jul 16, 2021

Hm, it might be possible. If you use the formatlistpat on such a line using len(matchstr(&formatlistpat, line)) does that return the length of the indent you need?

Nope, it reports:

image

@habamax
Copy link
Contributor

habamax commented Jul 16, 2021

lol we have used wrong position of the args

@habamax
Copy link
Contributor

habamax commented Jul 16, 2021

Hm, it might be possible. If you use the formatlistpat on such a line using len(matchstr(&formatlistpat, line)) does that return the length of the indent you need?

echo len(matchstr(getline(1), &formatlistpat))

returns 5 ^^^^, which is 1 char less than needed but that should be covered by `list:1` then.

@chrisbra
Copy link
Member Author

I was more thinking, that when using briopt=list:-1 use the indent that formatlistpat matches. Not sure if this really makes sense for the normal formatlistpat usage.

@habamax
Copy link
Contributor

habamax commented Jul 16, 2021

I was more thinking, that when using briopt=list:-1 use the indent that formatlistpat matches. Not sure if this really makes sense for the normal formatlistpat usage.

Hmm, you are right -- I don't have to add anything to indent:
image

@habamax
Copy link
Contributor

habamax commented Jul 16, 2021

To be clear, yes, using indent of the matched formatlistpat should be ok

if (regmatch.regprog != NULL && vim_regexec(&regmatch, line, 0))
{
vim_regfree(regmatch.regprog);
bri += wp->w_briopt_list;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be smth like

›       ›       bri += wp->w_briopt_list > 0 ? wp->w_briopt_list : len(regmatch???);

provided there is another condition in the outer if (wp->w_briopt_list > 0 || wp->w_briopt_list == -1)

For the formatlistpat indentation?

Copy link
Contributor

@habamax habamax Jul 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

having formatlistpat and set briopt+=list:-1 +

    // add additional indent for numbered lists
    if (wp->w_briopt_list > 0 || wp->w_briopt_list == -1)
    {
        regmatch_T          regmatch;

        regmatch.regprog = vim_regcomp(curbuf->b_p_flp,
                                   RE_MAGIC + RE_STRING + RE_AUTO + RE_STRICT);
        if (regmatch.regprog != NULL)
        {
            if (vim_regexec(&regmatch, line, 0))
                if (wp->w_briopt_list > 0)
                    bri += wp->w_briopt_list;
                else
                    bri += (*regmatch.endp - *regmatch.startp);
            vim_regfree(regmatch.regprog);
        }
    }


janlazo added a commit to janlazo/neovim that referenced this pull request Aug 8, 2021
Problem:    'breakindent' does not work well for bulleted and numbered lists.
Solution:   Add the "list" entry to 'breakindentopt'. (Christian Brabandt,
            closes vim/vim#8564, closes vim/vim#1661)
vim/vim@4a0b85a
janlazo added a commit to janlazo/neovim that referenced this pull request Aug 9, 2021
Problem:    'breakindent' does not work well for bulleted and numbered lists.
Solution:   Add the "list" entry to 'breakindentopt'. (Christian Brabandt,
            closes vim/vim#8564, closes vim/vim#1661)
vim/vim@4a0b85a
janlazo added a commit to janlazo/neovim that referenced this pull request Aug 9, 2021
Problem:    'breakindent' does not work well for bulleted and numbered lists.
Solution:   Add the "list" entry to 'breakindentopt'. (Christian Brabandt,
            closes vim/vim#8564, closes vim/vim#1661)
vim/vim@4a0b85a
janlazo added a commit to janlazo/neovim that referenced this pull request Aug 9, 2021
Problem:    'breakindent' does not work well for bulleted and numbered lists.
Solution:   Add the "list" entry to 'breakindentopt'. (Christian Brabandt,
            closes vim/vim#8564, closes vim/vim#1661)
vim/vim@4a0b85a
github-actions bot pushed a commit to dundargoc/neovim that referenced this pull request Aug 13, 2021
Problem:    'breakindent' does not work well for bulleted and numbered lists.
Solution:   Add the "list" entry to 'breakindentopt'. (Christian Brabandt,
            closes vim/vim#8564, closes vim/vim#1661)
vim/vim@4a0b85a
github-actions bot pushed a commit to dundargoc/neovim that referenced this pull request Aug 13, 2021
Problem:    'breakindent' does not work well for bulleted and numbered lists.
Solution:   Add the "list" entry to 'breakindentopt'. (Christian Brabandt,
            closes vim/vim#8564, closes vim/vim#1661)
vim/vim@4a0b85a
github-actions bot pushed a commit to dundargoc/neovim that referenced this pull request Aug 13, 2021
Problem:    'breakindent' does not work well for bulleted and numbered lists.
Solution:   Add the "list" entry to 'breakindentopt'. (Christian Brabandt,
            closes vim/vim#8564, closes vim/vim#1661)
vim/vim@4a0b85a
chrisbra added a commit to chrisbra/vim that referenced this pull request Aug 30, 2021
Problem:    'breakindent' does not work well for bulleted and numbered lists.
Solution:   Add the "list" entry to 'breakindentopt'. (Christian Brabandt,
            closes vim#8564, closes vim#1661)
muniter pushed a commit to muniter/neovim that referenced this pull request Sep 8, 2021
Problem:    'breakindent' does not work well for bulleted and numbered lists.
Solution:   Add the "list" entry to 'breakindentopt'. (Christian Brabandt,
            closes vim/vim#8564, closes vim/vim#1661)
vim/vim@4a0b85a
lewis6991 pushed a commit to lewis6991/neovim that referenced this pull request Dec 12, 2021
Problem:    'breakindent' does not work well for bulleted and numbered lists.
Solution:   Add the "list" entry to 'breakindentopt'. (Christian Brabandt,
            closes vim/vim#8564, closes vim/vim#1661)
vim/vim@4a0b85a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants