Patch 8.2.4093

10 views
Skip to first unread message

Bram Moolenaar

unread,
Jan 15, 2022, 5:01:44 AM1/15/22
to vim...@googlegroups.com

Patch 8.2.4093
Problem: Cached breakindent values not initialized properly.
Solution: Initialize and cache formatlistpat. (Christian Brabandt,
closes #9526, closes #9512)
Files: runtime/doc/options.txt, src/indent.c, src/option.c,
src/proto/option.pro, src/testdir/test_breakindent.vim


*** ../vim-8.2.4092/runtime/doc/options.txt 2021-12-26 12:07:24.798944010 +0000
--- runtime/doc/options.txt 2022-01-15 09:50:48.197456124 +0000
***************
*** 1370,1375 ****
--- 1370,1376 ----
text should normally be narrower. This prevents
text indented almost to the right window border
occupying lot of vertical space when broken.
+ (default: 20)
shift:{n} After applying 'breakindent', the wrapped line's
beginning will be shifted by the given number of
characters. It permits dynamic French paragraph
*** ../vim-8.2.4092/src/indent.c 2022-01-07 16:55:27.112417600 +0000
--- src/indent.c 2022-01-15 10:00:12.996681829 +0000
***************
*** 924,929 ****
--- 924,931 ----
# endif
static int prev_list = 0; // cached list value
static int prev_listopt = 0; // cached w_p_briopt_list value
+ // cached formatlistpat value
+ static char_u *prev_flp = NULL;
int bri = 0;
// window width minus window margin space, i.e. what rests for text
const int eff_wwidth = wp->w_width
***************
*** 931,940 ****
&& (vim_strchr(p_cpo, CPO_NUMCOL) == NULL)
? number_width(wp) + 1 : 0);

! // used cached indent, unless line, 'tabstop' or briopt_list changed
if (prev_line != line || prev_ts != wp->w_buffer->b_p_ts
|| prev_tick != CHANGEDTICK(wp->w_buffer)
|| prev_listopt != wp->w_briopt_list
# ifdef FEAT_VARTABS
|| prev_vts != wp->w_buffer->b_p_vts_array
# endif
--- 933,948 ----
&& (vim_strchr(p_cpo, CPO_NUMCOL) == NULL)
? number_width(wp) + 1 : 0);

