]> git.pld-linux.org Git - packages/vim.git/blame - javascript.vim
- updated to 7.1.285
[packages/vim.git] / javascript.vim
CommitLineData
efb89a59
JR
1" Vim syntax file
2" Language: JavaScript
e80d24ca
AG
3" Maintainer: Yi Zhao (ZHAOYI) <zzlinux AT hotmail DOT com>
4" Last Change: 2007 Jan. 30th
5" Version: 0.7.3
6" Changes: Add the keywords for JavaScript 1.7: let, yield,
7"
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.
efb89a59
JR
21if version < 600 && exists("javaScript_fold")
22 unlet javaScript_fold
e80d24ca
AG
23else
24 let javaScript_fold = 'false'
efb89a59
JR
25endif
26
e80d24ca
AG
27"" dollar sigh is permittd anywhere in an identifier
28setlocal iskeyword+=$
29
30syntax sync fromstart
31syntax sync maxlines=200
32
33"" JavaScript comments
34syntax keyword javaScriptCommentTodo TODO FIXME XXX TBD contained
35syntax region javaScriptLineComment start=+\/\/+ end=+$+ keepend contains=javaScriptCommentTodo,@Spell
36syntax region javaScriptLineComment start=+^\s*\/\/+ skip=+\n\s*\/\/+ end=+$+ keepend contains=javaScriptCommentTodo,@Spell fold
37syntax region javaScriptCvsTag start="\$\cid:" end="\$" oneline contained
38syntax region javaScriptComment start="/\*" end="\*/" contains=javaScriptCommentTodo,javaScriptCvsTag,@Spell fold
39
40"" JSDoc support start
41if !exists("javascript_ignore_javaScriptdoc")
42 syntax case ignore
43
44 "" syntax coloring for javadoc comments (HTML)
45 "syntax include @javaHtml <sfile>:p:h/html.vim
46 "unlet b:current_syntax
47
48 syntax region javaScriptDocComment matchgroup=javaScriptComment start="/\*\*\s*$" end="\*/" contains=javaScriptDocTags,javaScriptCommentTodo,javaScriptCvsTag,@javaScriptHtml,@Spell fold
49 syntax match javaScriptDocTags contained "@\(param\|argument\|requires\|exception\|throws\|type\|class\|extends\|see\|link\|member\|base\|file\)\>" nextgroup=javaScriptDocParam,javaScriptDocSeeTag skipwhite
50 syntax match javaScriptDocTags contained "@\(deprecated\|fileoverview\|author\|license\|version\|returns\=\|constructor\|private\|final\|ignore\|addon\|exec\)\>"
51 syntax match javaScriptDocParam contained "\%(#\|\w\|\.\|:\|\/\)\+"
52 syntax region javaScriptDocSeeTag contained matchgroup=javaScriptDocSeeTag start="{" end="}" contains=javaScriptDocTags
efb89a59 53
e80d24ca
AG
54 syntax case match
55endif "" JSDoc end
efb89a59 56
e80d24ca
AG
57syntax case match
58
59"" Syntax in the JavaScript code
60syntax match javaScriptSpecial "\\\d\d\d\|\\x\x\{2\}\|\\u\x\{4\}\|\\."
61syntax region javaScriptStringD start=+"+ skip=+\\\\\|\\$"+ end=+"+ contains=javaScriptSpecial,@htmlPreproc
62syntax region javaScriptStringS start=+'+ skip=+\\\\\|\\$'+ end=+'+ contains=javaScriptSpecial,@htmlPreproc
63syntax region javaScriptRegexpString start=+/\(\*\|/\)\@!+ skip=+\\\\\|\\/+ end=+/[gim]\{-,3}\(\s*[),.;$]\)\@=+ contains=javaScriptSpecial,@htmlPreproc oneline
64syntax match javaScriptNumber /\<-\=\d\+L\=\>\|\<0[xX]\x\+\>/
65syntax match javaScriptFloat /\<-\=\%(\d\+\.\d\+\|\d\+\.\|\.\d\+\)\%([eE][+-]\=\d\+\)\=\>/
66syntax match javaScriptLabel /\(?\s*\)\@<!\<\w\+\(\s*:\)\@=/
efb89a59 67
e80d24ca
AG
68"" JavaScript Prototype
69syntax keyword javaScriptPrototype prototype
efb89a59
JR
70
71"" Programm Keywords
e80d24ca
AG
72syntax keyword javaScriptSource import export
73syntax keyword javaScriptType const this var void yield
74syntax keyword javaScriptOperator delete new in instanceof let typeof
75syntax keyword javaScriptBoolean true false
76syntax keyword javaScriptNull null
efb89a59
JR
77
78"" Statement Keywords
e80d24ca
AG
79syntax keyword javaScriptConditional if else
80syntax keyword javaScriptRepeat do while for
81syntax keyword javaScriptBranch break continue switch case default return
82syntax keyword javaScriptStatement try catch throw with finally
efb89a59 83
e80d24ca 84syntax keyword javaScriptGlobalObjects Array Boolean Date Function Infinity JavaArray JavaClass JavaObject JavaPackage Math Number NaN Object Packages RegExp String Undefined java netscape sun
efb89a59 85
e80d24ca
AG
86syntax keyword javaScriptExceptions Error EvalError RangeError ReferenceError SyntaxError TypeError URIError
87
88syntax 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
89
90"" DOM/HTML/CSS specified things
91
92 " DOM2 Objects
93 syntax keyword javaScriptGlobalObjects DOMImplementation DocumentFragment Document Node NodeList NamedNodeMap CharacterData Attr Element Text Comment CDATASection DocumentType Notation Entity EntityReference ProcessingInstruction
94 syntax keyword javaScriptExceptions DOMException
95
96 " DOM2 CONSTANT
97 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
98 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
99
100 " HTML events and internal variables
101 syntax case ignore
102 syntax keyword javaScriptHtmlEvents onblur onclick oncontextmenu ondblclick onfocus onkeydown onkeypress onkeyup onmousedown onmousemove onmouseout onmouseover onmouseup onresize
103 syntax case match
104
105" Follow stuff should be highligh within a special context
106" While it can't be handled with context depended with Regex based highlight
107" So, turn it off by default
108if exists("javascript_enable_domhtmlcss")
efb89a59 109
e80d24ca
AG
110 " DOM2 things
111 syntax match javaScriptDomElemAttrs contained /\%(nodeName\|nodeValue\|nodeType\|parentNode\|childNodes\|firstChild\|lastChild\|previousSibling\|nextSibling\|attributes\|ownerDocument\|namespaceURI\|prefix\|localName\|tagName\)\>/
112 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
113 " HTML things
114 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\)\>/
115 syntax match javaScriptHtmlElemFuncs contained /\%(blur\|click\|focus\|scrollIntoView\|addEventListener\|dispatchEvent\|removeEventListener\|item\)\>/ nextgroup=javaScriptParen skipwhite
efb89a59 116
e80d24ca
AG
117 " CSS Styles in JavaScript
118 syntax keyword javaScriptCssStyles contained color font fontFamily fontSize fontSizeAdjust fontStretch fontStyle fontVariant fontWeight letterSpacing lineBreak lineHeight quotes rubyAlign rubyOverhang rubyPosition
119 syntax keyword javaScriptCssStyles contained textAlign textAlignLast textAutospace textDecoration textIndent textJustify textJustifyTrim textKashidaSpace textOverflowW6 textShadow textTransform textUnderlinePosition
120 syntax keyword javaScriptCssStyles contained unicodeBidi whiteSpace wordBreak wordSpacing wordWrap writingMode
121 syntax keyword javaScriptCssStyles contained bottom height left position right top width zIndex
122 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
123 syntax keyword javaScriptCssStyles contained margin marginBottom marginLeft marginRight marginTop outline outlineColor outlineStyle outlineWidth padding paddingBottom paddingLeft paddingRight paddingTop
124 syntax keyword javaScriptCssStyles contained listStyle listStyleImage listStylePosition listStyleType
125 syntax keyword javaScriptCssStyles contained background backgroundAttachment backgroundColor backgroundImage gackgroundPosition backgroundPositionX backgroundPositionY backgroundRepeat
126 syntax keyword javaScriptCssStyles contained clear clip clipBottom clipLeft clipRight clipTop content counterIncrement counterReset cssFloat cursor direction display filter layoutGrid layoutGridChar layoutGridLine layoutGridMode layoutGridType
127 syntax keyword javaScriptCssStyles contained marks maxHeight maxWidth minHeight minWidth opacity MozOpacity overflow overflowX overflowY verticalAlign visibility zoom cssText
128 syntax keyword javaScriptCssStyles contained scrollbar3dLightColor scrollbarArrowColor scrollbarBaseColor scrollbarDarkShadowColor scrollbarFaceColor scrollbarHighlightColor scrollbarShadowColor scrollbarTrackColor
129
130 " Highlight ways
131 syntax match javaScriptDotNotation "\." nextgroup=javaScriptPrototype,javaScriptDomElemAttrs,javaScriptDomElemFuncs,javaScriptHtmlElemAttrs,javaScriptHtmlElemFuncs
132 syntax match javaScriptDotNotation "\.style\." nextgroup=javaScriptCssStyles
133
134endif "DOM/HTML/CSS
135
136"" end DOM/HTML/CSS specified things
137
138
139"" Code blocks
140syntax 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
141syntax region javaScriptBracket matchgroup=javaScriptBracket transparent start="\[" end="\]" contains=@javaScriptAll,javaScriptParensErrB,javaScriptParensErrC,javaScriptBracket,javaScriptParen,javaScriptBlock,@htmlPreproc
142syntax region javaScriptParen matchgroup=javaScriptParen transparent start="(" end=")" contains=@javaScriptAll,javaScriptParensErrA,javaScriptParensErrC,javaScriptParen,javaScriptBracket,javaScriptBlock,@htmlPreproc
143syntax region javaScriptBlock matchgroup=javaScriptBlock transparent start="{" end="}" contains=@javaScriptAll,javaScriptParensErrA,javaScriptParensErrB,javaScriptParen,javaScriptBracket,javaScriptBlock,@htmlPreproc
144
145"" catch errors caused by wrong parenthesis
146syntax match javaScriptParensError ")\|}\|\]"
147syntax match javaScriptParensErrA contained "\]"
148syntax match javaScriptParensErrB contained ")"
149syntax match javaScriptParensErrC contained "}"
efb89a59
JR
150
151if main_syntax == "javascript"
e80d24ca 152 syntax sync ccomment javaScriptComment
efb89a59
JR
153endif
154
e80d24ca 155"" Fold control
117a7b07 156if exists("javaScript_fold")
e80d24ca
AG
157 syntax match javaScriptFunction /\<function\>/ nextgroup=javaScriptFuncName skipwhite
158 syntax region javaScriptFuncName contained matchgroup=javaScriptFuncName start=/\%(\$\|\w\)*\s*(/ end=/)/ contains=javaScriptLineComment,javaScriptComment nextgroup=javaScriptFuncBlock skipwhite skipempty
159 syntax region javaScriptFuncBlock contained matchgroup=javaScriptFuncBlock start="{" end="}" contains=@javaScriptAll,javaScriptParensErrA,javaScriptParensErrB,javaScriptParen,javaScriptBracket,javaScriptBlock fold
117a7b07 160
e80d24ca
AG
161 "" Fold setting
162 setlocal foldlevel=6
117a7b07 163 setlocal foldmethod=syntax
e80d24ca
AG
164
165 setlocal foldtext=FT_JavaScriptDoc()
166
167 "" Default fold text for JavaScript JSDoc and Function
168 function! FT_JavaScriptDoc()
169 let i = 0
170 while i < 3
171 let line = getline(v:foldstart + i)
172 "let line = substitute(line, '^\s\+', '', '')
173 let line = substitute(line, '\s\+$', '', '')
174 if match(line, '\w\+') >= 0
175 break
176 endif
177 let i += 1
178 endwhile
179 return v:folddashes . line
180 endfunction
181
117a7b07 182else
e80d24ca 183 syntax keyword javaScriptFunction function
117a7b07
AG
184endif
185
efb89a59
JR
186" Define the default highlighting.
187" For version 5.7 and earlier: only when not done already
188" For version 5.8 and later: only when an item doesn't have highlighting yet
189if version >= 508 || !exists("did_javascript_syn_inits")
190 if version < 508
191 let did_javascript_syn_inits = 1
192 command -nargs=+ HiLink hi link <args>
193 else
194 command -nargs=+ HiLink hi def link <args>
195 endif
e80d24ca
AG
196 HiLink javaScriptComment Comment
197 HiLink javaScriptLineComment Comment
198 HiLink javaScriptDocComment Comment
199 HiLink javaScriptCommentTodo Todo
200 HiLink javaScriptCvsTag Function
201 HiLink javaScriptDocTags Special
202 HiLink javaScriptDocSeeTag Function
203 HiLink javaScriptDocParam Function
204 HiLink javaScriptStringS String
205 HiLink javaScriptStringD String
206 HiLink javaScriptRegexpString String
207 HiLink javaScriptCharacter Character
208 HiLink javaScriptPrototype Type
209 HiLink javaScriptConditional Conditional
210 HiLink javaScriptBranch Conditional
211 HiLink javaScriptRepeat Repeat
212 HiLink javaScriptStatement Statement
213 HiLink javaScriptFunction Function
214 HiLink javaScriptError Error
215 HiLink javaScriptParensError Error
216 HiLink javaScriptParensErrA Error
217 HiLink javaScriptParensErrB Error
218 HiLink javaScriptParensErrC Error
219 HiLink javaScriptOperator Operator
220 HiLink javaScriptType Type
221 HiLink javaScriptNull Type
222 HiLink javaScriptNumber Number
223 HiLink javaScriptFloat Number
224 HiLink javaScriptBoolean Boolean
225 HiLink javaScriptLabel Label
226 HiLink javaScriptSpecial Special
227 HiLink javaScriptSource Special
228 HiLink javaScriptGlobalObjects Special
229 HiLink javaScriptExceptions Special
230
231 HiLink javaScriptDomErrNo Constant
232 HiLink javaScriptDomNodeConsts Constant
233 HiLink javaScriptDomElemAttrs Label
234 HiLink javaScriptDomElemFuncs PreProc
235
236 HiLink javaScriptHtmlEvents Special
237 HiLink javaScriptHtmlElemAttrs Label
238 HiLink javaScriptHtmlElemFuncs PreProc
239
240 HiLink javaScriptCssStyles Label
241
efb89a59
JR
242 delcommand HiLink
243endif
244
117a7b07 245" Define the htmlJavaScript for HTML syntax html.vim
e80d24ca 246"syntax clear htmlJavaScript
117a7b07 247"syntax clear javaScriptExpression
e80d24ca
AG
248syntax cluster htmlJavaScript contains=@javaScriptAll,javaScriptBracket,javaScriptParen,javaScriptBlock,javaScriptParenError
249syntax cluster javaScriptExpression contains=@javaScriptAll,javaScriptBracket,javaScriptParen,javaScriptBlock,javaScriptParenError,@htmlPreproc
117a7b07 250
efb89a59
JR
251let b:current_syntax = "javascript"
252if main_syntax == 'javascript'
253 unlet main_syntax
254endif
255
256" vim: ts=4
This page took 0.059425 seconds and 4 git commands to generate.