summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-05-05 15:48:00 +0200
committerBram Moolenaar <Bram@vim.org>2019-05-05 15:48:00 +0200
commitde24a8701328b1cce7cad0ee11b415369b482420 (patch)
tree9b5cef424fb7aafb173240dfc41e6d62afdeb3d0
parentcf6a55c4b0cbf38b0c3fbed5ffd9a3fd0d2ede0e (diff)
patch 8.1.1276: cannot combine text properties with syntax highlightingv8.1.1276
Problem: Cannot combine text properties with syntax highlighting. Solution: Add the "combine" field to prop_type_add(). (closes #4343)
-rw-r--r--runtime/doc/eval.txt3
-rw-r--r--runtime/doc/textprop.txt6
-rw-r--r--src/screen.c34
-rw-r--r--src/structs.h1
-rw-r--r--src/testdir/test_textprop.vim17
-rw-r--r--src/version.c2
6 files changed, 49 insertions, 14 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index bc18daaca2..e1ce00fa63 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -7218,6 +7218,9 @@ prop_type_add({name}, {props}) *prop_type_add()* *E969* *E970*
properties the one with the highest priority
will be used; negative values can be used, the
default priority is zero
+ combine when TRUE combine the highlight with any
+ syntax highlight; when omitted of FALSE syntax
+ highlight will not be used
start_incl when TRUE inserts at the start position will
be included in the text property
end_incl when TRUE inserts at the end position will be
diff --git a/runtime/doc/textprop.txt b/runtime/doc/textprop.txt
index 375255134a..263c40eb1c 100644
--- a/runtime/doc/textprop.txt
+++ b/runtime/doc/textprop.txt
@@ -1,4 +1,4 @@
-*textprop.txt* For Vim version 8.1. Last change: 2019 Jan 08
+*textprop.txt* For Vim version 8.1. Last change: 2019 May 05
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -57,6 +57,10 @@ Property Types ~
A text property normally has the name of a property type, which defines
how to highlight the text. The property type can have these entries:
"highlight" name of the highlight group to use
+ "combine" when TRUE the text property highlighting is combined
+ with any syntax highligting, when omitted or FALSE the
+ text property highlighting replaces the syntax
+ highlighting
"priority" when properties overlap, the one with the highest
priority will be used.
"start_incl" when TRUE inserts at the start position will be
diff --git a/src/screen.c b/src/screen.c
index 862a635842..eb81bee84a 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -3059,6 +3059,7 @@ win_line(
int text_props_active = 0;
proptype_T *text_prop_type = NULL;
int text_prop_attr = 0;
+ int text_prop_combine = FALSE;
#endif
#ifdef FEAT_SPELL
int has_spell = FALSE; /* this buffer has spell checking */
@@ -4261,6 +4262,7 @@ win_line(
text_prop_idxs[text_props_active++] = text_prop_next++;
text_prop_attr = 0;
+ text_prop_combine = FALSE;
if (text_props_active > 0)
{
// Sort the properties on priority and/or starting last.
@@ -4273,17 +4275,17 @@ win_line(
for (pi = 0; pi < text_props_active; ++pi)
{
int tpi = text_prop_idxs[pi];
- proptype_T *pt = text_prop_type_by_id(wp->w_buffer, text_props[tpi].tp_type);
+ proptype_T *pt = text_prop_type_by_id(
+ wp->w_buffer, text_props[tpi].tp_type);
if (pt != NULL)
{
int pt_attr = syn_id2attr(pt->pt_hl_id);
text_prop_type = pt;
- if (text_prop_attr == 0)
- text_prop_attr = pt_attr;
- else
- text_prop_attr = hl_combine_attr(text_prop_attr, pt_attr);
+ text_prop_attr =
+ hl_combine_attr(text_prop_attr, pt_attr);
+ text_prop_combine = pt->pt_flags & PT_FLAG_COMBINE;
}
}
}
@@ -4314,7 +4316,13 @@ win_line(
attr_pri = FALSE;
#ifdef FEAT_TEXT_PROP
if (text_prop_type != NULL)
- char_attr = text_prop_attr;
+ {
+ if (text_prop_combine)
+ char_attr = hl_combine_attr(
+ syntax_attr, text_prop_attr);
+ else
+ char_attr = text_prop_attr;
+ }
else
#endif
#ifdef FEAT_SYN_HL
@@ -4664,14 +4672,18 @@ win_line(
ptr = line + v;
# ifdef FEAT_TEXT_PROP
- // Text properties overrule syntax highlighting.
- if (text_prop_attr == 0)
-#endif
+ // 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)
- char_attr = syntax_attr;
+ char_attr = comb_attr;
else
- char_attr = hl_combine_attr(syntax_attr, char_attr);
+ char_attr = hl_combine_attr(comb_attr, char_attr);
}
# ifdef FEAT_CONCEAL
/* no concealing past the end of the line, it interferes
diff --git a/src/structs.h b/src/structs.h
index c992e2a7ff..fa8a7655fa 100644
--- a/src/structs.h
+++ b/src/structs.h
@@ -727,6 +727,7 @@ typedef struct proptype_S
#define PT_FLAG_INS_START_INCL 1 // insert at start included in property
#define PT_FLAG_INS_END_INCL 2 // insert at end included in property
+#define PT_FLAG_COMBINE 4 // combine with syntax highlight
// Sign group
typedef struct signgroup_S
diff --git a/src/testdir/test_textprop.vim b/src/testdir/test_textprop.vim
index eab7aaab79..a48aa91a43 100644
--- a/src/testdir/test_textprop.vim
+++ b/src/testdir/test_textprop.vim
@@ -559,14 +559,23 @@ funct Test_textprop_screenshots()
return
endif
call writefile([
- \ "call setline(1, ['One two', 'Numbér 123 änd thœn 4¾7.', '--aa--bb--cc--dd--'])",
+ \ "call setline(1, ["
+ \ .. "'One two',"
+ \ .. "'Numbér 123 änd thœn 4¾7.',"
+ \ .. "'--aa--bb--cc--dd--',"
+ \ .. "'// comment with error in it',"
+ \ .. "])",
\ "hi NumberProp ctermfg=blue",
\ "hi LongProp ctermbg=yellow",
+ \ "hi BackgroundProp ctermbg=lightgrey",
+ \ "hi UnderlineProp cterm=underline",
\ "call prop_type_add('number', {'highlight': 'NumberProp'})",
\ "call prop_type_add('long', {'highlight': 'LongProp'})",
\ "call prop_type_add('start', {'highlight': 'NumberProp', 'start_incl': 1})",
\ "call prop_type_add('end', {'highlight': 'NumberProp', 'end_incl': 1})",
\ "call prop_type_add('both', {'highlight': 'NumberProp', 'start_incl': 1, 'end_incl': 1})",
+ \ "call prop_type_add('background', {'highlight': 'BackgroundProp', 'combine': 1})",
+ \ "call prop_type_add('error', {'highlight': 'UnderlineProp', 'combine': 1})",
\ "call prop_add(1, 4, {'end_lnum': 3, 'end_col': 3, 'type': 'long'})",
\ "call prop_add(2, 9, {'length': 3, 'type': 'number'})",
\ "call prop_add(2, 24, {'length': 4, 'type': 'number'})",
@@ -574,13 +583,17 @@ funct Test_textprop_screenshots()
\ "call prop_add(3, 7, {'length': 2, 'type': 'start'})",
\ "call prop_add(3, 11, {'length': 2, 'type': 'end'})",
\ "call prop_add(3, 15, {'length': 2, 'type': 'both'})",
+ \ "call prop_add(4, 12, {'length': 10, 'type': 'background'})",
+ \ "call prop_add(4, 17, {'length': 5, 'type': 'error'})",
\ "set number",
\ "hi clear SpellBad",
\ "set spell",
+ \ "syn match Comment '//.*'",
+ \ "hi Comment ctermfg=green",
\ "normal 3G0llix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>",
\ "normal 3G0lli\<BS>\<Esc>",
\], 'XtestProp')
- let buf = RunVimInTerminal('-S XtestProp', {'rows': 6})
+ let buf = RunVimInTerminal('-S XtestProp', {'rows': 7})
call VerifyScreenDump(buf, 'Test_textprop_01', {})
" clean up
diff --git a/src/version.c b/src/version.c
index 6838624550..3e2f472467 100644
--- a/src/version.c
+++ b/src/version.c
@@ -768,6 +768,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1276,
+/**/
1275,
/**/
1274,