vim-patch: 7.4.353

Make 'breakindent' work with the 'list' option.

Originally patched in vim patch 7.4.353, by chrisbra
(https://code.google.com/p/vim/source/detail?r=d42a1d3b74d40f580359dbd139d2d0dfa7235252)

Updated version.c.
This commit is contained in:
Felipe Morales
2014-08-16 12:58:11 -04:00
parent 22c782bcb2
commit dfdfee0260
6 changed files with 164 additions and 15 deletions

View File

@@ -997,7 +997,6 @@ int win_lbr_chartabsize(win_T *wp, char_u *line, char_u *s, colnr_T col, int *he
if (wp->w_p_lbr if (wp->w_p_lbr
&& vim_isbreak(c) && vim_isbreak(c)
&& !vim_isbreak(s[1]) && !vim_isbreak(s[1])
&& !wp->w_p_list
&& wp->w_p_wrap && wp->w_p_wrap
&& (wp->w_width != 0)) { && (wp->w_width != 0)) {
// Count all characters from first non-blank after a blank up to next // Count all characters from first non-blank after a blank up to next

View File

@@ -8157,9 +8157,10 @@ void find_mps_values(int *initc, int *findc, int *backwards, int switchit)
} }
} }
/* This is called when 'breakindentopt' is changed and whenn a window is /* This is called when 'breakindentopt' is changed and when a window is
initialized */ initialized */
int briopt_check() { int briopt_check(void)
{
char_u *p; char_u *p;
int bri_shift = 0; int bri_shift = 0;
long bri_min = 20; long bri_min = 20;

View File

@@ -2197,6 +2197,7 @@ win_line (
char_u extra[18]; /* line number and 'fdc' must fit in here */ char_u extra[18]; /* line number and 'fdc' must fit in here */
int n_extra = 0; /* number of extra chars */ int n_extra = 0; /* number of extra chars */
char_u *p_extra = NULL; /* string of extra chars, plus NUL */ char_u *p_extra = NULL; /* string of extra chars, plus NUL */
char_u *p_extra_free = NULL; /* p_extra needs to be freed */
int c_extra = NUL; /* extra chars, all the same */ int c_extra = NUL; /* extra chars, all the same */
int extra_attr = 0; /* attributes when n_extra != 0 */ int extra_attr = 0; /* attributes when n_extra != 0 */
static char_u *at_end_str = (char_u *)""; /* used for p_extra when static char_u *at_end_str = (char_u *)""; /* used for p_extra when
@@ -3108,6 +3109,10 @@ win_line (
} }
--n_extra; --n_extra;
} else { } else {
if (p_extra_free != NULL) {
free(p_extra_free);
p_extra_free = NULL;
}
/* /*
* Get a character from the line itself. * Get a character from the line itself.
*/ */
@@ -3408,21 +3413,22 @@ win_line (
/* /*
* Found last space before word: check for line break. * Found last space before word: check for line break.
*/ */
if (wp->w_p_lbr && vim_isbreak(c) && !vim_isbreak(*ptr) if (wp->w_p_lbr && vim_isbreak(c) && !vim_isbreak(*ptr)) {
&& !wp->w_p_list) {
char_u *p = ptr - ( char_u *p = ptr - (
has_mbyte ? mb_l : has_mbyte ? mb_l :
1); 1);
// TODO: is passing p for start of the line OK? // TODO: is passing p for start of the line OK?
n_extra = win_lbr_chartabsize(wp, p, p, (colnr_T)vcol, NULL) - 1; n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol, NULL) - 1;
c_extra = ' '; c_extra = ' ';
if (vim_iswhite(c)) { if (vim_iswhite(c)) {
if (c == TAB) if (c == TAB)
/* See "Tab alignment" below. */ /* See "Tab alignment" below. */
FIX_FOR_BOGUSCOLS; FIX_FOR_BOGUSCOLS;
if (!wp->w_p_list) {
c = ' '; c = ' ';
} }
} }
}
if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ') { if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ') {
c = lcs_trail; c = lcs_trail;
@@ -3451,9 +3457,36 @@ win_line (
* into "ScreenLines". * into "ScreenLines".
*/ */
if (c == TAB && (!wp->w_p_list || lcs_tab1)) { if (c == TAB && (!wp->w_p_list || lcs_tab1)) {
int tab_len = 0;
/* tab amount depends on current column */ /* tab amount depends on current column */
n_extra = (int)wp->w_buffer->b_p_ts tab_len = (int)wp->w_buffer->b_p_ts
- vcol % (int)wp->w_buffer->b_p_ts - 1; - vcol % (int)wp->w_buffer->b_p_ts - 1;
if (!wp->w_p_lbr) {
n_extra = tab_len;
} else {
char_u *p;
int len = n_extra;
int i;
int saved_nextra = n_extra;
/* if n_extra > 0, it gives the number of chars to use for
* a tab, else we need to calculate the width for a tab */
len = (tab_len * mb_char2len(lcs_tab2));
if (n_extra > 0) {
len += n_extra - tab_len;
}
c = lcs_tab1;
p = xmalloc(len + 1);
memset(p, ' ', len);
p[len] = NUL;
p_extra_free = p;
for (i = 0; i < tab_len; i++) {
mb_char2bytes(lcs_tab2, p);
p += mb_char2len(lcs_tab2);
n_extra += mb_char2len(lcs_tab2) - (saved_nextra > 0 ? 1: 0);
}
p_extra = p_extra_free;
}
/* Tab alignment should be identical regardless of /* Tab alignment should be identical regardless of
* 'conceallevel' value. So tab compensates of all * 'conceallevel' value. So tab compensates of all
* previous concealed characters, and thus resets vcol_off * previous concealed characters, and thus resets vcol_off
@@ -3464,8 +3497,12 @@ win_line (
mb_utf8 = FALSE; /* don't draw as UTF-8 */ mb_utf8 = FALSE; /* don't draw as UTF-8 */
if (wp->w_p_list) { if (wp->w_p_list) {
c = lcs_tab1; c = lcs_tab1;
if (wp->w_p_lbr) {
c_extra = NUL; /* using p_extra from above */
} else {
c_extra = lcs_tab2; c_extra = lcs_tab2;
n_attr = n_extra + 1; }
n_attr = tab_len + 1;
extra_attr = hl_attr(HLF_8); extra_attr = hl_attr(HLF_8);
saved_attr2 = char_attr; /* save current attr */ saved_attr2 = char_attr; /* save current attr */
mb_c = c; mb_c = c;
@@ -3527,9 +3564,20 @@ win_line (
p_extra = transchar(c); p_extra = transchar(c);
if ((dy_flags & DY_UHEX) && wp->w_p_rl) if ((dy_flags & DY_UHEX) && wp->w_p_rl)
rl_mirror(p_extra); /* reverse "<12>" */ rl_mirror(p_extra); /* reverse "<12>" */
n_extra = byte2cells(c) - 1;
c_extra = NUL; c_extra = NUL;
if (wp->w_p_lbr) {
char_u *p;
c = *p_extra;
p = xmalloc(n_extra + 1);
memset(p, ' ', n_extra);
STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1);
p[n_extra] = NUL;
p_extra_free = p_extra = p;
} else {
n_extra = byte2cells(c) - 1;
c = *p_extra++; c = *p_extra++;
}
if (!attr_pri) { if (!attr_pri) {
n_attr = n_extra + 1; n_attr = n_extra + 1;
extra_attr = hl_attr(HLF_8); extra_attr = hl_attr(HLF_8);

View File

@@ -0,0 +1,62 @@
Test for linebreak and list option
STARTTEST
:so small.vim
:if !exists("+linebreak") | e! test.ok | w! test.out | qa! | endif
:10new|:vsp|:vert resize 20
:put =\"\tabcdef hijklmn\tpqrstuvwxyz\u00a01060ABCDEFGHIJKLMNOP \"
:norm! zt
:set ts=4 sw=4 sts=4 linebreak sbr=+ wrap
:fu! ScreenChar(width)
: let c=''
: for j in range(1,4)
: for i in range(1,a:width)
: let c.=nr2char(screenchar(j, i))
: endfor
: let c.="\n"
: endfor
: return c
:endfu
:fu! DoRecordScreen()
: wincmd l
: $put =printf(\"\n%s\", g:test)
: $put =g:line
: wincmd p
:endfu
:let g:test="Test 1: set linebreak"
:redraw!
:let line=ScreenChar(winwidth(0))
:call DoRecordScreen()
:let g:test="Test 2: set linebreak + set list"
:set linebreak list listchars=
:redraw!
:let line=ScreenChar(winwidth(0))
:call DoRecordScreen()
:let g:test ="Test 3: set linebreak + set list + fancy listchars"
:exe "set linebreak list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6"
:redraw!
:let line=ScreenChar(winwidth(0))
:call DoRecordScreen()
:let g:test ="Test 4: set linebreak nolist"
:set nolist linebreak
:redraw!
:let line=ScreenChar(winwidth(0))
:call DoRecordScreen()
:let g:test ="Test 5: set nolinebreak list"
:set list nolinebreak
:redraw!
:let line=ScreenChar(winwidth(0))
:call DoRecordScreen()
:let g:test ="Test 6: set linebreak with tab and 1 line as long as screen: should break!"
:set nolist linebreak ts=8
:let line="1\t".repeat('a', winwidth(0)-2)
:$put =line
:$
:norm! zt
:redraw!
:let line=ScreenChar(winwidth(0))
:call DoRecordScreen()
:%w! test.out
:qa!
ENDTEST
dummy text

View File

@@ -0,0 +1,39 @@
abcdef hijklmn pqrstuvwxyz 1060ABCDEFGHIJKLMNOP
Test 1: set linebreak
abcdef
+hijklmn
+pqrstuvwxyz 1060ABC
+DEFGHIJKLMNOP
Test 2: set linebreak + set list
^Iabcdef hijklmn^I
+pqrstuvwxyz 1060ABC
+DEFGHIJKLMNOP
Test 3: set linebreak + set list + fancy listchars
▕———abcdef
+hijklmn▕———
+pqrstuvwxyz␣1060ABC
+DEFGHIJKLMNOPˑ¶
Test 4: set linebreak nolist
abcdef
+hijklmn
+pqrstuvwxyz 1060ABC
+DEFGHIJKLMNOP
Test 5: set nolinebreak list
▕———abcdef hijklmn▕—
+pqrstuvwxyz␣1060ABC
+DEFGHIJKLMNOPˑ¶
1 aaaaaaaaaaaaaaaaaa
Test 6: set linebreak with tab and 1 line as long as screen: should break!
1
+aaaaaaaaaaaaaaaaaa
~
~

View File

@@ -242,14 +242,14 @@ static int included_patches[] = {
//356 NA //356 NA
//355, //355,
//354, //354,
//353, 353,
//352, //352,
//351, //351,
//350, //350,
//349, //349,
//348, //348,
//347, //347,
//346, 346,
//345, //345,
//344, //344,
//343, //343,
@@ -257,7 +257,7 @@ static int included_patches[] = {
//341, //341,
//340 NA //340 NA
//339, //339,
//338, 338,
//337, //337,
//336, //336,
335, 335,