Skip to content

Commit e713ddc

Browse files
committed
ADDED: folds, and foldmethod JavaScriptFold() to file
1 parent 46c8f78 commit e713ddc

File tree

1 file changed

+43
-29
lines changed

1 file changed

+43
-29
lines changed

syntax/javascript.vim

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,17 @@ setlocal iskeyword+=$
2828

2929
syntax sync fromstart
3030

31-
"" JavaScript comments
31+
"" JavaScript comments"{{{
3232
syn keyword javaScriptCommentTodo TODO FIXME XXX TBD contained
3333
syn match javaScriptLineComment "\/\/.*" contains=@Spell,javaScriptCommentTodo
3434
syn match javaScriptCommentSkip "^[ \t]*\*\($\|[ \t]\+\)"
3535
syn region javaScriptComment start="/\*" end="\*/" contains=@Spell,javaScriptCommentTodo
36-
37-
"" JSDoc support start
36+
"}}}
37+
"" JSDoc support start"{{{
3838
if !exists("javascript_ignore_javaScriptdoc")
3939
syntax case ignore
4040

41-
"" syntax coloring for javadoc comments (HTML)
42-
"syntax include @javaHtml <sfile>:p:h/html.vim
41+
" syntax coloring for JSDoc comments (HTML)
4342
"unlet b:current_syntax
4443

4544
syntax region javaScriptDocComment matchgroup=javaScriptComment start="/\*\*\s*$" end="\*/" contains=javaScriptDocTags,javaScriptCommentTodo,javaScriptCvsTag,@javaScriptHtml,@Spell fold
@@ -50,10 +49,10 @@ if !exists("javascript_ignore_javaScriptdoc")
5049

5150
syntax case match
5251
endif "" JSDoc end
53-
52+
"}}}
5453
syntax case match
5554

