updated for version 7.0194

This commit is contained in:
Bram Moolenaar
2006-02-08 09:20:24 +00:00
parent 9f2c6e1deb
commit 8b6144bdfe
31 changed files with 822 additions and 346 deletions

View File

@ -1,7 +1,7 @@
" Vim completion script
" Language: C
" Maintainer: Bram Moolenaar <Bram@vim.org>
" Last Change: 2006 Feb 03
" Last Change: 2006 Feb 06
" This function is used for the 'omnifunc' option.
@ -213,22 +213,29 @@ endfunction
" If it is a variable we may add "." or "->". Don't do it for other types,
" such as a typedef, by not including the info that s:GetAddition() uses.
function! s:Tag2item(val)
let x = substitute(a:val['cmd'], '^/^', '', '')
let x = substitute(x, '$/$', '', '')
let x = substitute(x, a:val['name'], '@@', '')
if has_key(a:val, "kind")
if a:val["kind"] == 'v'
return {'match': a:val['name'], 'tagline': "\t" . a:val['cmd'], 'dict': a:val}
return {'match': a:val['name'], 'tagline': "\t" . a:val['cmd'], 'dict': a:val, 'extra': x}
endif
if a:val["kind"] == 'f'
return {'match': a:val['name'] . '(', 'tagline': ""}
return {'match': a:val['name'] . '(', 'tagline': "", 'extra': x}
endif
endif
return {'match': a:val['name'], 'tagline': ''}
return {'match': a:val['name'], 'tagline': '', 'extra': x}
endfunction
" Turn a match item "val" into an item for completion.
" "val['match']" is the matching item.
" "val['tagline']" is the tagline in which the last part was found.
function! s:Tagline2item(val, brackets)
return a:val['match'] . a:brackets . s:GetAddition(a:val['tagline'], a:val['match'], [a:val], a:brackets == '')
let word = a:val['match'] . a:brackets . s:GetAddition(a:val['tagline'], a:val['match'], [a:val], a:brackets == '')
if has_key(a:val, 'extra')
return {'word': word, 'menu': a:val['extra']}
endif
return {'word': word, 'menu': substitute(a:val['tagline'], word, '@@', '')}
endfunction

View File

