• R/O
  • SSH

vim: コミット

Mirror of the Vim source from https://github.com/vim/vim


コミットメタ情報

リビジョン164d59ddd48a5a59be249de198d6d51e6f8acb4c (tree)
日時2022-01-15 19:15:03
作者Bram Moolenaar <Bram@vim....>
コミッターBram Moolenaar

ログメッセージ

patch 8.2.4093: cached breakindent values not initialized properly

Commit: https://github.com/vim/vim/commit/c53b467473160b5cfce77277fbae414bf43e66ce
Author: Christian Brabandt <cb@256bit.org>
Date: Sat Jan 15 10:01:05 2022 +0000

patch 8.2.4093: cached breakindent values not initialized properly
Problem: Cached breakindent values not initialized properly.
Solution: Initialize and cache formatlistpat. (Christian Brabandt,
closes #9526, closes #9512)

変更サマリ

差分

diff -r 33918a28ec46 -r 164d59ddd48a runtime/doc/options.txt
--- a/runtime/doc/options.txt Fri Jan 14 22:30:04 2022 +0100
+++ b/runtime/doc/options.txt Sat Jan 15 11:15:03 2022 +0100
@@ -1370,6 +1370,7 @@
13701370 text should normally be narrower. This prevents
13711371 text indented almost to the right window border
13721372 occupying lot of vertical space when broken.
1373+ (default: 20)
13731374 shift:{n} After applying 'breakindent', the wrapped line's
13741375 beginning will be shifted by the given number of
13751376 characters. It permits dynamic French paragraph
diff -r 33918a28ec46 -r 164d59ddd48a src/indent.c
--- a/src/indent.c Fri Jan 14 22:30:04 2022 +0100
+++ b/src/indent.c Sat Jan 15 11:15:03 2022 +0100
@@ -924,6 +924,8 @@
924924 # endif
925925 static int prev_list = 0; // cached list value
926926 static int prev_listopt = 0; // cached w_p_briopt_list value
927+ // cached formatlistpat value
928+ static char_u *prev_flp = NULL;
927929 int bri = 0;
928930 // window width minus window margin space, i.e. what rests for text
929931 const int eff_wwidth = wp->w_width
@@ -931,10 +933,16 @@
931933 && (vim_strchr(p_cpo, CPO_NUMCOL) == NULL)
932934 ? number_width(wp) + 1 : 0);
933935
934- // used cached indent, unless line, 'tabstop' or briopt_list changed
936+ // used cached indent, unless
937+ // - line pointer changed
938+ // - 'tabstop' changed
939+ // - 'briopt_list changed' changed or
940+ // - 'formatlistpattern' changed
935941 if (prev_line != line || prev_ts != wp->w_buffer->b_p_ts
936942 || prev_tick != CHANGEDTICK(wp->w_buffer)
937943 || prev_listopt != wp->w_briopt_list
944+ || (prev_flp == NULL
945+ || (STRCMP(prev_flp, get_flp_value(wp->w_buffer)) != 0))
938946 # ifdef FEAT_VARTABS
939947 || prev_vts != wp->w_buffer->b_p_vts_array
940948 # endif
@@ -953,13 +961,16 @@
953961 (int)wp->w_buffer->b_p_ts, wp->w_p_list);
954962 # endif
955963 prev_listopt = wp->w_briopt_list;
964+ prev_list = 0;
965+ vim_free(prev_flp);
966+ prev_flp = vim_strsave(get_flp_value(wp->w_buffer));
956967 // add additional indent for numbered lists
957968 if (wp->w_briopt_list != 0)
958969 {
959970 regmatch_T regmatch;
960971
961- regmatch.regprog = vim_regcomp(curbuf->b_p_flp,
962- RE_MAGIC + RE_STRING + RE_AUTO + RE_STRICT);
972+ regmatch.regprog = vim_regcomp(prev_flp,
973+ RE_MAGIC + RE_STRING + RE_AUTO + RE_STRICT);
963974
964975 if (regmatch.regprog != NULL)
965976 {
diff -r 33918a28ec46 -r 164d59ddd48a src/option.c
--- a/src/option.c Fri Jan 14 22:30:04 2022 +0100
+++ b/src/option.c Sat Jan 15 11:15:03 2022 +0100
@@ -7053,6 +7053,18 @@
70537053 }
70547054
70557055 /*
7056+ * Get the local or global value of 'formatlistpat'.
7057+ */
7058+ char_u *
7059+get_flp_value(buf_T *buf)
7060+{
7061+ return buf->b_p_flp ? buf->b_p_flp : p_flp;
7062+ if (buf->b_p_flp == NULL || *buf->b_p_flp == NUL)
7063+ return p_flp;
7064+ return buf->b_p_flp;
7065+}
7066+
7067+/*
70567068 * Get the local or global value of the 'virtualedit' flags.
70577069 */
70587070 unsigned int
diff -r 33918a28ec46 -r 164d59ddd48a src/proto/option.pro
--- a/src/proto/option.pro Fri Jan 14 22:30:04 2022 +0100
+++ b/src/proto/option.pro Sat Jan 15 11:15:03 2022 +0100
@@ -73,6 +73,7 @@
7373 long get_scrolloff_value(void);
7474 long get_sidescrolloff_value(void);
7575 unsigned int get_bkc_value(buf_T *buf);
76+char_u *get_flp_value(buf_T *buf);
7677 unsigned int get_ve_flags(void);
7778 char_u *get_showbreak_value(win_T *win);
7879 dict_T *get_winbuf_options(int bufopt);
diff -r 33918a28ec46 -r 164d59ddd48a src/testdir/test_breakindent.vim
--- a/src/testdir/test_breakindent.vim Fri Jan 14 22:30:04 2022 +0100
+++ b/src/testdir/test_breakindent.vim Sat Jan 15 11:15:03 2022 +0100
@@ -849,4 +849,61 @@
849849 %bw!
850850 endfunc
851851
852+func Test_no_spurious_match()
853+ let s:input = printf('- y %s y %s', repeat('x', 50), repeat('x', 50))
854+ call s:test_windows('setl breakindent breakindentopt=list:-1 formatlistpat=^- hls')
855+ let @/ = '\%>3v[y]'
856+ redraw!
857+ call searchcount().total->assert_equal(1)
858+ " cleanup
859+ set hls&vim
860+ let s:input = "\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP"
861+ bwipeout!
862+endfunc
863+
864+func Test_no_extra_indent()
865+ call s:test_windows('setl breakindent breakindentopt=list:-1,min:10')
866+ %d
867+ let &l:formatlistpat='^\s*\d\+\.\s\+'
868+ let text = 'word '
869+ let len = text->strcharlen()
870+ let line1 = text->repeat((winwidth(0) / len) * 2)
871+ let line2 = repeat(' ', 2) .. '1. ' .. line1
872+ call setline(1, [line2])
873+ redraw!
874+ " 1) matches formatlist pattern, so indent
875+ let expect = [
876+ \ " 1. word word word ",
877+ \ " word word word ",
878+ \ " word word ",
879+ \ "~ ",
880+ \ ]
881+ let lines = s:screen_lines2(1, 4, 20)
882+ call s:compare_lines(expect, lines)
883+ " 2) change formatlist pattern
884+ " -> indent adjusted
885+ let &l:formatlistpat='^\s*\d\+\.'
886+ let expect = [
887+ \ " 1. word word word ",
888+ \ " word word word ",
889+ \ " word word ",
890+ \ "~ ",
891+ \ ]
892+ let lines = s:screen_lines2(1, 4, 20)
893+ " 3) add something in front, no additional indent
894+ norm! gg0
895+ exe ":norm! 5iword \<esc>"
896+ redraw!
897+ let expect = [
898+ \ "word word word word ",
899+ \ "word 1. word word ",
900+ \ "word word word word ",
901+ \ "word word ",
902+ \ "~ ",
903+ \ ]
904+ let lines = s:screen_lines2(1, 5, 20)
905+ call s:compare_lines(expect, lines)
906+ bwipeout!
907+endfunc
908+
852909 " vim: shiftwidth=2 sts=2 expandtab
diff -r 33918a28ec46 -r 164d59ddd48a src/version.c
--- a/src/version.c Fri Jan 14 22:30:04 2022 +0100
+++ b/src/version.c Sat Jan 15 11:15:03 2022 +0100
@@ -751,6 +751,8 @@
751751 static int included_patches[] =
752752 { /* Add new patch number below this line */
753753 /**/
754+ 4093,
755+/**/
754756 4092,
755757 /**/
756758 4091,
旧リポジトリブラウザで表示