Skip to content

Commit 0b1a506

Browse files
authored
Merge pull request vim-jp#53 from rgreenblatt/master
Check if in_cpp_family rather than just cpp
2 parents 1c9c604 + 71c7a06 commit 0b1a506

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

syntax/c.vim

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" Vim syntax file
22
" Language: C
33
" Maintainer: Bram Moolenaar <[email protected]>
4-
" Last Change: 2019 Nov 29
4+
" Last Change: 2021 Jan 11
55

66
" Quit when a (custom) syntax file was already loaded
77
if exists("b:current_syntax")
@@ -13,6 +13,9 @@ set cpo&vim
1313

1414
let s:ft = matchstr(&ft, '^\([^.]\)\+')
1515

16+
" check if this was included from cpp.vim
17+
let s:in_cpp_family = exists("b:filetype_in_cpp_family")
18+
1619
" Optional embedded Autodoc parsing
1720
" To enable it add: let g:c_autodoc = 1
1821
" to your .vimrc
@@ -55,7 +58,7 @@ if !exists("c_no_cformat")
5558
endif
5659

5760
" cCppString: same as cString, but ends at end of line
58-
if s:ft ==# "cpp" && !exists("cpp_no_cpp11") && !exists("c_no_cformat")
61+
if s:in_cpp_family && !exists("cpp_no_cpp11") && !exists("c_no_cformat")
5962
" ISO C++11
6063
syn region cString start=+\(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell extend
6164
syn region cCppString start=+\(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,cFormat,@Spell
@@ -87,7 +90,7 @@ syn match cSpecialCharacter display "L\='\\\o\{1,3}'"
8790
syn match cSpecialCharacter display "'\\x\x\{1,2}'"
8891
syn match cSpecialCharacter display "L'\\x\x\+'"
8992

90-
if (s:ft ==# "c" && !exists("c_no_c11")) || (s:ft ==# "cpp" && !exists("cpp_no_cpp11"))
93+
if (s:ft ==# "c" && !exists("c_no_c11")) || (s:in_cpp_family && !exists("cpp_no_cpp11"))
9194
" ISO C11 or ISO C++ 11
9295
if exists("c_no_cformat")
9396
syn region cString start=+\%(U\|u8\=\)"+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,@Spell extend
@@ -130,7 +133,7 @@ endif
130133
" But avoid matching <::.
131134
syn cluster cParenGroup contains=cParenError,cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserLabel,cBitField,cOctalZero,@cCppOutInGroup,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom
132135
if exists("c_no_curly_error")
133-
if s:ft ==# 'cpp' && !exists("cpp_no_cpp11")
136+
if s:in_cpp_family && !exists("cpp_no_cpp11")
134137
syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,@cStringGroup,@Spell
135138
" cCppParen: same as cParen but ends at end-of-line; used in cDefine
136139
syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell
@@ -144,7 +147,7 @@ if exists("c_no_curly_error")
144147
syn match cErrInParen display contained "^[{}]\|^<%\|^%>"
145148
endif
146149
elseif exists("c_no_bracket_error")
147-
if s:ft ==# 'cpp' && !exists("cpp_no_cpp11")
150+
if s:in_cpp_family && !exists("cpp_no_cpp11")
148151
syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,@cStringGroup,@Spell
149152
" cCppParen: same as cParen but ends at end-of-line; used in cDefine
150153
syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell
@@ -158,7 +161,7 @@ elseif exists("c_no_bracket_error")
158161
syn match cErrInParen display contained "[{}]\|<%\|%>"
159162
endif
160163
else
161-
if s:ft ==# 'cpp' && !exists("cpp_no_cpp11")
164+
if s:in_cpp_family && !exists("cpp_no_cpp11")
162165
syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,cErrInBracket,cCppBracket,@cStringGroup,@Spell
163166
" cCppParen: same as cParen but ends at end-of-line; used in cDefine
164167
syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cErrInBracket,cParen,cBracket,cString,@Spell
@@ -272,12 +275,13 @@ if exists("c_gnu")
272275
syn keyword cType __label__ __complex__ __volatile__
273276
endif
274277

275-
syn keyword cStructure struct union enum typedef
278+
syn keyword cTypedef typedef
279+
syn keyword cStructure struct union enum
276280
syn keyword cStorageClass static register auto volatile extern const
277281
if exists("c_gnu")
278282
syn keyword cStorageClass inline __attribute__
279283
endif
280-
if !exists("c_no_c99") && s:ft !=# 'cpp'
284+
if !exists("c_no_c99") && !s:in_cpp_family
281285
syn keyword cStorageClass inline restrict
282286
endif
283287
if !exists("c_no_c11")
@@ -311,8 +315,7 @@ if !exists("c_no_ansi") || exists("c_ansi_constants") || exists("c_gnu")
311315
if exists("c_gnu")
312316
syn keyword cConstant __GNUC__ __FUNCTION__ __PRETTY_FUNCTION__ __func__
313317
endif
314-
syn keyword cConstant __LINE__ __FILE__ __DATE__ __TIME__ __STDC__
315-
syn keyword cConstant __STDC_VERSION__
318+
syn keyword cConstant __LINE__ __FILE__ __DATE__ __TIME__ __STDC__ __STDC_VERSION__ __STDC_HOSTED__
316319
syn keyword cConstant CHAR_BIT MB_LEN_MAX MB_CUR_MAX
317320
syn keyword cConstant UCHAR_MAX UINT_MAX ULONG_MAX USHRT_MAX
318321
syn keyword cConstant CHAR_MIN INT_MIN LONG_MIN SHRT_MIN
@@ -346,6 +349,8 @@ if !exists("c_no_ansi") || exists("c_ansi_constants") || exists("c_gnu")
346349
syn keyword cConstant SIGSTOP SIGTERM SIGTRAP SIGTSTP SIGTTIN SIGTTOU SIGUSR1 SIGUSR2
347350
syn keyword cConstant _IOFBF _IOLBF _IONBF BUFSIZ EOF WEOF FOPEN_MAX FILENAME_MAX L_tmpnam
348351
syn keyword cConstant SEEK_CUR SEEK_END SEEK_SET TMP_MAX stderr stdin stdout EXIT_FAILURE EXIT_SUCCESS RAND_MAX
352+
" used in assert.h
353+
syn keyword cConstant NDEBUG
349354
" POSIX 2001
350355
syn keyword cConstant SIGBUS SIGPOLL SIGPROF SIGSYS SIGURG SIGVTALRM SIGXCPU SIGXFSZ
351356
" non-POSIX signals
@@ -418,7 +423,7 @@ endif
418423
syn cluster cLabelGroup contains=cUserLabel
419424
syn match cUserCont display "^\s*\zs\I\i*\s*:$" contains=@cLabelGroup
420425
syn match cUserCont display ";\s*\zs\I\i*\s*:$" contains=@cLabelGroup
421-
if s:ft ==# 'cpp'
426+
if s:in_cpp_family
422427
syn match cUserCont display "^\s*\zs\%(class\|struct\|enum\)\@!\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup
423428
syn match cUserCont display ";\s*\zs\%(class\|struct\|enum\)\@!\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup
424429
else
@@ -475,6 +480,7 @@ hi def link cSpecialError cError
475480
hi def link cCurlyError cError
476481
hi def link cOperator Operator
477482
hi def link cStructure Structure
483+
hi def link cTypedef Structure
478484
hi def link cStorageClass StorageClass
479485
hi def link cInclude Include
480486
hi def link cPreProc PreProc

syntax/cpp.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ if exists("b:current_syntax")
99
finish
1010
endif
1111

12+
" inform C syntax that the file was included from cpp.vim
13+
let b:filetype_in_cpp_family = 1
14+
1215
" Read the C syntax to start with
1316
runtime! syntax/c.vim
1417
unlet b:current_syntax

0 commit comments

Comments
 (0)