Refactor and optimize C/C++ syntax highlights
This commit is contained in:
@@ -3,49 +3,84 @@
|
||||
" Author: Kenneth Benzie (Benie) <k.benzie83@gmail.com>
|
||||
" Last Modified: September 04, 2016
|
||||
|
||||
" Match delimiter expressions: (expr) {expr} : ;
|
||||
" ^ ^ ^ ^ ^ ^
|
||||
syn match cDelimiter '[()\[\]:;]'
|
||||
" Match single character operators, ordering within the [] is important
|
||||
syn match cOperator '[\*=\.\^\~+\-,&|!%?]'
|
||||
" Match single character operators if they are surrounded by white space: / < >
|
||||
" ^ ^ ^
|
||||
syn match cOperator '\(\s\zs\/\s\ze\|\s\zs<\s\ze\|\s\zs>\s\ze\)'
|
||||
" Match multi character operators
|
||||
syn match cOperator '\(+=\|-=\|\*=\|/=\|%=\|\ˆ=\|&=\||=\|<<\|>>\|>>=\)'
|
||||
syn match cOperator '\(<<=\|==\|!=\|<=\|>=\|&&\|||\|++\|--\|->\*\|->\)'
|
||||
" Match : in ternary operator as cOperator
|
||||
syn region cOperatorTernary matchgroup=cOperator start='?' end=':' transparent
|
||||
" TODO: Match operator/ operator< operator>
|
||||
" Match function expressions: expr()
|
||||
" ^^^^
|
||||
syn match cFunction '\w[A-Za-z0-9_]*\ze\s*('
|
||||
" Match label expressions: expr:
|
||||
" ^^^^
|
||||
syn match cLabel '^\s*\w[A-Za-z0-9_]\+\ze::\@!' contains=cppAccess
|
||||
if !exists('c_no_function')
|
||||
" Match function expressions: expr()
|
||||
" ^^^^
|
||||
syn match cFunction '\a\w*\ze\s*(' display
|
||||
|
||||
" Match Doxygen comments
|
||||
let g:c_doxygen = get(g:, 'c_doxygen', 1)
|
||||
if exists('g:c_doxygen') && g:c_doxygen
|
||||
syn region cDoxygenMarkdownMono oneline start='`' end='`'
|
||||
syn match cDoxygenUrl /https\?:\/\/\(\w\+\(:\w\+\)\?@\)\?\([A-Za-z][-_0-9A-Za-z]*\.\)\{1,}\(\w\{2,}\.\?\)\{1,}\(:[0-9]\{1,5}\)\?\S*/
|
||||
syn region cDoxygenComment oneline start='\/\/\/' end='$' contains=cDoxygenMarkdownMono,cDoxygenUrl,@Spell
|
||||
syn region cDoxygen oneline matchgroup=cComment start='\/\/\/\s*[\\@]brief\s\+' end='$' contains=cDoxygenMarkdownMono,@Spell
|
||||
syn region cDoxygen oneline matchgroup=cComment start='\/\/\/\s*[\\@]tparam\s\+' end='\(\s.*$\|$\)'
|
||||
syn region cDoxygen oneline matchgroup=cComment start='\/\/\/\s*[\\@]param\(\[\(\|in\|out\|in,out\)\]\)\=\s\+' end='\(\s.*$\|$\)'
|
||||
syn match cDoxygenTodo 'todo' contained
|
||||
syn region cComment oneline start='\/\/\/\s*[\\@]\zetodo\s\+' end='$' contains=cDoxygenTodo,@Spell
|
||||
hi default link cDoxygenMarkdownMono SpecialComment
|
||||
hi default link cDoxygenUrl Underlined
|
||||
hi default link cDoxygenComment cComment
|
||||
hi default link cDoxygen SpecialComment
|
||||
hi default link cDoxygenTodo Todo
|
||||
hi default link cFunction Function
|
||||
endif
|
||||
|
||||
if !exists('c_no_delimiters')
|
||||
" Match delimiter expressions: (expr) {expr} ;
|
||||
" ^ ^ ^ ^ ^
|
||||
syn match cDelimiter '[()\[\];:]' display
|
||||
|
||||
" Match curly braces with cDelimiter highlight group
|
||||
syn region cBlock matchgroup=cDelimiter start="{" end="}" transparent fold
|
||||
" Match curly braces with cDelimiter highlight group
|
||||
syn region cBlock matchgroup=cDelimiter start="{" end="}" transparent fold
|
||||
|
||||
" Define additional highlight groups
|
||||
hi default link cDelimiter Delimiter
|
||||
hi default link cFunction Function
|
||||
hi link cUserCont Delimiter
|
||||
hi default link cDelimiter cUserCont
|
||||
endif
|
||||
|
||||
if !exists('c_no_operators')
|
||||
" Match: * - . ^ ~ + - , & | ! % ? < > order is important
|
||||
" ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
|
||||
syn match cOperator '[\*=\.\^\~+\-,&|!%?><]' display
|
||||
|
||||
" Match: / don't override // or /* or */
|
||||
" ^
|
||||
syn match cOperator '[\*\/]\@<!\/[\*\/]\@!' display
|
||||
|
||||
" Match: (expr) ? true : false;
|
||||
" ^ ^
|
||||
syn region cOperatorTernary matchgroup=cOperator start='?' end=':' transparent display
|
||||
endif
|
||||
|
||||
let g:c_doxygen = get(g:, 'c_doxygen', 1)
|
||||
if exists('g:c_doxygen') && g:c_doxygen
|
||||
" Match: comment leader
|
||||
syn match cDoxygenLeader '^\s*\/\/\/' contained display
|
||||
|
||||
" Match: @param name description.
|
||||
" ^^^^
|
||||
syn region cDoxygenSpecial matchgroup=cDoxygenComment start='@param\(\[\(\|in\|out\|in,out\)\]\)\=\s\+' end='\(\s\|$\)' contained display
|
||||
|
||||
" Match: @tparam name description.
|
||||
" ^^^^
|
||||
syn region cDoxygenSpecial matchgroup=cDoxygenComment start='@tparam\s\+' end='\(\s\|$\)' contained display
|
||||
|
||||
" Match: `markdown monospace`
|
||||
" ^^^^^^^^^^^^^^^^^^^^
|
||||
syn region cDoxygenSpecial start='`' end='`' contained contains=@NoSpell,cDoxygenLeader display
|
||||
|
||||
" Match: @brief Description. @return Description.
|
||||
" ^^^^^^^^^^^^ ^^^^^^^^^^^^
|
||||
syn region cDoxygenSpecial matchgroup=cDoxygenComment start='@\(brief\|return[s]\?\|attention\)' end='\(^\s*\/\/\/\s*$\|^\(\s*\/\/\/\)\@!\)' contained contains=@Spell,cDoxygenLeader,cDoxygenSpecial display
|
||||
|
||||
" Match: @def MACRO
|
||||
" ^^^^^
|
||||
syn region cDoxygenSpecial matchgroup=cDoxygenComment start='@def' end='$' contained display
|
||||
|
||||
" Match: something ///< description.
|
||||
" ^^^^^^^^^^^^
|
||||
syn region cDoxygenSpecial matchgroup=cDoxygenComment oneline start='\/\/\/<' end='$' display
|
||||
|
||||
" Match: @todo description.
|
||||
" ^^^^
|
||||
syn match cDoxygenTodo '@\zstodo' contained display
|
||||
|
||||
" Match: http://some.url
|
||||
" ^^^^^^^^^^^^^^^
|
||||
syn match cDoxygenUrl /https\?:\/\/\(\w\+\(:\w\+\)\?@\)\?\([A-Za-z][-_0-9A-Za-z]*\.\)\{1,}\(\w\{2,}\.\?\)\{1,}\(:[0-9]\{1,5}\)\?\S*/ contained display
|
||||
|
||||
" Match: /// Description.
|
||||
" ^^^^^^^^^^^^^^^^
|
||||
syn region cDoxygenComment fold start='^\s*\/\/\/' end='^\(\s*\/\/\/\)\@!' contains=@Spell,cDoxygenSpecial,cDoxygenTodo,cDoxygenUrl
|
||||
|
||||
hi default link cDoxygenComment cComment
|
||||
hi default link cDoxygenLeader cDoxygenComment
|
||||
hi default link cDoxygenSpecial SpecialComment
|
||||
hi default link cDoxygenTodo Todo
|
||||
hi default link cDoxygenUrl Underlined
|
||||
endif
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
" Language: C++
|
||||
" Description: Additional C++ syntax file.
|
||||
" Author: Kenneth Benzie (Benie) k.benzie83@gmail.com
|
||||
" Last Modified: September 04, 2016
|
||||
|
||||
" Match delimiter expressions: <expr>, ex::pr
|
||||
" ^ ^ ^^
|
||||
syn match cppDelimiter '\(<\|>\|::\)'
|
||||
" Match keyword logic operators
|
||||
syn keyword cppOperator and and_eq bitand bitor compl not not_eq or or_eq xor xor_eq
|
||||
" Match keyword operators
|
||||
syn keyword cppOperator new delete alignas alignof decltype
|
||||
" Match single character operators if they are surrounded by white space: / < >
|
||||
" ^ ^ ^
|
||||
syn match cppOperator '\(\s\zs\/\s\ze\|\s\zs<\s\ze\|\s\zs>\s\ze\)'
|
||||
" Match nested namespace expressions: expr::
|
||||
" ^^^^
|
||||
syn match cppNestedNameSpecifier '\w[A-Za-z0-9_]*\ze::'
|
||||
" Match multi character operators, override cppDelimiter matches for < >
|
||||
" ^ ^
|
||||
syn match cppOperator '\(<<\ze\s\|\s\zs>>\|>>=\|<<=\|<=\|>=\|->\*\|->\)'
|
||||
" Match = delete; as a statement
|
||||
" ^^^^^^
|
||||
" TODO: For some reason \zs stop this from matching, so the cppEquals hack was
|
||||
" added to work around the failure to highlight in that case. This is terrible
|
||||
" and a fix needs to be found.
|
||||
syn match cppEquals '='
|
||||
syn match cppStatement '=\s\+delete\ze\s*;' contains=cppEquals
|
||||
hi default link cppEquals cppOperator
|
||||
|
||||
" Define additional highlight groups
|
||||
hi default link cppDelimiter Delimiter
|
||||
|
||||
" Override default highlight groups
|
||||
hi link cppCast Operator
|
||||
hi link cppModifier Statement
|
||||
hi link cppNestedNameSpecifier Include
|
||||
Reference in New Issue
Block a user