! // used cached indent, unless
! // - line pointer changed
! // - 'tabstop' changed
! // - 'briopt_list changed' changed or
! // - 'formatlistpattern' changed
if (prev_line != line || prev_ts != wp->w_buffer->b_p_ts
|| prev_tick != CHANGEDTICK(wp->w_buffer)
|| prev_listopt != wp->w_briopt_list
+ || (prev_flp == NULL
+ || (STRCMP(prev_flp, get_flp_value(wp->w_buffer)) != 0))
# ifdef FEAT_VARTABS
|| prev_vts != wp->w_buffer->b_p_vts_array
# endif
***************
*** 953,965 ****
(int)wp->w_buffer->b_p_ts, wp->w_p_list);
# endif
prev_listopt = wp->w_briopt_list;
// add additional indent for numbered lists
if (wp->w_briopt_list != 0)
{
regmatch_T regmatch;

! regmatch.regprog = vim_regcomp(curbuf->b_p_flp,
! RE_MAGIC + RE_STRING + RE_AUTO + RE_STRICT);

if (regmatch.regprog != NULL)
{
--- 961,976 ----
(int)wp->w_buffer->b_p_ts, wp->w_p_list);
# endif
prev_listopt = wp->w_briopt_list;
+ prev_list = 0;
+ vim_free(prev_flp);
+ prev_flp = vim_strsave(get_flp_value(wp->w_buffer));
// add additional indent for numbered lists
if (wp->w_briopt_list != 0)
{
regmatch_T regmatch;

! regmatch.regprog = vim_regcomp(prev_flp,
! RE_MAGIC + RE_STRING + RE_AUTO + RE_STRICT);

if (regmatch.regprog != NULL)
{
*** ../vim-8.2.4092/src/option.c 2022-01-08 12:41:12.208795550 +0000
--- src/option.c 2022-01-15 09:50:48.197456124 +0000
***************
*** 7053,7058 ****
--- 7053,7070 ----
}

/*
+ * Get the local or global value of 'formatlistpat'.
+ */
+ char_u *
+ get_flp_value(buf_T *buf)
+ {
+ return buf->b_p_flp ? buf->b_p_flp : p_flp;
+ if (buf->b_p_flp == NULL || *buf->b_p_flp == NUL)
+ return p_flp;
+ return buf->b_p_flp;
+ }
+
+ /*
* Get the local or global value of the 'virtualedit' flags.
*/
unsigned int
*** ../vim-8.2.4092/src/proto/option.pro 2021-12-06 11:03:50.950900210 +0000
--- src/proto/option.pro 2022-01-15 09:50:48.197456124 +0000
***************
*** 73,78 ****
--- 73,79 ----
long get_scrolloff_value(void);
long get_sidescrolloff_value(void);
unsigned int get_bkc_value(buf_T *buf);
+ char_u *get_flp_value(buf_T *buf);
unsigned int get_ve_flags(void);
char_u *get_showbreak_value(win_T *win);
dict_T *get_winbuf_options(int bufopt);
*** ../vim-8.2.4092/src/testdir/test_breakindent.vim 2021-09-02 19:05:22.925120220 +0100
--- src/testdir/test_breakindent.vim 2022-01-15 09:50:48.197456124 +0000
***************
*** 849,852 ****
--- 849,909 ----
%bw!
endfunc

+ func Test_no_spurious_match()
+ let s:input = printf('- y %s y %s', repeat('x', 50), repeat('x', 50))
+ call s:test_windows('setl breakindent breakindentopt=list:-1 formatlistpat=^- hls')
+ let @/ = '\%>3v[y]'
+ redraw!
+ call searchcount().total->assert_equal(1)
+ " cleanup
+ set hls&vim
+ let s:input = "\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP"
+ bwipeout!
+ endfunc
+
+ func Test_no_extra_indent()
+ call s:test_windows('setl breakindent breakindentopt=list:-1,min:10')
+ %d
+ let &l:formatlistpat='^\s*\d\+\.\s\+'
+ let text = 'word '
+ let len = text->strcharlen()
+ let line1 = text->repeat((winwidth(0) / len) * 2)
+ let line2 = repeat(' ', 2) .. '1. ' .. line1
+ call setline(1, [line2])
+ redraw!
+ " 1) matches formatlist pattern, so indent
+ let expect = [
+ \ " 1. word word word ",
+ \ " word word word ",
+ \ " word word ",
+ \ "~ ",
+ \ ]
+ let lines = s:screen_lines2(1, 4, 20)
+ call s:compare_lines(expect, lines)
+ " 2) change formatlist pattern
+ " -> indent adjusted
+ let &l:formatlistpat='^\s*\d\+\.'
+ let expect = [
+ \ " 1. word word word ",
+ \ " word word word ",
+ \ " word word ",
+ \ "~ ",
+ \ ]
+ let lines = s:screen_lines2(1, 4, 20)
+ " 3) add something in front, no additional indent
+ norm! gg0
+ exe ":norm! 5iword \<esc>"
+ redraw!
+ let expect = [
+ \ "word word word word ",
+ \ "word 1. word word ",
+ \ "word word word word ",
+ \ "word word ",
+ \ "~ ",
+ \ ]
+ let lines = s:screen_lines2(1, 5, 20)
+ call s:compare_lines(expect, lines)
+ bwipeout!
+ endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.4092/src/version.c 2022-01-14 21:28:55.580849073 +0000
--- src/version.c 2022-01-15 09:56:29.829032222 +0000
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 4093,
/**/

--
PRINCE: He's come to rescue me, father.
LAUNCELOT: (embarrassed) Well, let's not jump to conclusions ...
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Dominique Pellé

unread,
Jan 15, 2022, 5:44:06 AM1/15/22
to vim_dev
Bram Moolenaar <Br...@moolenaar.net> wrote:

> Patch 8.2.4093
> Problem: Cached breakindent values not initialized properly.
> Solution: Initialize and cache formatlistpat. (Christian Brabandt,
> closes #9526, closes #9512)
> Files: runtime/doc/options.txt, src/indent.c, src/option.c,
> src/proto/option.pro, src/testdir/test_breakindent.vim

...snip...

> /*
> + * Get the local or global value of 'formatlistpat'.
> + */
> + char_u *
> + get_flp_value(buf_T *buf)
> + {
> + return buf->b_p_flp ? buf->b_p_flp : p_flp;
> + if (buf->b_p_flp == NULL || *buf->b_p_flp == NUL)
> + return p_flp;
> + return buf->b_p_flp;
> + }

Code is deadcode after the first return.
gcc-11 reports:

option.c:7062:9: warning: code will never be executed [-Wunreachable-code]
if (buf->b_p_flp == NULL || *buf->b_p_flp == NUL)
^~~

Regards
Dominique

Bram Moolenaar

unread,
Jan 15, 2022, 6:01:09 AM1/15/22
to vim...@googlegroups.com, Dominique Pellé
The first line should not be there, b_p_flp should not be NULL (after
initialization) but can be empty.
This also suggests there is no test for using the global value...

--
Overflow on /dev/null, please empty the bit bucket.

Christian Brabandt

unread,
Jan 15, 2022, 12:57:29 PM1/15/22
to vim_dev

On Sa, 15 Jan 2022, Dominique Pellé wrote:

> option.c:7062:9: warning: code will never be executed [-Wunreachable-code]
> if (buf->b_p_flp == NULL || *buf->b_p_flp == NUL)
> ^~~

Ooops that was a first version and should have been removed.
Here is another patch on top of that:

```patch
diff --git a/src/option.c b/src/option.c
index 0a75c2417..ff539683e 100644
--- a/src/option.c
+++ b/src/option.c
@@ -7058,7 +7058,6 @@ get_bkc_value(buf_T *buf)
char_u *
get_flp_value(buf_T *buf)
{
- return buf->b_p_flp ? buf->b_p_flp : p_flp;
if (buf->b_p_flp == NULL || *buf->b_p_flp == NUL)
return p_flp;
return buf->b_p_flp;
diff --git a/src/testdir/test_breakindent.vim b/src/testdir/test_breakindent.vim
index 2ac127dd5..eefaa6269 100644
--- a/src/testdir/test_breakindent.vim
+++ b/src/testdir/test_breakindent.vim
@@ -890,7 +890,22 @@ func Test_no_extra_indent()
\ "~ ",
\ ]
let lines = s:screen_lines2(1, 4, 20)
- " 3) add something in front, no additional indent
+ " 3) no local formatlist pattern,
+ " so use global one -> indent
+ let g_flp = &g:flp
+ let &g:formatlistpat='^\s*\d\+\.\s\+'
+ let &l:formatlistpat=''
+ let expect = [
+ \ " 1. word word word ",
+ \ " word word word ",
+ \ " word word ",
+ \ "~ ",
+ \ ]
+ let lines = s:screen_lines2(1, 4, 20)
+ call s:compare_lines(expect, lines)
+ let &g:flp = g_flp
+ let &l:formatlistpat='^\s*\d\+\.'
+ " 4) add something in front, no additional indent
norm! gg0
exe ":norm! 5iword \<esc>"
redraw!
```

Or may be we do not even need this special case of using the global
formatlistpattern when the local formatlistpattern is null ? Not sure.

Best,
Christian
--
Jeder klagt über sein Gedächnis, aber niemand über seinen Verstand.
-- François de La Rochefoucauld
Reply all
Reply to author
Forward
0 new messages