@ -1,7 +1,7 @@
" Vim completion script
" Language: XHTML 1.0 Strict
" Maintainer: Mikolaj Machowski ( mikmach AT wp DOT pl )
" Last Change: 2006 Jan 30
" Last Change: 2006 Feb 6
function! htmlcomplete#CompleteTags(findstart, base)
if a:findstart
@ -13,11 +13,14 @@ function! htmlcomplete#CompleteTags(findstart, base)
while start >= 0 && line[start - 1] =~ '\(\k\|[:.-]\)'
let start -= 1
endwhile
" Handling of entities {{{
if start >= 0 && line[start - 1] =~ '&'
let b:entitiescompl = 1
let b:compl_context = ''
return start
endif
" }}}
" Handling of <style> tag {{{
let stylestart = searchpair('<style\>', '', '<\/style\>', "bnW")
let styleend = searchpair('<style\>', '', '<\/style\>', "nW")
if stylestart != 0 && styleend != 0
@ -29,6 +32,8 @@ function! htmlcomplete#CompleteTags(findstart, base)
endwhile
endif
endif
" }}}
" Handling of <script> tag {{{
let scriptstart = searchpair('<script\>', '', '<\/script\>', "bnW")
let scriptend = searchpair('<script\>', '', '<\/script\>', "nW")
if scriptstart != 0 && scriptend != 0
@ -36,16 +41,44 @@ function! htmlcomplete#CompleteTags(findstart, base)
let start = col('.') - 1
let b:jscompl = 1
let b:jsrange = [scriptstart, scriptend]
while start >= 0 && line[start - 1] =~ '\(\k\|-\)'
while start >= 0 && line[start - 1] =~ '\w'
let start -= 1
endwhile
" We are inside of <script> tag. But we should also get contents
" of all linked external files and (secondary, less probably) other <script> tags
" This logic could possible be done in separate function - may be
" reused in events scripting (also with option could be reused for
" CSS
let b:js_extfiles = []
let l = line('.')
let c = col('.')
call cursor(1,1)
while search('<\@<=script\>', 'W') && line('.') <= l
if synIDattr(synID(line('.'),col('.')-1,0),"name") !~? 'comment'
let sname = matchstr(getline('.'), '<script[^>]*src\s*=\s*\([''"]\)\zs.\{-}\ze\1')
if filereadable(sname)
let b:js_extfiles += readfile(sname)
endif
endif
endwhile
call cursor(1,1)
let js_scripttags = []
while search('<script\>', 'W') && line('.') < l
if matchstr(getline('.'), '<script[^>]*src') == ''
let js_scripttag = getline(line('.'), search('</script>', 'W'))
let js_scripttags += js_scripttag
endif
endwhile
let b:js_extfiles += js_scripttags
call cursor(l,c)
unlet! l c
endif
endif
" }}}
if !exists("b:csscompl") && !exists("b:jscompl")
let b:compl_context = getline('.')[0:(compl_begin)]
if b:compl_context !~ '<[^>]*$'
" Look like we may have broken tag. Check previous lines. Up to
" 10?
" Look like we may have broken tag. Check previous lines.
let i = 1
while 1
let context_line = getline(curline-i)
@ -65,6 +98,14 @@ function! htmlcomplete#CompleteTags(findstart, base)
unlet! i
endif
let b:compl_context = matchstr(b:compl_context, '.*\zs<.*')
" Return proper start for on-events. Without that beginning of
" completion will be badly reported
if b:compl_context =~? 'on[a-z]*\s*=\s*\(''[^'']*\|"[^"]*\)$'
let start = col('.') - 1
while start >= 0 && line[start - 1] =~ '\w'
let start -= 1
endwhile
endif
else
let b:compl_context = getline('.')[0:compl_begin]
endif
@ -76,14 +117,15 @@ function! htmlcomplete#CompleteTags(findstart, base)
" a:base is very short - we need context
let context = b:compl_context
" Check if we should do CSS completion inside of <style> tag
" or JS completion inside of <script> tag
if exists("b:csscompl")
unlet! b:csscompl
let context = b:compl_context
unlet! b:compl_context
return csscomplete#CompleteCSS(0, context)
elseif exists("b:jscompl")
unlet! b:jscompl
let context = b:compl_context
return javascriptcomplete#CompleteJS(0, context)
return javascriptcomplete#CompleteJS(0, a:base)
else
if len(b:compl_context) == 0 && !exists("b:entitiescompl")
return []
@ -91,7 +133,7 @@ function! htmlcomplete#CompleteTags(findstart, base)
let context = matchstr(b:compl_context, '.\zs.*')
endif
unlet! b:compl_context
" Make entities completion
" Entities completion {{{
if exists("b:entitiescompl")
unlet! b:entitiescompl
@ -122,6 +164,7 @@ function! htmlcomplete#CompleteTags(findstart, base)
endif
" }}}
if context =~ '>'
" Generally if context contains > it means we are outside of tag and
" should abandon action - with one exception: <style> span { bo
@ -142,13 +185,11 @@ function! htmlcomplete#CompleteTags(findstart, base)
\ "onmouseover", "onmouseout", "onkeypress", "onkeydown", "onkeyup"]
let focus = ["accesskey", "tabindex", "onfocus", "onblur"]
let coregroup = coreattrs + i18n + events
" find tags matching with "context"
" If context contains > it means we are already outside of tag and we
" should abandon action
" If context contains white space it is attribute.
" It could be also value of attribute...
" We have to get first word to offer
" proper completions
" It can be also value of attribute.
" We have to get first word to offer proper completions
if context == ''
let tag = ''
else
@ -160,11 +201,12 @@ function! htmlcomplete#CompleteTags(findstart, base)
" 1. Events attributes
if context =~ '\s'
" Sort out style, class, and on* cases
if context =~ "\\(on[a-z]*\\|id\\|style\\|class\\)\\s*=\\s*[\"']"
if context =~ "\\(id\\|class\\)\\s*=\\s*[\"'][a-zA-Z0-9_ -]*$"
if context =~ "class\\s*=\\s*[\"'][a-zA-Z0-9_ -]*$"
if context =~? "\\(on[a-z]*\\|id\\|style\\|class\\)\\s*=\\s*[\"']"
" Id, class completion {{{
if context =~? "\\(id\\|class\\)\\s*=\\s*[\"'][a-zA-Z0-9_ -]*$"
if context =~? "class\\s*=\\s*[\"'][a-zA-Z0-9_ -]*$"
let search_for = "class"
elseif context =~ "id\\s*=\\s*[\"'][a-zA-Z0-9_ -]*$"
elseif context =~? "id\\s*=\\s*[\"'][a-zA-Z0-9_ -]*$"
let search_for = "id"
endif
" Handle class name completion
@ -327,17 +369,59 @@ function! htmlcomplete#CompleteTags(findstart, base)
return res + res2
elseif context =~ "style\\s*=\\s*[\"'][^\"']*$"
elseif context =~? "style\\s*=\\s*[\"'][^\"']*$"
return csscomplete#CompleteCSS(0, context)
endif
let stripbase = matchstr(context, ".*\\(on[a-z]*\\|style\\|class\\)\\s*=\\s*[\"']\\zs.*")
" }}}
" Complete on-events {{{
if context =~? 'on[a-z]*\s*=\s*\(''[^'']*\|"[^"]*\)$'
" We have to:
" 1. Find external files
let b:js_extfiles = []
let l = line('.')
let c = col('.')
call cursor(1,1)
while search('<\@<=script\>', 'W') && line('.') <= l
if synIDattr(synID(line('.'),col('.')-1,0),"name") !~? 'comment'
let sname = matchstr(getline('.'), '<script[^>]*src\s*=\s*\([''"]\)\zs.\{-}\ze\1')
if filereadable(sname)
let b:js_extfiles += readfile(sname)
endif
endif
endwhile
" 2. Find at least one <script> tag
call cursor(1,1)
let js_scripttags = []
while search('<script\>', 'W') && line('.') < l
if matchstr(getline('.'), '<script[^>]*src') == ''
let js_scripttag = getline(line('.'), search('</script>', 'W'))
let js_scripttags += js_scripttag
endif
endwhile
let b:js_extfiles += js_scripttags
" 3. Proper call for javascriptcomplete#CompleteJS
call cursor(l,c)
let js_context = matchstr(a:base, '\w\+$')
let js_shortcontext = substitute(a:base, js_context.'$', '', '')
let b:compl_context = context
let b:jsrange = [l, l]
unlet! l c
"return map(javascriptcomplete#CompleteJS(0, js_context), 'js_shortcontext.v:val')
return javascriptcomplete#CompleteJS(0, js_context)
endif
" }}}
let stripbase = matchstr(context, ".*\\(on[a-zA-Z]*\\|style\\|class\\)\\s*=\\s*[\"']\\zs.*")
" Now we have context stripped from all chars up to style/class.
" It may fail with some strange style value combinations.
if stripbase !~ "[\"']"
return []
endif
endif
" Value of attribute completion {{{
" If attr contains =\s*[\"'] we catched value of attribute
if attr =~ "=\s*[\"']"
" Let do attribute specific completion
@ -413,6 +497,8 @@ function! htmlcomplete#CompleteTags(findstart, base)
return res + res2
endif
" }}}
" Attribute completion {{{
" Shorten context to not include last word
let sbase = matchstr(context, '.*\ze\s.*')
if tag =~ '^\(abbr\|acronym\|address\|b\|bdo\|big\|caption\|cite\|code\|dd\|dfn\|div\|dl\|dt\|em\|fieldset\|h\d\|hr\|i\|kbd\|li\|noscript\|ol\|p\|samp\|small\|span\|strong\|sub\|sup\|tt\|ul\|var\)$'
@ -506,7 +592,8 @@ function! htmlcomplete#CompleteTags(findstart, base)
return res + res2
endif
" Close tag
" }}}
" Close tag {{{
let b:unaryTagsStack = "base meta link hr br param img area input col"
if context =~ '^\/'
let opentag = xmlcomplete#GetLastOpenTag("b:unaryTagsStack")
@ -521,10 +608,13 @@ function! htmlcomplete#CompleteTags(findstart, base)
" If returns empty string assume <body>. Safe bet.
let opentag = 'body'
endif
" }}}
" Load data {{{
if !exists("g:xmldata_xhtml10s")
runtime! autoload/xml/xhtml10s.vim
endif
" }}}
" Tag completion {{{
let tags = g:xmldata_xhtml10s[opentag][0]
@ -538,5 +628,7 @@ function! htmlcomplete#CompleteTags(findstart, base)
return res + res2
" }}}
endif
endfunction
" vim:set foldmethod=marker:

