Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim syntax file |
| 2 | " Language: Objective C |
| 3 | " Maintainer: Kazunobu Kuriyama <kazunobu.kuriyama@nifty.com> |
| 4 | " Ex-maintainer: Anthony Hodsdon <ahodsdon@fastmail.fm> |
| 5 | " First Author: Valentino Kyriakides <1kyriaki@informatik.uni-hamburg.de> |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 6 | " Last Change: 2007 Feb 21 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7 | |
| 8 | " For version 5.x: Clear all syntax items |
| 9 | " For version 6.x: Quit when a syntax file was already loaded |
| 10 | if version < 600 |
| 11 | syntax clear |
| 12 | elseif exists("b:current_syntax") |
| 13 | finish |
| 14 | endif |
| 15 | |
| 16 | if &filetype != 'objcpp' |
| 17 | " Read the C syntax to start with |
| 18 | if version < 600 |
| 19 | source <sfile>:p:h/c.vim |
| 20 | else |
| 21 | runtime! syntax/c.vim |
| 22 | endif |
| 23 | endif |
| 24 | |
| 25 | " Objective C extentions follow below |
| 26 | " |
| 27 | " NOTE: Objective C is abbreviated to ObjC/objc |
| 28 | " and uses *.h, *.m as file extensions! |
| 29 | |
| 30 | |
| 31 | " ObjC keywords, types, type qualifiers etc. |
| 32 | syn keyword objcStatement self super _cmd |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 33 | syn keyword objcType id Class SEL IMP BOOL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 34 | syn keyword objcTypeModifier bycopy in out inout oneway |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 35 | syn keyword objcConstant nil Nil |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 36 | |
| 37 | " Match the ObjC #import directive (like C's #include) |
| 38 | syn region objcImported display contained start=+"+ skip=+\\\\\|\\"+ end=+"+ |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 39 | syn match objcImported display contained "<[-_0-9a-zA-Z.\/]*>" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 40 | syn match objcImport display "^\s*\(%:\|#\)\s*import\>\s*["<]" contains=objcImported |
| 41 | |
| 42 | " Match the important ObjC directives |
| 43 | syn match objcScopeDecl "@public\|@private\|@protected" |
| 44 | syn match objcDirective "@interface\|@implementation" |
| 45 | syn match objcDirective "@class\|@end\|@defs" |
| 46 | syn match objcDirective "@encode\|@protocol\|@selector" |
Bram Moolenaar | 36fc535 | 2006-03-04 21:49:37 +0000 | [diff] [blame] | 47 | syn match objcDirective "@try\|@catch\|@finally\|@throw\|@synchronized" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 48 | |
| 49 | " Match the ObjC method types |
| 50 | " |
| 51 | " NOTE: here I match only the indicators, this looks |
| 52 | " much nicer and reduces cluttering color highlightings. |
| 53 | " However, if you prefer full method declaration matching |
| 54 | " append .* at the end of the next two patterns! |
| 55 | " |
| 56 | syn match objcInstMethod "^\s*-\s*" |
| 57 | syn match objcFactMethod "^\s*+\s*" |
| 58 | |
| 59 | " To distinguish from a header inclusion from a protocol list. |
| 60 | syn match objcProtocol display "<[_a-zA-Z][_a-zA-Z0-9]*>" contains=objcType,cType,Type |
| 61 | |
| 62 | |
| 63 | " To distinguish labels from the keyword for a method's parameter. |
| 64 | syn region objcKeyForMethodParam display |
| 65 | \ start="^\s*[_a-zA-Z][_a-zA-Z0-9]*\s*:\s*(" |
| 66 | \ end=")\s*[_a-zA-Z][_a-zA-Z0-9]*" |
| 67 | \ contains=objcType,objcTypeModifier,cType,cStructure,cStorageClass,Type |
| 68 | |
| 69 | " Objective-C Constant Strings |
| 70 | syn match objcSpecial display "%@" contained |
| 71 | syn region objcString start=+\(@"\|"\)+ skip=+\\\\\|\\"+ end=+"+ contains=cFormat,cSpecial,objcSpecial |
| 72 | |
| 73 | " Objective-C Message Expressions |
| 74 | syn region objcMessage display start="\[" end="\]" contains=objcMessage,objcStatement,objcType,objcTypeModifier,objcString,objcConstant,objcDirective,cType,cStructure,cStorageClass,cString,cCharacter,cSpecialCharacter,cNumbers,cConstant,cOperator,cComment,cCommentL,Type |
| 75 | |
| 76 | syn cluster cParenGroup add=objcMessage |
| 77 | syn cluster cPreProcGroup add=objcMessage |
| 78 | |
| 79 | " Define the default highlighting. |
| 80 | " For version 5.7 and earlier: only when not done already |
| 81 | " For version 5.8 and later: only when an item doesn't have highlighting yet |
| 82 | if version >= 508 || !exists("did_objc_syntax_inits") |
| 83 | if version < 508 |
| 84 | let did_objc_syntax_inits = 1 |
| 85 | command -nargs=+ HiLink hi link <args> |
| 86 | else |
| 87 | command -nargs=+ HiLink hi def link <args> |
| 88 | endif |
| 89 | |
| 90 | HiLink objcImport Include |
| 91 | HiLink objcImported cString |
| 92 | HiLink objcTypeModifier objcType |
| 93 | HiLink objcType Type |
| 94 | HiLink objcScopeDecl Statement |
| 95 | HiLink objcInstMethod Function |
| 96 | HiLink objcFactMethod Function |
| 97 | HiLink objcStatement Statement |
| 98 | HiLink objcDirective Statement |
| 99 | HiLink objcKeyForMethodParam None |
| 100 | HiLink objcString cString |
| 101 | HiLink objcSpecial Special |
| 102 | HiLink objcProtocol None |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 103 | HiLink objcConstant cConstant |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 104 | |
| 105 | delcommand HiLink |
| 106 | endif |
| 107 | |
| 108 | let b:current_syntax = "objc" |
| 109 | |
| 110 | " vim: ts=8 |