comparison runtime/autoload/javascriptcomplete.vim @ 659:d6a69271cb9a v7.0194

updated for version 7.0194
author vimboss
date Wed, 08 Feb 2006 09:20:24 +0000
parents bc95c6c4bac1
children 9090f866cd57
comparison
equal deleted inserted replaced
658:903088c7a7c6 659:d6a69271cb9a
1 " Vim completion script 1 " Vim completion script
2 " Language: Java Script 2 " Language: Java Script
3 " Maintainer: Mikolaj Machowski ( mikmach AT wp DOT pl ) 3 " Maintainer: Mikolaj Machowski ( mikmach AT wp DOT pl )
4 " Last Change: 2006 Jan 30 4 " Last Change: 2006 Feb 6
5 5
6 function! javascriptcomplete#CompleteJS(findstart, base) 6 function! javascriptcomplete#CompleteJS(findstart, base)
7 if a:findstart 7 if a:findstart
8 " locate the start of the word 8 " locate the start of the word
9 let line = getline('.') 9 let line = getline('.')
10 let start = col('.') - 1 10 let start = col('.') - 1
11 let curline = line('.') 11 let curline = line('.')
12 let compl_begin = col('.') - 2 12 let compl_begin = col('.') - 2
13 " Bit risky but JS is rather limited language and local chars shouldn't 13 " Bit risky but JS is rather limited language and local chars shouldn't
14 " fint way into names 14 " fint way into names
15 while start >= 0 && line[start - 1] =~ '\w' 15 while start >= 0 && line[start - 1] =~ '\w'
16 let start -= 1 16 let start -= 1
17 endwhile 17 endwhile
18 let b:compl_context = getline('.')[0:compl_begin] 18 let b:compl_context = getline('.')[0:compl_begin]
19 return start 19 return start
20 else 20 else
21 " Initialize base return lists 21 " Initialize base return lists
22 let res = [] 22 let res = []
23 let res2 = [] 23 let res2 = []
24 " a:base is very short - we need context 24 " a:base is very short - we need context
25 " Shortcontext is context without a:base, useful for checking if we are
26 " looking for objects and for what objects we are looking for
25 let context = b:compl_context 27 let context = b:compl_context
26 " Shortcontext is context without a:base, useful for checking if we are
27 " looking for objects
28 let shortcontext = substitute(context, a:base.'$', '', '') 28 let shortcontext = substitute(context, a:base.'$', '', '')
29 unlet! b:compl_context 29 unlet! b:compl_context
30 30
31 if exists("b:jsrange")
32 let file = getline(b:jsrange[0],b:jsrange[1])
33 unlet! b:jsrange
34
35 if len(b:js_extfiles) > 0
36 let file = b:js_extfiles + file
37 endif
38
39 else
40 let file = getline(1, '$')
41 endif
42
43
44 " Completion of properties, methods, etc. {{{
31 if shortcontext =~ '\.$' 45 if shortcontext =~ '\.$'
32 " Complete methods and properties for objects 46 " Complete methods and properties for objects
33 " DOM separate 47 " DOM separate
34 let doms = ['style.'] 48 let doms = ['style.']
35 " Arrays 49 " Arrays
89 call map(objemeth, 'v:val."("') 103 call map(objemeth, 'v:val."("')
90 let objes = objeprop + objemeth 104 let objes = objeprop + objemeth
91 105
92 " RegExp 106 " RegExp
93 let regeprop = ['constructor', 'global', 'ignoreCase', 'lastIndex', 'multiline', 'source', 'prototype'] 107 let regeprop = ['constructor', 'global', 'ignoreCase', 'lastIndex', 'multiline', 'source', 'prototype']
94 let regemeth = ['exec', 'toSource', 'toString', 'test', 'watch', 'unwatch'] 108 let regemeth = ['exec', 'test', 'toSource', 'toString', 'watch', 'unwatch']
95 call map(regemeth, 'v:val."("') 109 call map(regemeth, 'v:val."("')
96 let reges = regeprop + regemeth 110 let reges = regeprop + regemeth
97 111
98 " String 112 " String
99 let striprop = ['constructor', 'length', 'prototype'] 113 let striprop = ['constructor', 'length', 'prototype']
104 \ 'toSource', 'toString', 'toUpperCase', 'watch', 'unwatch'] 118 \ 'toSource', 'toString', 'toUpperCase', 'watch', 'unwatch']
105 call map(strimeth, 'v:val."("') 119 call map(strimeth, 'v:val."("')
106 let stris = striprop + strimeth 120 let stris = striprop + strimeth
107 121
108 " User created properties 122 " User created properties
109 if exists("b:jsrange")
110 let file = getline(b:jsrange[0],b:jsrange[1])
111 unlet! b:jsrange
112 else
113 let file = getline(1, '$')
114 endif
115 let user_props1 = filter(copy(file), 'v:val =~ "this\\.\\w"') 123 let user_props1 = filter(copy(file), 'v:val =~ "this\\.\\w"')
116 let juser_props1 = join(user_props1, ' ') 124 let juser_props1 = join(user_props1, ' ')
117 let user_props1 = split(juser_props1, '\zethis\.') 125 let user_props1 = split(juser_props1, '\zethis\.')
118 unlet! juser_props1 126 unlet! juser_props1
119 call map(user_props1, 'matchstr(v:val, "this\\.\\zs\\w\\+\\ze")') 127 call map(user_props1, 'matchstr(v:val, "this\\.\\zs\\w\\+\\ze")')
128
120 let user_props2 = filter(copy(file), 'v:val =~ "\\.prototype\\.\\w"') 129 let user_props2 = filter(copy(file), 'v:val =~ "\\.prototype\\.\\w"')
121 call map(user_props2, 'matchstr(v:val, "\\.prototype\\.\\zs\\w\\+\\ze")') 130 let juser_props2 = join(user_props2, ' ')
131 let user_props2 = split(juser_props2, '\zeprototype\.')
132 unlet! juser_props2
133 call map(user_props2, 'matchstr(v:val, "prototype\\.\\zs\\w\\+\\ze")')
122 let user_props = user_props1 + user_props2 134 let user_props = user_props1 + user_props2
123 135
124 " HTML DOM properties 136 " HTML DOM properties
125 " Anchors - anchor. 137 " Anchors - anchor.
126 let anchprop = ['accessKey', 'charset', 'coords', 'href', 'hreflang', 'id', 'innerHTML', 138 let anchprop = ['accessKey', 'charset', 'coords', 'href', 'hreflang', 'id', 'innerHTML',
147 let documeth = ['close', 'createAttribute', 'createElement', 'createTextNode', 'focus', 'getElementById', 159 let documeth = ['close', 'createAttribute', 'createElement', 'createTextNode', 'focus', 'getElementById',
148 \ 'getElementsByName', 'getElementsByTagName', 'open', 'write', 'writeln', 160 \ 'getElementsByName', 'getElementsByTagName', 'open', 'write', 'writeln',
149 \ 'onClick', 'onDblClick', 'onFocus', 'onKeyDown', 'onKeyPress', 'onKeyUp', 161 \ 'onClick', 'onDblClick', 'onFocus', 'onKeyDown', 'onKeyPress', 'onKeyUp',
150 \ 'onMouseDown', 'onMouseMove', 'onMouseOut', 'onMouseOver', 'onMouseUp', 'onResize'] 162 \ 'onMouseDown', 'onMouseMove', 'onMouseOut', 'onMouseOver', 'onMouseUp', 'onResize']
151 call map(documeth, 'v:val."("') 163 call map(documeth, 'v:val."("')
152 let docus = docuprop + documeth 164 let docuxprop = ['attributes', 'childNodes', 'doctype', 'documentElement', 'firstChild',
165 \ 'implementation', 'namespaceURI', 'nextSibling', 'nodeName', 'nodeType',
166 \ 'nodeValue', 'ownerDocument', 'parentNode', 'previousSibling']
167 let docuxmeth = ['createAttribute', 'createCDATASection',
168 \ 'createComment', 'createDocument', 'createDocumentFragment',
169 \ 'createElement', 'createEntityReference', 'createProcessingInstruction',
170 \ 'createTextNode']
171 call map(docuxmeth, 'v:val."("')
172 let docus = docuprop + docuxprop + documeth + docuxmeth
153 " Form - form. 173 " Form - form.
154 let formprop = ['elements', 'acceptCharset', 'action', 'encoding', 'enctype', 'id', 'length', 174 let formprop = ['elements', 'acceptCharset', 'action', 'encoding', 'enctype', 'id', 'length',
155 \ 'method', 'name', 'tabIndex', 'target'] 175 \ 'method', 'name', 'tabIndex', 'target']
156 let formmeth = ['reset', 'submit', 'onReset', 'onSubmit'] 176 let formmeth = ['reset', 'submit', 'onReset', 'onSubmit']
157 call map(formmeth, 'v:val."("') 177 call map(formmeth, 'v:val."("')
176 let ifraprop = ['align', 'frameBorder', 'height', 'id', 'longDesc', 'marginHeight', 'marginWidth', 196 let ifraprop = ['align', 'frameBorder', 'height', 'id', 'longDesc', 'marginHeight', 'marginWidth',
177 \ 'name', 'scrolling', 'src', 'width'] 197 \ 'name', 'scrolling', 'src', 'width']
178 let ifras = ifraprop 198 let ifras = ifraprop
179 " Image - image. 199 " Image - image.
180 let imagprop = ['align', 'alt', 'border', 'complete', 'height', 'hspace', 'id', 'isMap', 'longDesc', 200 let imagprop = ['align', 'alt', 'border', 'complete', 'height', 'hspace', 'id', 'isMap', 'longDesc',
181 \ 'lowsrc', 'name', 'src', 'useMap', 'vspace', 'width'] 201 \ 'lowSrc', 'name', 'src', 'useMap', 'vspace', 'width']
182 let imagmeth = ['onAbort', 'onError', 'onLoad'] 202 let imagmeth = ['onAbort', 'onError', 'onLoad']
183 call map(imagmeth, 'v:val."("') 203 call map(imagmeth, 'v:val."("')
184 let imags = histprop + imagmeth 204 let imags = histprop + imagmeth
185 " Button - accessible only by other properties 205 " Button - accessible only by other properties
186 let buttprop = ['accessKey', 'disabled', 'form', 'id', 'name', 'tabIndex', 'type', 'value'] 206 let buttprop = ['accessKey', 'disabled', 'form', 'id', 'name', 'tabIndex', 'type', 'value']
280 \ 'backgroundPosition', 'backgroundRepeat', 300 \ 'backgroundPosition', 'backgroundRepeat',
281 \ 'border', 'borderBottom', 'borderLeft', 'borderRight', 'borderTop', 301 \ 'border', 'borderBottom', 'borderLeft', 'borderRight', 'borderTop',
282 \ 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 302 \ 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor',
283 \ 'borderBottomStyle', 'borderLeftStyle', 'borderRightStyle', 'borderTopStyle', 303 \ 'borderBottomStyle', 'borderLeftStyle', 'borderRightStyle', 'borderTopStyle',
284 \ 'borderBottomWidth', 'borderLeftWidth', 'borderRightWidth', 'borderTopWidth', 304 \ 'borderBottomWidth', 'borderLeftWidth', 'borderRightWidth', 'borderTopWidth',
285 \ 'borderColor', 'borderStyle', 'borderWidth', 'margin', 'marginBottom', 305 \ 'borderColor', 'borderStyle', 'borderWidth', 'margin', 'marginBottom',
286 \ 'marginLeft', 'marginRight', 'marginTop', 'outline', 'outlineStyle', 'outlineWidth', 306 \ 'marginLeft', 'marginRight', 'marginTop', 'outline', 'outlineStyle', 'outlineWidth',
287 \ 'outlineColor', 'outlineStyle', 'outlineWidth', 'padding', 'paddingBottom', 307 \ 'outlineColor', 'outlineStyle', 'outlineWidth', 'padding', 'paddingBottom',
288 \ 'paddingLeft', 'paddingRight', 'paddingTop', 308 \ 'paddingLeft', 'paddingRight', 'paddingTop',
289 \ 'clear', 'clip', 'clipBottom', 'clipLeft', 'clipRight', 'clipTop', 'content', 309 \ 'clear', 'clip', 'clipBottom', 'clipLeft', 'clipRight', 'clipTop', 'content',
290 \ 'counterIncrement', 'counterReset', 'cssFloat', 'cursor', 'direction', 310 \ 'counterIncrement', 'counterReset', 'cssFloat', 'cursor', 'direction',
291 \ 'display', 'markerOffset', 'marks', 'maxHeight', 'maxWidth', 'minHeight', 311 \ 'display', 'markerOffset', 'marks', 'maxHeight', 'maxWidth', 'minHeight',
292 \ 'minWidth', 'overflow', 'overflowX', 'overflowY', 'verticalAlign', 'visibility', 312 \ 'minWidth', 'overflow', 'overflowX', 'overflowY', 'verticalAlign', 'visibility',
293 \ 'width', 313 \ 'width',
294 \ 'listStyle', 'listStyleImage', 'listStylePosition', 'listStyleType', 314 \ 'listStyle', 'listStyleImage', 'listStylePosition', 'listStyleType',
295 \ 'cssText', 'bottom', 'height', 'left', 'position', 'right', 'top', 'width', 'zindex', 315 \ 'cssText', 'bottom', 'height', 'left', 'position', 'right', 'top', 'width', 'zindex',
296 \ 'orphans', 'widows', 'page', 'pageBreakAfter', 'pageBreakBefore', 'pageBreakInside', 316 \ 'orphans', 'widows', 'page', 'pageBreakAfter', 'pageBreakBefore', 'pageBreakInside',
318 call map(trowmeth, 'v:val."("') 338 call map(trowmeth, 'v:val."("')
319 let trows = trowprop + trowmeth 339 let trows = trowprop + trowmeth
320 " Textarea - accessible only by other properties 340 " Textarea - accessible only by other properties
321 let tareprop = ['accessKey', 'cols', 'defaultValue', 341 let tareprop = ['accessKey', 'cols', 'defaultValue',
322 \ 'disabled', 'form', 'id', 'name', 'readOnly', 'rows', 342 \ 'disabled', 'form', 'id', 'name', 'readOnly', 'rows',
323 \ 'tabIndex', 'type', 'value'] 343 \ 'tabIndex', 'type', 'value', 'selectionStart', 'selectionEnd']
324 let taremeth = ['blur', 'focus', 'select', 'onBlur', 'onChange', 'onFocus'] 344 let taremeth = ['blur', 'focus', 'select', 'onBlur', 'onChange', 'onFocus']
325 call map(taremeth, 'v:val."("') 345 call map(taremeth, 'v:val."("')
326 let tares = tareprop + taremeth 346 let tares = tareprop + taremeth
327 " Window - window. 347 " Window - window.
328 let windprop = ['frames', 'closed', 'defaultStatus', 'length', 'name', 'opener', 'parent', 348 let windprop = ['frames', 'closed', 'defaultStatus', 'encodeURI', 'event', 'history',
329 \ 'self', 'status', 'top'] 349 \ 'length', 'location', 'name', 'onload', 'opener', 'parent', 'screen', 'self',
350 \ 'status', 'top', 'XMLHttpRequest', 'ActiveXObject']
330 let windmeth = ['alert', 'blur', 'clearInterval', 'clearTimeout', 'close', 'confirm', 'focus', 351 let windmeth = ['alert', 'blur', 'clearInterval', 'clearTimeout', 'close', 'confirm', 'focus',
331 \ 'moveBy', 'moveTo', 'open', 'print', 'prompt', 'scrollBy', 'scrollTo', 'setInterval', 352 \ 'moveBy', 'moveTo', 'open', 'print', 'prompt', 'scrollBy', 'scrollTo', 'setInterval',
332 \ 'setTimeout'] 353 \ 'setTimeout']
333 call map(windmeth, 'v:val."("') 354 call map(windmeth, 'v:val."("')
334 let winds = windprop + windmeth 355 let winds = windprop + windmeth
335 " XMLHttpRequest - access by new xxx() 356 " XMLHttpRequest - access by new xxx()
336 let xmlhprop = ['onreadystatechange', 'readyState', 'responseText', 'responseXML', 357 let xmlhprop = ['onreadystatechange', 'readyState', 'responseText', 'responseXML',
337 \ 'status', 'statusText'] 358 \ 'status', 'statusText', 'parseError']
338 let xmlhmeth = ['abort', 'getAllResponseHeaders', 'getResponseHeaders', 'open', 359 let xmlhmeth = ['abort', 'getAllResponseHeaders', 'getResponseHeaders', 'open',
339 \ 'send', 'setRequestHeader'] 360 \ 'send', 'setRequestHeader']
340 call map(xmlhmeth, 'v:val."("') 361 call map(xmlhmeth, 'v:val."("')
341 let xmlhs = xmlhprop + xmlhmeth 362 let xmlhs = xmlhprop + xmlhmeth
342 363
364 " XML DOM
365 " Attributes - element.attributes[x].
366 let xdomattrprop = ['name', 'specified', 'value']
367 " Element - anyelement.
368 let xdomelemprop = ['attributes', 'childNodes', 'firstChild', 'lastChild',
369 \ 'namespaceURI', 'nextSibling', 'nodeName', 'nodeType', 'nodeValue',
370 \ 'ownerDocument', 'parentNode', 'prefix', 'previousSibling', 'tagName']
371 let xdomelemmeth = ['appendChild', 'cloneNode', 'getAttribute', 'getAttributeNode',
372 \ 'getElementsByTagName', 'hasChildNodes', 'insertBefore', 'normalize',
373 \ 'removeAttribute', 'removeAttributeNode', 'removeChild', 'replaceChild',
374 \ 'setAttribute', 'setAttributeNode']
375 call map(xdomelemmeth, 'v:val."("')
376 let xdomelems = xdomelemprop + xdomelemmeth
377 " Node - anynode.
378 let xdomnodeprop = ['attributes', 'childNodes', 'firstChild', 'lastChild',
379 \ 'namespaceURI', 'nextSibling', 'nodeName', 'nodeType', 'nodeValue',
380 \ 'ownerDocument', 'parentNode', 'prefix', 'previousSibling']
381 let xdomnodemeth = ['appendChild', 'cloneNode',
382 \ 'hasChildNodes', 'insertBefore', 'removeChild', 'replaceChild']
383 call map(xdomnodemeth, 'v:val."("')
384 let xdomnodes = xdomnodeprop + xdomnodemeth
385 " NodeList
386 let xdomnliss = ['length', 'item(']
387 " Error - parseError.
388 let xdomerror = ['errorCode', 'reason', 'line', 'linepos', 'srcText', 'url', 'filepos']
389
390 " Find object type declaration to reduce number of suggestions. {{{
391 " 1. Get object name
392 " 2. Find object declaration line
393 " 3. General declaration follows "= new Type" syntax, additional else
394 " for regexp "= /re/"
395 " 4. Make correction for Microsoft.XMLHTTP ActiveXObject
396 " 5. Repeat for external files
343 let object = matchstr(shortcontext, '\zs\w\+\ze\(\[.\{-}\]\)\?\.$') 397 let object = matchstr(shortcontext, '\zs\w\+\ze\(\[.\{-}\]\)\?\.$')
344 let decl_line = search(object.'.\{-}=\s*new\s*', 'bn') 398 if len(object) > 0
345 let object_type = matchstr(getline(decl_line), object.'.\{-}=\s*new\s*\zs\w\+\ze') 399 let decl_line = search(object.'.\{-}=\s*new\s*', 'bn')
400 if decl_line > 0
401 let object_type = matchstr(getline(decl_line), object.'.\{-}=\s*new\s*\zs\w\+\ze')
402 if object_type == 'ActiveXObject' && matchstr(getline(decl_line), object.'.\{-}=\s*new\s*ActiveXObject\s*(.Microsoft\.XMLHTTP.)') != ''
403 let object_type = 'XMLHttpRequest'
404 endif
405 else
406 let decl_line = search('var\s*'.object.'\s*=\s*\/', 'bn')
407 if decl_line > 0
408 let object_type = 'RegExp'
409 endif
410 endif
411 " We didn't find var declaration in current file but we may have
412 " something in external files.
413 if decl_line == 0 && exists("b:js_extfiles")
414 let dext_line = filter(copy(b:js_extfiles), 'v:val =~ "'.object.'.\\{-}=\\s*new\\s*"')
415 if len(dext_line) > 0
416 let object_type = matchstr(dext_line[-1], object.'.\{-}=\s*new\s*\zs\w\+\ze')
417 if object_type == 'ActiveXObject' && matchstr(dext_line[-1], object.'.\{-}=\s*new\s*ActiveXObject\s*(.Microsoft\.XMLHTTP.)') != ''
418 let object_type = 'XMLHttpRequest'
419 endif
420 else
421 let dext_line = filter(copy(b:js_extfiles), 'v:val =~ "var\s*'.object.'\\s*=\\s*\\/"')
422 if len(dext_line) > 0
423 let object_type = 'RegExp'
424 endif
425 endif
426 endif
427 endif
428 " }}}
429
430 if !exists('object_type')
431 let object_type = ''
432 endif
346 433
347 if object_type == 'Date' 434 if object_type == 'Date'
348 let values = dates 435 let values = dates
349 elseif object_type == 'Image' 436 elseif object_type == 'Image'
350 let values = imags 437 let values = imags
355 let values = arrays 442 let values = arrays
356 elseif object_type == 'XMLHttpRequest' 443 elseif object_type == 'XMLHttpRequest'
357 let values = xmlhs 444 let values = xmlhs
358 elseif object_type == 'String' 445 elseif object_type == 'String'
359 let values = stris 446 let values = stris
447 elseif object_type == 'RegExp'
448 let values = reges
449 elseif object_type == 'Math'
450 let values = maths
360 endif 451 endif
361 452
362 if !exists('values') 453 if !exists('values')
363 " List of properties 454 " List of properties
364 if shortcontext =~ 'Math\.$' 455 if shortcontext =~ 'Math\.$'
365 let values = maths 456 let values = maths
366 elseif shortcontext =~ 'anchor\.$' 457 elseif shortcontext =~ 'anchors\(\[.\{-}\]\)\?\.$'
367 let values = anths 458 let values = anths
368 elseif shortcontext =~ 'area\.$' 459 elseif shortcontext =~ 'area\.$'
369 let values = areas 460 let values = areas
370 elseif shortcontext =~ 'base\.$' 461 elseif shortcontext =~ 'base\.$'
371 let values = bases 462 let values = bases
372 elseif shortcontext =~ 'body\.$' 463 elseif shortcontext =~ 'body\.$'
373 let values = bodys 464 let values = bodys
374 elseif shortcontext =~ 'document\.$' 465 elseif shortcontext =~ 'document\.$'
375 let values = docus 466 let values = docus
376 elseif shortcontext =~ 'form\.$' 467 elseif shortcontext =~ 'forms\(\[.\{-}\]\)\?\.$'
377 let values = forms 468 let values = forms
378 elseif shortcontext =~ 'frameset\.$' 469 elseif shortcontext =~ 'frameset\.$'
379 let values = fsets 470 let values = fsets
380 elseif shortcontext =~ 'history\.$' 471 elseif shortcontext =~ 'history\.$'
381 let values = hists 472 let values = hists
382 elseif shortcontext =~ 'iframe\.$' 473 elseif shortcontext =~ 'iframe\.$'
383 let values = ifras 474 let values = ifras
384 elseif shortcontext =~ 'image\.$' 475 elseif shortcontext =~ 'images\(\[.\{-}\]\)\?\.$'
385 let values = imags 476 let values = imags
386 elseif shortcontext =~ 'link\.$' 477 elseif shortcontext =~ 'links\(\[.\{-}\]\)\?\.$'
387 let values = links 478 let values = links
388 elseif shortcontext =~ 'location\.$' 479 elseif shortcontext =~ 'location\.$'
389 let values = locas 480 let values = locas
390 elseif shortcontext =~ 'meta\.$' 481 elseif shortcontext =~ 'meta\.$'
391 let values = metas 482 let values = metas
403 let values = tdats 494 let values = tdats
404 elseif shortcontext =~ 'TableRow\.$' 495 elseif shortcontext =~ 'TableRow\.$'
405 let values = trows 496 let values = trows
406 elseif shortcontext =~ 'window\.$' 497 elseif shortcontext =~ 'window\.$'
407 let values = winds 498 let values = winds
499 elseif shortcontext =~ 'parseError\.$'
500 let values = xdomerror
501 elseif shortcontext =~ 'attributes\[\d\+\]\.$'
502 let values = xdomattrprop
408 else 503 else
409 let values = user_props + arrays + dates + funcs + maths + numbs + objes + reges + stris 504 let values = user_props + arrays + dates + funcs + maths + numbs + objes + reges + stris
410 let values += doms + anths + areas + bases + bodys + docus + forms + frams + fsets + hists 505 let values += doms + anths + areas + bases + bodys + docus + forms + frams + fsets + hists
411 let values += ifras + imags + links + locas + metas + navis + objes + scres + styls 506 let values += ifras + imags + links + locas + metas + navis + objes + scres
412 let values += tabls + trows + winds 507 let values += tabls + trows + tares + winds
508 let values += xdomnodes + xdomnliss + xdomelems
413 endif 509 endif
414 endif 510 endif
415 511
416 for m in values 512 for m in values
417 if m =~? '^'.a:base 513 if m =~? '^'.a:base
423 519
424 unlet! values 520 unlet! values
425 return res + res2 521 return res + res2
426 522
427 endif 523 endif
428 524 " }}}
429 if exists("b:jsrange")
430 let file = getline(b:jsrange[0],b:jsrange[1])
431 unlet! b:jsrange
432 else
433 let file = getline(1, '$')
434 endif
435 525
436 " Get variables data. 526 " Get variables data.
437 let variables = filter(copy(file), 'v:val =~ "var\\s"') 527 let variables = filter(copy(file), 'v:val =~ "var\\s"')
438 call map(variables, 'matchstr(v:val, ".\\{-}var\\s\\+\\zs.*\\ze")') 528 call map(variables, 'matchstr(v:val, ".\\{-}var\\s\\+\\zs.*\\ze")')
439 call map(variables, 'substitute(v:val, ";\\|$", ",", "g")') 529 call map(variables, 'substitute(v:val, ";\\|$", ",", "g")')
440 let vars = [] 530 let vars = []
441 " This loop is necessary to get variable names from constructs like: 531 " This loop (and next one) is necessary to get variable names from
442 " var var1, var2, var3 = "something"; 532 " constructs like: var var1, var2, var3 = "something";
443 for i in range(len(variables)) 533 for i in range(len(variables))
444 let comma_separated = split(variables[i], ',\s*') 534 let comma_separated = split(variables[i], ',\s*')
445 call map(comma_separated, 'matchstr(v:val, "\\w\\+")') 535 call map(comma_separated, 'matchstr(v:val, "\\w\\+")')
446 let vars += comma_separated 536 let vars += comma_separated
447 endfor 537 endfor
448 538
449 let variables = sort(vars) 539 let variables = sort(vars)
450 540 unlet! vars
451 " Add undeclared variables. 541
542 " Add "no var" variables.
452 let undeclared_variables = filter(copy(file), 'v:val =~ "^\\s*\\w\\+\\s*="') 543 let undeclared_variables = filter(copy(file), 'v:val =~ "^\\s*\\w\\+\\s*="')
453 call map(undeclared_variables, 'matchstr(v:val, "^\\s*\\zs\\w\\+\\ze")') 544 let u_vars = []
454 545 for i in range(len(undeclared_variables))
455 let variables += sort(undeclared_variables) 546 let split_equal = split(undeclared_variables[i], '\s*=')
547 call map(split_equal, 'matchstr(v:val, "\\w\\+$")')
548 let u_vars += split_equal
549 endfor
550
551 let variables += sort(u_vars)
552 unlet! u_vars
456 553
457 " Get functions 554 " Get functions
458 let functions = filter(copy(file), 'v:val =~ "^\\s*function\\s"') 555 let functions = filter(copy(file), 'v:val =~ "^\\s*function\\s"')
459 let arguments = copy(functions) 556 let arguments = copy(functions)
460 call map(functions, 'matchstr(v:val, "^\\s*function\\s\\+\\zs\\w\\+")') 557 call map(functions, 'matchstr(v:val, "^\\s*function\\s\\+\\zs\\w\\+")')
461 call map(functions, 'v:val."("') 558 call map(functions, 'v:val."("')
559 let functions = sort(functions)
462 560
463 " Get functions arguments 561 " Get functions arguments
464 call map(arguments, 'matchstr(v:val, "function.\\{-}(\\zs.\\{-}\\ze)")') 562 call map(arguments, 'matchstr(v:val, "function.\\{-}(\\zs.\\{-}\\ze)")')
465 let jargs = join(arguments, ',') 563 let jargs = join(arguments, ',')
466 let jargs = substitute(jargs, '\s', '', 'g') 564 let jargs = substitute(jargs, '\s', '', 'g')
467 let arguments = split(jargs, ',') 565 let arguments = split(jargs, ',')
566 let arguments = sort(arguments)
468 567
469 " Built-in functions 568 " Built-in functions
470 let builtin = [] 569 let builtin = ['alert(', 'confirm(']
471 570
472 " Top-level HTML DOM objects 571 " Top-level HTML DOM objects
473 let htmldom = ['document', 'anchor', 'area', 'base', 'body', 'document', 'event', 'form', 'frame', 'frameset', 'history', 'iframe', 'image', 'input', 'link', 'location', 'meta', 'navigator', 'object', 'option', 'screen', 'select', 'table', 'tableData', 'tableHeader', 'tableRow', 'textarea', 'window'] 572 let htmldom = ['document', 'anchor', 'area', 'base', 'body', 'document', 'event', 'form', 'frame', 'frameset', 'history', 'iframe', 'image', 'input', 'link', 'location', 'meta', 'navigator', 'object', 'option', 'screen', 'select', 'table', 'tableData', 'tableHeader', 'tableRow', 'textarea', 'window']
474 call map(htmldom, 'v:val."."') 573 call map(htmldom, 'v:val."."')
475 574
491 endif 590 endif
492 endfor 591 endfor
493 592
494 return res + res2 593 return res + res2
495 endfunction 594 endfunction
595
596 " vim:set foldmethod=marker: