Patch 8.1.2153

10 views
Skip to first unread message

Bram Moolenaar

unread,
Oct 16, 2019, 8:39:09 AM10/16/19
to vim...@googlegroups.com

Patch 8.1.2153
Problem: Combining text property and syntax highlight is wrong. (Nick
Jensen)
Solution: Compute the syntax highlight attribute much earlier.
(closes #5057)
Files: src/drawline.c, src/testdir/test_textprop.vim,
src/testdir/dumps/Test_textprop_syn_1.dump


*** ../vim-8.1.2152/src/drawline.c 2019-10-05 21:57:07.283725593 +0200
--- src/drawline.c 2019-10-16 14:12:27.006210435 +0200
***************
*** 307,312 ****
--- 307,313 ----
#endif
#ifdef FEAT_SPELL
int has_spell = FALSE; // this buffer has spell checking
+ int can_spell;
# define SPWORDLEN 150
char_u nextline[SPWORDLEN * 2];// text with start of the next line
int nextlinecol = 0; // column where nextline[] starts
***************
*** 747,752 ****
--- 748,756 ----
win_attr = wcr_attr;
area_highlighting = TRUE;
}
+ if (vi_attr != 0 && win_attr != 0)
+ vi_attr = hl_combine_attr(win_attr, vi_attr);
+
#ifdef FEAT_TEXT_PROP
if (WIN_IS_POPUP(wp))
screen_line_flags |= SLF_POPUP;
***************
*** 1281,1291 ****
break;
}

