]> granicus.if.org Git - vim/commitdiff
patch 8.1.1276: cannot combine text properties with syntax highlighting v8.1.1276
authorBram Moolenaar <Bram@vim.org>
Sun, 5 May 2019 13:48:00 +0000 (15:48 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 5 May 2019 13:48:00 +0000 (15:48 +0200)
Problem:    Cannot combine text properties with syntax highlighting.
Solution:   Add the "combine" field to prop_type_add(). (closes #4343)

runtime/doc/eval.txt
runtime/doc/textprop.txt
src/screen.c
src/structs.h
src/testdir/test_textprop.vim
src/version.c

index bc18daaca290a36a01a64ed83bb633e840cffa37..e1ce00fa638b98ebb49507f2af6a901ee66257f4 100644 (file)
@@ -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
index 375255134a444d839426fdbc90705f59f2cc1a93..263c40eb1ce875c965e59e11b75943c1c58513f7 100644 (file)
@@ -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
index 862a63584215ffd97ae4647931e315800f5a0825..eb81bee84afd191be1a550678af72e6773e5ec70 100644 (file)
@@ -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
index c992e2a7ff6a40ee247c9692e25e7cfe770e5a4c..fa8a7655fa7115afbbe673295513f8f6c52c525b 100644 (file)
@@ -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
index eab7aaab7991209a0431c82ab7a6ed116a454d70..a48aa91a434788b3d55a437f85640bb513a7bea8 100644 (file)
@@ -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
index 6838624550edf385bfbe54bd25c120b0eb915df3..3e2f4724674f084692432cedb743307e9fa95452 100644 (file)
@@ -767,6 +767,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1276,
 /**/
     1275,
 /**/