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