56-
"" Syntax in the JavaScript code
55+
"" Syntax in the JavaScript code"{{{
5756
syn match javaScriptSpecial "\\\d\d\d\|\\."
5857
syn region javaScriptStringD start=+"+ skip=+\\\\\|\\"+ end=+"\|$+ contains=javaScriptSpecial,@htmlPreproc
5958
syn region javaScriptStringS start=+'+ skip=+\\\\\|\\'+ end=+'\|$+ contains=javaScriptSpecial,@htmlPreproc
@@ -68,10 +67,10 @@ syn region javaScriptRegexpString start=+/[^/*]+me=e-1 skip=+\\\\\|\\/+ end
6867
" syntax match javaScriptNumber /\<-\=\d\+L\=\>\|\<0[xX]\x\+\>/
6968
syntax match javaScriptFloat /\<-\=\%(\d\+\.\d\+\|\d\+\.\|\.\d\+\)\%([eE][+-]\=\d\+\)\=\>/
7069
" syntax match javaScriptLabel /\(?\s*\)\@<!\<\w\+\(\s*:\)\@=/
71-
72-
"" JavaScript Prototype
70+
"}}}
71+
"" JavaScript Prototype"{{{
7372
syntax keyword javaScriptPrototype prototype
74-
73+
"}}}
7574
" DOM, Browser and Ajax Support {{{
7675
""""""""""""""""""""""""
7776
syntax keyword javaScriptBrowserObjects window navigator screen history location
@@ -93,8 +92,7 @@ syntax keyword javaScriptEventListenerKeywords blur click focus mouseover mou
9392

9493
syntax keyword javaScriptEventListenerMethods scrollIntoView addEventListener dispatchEvent removeEventListener preventDefault stopPropagation
9594
" }}}
96-
97-
"" Programm Keywords
95+
"" Programm Keywords"{{{
9896
syntax keyword javaScriptSource import export
9997
syntax keyword javaScriptIdentifier arguments this let var void yield
10098
syntax keyword javaScriptOperator delete new instanceof typeof
@@ -103,8 +101,8 @@ syntax keyword javaScriptNull null undefined
103101
syntax keyword javaScriptMessage alert confirm prompt status
104102
syntax keyword javaScriptGlobal self top parent
105103
syntax keyword javaScriptDeprecated escape unescape all applets alinkColor bgColor fgColor linkColor vlinkColor xmlEncoding
106-
107-
"" Statement Keywords
104+
"}}}
105+
"" Statement Keywords"{{{
108106
syntax keyword javaScriptConditional if else switch
109107
syntax keyword javaScriptRepeat do while for in
110108
syntax keyword javaScriptBranch break continue
@@ -116,35 +114,37 @@ syntax keyword javaScriptGlobalObjects Array Boolean Date Function Infinity Mat
116114
syntax keyword javaScriptExceptions try catch throw finally Error EvalError RangeError ReferenceError SyntaxError TypeError URIError
117115

118116
syntax keyword javaScriptReserved 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
117+
"}}}
118+
"" DOM/HTML/CSS specified things"{{{
119119

120-
"" DOM/HTML/CSS specified things
121-
122-
" DOM2 Objects
120+
" DOM2 Objects"{{{
123121
syntax keyword javaScriptType DOMImplementation DocumentFragment Node NodeList NamedNodeMap CharacterData Attr Element Text Comment CDATASection DocumentType Notation Entity EntityReference ProcessingInstruction
124122
syntax keyword javaScriptExceptions DOMException
125-
126-
" DOM2 CONSTANT
123+
"}}}
124+
" DOM2 CONSTANT"{{{
127125
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
128126
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
129-
130-
" HTML events and internal variables
127+
"}}}
128+
" HTML events and internal variables"{{{
131129
syntax case ignore
132130
syntax keyword javaScriptHtmlEvents onblur onclick oncontextmenu ondblclick onfocus onkeydown onkeypress onkeyup onmousedown onmousemove onmouseout onmouseover onmouseup onresize onload onsubmit
133131
syntax case match
132+
"}}}
134133

135134
" Follow stuff should be highligh within a special context
136135
" While it can't be handled with context depended with Regex based highlight
137136
" So, turn it off by default
138137
if exists("javascript_enable_domhtmlcss")
139138

140-
" DOM2 things
139+
" DOM2 things"{{{
141140
syntax match javaScriptDomElemAttrs contained /\%(nodeName\|nodeValue\|nodeType\|parentNode\|childNodes\|firstChild\|lastChild\|previousSibling\|nextSibling\|attributes\|ownerDocument\|namespaceURI\|prefix\|localName\|tagName\)\>/
142141
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
143-
" HTML things
142+
"}}}
143+
" HTML things"{{{
144144
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\)\>/
145145
syntax match javaScriptHtmlElemFuncs contained /\%(blur\|click\|focus\|scrollIntoView\|addEventListener\|dispatchEvent\|removeEventListener\|item\)\>/ nextgroup=javaScriptParen skipwhite
146-
147-
" CSS Styles in JavaScript
146+
"}}}
147+
" CSS Styles in JavaScript"{{{
148148
syntax keyword javaScriptCssStyles contained color font fontFamily fontSize fontSizeAdjust fontStretch fontStyle fontVariant fontWeight letterSpacing lineBreak lineHeight quotes rubyAlign rubyOverhang rubyPosition
149149
syntax keyword javaScriptCssStyles contained textAlign textAlignLast textAutospace textDecoration textIndent textJustify textJustifyTrim textKashidaSpace textOverflowW6 textShadow textTransform textUnderlinePosition
150150
syntax keyword javaScriptCssStyles contained unicodeBidi whiteSpace wordBreak wordSpacing wordWrap writingMode
@@ -156,14 +156,14 @@ if exists("javascript_enable_domhtmlcss")
156156
syntax keyword javaScriptCssStyles contained clear clip clipBottom clipLeft clipRight clipTop content counterIncrement counterReset cssFloat cursor direction display filter layoutGrid layoutGridChar layoutGridLine layoutGridMode layoutGridType
157157
syntax keyword javaScriptCssStyles contained marks maxHeight maxWidth minHeight minWidth opacity MozOpacity overflow overflowX overflowY verticalAlign visibility zoom cssText
158158
syntax keyword javaScriptCssStyles contained scrollbar3dLightColor scrollbarArrowColor scrollbarBaseColor scrollbarDarkShadowColor scrollbarFaceColor scrollbarHighlightColor scrollbarShadowColor scrollbarTrackColor
159-
160-
" Highlight ways
159+
"}}}
160+
" Highlight ways"{{{
161161
syntax match javaScriptDotNotation "\." nextgroup=javaScriptPrototype,javaScriptDomElemAttrs,javaScriptDomElemFuncs,javaScriptHtmlElemAttrs,javaScriptHtmlElemFuncs
162162
syntax match javaScriptDotNotation "\.style\." nextgroup=javaScriptCssStyles
163-
163+
"}}}
164164
endif "DOM/HTML/CSS
165165

166-
"" end DOM/HTML/CSS specified things
166+
"" end DOM/HTML/CSS specified things""}}}
167167

168168

169169
"" Code blocks
@@ -185,6 +185,20 @@ syn match javaScriptOpSymbols "=\{1,3}\|!==\|!=\|<\|>\|>=\|<=\|++\|+=\|--\|-=
185185
syn match javaScriptEndColons "[;,]$"
186186
syn match javaScriptLogicSymbols "\(&&\)\|\(||\)"
187187

188+
" JavaScriptFold Function {{{
189+
190+
function! JavaScriptFold()
191+
setl foldmethod=syntax
192+
setl foldlevelstart=1
193+
syn region foldBraces start=/{/ end=/}/ transparent fold keepend extend
194+
195+
setl foldtext=FoldText()
196+
endfunction
197+
198+
au FileType javascript call JavaScriptFold()
199+
200+
" }}}
201+
188202
" Define the default highlighting.
189203
" For version 5.7 and earlier: only when not done already
190204
" For version 5.8 and later: only when an item doesn't have highlighting yet

0 commit comments

Comments
 (0)