1
1
" Vim syntax file
2
2
" Language: C
3
3
" Maintainer: Bram Moolenaar <[email protected] >
4
- " Last Change: 2019 Nov 29
4
+ " Last Change: 2021 Jan 11
5
5
6
6
" Quit when a (custom) syntax file was already loaded
7
7
if exists (" b:current_syntax" )
@@ -13,6 +13,9 @@ set cpo&vim
13
13
14
14
let s: ft = matchstr (&ft , ' ^\([^.]\)\+' )
15
15
16
+ " check if this was included from cpp.vim
17
+ let s: in_cpp_family = exists (" b:filetype_in_cpp_family" )
18
+
16
19
" Optional embedded Autodoc parsing
17
20
" To enable it add: let g:c_autodoc = 1
18
21
" to your .vimrc
@@ -55,7 +58,7 @@ if !exists("c_no_cformat")
55
58
endif
56
59
57
60
" 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" )
59
62
" ISO C++11
60
63
syn region cString start =+ \( L\| u\| u8\| U\| R\| LR\| u8R\| uR\| UR\)\= "+ skip =+ \\\\\|\\ "+ end =+ "+ contains =cSpecial,cFormat,@Spell extend
61
64
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}'"
87
90
syn match cSpecialCharacter display " '\\ x\x\{ 1,2}'"
88
91
syn match cSpecialCharacter display " L'\\ x\x\+ '"
89
92
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" ))
91
94
" ISO C11 or ISO C++ 11
92
95
if exists (" c_no_cformat" )
93
96
syn region cString start =+ \% (U\| u8\=\) "+ skip =+ \\\\\|\\ "+ end =+ "+ contains =cSpecial,@Spell extend
@@ -130,7 +133,7 @@ endif
130
133
" But avoid matching <::.
131
134
syn cluster cParenGroup contains =cParenError,cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserLabel,cBitField,cOctalZero,@cCppOutInGroup,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom
132
135
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" )
134
137
syn region cParen transparent start =' (' end =' )' contains =ALLBUT,@cParenGroup,cCppParen,@cStringGroup,@Spell
135
138
" cCppParen: same as cParen but ends at end-of-line; used in cDefine
136
139
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")
144
147
syn match cErrInParen display contained " ^[{}]\| ^<%\| ^%>"
145
148
endif
146
149
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" )
148
151
syn region cParen transparent start =' (' end =' )' contains =ALLBUT,@cParenGroup,cCppParen,@cStringGroup,@Spell
149
152
" cCppParen: same as cParen but ends at end-of-line; used in cDefine
150
153
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")
158
161
syn match cErrInParen display contained " [{}]\| <%\| %>"
159
162
endif
160
163
else
161
- if s: ft == # ' cpp ' && ! exists (" cpp_no_cpp11" )
164
+ if s: in_cpp_family && ! exists (" cpp_no_cpp11" )
162
165
syn region cParen transparent start =' (' end =' )' contains =ALLBUT,@cParenGroup,cCppParen,cErrInBracket,cCppBracket,@cStringGroup,@Spell
163
166
" cCppParen: same as cParen but ends at end-of-line; used in cDefine
164
167
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")
272
275
syn keyword cType __label__ __complex__ __volatile__
273
276
endif
274
277
275
- syn keyword cStructure struct union enum typedef
278
+ syn keyword cTypedef typedef
279
+ syn keyword cStructure struct union enum
276
280
syn keyword cStorageClass static register auto volatile extern const
277
281
if exists (" c_gnu" )
278
282
syn keyword cStorageClass inline __attribute__
279
283
endif
280
- if ! exists (" c_no_c99" ) && s: ft !=# ' cpp '
284
+ if ! exists (" c_no_c99" ) && ! s: in_cpp_family
281
285
syn keyword cStorageClass inline restrict
282
286
endif
283
287
if ! exists (" c_no_c11" )
@@ -311,8 +315,7 @@ if !exists("c_no_ansi") || exists("c_ansi_constants") || exists("c_gnu")
311
315
if exists (" c_gnu" )
312
316
syn keyword cConstant __GNUC__ __FUNCTION__ __PRETTY_FUNCTION__ __func__
313
317
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__
316
319
syn keyword cConstant CHAR_BIT MB_LEN_MAX MB_CUR_MAX
317
320
syn keyword cConstant UCHAR_MAX UINT_MAX ULONG_MAX USHRT_MAX
318
321
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")
346
349
syn keyword cConstant SIGSTOP SIGTERM SIGTRAP SIGTSTP SIGTTIN SIGTTOU SIGUSR1 SIGUSR2
347
350
syn keyword cConstant _IOFBF _IOLBF _IONBF BUFSIZ EOF WEOF FOPEN_MAX FILENAME_MAX L_tmpnam
348
351
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
349
354
" POSIX 2001
350
355
syn keyword cConstant SIGBUS SIGPOLL SIGPROF SIGSYS SIGURG SIGVTALRM SIGXCPU SIGXFSZ
351
356
" non-POSIX signals
@@ -418,7 +423,7 @@ endif
418
423
syn cluster cLabelGroup contains =cUserLabel
419
424
syn match cUserCont display " ^\s *\z s\I\i *\s *:$" contains =@cLabelGroup
420
425
syn match cUserCont display " ;\s *\z s\I\i *\s *:$" contains =@cLabelGroup
421
- if s: ft == # ' cpp '
426
+ if s: in_cpp_family
422
427
syn match cUserCont display " ^\s *\z s\% (class\| struct\| enum\)\@ !\I\i *\s *:[^:]" me =e - 1 contains =@cLabelGroup
423
428
syn match cUserCont display " ;\s *\z s\% (class\| struct\| enum\)\@ !\I\i *\s *:[^:]" me =e - 1 contains =@cLabelGroup
424
429
else
@@ -475,6 +480,7 @@ hi def link cSpecialError cError
475
480
hi def link cCurlyError cError
476
481
hi def link cOperator Operator
477
482
hi def link cStructure Structure
483
+ hi def link cTypedef Structure
478
484
hi def link cStorageClass StorageClass
479
485
hi def link cInclude Include
480
486
hi def link cPreProc PreProc
0 commit comments