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