From eda6bcbfbac1e09ab692069342d4846f838786d2 Mon Sep 17 00:00:00 2001 From: rhysd Date: Fri, 16 May 2014 14:21:26 +0900 Subject: [PATCH] Fix highlight on unnamed class, struct and enum Problem: In C++, unnamed derived class and struct can be defined using ':'. enum also can be defined with specific underlying type using ':'. They are highlighted as labels wrongly. ``` struct base{}; int main() { // // Below 'enum', 'struct' and 'class' are highlighted as label // // Specify enum's underlying type enum : int {} aaa; // unnamed derived struct struct : base {} bbb; // unnamed derived class class : base {} ccc; return 0; } ``` Solution: Check that labels don't match to them. --- syntax/c.vim | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/syntax/c.vim b/syntax/c.vim index 7a58ae7..09bd602 100644 --- a/syntax/c.vim +++ b/syntax/c.vim @@ -379,8 +379,13 @@ endif syn cluster cLabelGroup contains=cUserLabel syn match cUserCont display "^\s*\I\i*\s*:$" contains=@cLabelGroup syn match cUserCont display ";\s*\I\i*\s*:$" contains=@cLabelGroup -syn match cUserCont display "^\s*\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup -syn match cUserCont display ";\s*\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup +if s:ft ==# 'cpp' + syn match cUserCont display "^\s*\%(class\|struct\|enum\)\@!\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup + syn match cUserCont display ";\s*\%(class\|struct\|enum\)\@!\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup +else + syn match cUserCont display "^\s*\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup + syn match cUserCont display ";\s*\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup +endif syn match cUserLabel display "\I\i*" contained