View File

@ -1,33 +1,47 @@
" Vim completion script
" Language: Java Script
" Maintainer: Mikolaj Machowski ( mikmach AT wp DOT pl )
" Last Change: 2006 Jan 30
" Last Change: 2006 Feb 6
function! javascriptcomplete#CompleteJS(findstart, base)
if a:findstart
" locate the start of the word
let line = getline('.')
let start = col('.') - 1
" locate the start of the word
let line = getline('.')
let start = col('.') - 1
let curline = line('.')
let compl_begin = col('.') - 2
" Bit risky but JS is rather limited language and local chars shouldn't
" fint way into names
while start >= 0 && line[start - 1] =~ '\w'
while start >= 0 && line[start - 1] =~ '\w'
let start -= 1
endwhile
endwhile
let b:compl_context = getline('.')[0:compl_begin]
return start
return start
else
" Initialize base return lists
let res = []
let res2 = []
let res = []
let res2 = []
" a:base is very short - we need context
let context = b:compl_context
" Shortcontext is context without a:base, useful for checking if we are
" looking for objects
" looking for objects and for what objects we are looking for
let context = b:compl_context
let shortcontext = substitute(context, a:base.'$', '', '')
unlet! b:compl_context
if exists("b:jsrange")
let file = getline(b:jsrange[0],b:jsrange[1])
unlet! b:jsrange
if len(b:js_extfiles) > 0
let file = b:js_extfiles + file
endif
else
let file = getline(1, '$')
endif
" Completion of properties, methods, etc. {{{
if shortcontext =~ '\.$'
" Complete methods and properties for objects
" DOM separate
@ -91,7 +105,7 @@ function! javascriptcomplete#CompleteJS(findstart, base)
" RegExp
let regeprop = ['constructor', 'global', 'ignoreCase', 'lastIndex', 'multiline', 'source', 'prototype']
let regemeth = ['exec', 'toSource', 'toString', 'test', 'watch', 'unwatch']
let regemeth = ['exec', 'test', 'toSource', 'toString', 'watch', 'unwatch']
call map(regemeth, 'v:val."("')
let reges = regeprop + regemeth
@ -106,19 +120,17 @@ function! javascriptcomplete#CompleteJS(findstart, base)
let stris = striprop + strimeth
" User created properties
if exists("b:jsrange")
let file = getline(b:jsrange[0],b:jsrange[1])
unlet! b:jsrange
else
let file = getline(1, '$')
endif
let user_props1 = filter(copy(file), 'v:val =~ "this\\.\\w"')
let juser_props1 = join(user_props1, ' ')
let user_props1 = split(juser_props1, '\zethis\.')
unlet! juser_props1
call map(user_props1, 'matchstr(v:val, "this\\.\\zs\\w\\+\\ze")')
let user_props2 = filter(copy(file), 'v:val =~ "\\.prototype\\.\\w"')
call map(user_props2, 'matchstr(v:val, "\\.prototype\\.\\zs\\w\\+\\ze")')
let juser_props2 = join(user_props2, ' ')
let user_props2 = split(juser_props2, '\zeprototype\.')
unlet! juser_props2
call map(user_props2, 'matchstr(v:val, "prototype\\.\\zs\\w\\+\\ze")')
let user_props = user_props1 + user_props2
" HTML DOM properties
@ -149,7 +161,15 @@ function! javascriptcomplete#CompleteJS(findstart, base)
\ 'onClick', 'onDblClick', 'onFocus', 'onKeyDown', 'onKeyPress', 'onKeyUp',
\ 'onMouseDown', 'onMouseMove', 'onMouseOut', 'onMouseOver', 'onMouseUp', 'onResize']
call map(documeth, 'v:val."("')
let docus = docuprop + documeth
let docuxprop = ['attributes', 'childNodes', 'doctype', 'documentElement', 'firstChild',
\ 'implementation', 'namespaceURI', 'nextSibling', 'nodeName', 'nodeType',
\ 'nodeValue', 'ownerDocument', 'parentNode', 'previousSibling']
let docuxmeth = ['createAttribute', 'createCDATASection',
\ 'createComment', 'createDocument', 'createDocumentFragment',
\ 'createElement', 'createEntityReference', 'createProcessingInstruction',
\ 'createTextNode']
call map(docuxmeth, 'v:val."("')
let docus = docuprop + docuxprop + documeth + docuxmeth
" Form - form.
let formprop = ['elements', 'acceptCharset', 'action', 'encoding', 'enctype', 'id', 'length',
\ 'method', 'name', 'tabIndex', 'target']
@ -178,7 +198,7 @@ function! javascriptcomplete#CompleteJS(findstart, base)
let ifras = ifraprop
" Image - image.
let imagprop = ['align', 'alt', 'border', 'complete', 'height', 'hspace', 'id', 'isMap', 'longDesc',
\ 'lowsrc', 'name', 'src', 'useMap', 'vspace', 'width']
\ 'lowSrc', 'name', 'src', 'useMap', 'vspace', 'width']
let imagmeth = ['onAbort', 'onError', 'onLoad']
call map(imagmeth, 'v:val."("')
let imags = histprop + imagmeth
@ -282,13 +302,13 @@ function! javascriptcomplete#CompleteJS(findstart, base)
\ 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor',
\ 'borderBottomStyle', 'borderLeftStyle', 'borderRightStyle', 'borderTopStyle',
\ 'borderBottomWidth', 'borderLeftWidth', 'borderRightWidth', 'borderTopWidth',
\ 'borderColor', 'borderStyle', 'borderWidth', 'margin', 'marginBottom',
\ 'marginLeft', 'marginRight', 'marginTop', 'outline', 'outlineStyle', 'outlineWidth',
\ 'outlineColor', 'outlineStyle', 'outlineWidth', 'padding', 'paddingBottom',
\ 'paddingLeft', 'paddingRight', 'paddingTop',
\ 'clear', 'clip', 'clipBottom', 'clipLeft', 'clipRight', 'clipTop', 'content',
\ 'counterIncrement', 'counterReset', 'cssFloat', 'cursor', 'direction',
\ 'display', 'markerOffset', 'marks', 'maxHeight', 'maxWidth', 'minHeight',
\ 'borderColor', 'borderStyle', 'borderWidth', 'margin', 'marginBottom',
\ 'marginLeft', 'marginRight', 'marginTop', 'outline', 'outlineStyle', 'outlineWidth',
\ 'outlineColor', 'outlineStyle', 'outlineWidth', 'padding', 'paddingBottom',
\ 'paddingLeft', 'paddingRight', 'paddingTop',
\ 'clear', 'clip', 'clipBottom', 'clipLeft', 'clipRight', 'clipTop', 'content',
\ 'counterIncrement', 'counterReset', 'cssFloat', 'cursor', 'direction',
\ 'display', 'markerOffset', 'marks', 'maxHeight', 'maxWidth', 'minHeight',
\ 'minWidth', 'overflow', 'overflowX', 'overflowY', 'verticalAlign', 'visibility',
\ 'width',
\ 'listStyle', 'listStyleImage', 'listStylePosition', 'listStyleType',
@ -320,13 +340,14 @@ function! javascriptcomplete#CompleteJS(findstart, base)
" Textarea - accessible only by other properties
let tareprop = ['accessKey', 'cols', 'defaultValue',
\ 'disabled', 'form', 'id', 'name', 'readOnly', 'rows',
\ 'tabIndex', 'type', 'value']
\ 'tabIndex', 'type', 'value', 'selectionStart', 'selectionEnd']
let taremeth = ['blur', 'focus', 'select', 'onBlur', 'onChange', 'onFocus']
call map(taremeth, 'v:val."("')
let tares = tareprop + taremeth
" Window - window.
let windprop = ['frames', 'closed', 'defaultStatus', 'length', 'name', 'opener', 'parent',
\ 'self', 'status', 'top']
let windprop = ['frames', 'closed', 'defaultStatus', 'encodeURI', 'event', 'history',
\ 'length', 'location', 'name', 'onload', 'opener', 'parent', 'screen', 'self',
\ 'status', 'top', 'XMLHttpRequest', 'ActiveXObject']
let windmeth = ['alert', 'blur', 'clearInterval', 'clearTimeout', 'close', 'confirm', 'focus',
\ 'moveBy', 'moveTo', 'open', 'print', 'prompt', 'scrollBy', 'scrollTo', 'setInterval',
\ 'setTimeout']
@ -334,15 +355,81 @@ function! javascriptcomplete#CompleteJS(findstart, base)
let winds = windprop + windmeth
" XMLHttpRequest - access by new xxx()
let xmlhprop = ['onreadystatechange', 'readyState', 'responseText', 'responseXML',
\ 'status', 'statusText']
\ 'status', 'statusText', 'parseError']
let xmlhmeth = ['abort', 'getAllResponseHeaders', 'getResponseHeaders', 'open',
\ 'send', 'setRequestHeader']
call map(xmlhmeth, 'v:val."("')
let xmlhs = xmlhprop + xmlhmeth
" XML DOM
" Attributes - element.attributes[x].
let xdomattrprop = ['name', 'specified', 'value']
" Element - anyelement.
let xdomelemprop = ['attributes', 'childNodes', 'firstChild', 'lastChild',
\ 'namespaceURI', 'nextSibling', 'nodeName', 'nodeType', 'nodeValue',
\ 'ownerDocument', 'parentNode', 'prefix', 'previousSibling', 'tagName']
let xdomelemmeth = ['appendChild', 'cloneNode', 'getAttribute', 'getAttributeNode',
\ 'getElementsByTagName', 'hasChildNodes', 'insertBefore', 'normalize',
\ 'removeAttribute', 'removeAttributeNode', 'removeChild', 'replaceChild',
\ 'setAttribute', 'setAttributeNode']
call map(xdomelemmeth, 'v:val."("')
let xdomelems = xdomelemprop + xdomelemmeth
" Node - anynode.
let xdomnodeprop = ['attributes', 'childNodes', 'firstChild', 'lastChild',
\ 'namespaceURI', 'nextSibling', 'nodeName', 'nodeType', 'nodeValue',
\ 'ownerDocument', 'parentNode', 'prefix', 'previousSibling']
let xdomnodemeth = ['appendChild', 'cloneNode',
\ 'hasChildNodes', 'insertBefore', 'removeChild', 'replaceChild']
call map(xdomnodemeth, 'v:val."("')
let xdomnodes = xdomnodeprop + xdomnodemeth
" NodeList
let xdomnliss = ['length', 'item(']
" Error - parseError.
let xdomerror = ['errorCode', 'reason', 'line', 'linepos', 'srcText', 'url', 'filepos']
" Find object type declaration to reduce number of suggestions. {{{
" 1. Get object name
" 2. Find object declaration line
" 3. General declaration follows "= new Type" syntax, additional else
" for regexp "= /re/"
" 4. Make correction for Microsoft.XMLHTTP ActiveXObject
" 5. Repeat for external files
let object = matchstr(shortcontext, '\zs\w\+\ze\(\[.\{-}\]\)\?\.$')
let decl_line = search(object.'.\{-}=\s*new\s*', 'bn')
let object_type = matchstr(getline(decl_line), object.'.\{-}=\s*new\s*\zs\w\+\ze')
if len(object) > 0
let decl_line = search(object.'.\{-}=\s*new\s*', 'bn')
if decl_line > 0
let object_type = matchstr(getline(decl_line), object.'.\{-}=\s*new\s*\zs\w\+\ze')
if object_type == 'ActiveXObject' && matchstr(getline(decl_line), object.'.\{-}=\s*new\s*ActiveXObject\s*(.Microsoft\.XMLHTTP.)') != ''
let object_type = 'XMLHttpRequest'
endif
else
let decl_line = search('var\s*'.object.'\s*=\s*\/', 'bn')
if decl_line > 0
let object_type = 'RegExp'
endif
endif
" We didn't find var declaration in current file but we may have
" something in external files.
if decl_line == 0 && exists("b:js_extfiles")
let dext_line = filter(copy(b:js_extfiles), 'v:val =~ "'.object.'.\\{-}=\\s*new\\s*"')
if len(dext_line) > 0
let object_type = matchstr(dext_line[-1], object.'.\{-}=\s*new\s*\zs\w\+\ze')
if object_type == 'ActiveXObject' && matchstr(dext_line[-1], object.'.\{-}=\s*new\s*ActiveXObject\s*(.Microsoft\.XMLHTTP.)') != ''
let object_type = 'XMLHttpRequest'
endif
else
let dext_line = filter(copy(b:js_extfiles), 'v:val =~ "var\s*'.object.'\\s*=\\s*\\/"')
if len(dext_line) > 0
let object_type = 'RegExp'
endif
endif
endif
endif
" }}}
if !exists('object_type')
let object_type = ''
endif
if object_type == 'Date'
let values = dates
@ -357,13 +444,17 @@ function! javascriptcomplete#CompleteJS(findstart, base)
let values = xmlhs
elseif object_type == 'String'
let values = stris
elseif object_type == 'RegExp'
let values = reges
elseif object_type == 'Math'
let values = maths
endif
if !exists('values')
" List of properties
if shortcontext =~ 'Math\.$'
let values = maths
elseif shortcontext =~ 'anchor\.$'
elseif shortcontext =~ 'anchors\(\[.\{-}\]\)\?\.$'
let values = anths
elseif shortcontext =~ 'area\.$'
let values = areas
@ -373,7 +464,7 @@ function! javascriptcomplete#CompleteJS(findstart, base)
let values = bodys
elseif shortcontext =~ 'document\.$'
let values = docus
elseif shortcontext =~ 'form\.$'
elseif shortcontext =~ 'forms\(\[.\{-}\]\)\?\.$'
let values = forms
elseif shortcontext =~ 'frameset\.$'
let values = fsets
@ -381,9 +472,9 @@ function! javascriptcomplete#CompleteJS(findstart, base)
let values = hists
elseif shortcontext =~ 'iframe\.$'
let values = ifras
elseif shortcontext =~ 'image\.$'
elseif shortcontext =~ 'images\(\[.\{-}\]\)\?\.$'
let values = imags
elseif shortcontext =~ 'link\.$'
elseif shortcontext =~ 'links\(\[.\{-}\]\)\?\.$'
let values = links
elseif shortcontext =~ 'location\.$'
let values = locas
@ -405,11 +496,16 @@ function! javascriptcomplete#CompleteJS(findstart, base)
let values = trows
elseif shortcontext =~ 'window\.$'
let values = winds
elseif shortcontext =~ 'parseError\.$'
let values = xdomerror
elseif shortcontext =~ 'attributes\[\d\+\]\.$'
let values = xdomattrprop
else
let values = user_props + arrays + dates + funcs + maths + numbs + objes + reges + stris
let values += doms + anths + areas + bases + bodys + docus + forms + frams + fsets + hists
let values += ifras + imags + links + locas + metas + navis + objes + scres + styls
let values += tabls + trows + winds
let values += ifras + imags + links + locas + metas + navis + objes + scres
let values += tabls + trows + tares + winds
let values += xdomnodes + xdomnliss + xdomelems
endif
endif
@ -425,21 +521,15 @@ function! javascriptcomplete#CompleteJS(findstart, base)
return res + res2
endif
if exists("b:jsrange")
let file = getline(b:jsrange[0],b:jsrange[1])
unlet! b:jsrange
else
let file = getline(1, '$')
endif
" }}}
" Get variables data.
let variables = filter(copy(file), 'v:val =~ "var\\s"')
call map(variables, 'matchstr(v:val, ".\\{-}var\\s\\+\\zs.*\\ze")')
call map(variables, 'substitute(v:val, ";\\|$", ",", "g")')
let vars = []
" This loop is necessary to get variable names from constructs like:
" var var1, var2, var3 = "something";
" This loop (and next one) is necessary to get variable names from
" constructs like: var var1, var2, var3 = "something";
for i in range(len(variables))
let comma_separated = split(variables[i], ',\s*')
call map(comma_separated, 'matchstr(v:val, "\\w\\+")')
@ -447,27 +537,36 @@ function! javascriptcomplete#CompleteJS(findstart, base)
endfor
let variables = sort(vars)
unlet! vars
" Add undeclared variables.
" Add "no var" variables.
let undeclared_variables = filter(copy(file), 'v:val =~ "^\\s*\\w\\+\\s*="')
call map(undeclared_variables, 'matchstr(v:val, "^\\s*\\zs\\w\\+\\ze")')
let u_vars = []
for i in range(len(undeclared_variables))
let split_equal = split(undeclared_variables[i], '\s*=')
call map(split_equal, 'matchstr(v:val, "\\w\\+$")')
let u_vars += split_equal
endfor
let variables += sort(undeclared_variables)
let variables += sort(u_vars)
unlet! u_vars
" Get functions
let functions = filter(copy(file), 'v:val =~ "^\\s*function\\s"')
let arguments = copy(functions)
call map(functions, 'matchstr(v:val, "^\\s*function\\s\\+\\zs\\w\\+")')
call map(functions, 'v:val."("')
let functions = sort(functions)
" Get functions arguments
call map(arguments, 'matchstr(v:val, "function.\\{-}(\\zs.\\{-}\\ze)")')
let jargs = join(arguments, ',')
let jargs = substitute(jargs, '\s', '', 'g')
let arguments = split(jargs, ',')
let arguments = sort(arguments)
" Built-in functions
let builtin = []
let builtin = ['alert(', 'confirm(']
" Top-level HTML DOM objects
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']
@ -493,3 +592,5 @@ function! javascriptcomplete#CompleteJS(findstart, base)
return res + res2
endfunction
" vim:set foldmethod=marker:

View File

@ -1,7 +1,7 @@
" Vim completion script
" Language: XML
" Maintainer: Mikolaj Machowski ( mikmach AT wp DOT pl )
" Last Change: 2006 Jan 24
" Last Change: 2006 Feb 6
" This function will create Dictionary with users namespace strings and values
" canonical (system) names of data files. Names should be lowercase,
@ -396,11 +396,11 @@ return ''
endfunction
function! s:InComment()
return synIDattr(synID(line('.'), col('.'), 0), 'name') =~ 'Comment'
return synIDattr(synID(line('.'), col('.'), 0), 'name') =~ 'Comment\|String'
endfunction
function! s:InCommentAt(line, col)
return synIDattr(synID(a:line, a:col, 0), 'name') =~ 'Comment'
return synIDattr(synID(a:line, a:col, 0), 'name') =~ 'Comment\|String'
endfunction
function! s:SetKeywords()