]> git.pld-linux.org Git - packages/vim.git/blame - javascript.vim
Up to 9.1.0004
[packages/vim.git] / javascript.vim
CommitLineData
efb89a59
JR
1" Vim syntax file
2" Language: JavaScript
e80d24ca 3" Maintainer: Yi Zhao (ZHAOYI) <zzlinux AT hotmail DOT com>
574381bc
AM
4" Last Change: June 4, 2009
5" Version: 0.7.7
6" Changes: Add "undefined" as a type keyword
227e9a1a 7"
e80d24ca
AG
8" TODO:
9" - Add the HTML syntax inside the JSDoc
efb89a59
JR
10
11if !exists("main_syntax")
12 if version < 600
13 syntax clear
14 elseif exists("b:current_syntax")
15 finish
16 endif
17 let main_syntax = 'javascript'
18endif
19
e80d24ca 20"" Drop fold if it set but VIM doesn't support it.
227e9a1a
AG
21let b:javascript_fold='true'
22if version < 600 " Don't support the old version
23 unlet! b:javascript_fold
efb89a59
JR
24endif
25
e80d24ca
AG
26"" dollar sigh is permittd anywhere in an identifier
27setlocal iskeyword+=$
28
29syntax sync fromstart
e80d24ca
AG
30
31"" JavaScript comments
32syntax keyword javaScriptCommentTodo TODO FIXME XXX TBD contained
227e9a1a 33syntax region javaScriptLineComment start=+\/\/+ end=+$+ keepend contains=javaScriptCommentTodo,@Spell
e80d24ca
AG
34syntax region javaScriptLineComment start=+^\s*\/\/+ skip=+\n\s*\/\/+ end=+$+ keepend contains=javaScriptCommentTodo,@Spell fold
35syntax region javaScriptCvsTag start="\$\cid:" end="\$" oneline contained
36syntax region javaScriptComment start="/\*" end="\*/" contains=javaScriptCommentTodo,javaScriptCvsTag,@Spell fold
37
38"" JSDoc support start
39if !exists("javascript_ignore_javaScriptdoc")
40 syntax case ignore
41
42 "" syntax coloring for javadoc comments (HTML)
43 "syntax include @javaHtml <sfile>:p:h/html.vim
227e9a1a
AG
44 "unlet b:current_syntax
45
e80d24ca 46 syntax region javaScriptDocComment matchgroup=javaScriptComment start="/\*\*\s*$" end="\*/" contains=javaScriptDocTags,javaScriptCommentTodo,javaScriptCvsTag,@javaScriptHtml,@Spell fold
227e9a1a
AG
47 syntax match javaScriptDocTags contained "@\(param\|argument\|requires\|exception\|throws\|type\|class\|extends\|see\|link\|member\|module\|method\|title\|namespace\|optional\|default\|base\|file\)\>" nextgroup=javaScriptDocParam,javaScriptDocSeeTag skipwhite
48 syntax match javaScriptDocTags contained "@\(beta\|deprecated\|description\|fileoverview\|author\|license\|version\|returns\=\|constructor\|private\|protected\|final\|ignore\|addon\|exec\)\>"
e80d24ca
AG
49 syntax match javaScriptDocParam contained "\%(#\|\w\|\.\|:\|\/\)\+"
50 syntax region javaScriptDocSeeTag contained matchgroup=javaScriptDocSeeTag start="{" end="}" contains=javaScriptDocTags
efb89a59 51
e80d24ca
AG
52 syntax case match
53endif "" JSDoc end
efb89a59 54
e80d24ca
AG
55syntax case match
56
57"" Syntax in the JavaScript code
58syntax match javaScriptSpecial "\\\d\d\d\|\\x\x\{2\}\|\\u\x\{4\}\|\\."
59syntax region javaScriptStringD start=+"+ skip=+\\\\\|\\$"+ end=+"+ contains=javaScriptSpecial,@htmlPreproc
60syntax region javaScriptStringS start=+'+ skip=+\\\\\|\\$'+ end=+'+ contains=javaScriptSpecial,@htmlPreproc
574381bc 61syntax region javaScriptRegexpString start=+/\(\*\|/\)\@!+ skip=+\\\\\|\\/+ end=+/[gim]\{,3}+ contains=javaScriptSpecial,@htmlPreproc oneline
e80d24ca
AG
62syntax match javaScriptNumber /\<-\=\d\+L\=\>\|\<0[xX]\x\+\>/
63syntax match javaScriptFloat /\<-\=\%(\d\+\.\d\+\|\d\+\.\|\.\d\+\)\%([eE][+-]\=\d\+\)\=\>/
64syntax match javaScriptLabel /\(?\s*\)\@<!\<\w\+\(\s*:\)\@=/
efb89a59 65
227e9a1a
AG
66"" JavaScript Prototype
67syntax keyword javaScriptPrototype prototype
efb89a59
JR
68
69"" Programm Keywords
e80d24ca 70syntax keyword javaScriptSource import export
574381bc 71syntax keyword javaScriptType const this undefined var void yield
227e9a1a 72syntax keyword javaScriptOperator delete new in instanceof let typeof
e80d24ca
AG
73syntax keyword javaScriptBoolean true false
74syntax keyword javaScriptNull null
efb89a59
JR
75
76"" Statement Keywords
e80d24ca
AG
77syntax keyword javaScriptConditional if else
78syntax keyword javaScriptRepeat do while for
227e9a1a
AG
79syntax keyword javaScriptBranch break continue switch case default return
80syntax keyword javaScriptStatement try catch throw with finally
efb89a59 81
e80d24ca 82syntax keyword javaScriptGlobalObjects Array Boolean Date Function Infinity JavaArray JavaClass JavaObject JavaPackage Math Number NaN Object Packages RegExp String Undefined java netscape sun
efb89a59 83
e80d24ca
AG
84syntax keyword javaScriptExceptions Error EvalError RangeError ReferenceError SyntaxError TypeError URIError
85
227e9a1a 86syntax keyword javaScriptFutureKeys abstract enum int short boolean export interface static byte extends long super char final native synchronized class float package throws const goto private transient debugger implements protected volatile double import public
e80d24ca
AG
87
88"" DOM/HTML/CSS specified things
89
90 " DOM2 Objects
91 syntax keyword javaScriptGlobalObjects DOMImplementation DocumentFragment Document Node NodeList NamedNodeMap CharacterData Attr Element Text Comment CDATASection DocumentType Notation Entity EntityReference ProcessingInstruction
92 syntax keyword javaScriptExceptions DOMException
227e9a1a 93
e80d24ca
AG
94 " DOM2 CONSTANT
95 syntax keyword javaScriptDomErrNo INDEX_SIZE_ERR DOMSTRING_SIZE_ERR HIERARCHY_REQUEST_ERR WRONG_DOCUMENT_ERR INVALID_CHARACTER_ERR NO_DATA_ALLOWED_ERR NO_MODIFICATION_ALLOWED_ERR NOT_FOUND_ERR NOT_SUPPORTED_ERR INUSE_ATTRIBUTE_ERR INVALID_STATE_ERR SYNTAX_ERR INVALID_MODIFICATION_ERR NAMESPACE_ERR INVALID_ACCESS_ERR
227e9a1a
AG
96 syntax keyword javaScriptDomNodeConsts ELEMENT_NODE ATTRIBUTE_NODE TEXT_NODE CDATA_SECTION_NODE ENTITY_REFERENCE_NODE ENTITY_NODE PROCESSING_INSTRUCTION_NODE COMMENT_NODE DOCUMENT_NODE DOCUMENT_TYPE_NODE DOCUMENT_FRAGMENT_NODE NOTATION_NODE
97
e80d24ca
AG
98 " HTML events and internal variables
99 syntax case ignore
100 syntax keyword javaScriptHtmlEvents onblur onclick oncontextmenu ondblclick onfocus onkeydown onkeypress onkeyup onmousedown onmousemove onmouseout onmouseover onmouseup onresize
101 syntax case match
102
103" Follow stuff should be highligh within a special context
104" While it can't be handled with context depended with Regex based highlight
105" So, turn it off by default
106if exists("javascript_enable_domhtmlcss")
efb89a59 107
e80d24ca
AG
108 " DOM2 things
109 syntax match javaScriptDomElemAttrs contained /\%(nodeName\|nodeValue\|nodeType\|parentNode\|childNodes\|firstChild\|lastChild\|previousSibling\|nextSibling\|attributes\|ownerDocument\|namespaceURI\|prefix\|localName\|tagName\)\>/
110 syntax match javaScriptDomElemFuncs contained /\%(insertBefore\|replaceChild\|removeChild\|appendChild\|hasChildNodes\|cloneNode\|normalize\|isSupported\|hasAttributes\|getAttribute\|setAttribute\|removeAttribute\|getAttributeNode\|setAttributeNode\|removeAttributeNode\|getElementsByTagName\|getAttributeNS\|setAttributeNS\|removeAttributeNS\|getAttributeNodeNS\|setAttributeNodeNS\|getElementsByTagNameNS\|hasAttribute\|hasAttributeNS\)\>/ nextgroup=javaScriptParen skipwhite
111 " HTML things
112 syntax match javaScriptHtmlElemAttrs contained /\%(className\|clientHeight\|clientLeft\|clientTop\|clientWidth\|dir\|id\|innerHTML\|lang\|length\|offsetHeight\|offsetLeft\|offsetParent\|offsetTop\|offsetWidth\|scrollHeight\|scrollLeft\|scrollTop\|scrollWidth\|style\|tabIndex\|title\)\>/
113 syntax match javaScriptHtmlElemFuncs contained /\%(blur\|click\|focus\|scrollIntoView\|addEventListener\|dispatchEvent\|removeEventListener\|item\)\>/ nextgroup=javaScriptParen skipwhite
efb89a59 114
e80d24ca 115 " CSS Styles in JavaScript
227e9a1a
AG
116 syntax keyword javaScriptCssStyles contained color font fontFamily fontSize fontSizeAdjust fontStretch fontStyle fontVariant fontWeight letterSpacing lineBreak lineHeight quotes rubyAlign rubyOverhang rubyPosition
117 syntax keyword javaScriptCssStyles contained textAlign textAlignLast textAutospace textDecoration textIndent textJustify textJustifyTrim textKashidaSpace textOverflowW6 textShadow textTransform textUnderlinePosition
e80d24ca 118 syntax keyword javaScriptCssStyles contained unicodeBidi whiteSpace wordBreak wordSpacing wordWrap writingMode
227e9a1a 119 syntax keyword javaScriptCssStyles contained bottom height left position right top width zIndex
e80d24ca 120 syntax keyword javaScriptCssStyles contained border borderBottom borderLeft borderRight borderTop borderBottomColor borderLeftColor borderTopColor borderBottomStyle borderLeftStyle borderRightStyle borderTopStyle borderBottomWidth borderLeftWidth borderRightWidth borderTopWidth borderColor borderStyle borderWidth borderCollapse borderSpacing captionSide emptyCells tableLayout
227e9a1a
AG
121 syntax keyword javaScriptCssStyles contained margin marginBottom marginLeft marginRight marginTop outline outlineColor outlineStyle outlineWidth padding paddingBottom paddingLeft paddingRight paddingTop
122 syntax keyword javaScriptCssStyles contained listStyle listStyleImage listStylePosition listStyleType
e80d24ca 123 syntax keyword javaScriptCssStyles contained background backgroundAttachment backgroundColor backgroundImage gackgroundPosition backgroundPositionX backgroundPositionY backgroundRepeat
227e9a1a
AG
124 syntax keyword javaScriptCssStyles contained clear clip clipBottom clipLeft clipRight clipTop content counterIncrement counterReset cssFloat cursor direction display filter layoutGrid layoutGridChar layoutGridLine layoutGridMode layoutGridType
125 syntax keyword javaScriptCssStyles contained marks maxHeight maxWidth minHeight minWidth opacity MozOpacity overflow overflowX overflowY verticalAlign visibility zoom cssText
e80d24ca
AG
126 syntax keyword javaScriptCssStyles contained scrollbar3dLightColor scrollbarArrowColor scrollbarBaseColor scrollbarDarkShadowColor scrollbarFaceColor scrollbarHighlightColor scrollbarShadowColor scrollbarTrackColor
127
128 " Highlight ways
129 syntax match javaScriptDotNotation "\." nextgroup=javaScriptPrototype,javaScriptDomElemAttrs,javaScriptDomElemFuncs,javaScriptHtmlElemAttrs,javaScriptHtmlElemFuncs
130 syntax match javaScriptDotNotation "\.style\." nextgroup=javaScriptCssStyles
227e9a1a 131
e80d24ca
AG
132endif "DOM/HTML/CSS
133
134"" end DOM/HTML/CSS specified things
135
136
137"" Code blocks
138syntax cluster javaScriptAll contains=javaScriptComment,javaScriptLineComment,javaScriptDocComment,javaScriptStringD,javaScriptStringS,javaScriptRegexpString,javaScriptNumber,javaScriptFloat,javaScriptLabel,javaScriptSource,javaScriptType,javaScriptOperator,javaScriptBoolean,javaScriptNull,javaScriptFunction,javaScriptConditional,javaScriptRepeat,javaScriptBranch,javaScriptStatement,javaScriptGlobalObjects,javaScriptExceptions,javaScriptFutureKeys,javaScriptDomErrNo,javaScriptDomNodeConsts,javaScriptHtmlEvents,javaScriptDotNotation
139syntax region javaScriptBracket matchgroup=javaScriptBracket transparent start="\[" end="\]" contains=@javaScriptAll,javaScriptParensErrB,javaScriptParensErrC,javaScriptBracket,javaScriptParen,javaScriptBlock,@htmlPreproc
140syntax region javaScriptParen matchgroup=javaScriptParen transparent start="(" end=")" contains=@javaScriptAll,javaScriptParensErrA,javaScriptParensErrC,javaScriptParen,javaScriptBracket,javaScriptBlock,@htmlPreproc
227e9a1a 141syntax region javaScriptBlock matchgroup=javaScriptBlock transparent start="{" end="}" contains=@javaScriptAll,javaScriptParensErrA,javaScriptParensErrB,javaScriptParen,javaScriptBracket,javaScriptBlock,@htmlPreproc
e80d24ca
AG
142
143"" catch errors caused by wrong parenthesis
144syntax match javaScriptParensError ")\|}\|\]"
145syntax match javaScriptParensErrA contained "\]"
146syntax match javaScriptParensErrB contained ")"
147syntax match javaScriptParensErrC contained "}"
efb89a59
JR
148
149if main_syntax == "javascript"
574381bc
AM
150 syntax sync clear
151 syntax sync ccomment javaScriptComment minlines=200
152 syntax sync match javaScriptHighlight grouphere javaScriptBlock /{/
efb89a59
JR
153endif
154
e80d24ca 155"" Fold control
227e9a1a
AG
156if exists("b:javascript_fold")
157 syntax match javaScriptFunction /\<function\>/ nextgroup=javaScriptFuncName skipwhite
158 syntax match javaScriptOpAssign /=\@<!=/ nextgroup=javaScriptFuncBlock skipwhite skipempty
e80d24ca
AG
159 syntax region javaScriptFuncName contained matchgroup=javaScriptFuncName start=/\%(\$\|\w\)*\s*(/ end=/)/ contains=javaScriptLineComment,javaScriptComment nextgroup=javaScriptFuncBlock skipwhite skipempty
160 syntax region javaScriptFuncBlock contained matchgroup=javaScriptFuncBlock start="{" end="}" contains=@javaScriptAll,javaScriptParensErrA,javaScriptParensErrB,javaScriptParen,javaScriptBracket,javaScriptBlock fold
117a7b07 161
227e9a1a
AG
162 if &l:filetype=='javascript' && !&diff
163 " Fold setting
164 " Redefine the foldtext (to show a JS function outline) and foldlevel
165 " only if the entire buffer is JavaScript, but not if JavaScript syntax
166 " is embedded in another syntax (e.g. HTML).
167 setlocal foldmethod=syntax
168 setlocal foldlevel=4
169 endif
117a7b07 170else
e80d24ca 171 syntax keyword javaScriptFunction function
227e9a1a
AG
172 setlocal foldmethod<
173 setlocal foldlevel<
117a7b07
AG
174endif
175
efb89a59
JR
176" Define the default highlighting.
177" For version 5.7 and earlier: only when not done already
178" For version 5.8 and later: only when an item doesn't have highlighting yet
179if version >= 508 || !exists("did_javascript_syn_inits")
180 if version < 508
181 let did_javascript_syn_inits = 1
182 command -nargs=+ HiLink hi link <args>
183 else
184 command -nargs=+ HiLink hi def link <args>
185 endif
e80d24ca
AG
186 HiLink javaScriptComment Comment
187 HiLink javaScriptLineComment Comment
188 HiLink javaScriptDocComment Comment
189 HiLink javaScriptCommentTodo Todo
190 HiLink javaScriptCvsTag Function
191 HiLink javaScriptDocTags Special
192 HiLink javaScriptDocSeeTag Function
193 HiLink javaScriptDocParam Function
194 HiLink javaScriptStringS String
195 HiLink javaScriptStringD String
196 HiLink javaScriptRegexpString String
197 HiLink javaScriptCharacter Character
198 HiLink javaScriptPrototype Type
199 HiLink javaScriptConditional Conditional
200 HiLink javaScriptBranch Conditional
201 HiLink javaScriptRepeat Repeat
202 HiLink javaScriptStatement Statement
203 HiLink javaScriptFunction Function
204 HiLink javaScriptError Error
205 HiLink javaScriptParensError Error
206 HiLink javaScriptParensErrA Error
207 HiLink javaScriptParensErrB Error
208 HiLink javaScriptParensErrC Error
209 HiLink javaScriptOperator Operator
210 HiLink javaScriptType Type
211 HiLink javaScriptNull Type
212 HiLink javaScriptNumber Number
213 HiLink javaScriptFloat Number
214 HiLink javaScriptBoolean Boolean
215 HiLink javaScriptLabel Label
216 HiLink javaScriptSpecial Special
217 HiLink javaScriptSource Special
218 HiLink javaScriptGlobalObjects Special
219 HiLink javaScriptExceptions Special
220
221 HiLink javaScriptDomErrNo Constant
222 HiLink javaScriptDomNodeConsts Constant
223 HiLink javaScriptDomElemAttrs Label
224 HiLink javaScriptDomElemFuncs PreProc
225
226 HiLink javaScriptHtmlEvents Special
227 HiLink javaScriptHtmlElemAttrs Label
228 HiLink javaScriptHtmlElemFuncs PreProc
229
230 HiLink javaScriptCssStyles Label
231
efb89a59
JR
232 delcommand HiLink
233endif
234
117a7b07 235" Define the htmlJavaScript for HTML syntax html.vim
e80d24ca 236"syntax clear htmlJavaScript
117a7b07 237"syntax clear javaScriptExpression
e80d24ca
AG
238syntax cluster htmlJavaScript contains=@javaScriptAll,javaScriptBracket,javaScriptParen,javaScriptBlock,javaScriptParenError
239syntax cluster javaScriptExpression contains=@javaScriptAll,javaScriptBracket,javaScriptParen,javaScriptBlock,javaScriptParenError,@htmlPreproc
117a7b07 240
efb89a59
JR
241let b:current_syntax = "javascript"
242if main_syntax == 'javascript'
243 unlet main_syntax
244endif
245
246" vim: ts=4
This page took 0.141358 seconds and 4 git commands to generate.