! if (draw_state == WL_LINE && (area_highlighting
! #ifdef FEAT_SPELL
! || has_spell
! #endif
! ))
{
// handle Visual or match highlighting in this line
if (vcol == fromcol
--- 1285,1291 ----
break;
}

! if (draw_state == WL_LINE && (area_highlighting || extra_check))
{
// handle Visual or match highlighting in this line
if (vcol == fromcol
***************
*** 1397,1402 ****
--- 1397,1466 ----
}
#endif

+ if (extra_check)
+ {
+ #ifdef FEAT_TERMINAL
+ if (get_term_attr)
+ {
+ syntax_attr = term_get_attr(wp->w_buffer, lnum, vcol);
+
+ if (!attr_pri)
+ char_attr = syntax_attr;
+ else
+ char_attr = hl_combine_attr(syntax_attr, char_attr);
+ }
+ #endif
+
+ #ifdef FEAT_SYN_HL
+ // Get syntax attribute.
+ if (has_syntax)
+ {
+ // Get the syntax attribute for the character. If there
+ // is an error, disable syntax highlighting.
+ save_did_emsg = did_emsg;
+ did_emsg = FALSE;
+
+ v = (long)(ptr - line);
+ can_spell = TRUE;
+ syntax_attr = get_syntax_attr((colnr_T)v,
+ # ifdef FEAT_SPELL
+ has_spell ? &can_spell :
+ # endif
+ NULL, FALSE);
+
+ // combine syntax attribute with 'wincolor'
+ if (syntax_attr != 0 && win_attr != 0)
+ syntax_attr = hl_combine_attr(win_attr, syntax_attr);
+
+ if (did_emsg)
+ {
+ wp->w_s->b_syn_error = TRUE;
+ has_syntax = FALSE;
+ syntax_attr = 0;
+ }
+ else
+ did_emsg = save_did_emsg;
+ # ifdef SYN_TIME_LIMIT
+ if (wp->w_s->b_syn_slow)
+ has_syntax = FALSE;
+ # endif
+
+ // Need to get the line again, a multi-line regexp may
+ // have made it invalid.
+ line = ml_get_buf(wp->w_buffer, lnum, FALSE);
+ ptr = line + v;
+ # ifdef FEAT_CONCEAL
+ // no concealing past the end of the line, it interferes
+ // with line highlighting
+ if (*ptr == NUL)
+ syntax_flags = 0;
+ else
+ syntax_flags = get_syntax_info(&syntax_seqnr);
+ # endif
+ }
+ #endif
+ }
+
// Decide which of the highlight attributes to use.
attr_pri = TRUE;
#ifdef LINE_ATTR
***************
*** 1420,1426 ****
{
// Use line_attr when not in the Visual or 'incsearch' area
// (area_attr may be 0 when "noinvcur" is set).
! char_attr = line_attr;
attr_pri = FALSE;
}
#else
--- 1484,1495 ----
{
// Use line_attr when not in the Visual or 'incsearch' area
// (area_attr may be 0 when "noinvcur" is set).
! # ifdef FEAT_SYN_HL
! if (has_syntax)
! char_attr = hl_combine_attr(syntax_attr, line_attr);
! else
! # endif
! char_attr = line_attr;
attr_pri = FALSE;
}
#else
***************
*** 1742,1840 ****
if (extra_check)
{
#ifdef FEAT_SPELL
- int can_spell = TRUE;
- #endif
-
- #ifdef FEAT_TERMINAL
- if (get_term_attr)
- {
- syntax_attr = term_get_attr(wp->w_buffer, lnum, vcol);
-
- if (!attr_pri)
- char_attr = syntax_attr;
- else
- char_attr = hl_combine_attr(syntax_attr, char_attr);
- }
- #endif
-
- #ifdef FEAT_SYN_HL
- // Get syntax attribute, unless still at the start of the line
- // (double-wide char that doesn't fit).
- v = (long)(ptr - line);
- if (has_syntax && v > 0)
- {
- // Get the syntax attribute for the character. If there
- // is an error, disable syntax highlighting.
- save_did_emsg = did_emsg;
- did_emsg = FALSE;
-
- syntax_attr = get_syntax_attr((colnr_T)v - 1,
- # ifdef FEAT_SPELL
- has_spell ? &can_spell :
- # endif
- NULL, FALSE);
-
- if (did_emsg)
- {
- wp->w_s->b_syn_error = TRUE;
- has_syntax = FALSE;
- syntax_attr = 0;
- }
- else
- did_emsg = save_did_emsg;
-
- // combine syntax attribute with 'wincolor'
- if (win_attr != 0)
- syntax_attr = hl_combine_attr(win_attr, syntax_attr);
-
- # ifdef SYN_TIME_LIMIT
- if (wp->w_s->b_syn_slow)
- has_syntax = FALSE;
- # endif
-
- // Need to get the line again, a multi-line regexp may
- // have made it invalid.
- line = ml_get_buf(wp->w_buffer, lnum, FALSE);
- ptr = line + v;
-
- # ifdef FEAT_TEXT_PROP
- // Text properties overrule syntax highlighting or combine.
- if (text_prop_attr == 0 || text_prop_combine)
- # endif
- {
- int comb_attr = syntax_attr;
- # ifdef FEAT_TEXT_PROP
- comb_attr = hl_combine_attr(text_prop_attr, comb_attr);
- # endif
- if (!attr_pri)
- {
- #ifdef FEAT_SYN_HL
- if (cul_attr)
- char_attr = hl_combine_attr(
- comb_attr, cul_attr);
- else
- #endif
- if (line_attr)
- char_attr = hl_combine_attr(
- comb_attr, line_attr);
- else
- char_attr = comb_attr;
- }
- else
- char_attr = hl_combine_attr(comb_attr, char_attr);
- }
- # ifdef FEAT_CONCEAL
- // no concealing past the end of the line, it interferes
- // with line highlighting
- if (c == NUL)
- syntax_flags = 0;
- else
- syntax_flags = get_syntax_info(&syntax_seqnr);
- # endif
- }
- #endif
-
- #ifdef FEAT_SPELL
// Check spelling (unless at the end of the line).
// Only do this when there is no syntax highlighting, the
// @Spell cluster is not used or the current syntax item
--- 1811,1816 ----
*** ../vim-8.1.2152/src/testdir/test_textprop.vim 2019-09-04 21:56:48.979806628 +0200
--- src/testdir/test_textprop.vim 2019-10-16 12:51:13.732415486 +0200
***************
*** 652,660 ****

" screenshot test with textprop highlighting
func Test_textprop_screenshot_various()
" The Vim running in the terminal needs to use utf-8.
! if !CanRunVimInTerminal() || g:orig_encoding != 'utf-8'
! throw 'Skipped: cannot make screendumps or not using utf-8'
endif
call writefile([
\ "call setline(1, ["
--- 652,661 ----

" screenshot test with textprop highlighting
func Test_textprop_screenshot_various()
+ CheckScreendump
" The Vim running in the terminal needs to use utf-8.
! if g:orig_encoding != 'utf-8'
! throw 'Skipped: not using utf-8'
endif
call writefile([
\ "call setline(1, ["
***************
*** 750,758 ****

" screenshot test with Visual block mode operations
func Test_textprop_screenshot_visual()
! if !CanRunVimInTerminal()
! throw 'Skipped: cannot make screendumps'
! endif

" Delete two columns while text props are three chars wide.
call RunTestVisualBlock(2, '01')
--- 751,757 ----

" screenshot test with Visual block mode operations
func Test_textprop_screenshot_visual()
! CheckScreendump

" Delete two columns while text props are three chars wide.
call RunTestVisualBlock(2, '01')
***************
*** 762,770 ****
endfunc

func Test_textprop_after_tab()
! if !CanRunVimInTerminal()
! throw 'Skipped: cannot make screendumps'
! endif

let lines =<< trim END
call setline(1, [
--- 761,767 ----
endfunc

func Test_textprop_after_tab()
! CheckScreendump

let lines =<< trim END
call setline(1, [
***************
*** 785,790 ****
--- 782,809 ----
call delete('XtestPropTab')
endfunc

+ func Test_textprop_with_syntax()
+ CheckScreendump
+
+ let lines =<< trim END
+ call setline(1, [
+ \ "(abc)",
+ \ ])
+ syn match csParens "[()]" display
+ hi! link csParens MatchParen
+
+ call prop_type_add('TPTitle', #{ highlight: 'Title' })
+ call prop_add(1, 2, #{type: 'TPTitle', end_col: 5})
+ END
+ call writefile(lines, 'XtestPropSyn')
+ let buf = RunVimInTerminal('-S XtestPropSyn', {'rows': 6})
+ call VerifyScreenDump(buf, 'Test_textprop_syn_1', {})
+
+ " clean up
+ call StopVimInTerminal(buf)
+ call delete('XtestPropSyn')
+ endfunc
+
" Adding a text property to a new buffer should not fail
func Test_textprop_empty_buffer()
call prop_type_add('comment', {'highlight': 'Search'})
*** ../vim-8.1.2152/src/testdir/dumps/Test_textprop_syn_1.dump 2019-10-16 14:37:27.312201684 +0200
--- src/testdir/dumps/Test_textprop_syn_1.dump 2019-10-16 12:51:21.164375348 +0200
***************
*** 0 ****
--- 1,6 ----
+ >(+0&#40ffff15|a+0#e000e06#ffffff0|b|c|)+0#0000000#40ffff15| +0&#ffffff0@69
+ |~+0#4040ff13&| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ | +0#0000000&@56|1|,|1| @10|A|l@1|
*** ../vim-8.1.2152/src/version.c 2019-10-15 22:23:34.199941450 +0200
--- src/version.c 2019-10-16 12:45:03.374667471 +0200
***************
*** 755,756 ****
--- 755,758 ----
{ /* Add new patch number below this line */
+ /**/
+ 2153,
/**/

--
A law to reduce crime states: "It is mandatory for a motorist with criminal
intentions to stop at the city limits and telephone the chief of police as he
is entering the town.
[real standing law in Washington, United States of America]

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

John Marriott

unread,
Oct 16, 2019, 2:38:43 PM10/16/19
to vim...@googlegroups.com

On 16-Oct-2019 23:39, Bram Moolenaar wrote:
> Patch 8.1.2153
> Problem: Combining text property and syntax highlight is wrong. (Nick
> Jensen)
> Solution: Compute the syntax highlight attribute much earlier.
> (closes #5057)
> Files: src/drawline.c, src/testdir/test_textprop.vim,
> src/testdir/dumps/Test_textprop_syn_1.dump
>
>
After patches 2153 to 2161 (I'm pretty sure that 2153 is culprit)
mingw64 (gcc 9.2.1) throws this error if FEAT_SPELL is not defined:
gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603
-DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -DFEAT_GUI_MSWIN
-DFEAT_CLIPBOARD -pipe -march=native -Wall -O3 -fomit-frame-pointer
-freg-struct-return drawline.c -o gobjnative/drawline.o
drawline.c: In function 'win_line':
drawline.c:1424:4: error: 'can_spell' undeclared (first use in this
function); did you mean 'ex_spell'?
 1424 |    can_spell = TRUE;
      |    ^~~~~~~~~
      |    ex_spell
drawline.c:1424:4: note: each undeclared identifier is reported only
once for each function it appears in
make: *** [Make_cyg_ming.mak:1104: gobjnative/drawline.o] Error 1
make: Target 'gvim.exe' not remade because of errors.

The attached patch seems to correct it.
Cheers
drawline.c.8.1.2153.patch
Reply all
Reply to author
Forward
0 new messages