comparison runtime/autoload/syntaxcomplete.vim @ 1121:e63691e7c504

updated for version 7.1a
author vimboss
date Sat, 05 May 2007 17:54:07 +0000
parents c301dba834d0
children 73fe8baea242
comparison
equal deleted inserted replaced
1120:e6db096b07a1 1121:e63691e7c504
1 " Vim completion script 1 " Vim completion script
2 " Language: All languages, uses existing syntax highlighting rules 2 " Language: All languages, uses existing syntax highlighting rules
3 " Maintainer: David Fishburn <fishburn@ianywhere.com> 3 " Maintainer: David Fishburn <fishburn@ianywhere.com>
4 " Version: 2.0 4 " Version: 3.0
5 " Last Change: Fri May 05 2006 10:34:57 PM 5 " Last Change: Wed Nov 08 2006 10:46:46 AM
6 " Usage: For detailed help, ":help ft-syntax-omni" 6 " Usage: For detailed help, ":help ft-syntax-omni"
7 7
8 " Set completion with CTRL-X CTRL-O to autoloaded function. 8 " Set completion with CTRL-X CTRL-O to autoloaded function.
9 " This check is in place in case this script is 9 " This check is in place in case this script is
10 " sourced directly instead of using the autoload feature. 10 " sourced directly instead of using the autoload feature.
17 endif 17 endif
18 18
19 if exists('g:loaded_syntax_completion') 19 if exists('g:loaded_syntax_completion')
20 finish 20 finish
21 endif 21 endif
22 let g:loaded_syntax_completion = 20 22 let g:loaded_syntax_completion = 30
23 23
24 " Set ignorecase to the ftplugin standard 24 " Set ignorecase to the ftplugin standard
25 " This is the default setting, but if you define a buffer local
26 " variable you can override this on a per filetype.
25 if !exists('g:omni_syntax_ignorecase') 27 if !exists('g:omni_syntax_ignorecase')
26 let g:omni_syntax_ignorecase = &ignorecase 28 let g:omni_syntax_ignorecase = &ignorecase
29 endif
30
31 " Indicates whether we should use the iskeyword option to determine
32 " how to split words.
33 " This is the default setting, but if you define a buffer local
34 " variable you can override this on a per filetype.
35 if !exists('g:omni_syntax_use_iskeyword')
36 let g:omni_syntax_use_iskeyword = 1
37 endif
38
39 " Only display items in the completion window that are at least
40 " this many characters in length.
41 " This is the default setting, but if you define a buffer local
42 " variable you can override this on a per filetype.
43 if !exists('g:omni_syntax_minimum_length')
44 let g:omni_syntax_minimum_length = 0
27 endif 45 endif
28 46
29 " This script will build a completion list based on the syntax 47 " This script will build a completion list based on the syntax
30 " elements defined by the files in $VIMRUNTIME/syntax. 48 " elements defined by the files in $VIMRUNTIME/syntax.
31 let s:syn_remove_words = 'match,matchgroup=,contains,'. 49 let s:syn_remove_words = 'match,matchgroup=,contains,'.
35 let s:cache_list = [] 53 let s:cache_list = []
36 let s:prepended = '' 54 let s:prepended = ''
37 55
38 " This function is used for the 'omnifunc' option. 56 " This function is used for the 'omnifunc' option.
39 function! syntaxcomplete#Complete(findstart, base) 57 function! syntaxcomplete#Complete(findstart, base)
58
59 " Only display items in the completion window that are at least
60 " this many characters in length
61 if !exists('b:omni_syntax_ignorecase')
62 if exists('g:omni_syntax_ignorecase')
63 let b:omni_syntax_ignorecase = g:omni_syntax_ignorecase
64 else
65 let b:omni_syntax_ignorecase = &ignorecase
66 endif
67 endif
40 68
41 if a:findstart 69 if a:findstart
42 " Locate the start of the item, including "." 70 " Locate the start of the item, including "."
43 let line = getline('.') 71 let line = getline('.')
44 let start = col('.') - 1 72 let start = col('.') - 1
45 let lastword = -1 73 let lastword = -1
46 while start > 0 74 while start > 0
47 if line[start - 1] =~ '\w' 75 " if line[start - 1] =~ '\S'
76 " let start -= 1
77 " elseif line[start - 1] =~ '\.'
78 if line[start - 1] =~ '\k'
48 let start -= 1 79 let start -= 1
49 elseif line[start - 1] =~ '\.' 80 let lastword = a:findstart
50 " The user must be specifying a column name
51 if lastword == -1
52 let lastword = start
53 endif
54 let start -= 1
55 let b:sql_compl_type = 'column'
56 else 81 else
57 break 82 break
58 endif 83 endif
59 endwhile 84 endwhile
60 85
62 " Remember the text that comes before it in s:prepended. 87 " Remember the text that comes before it in s:prepended.
63 if lastword == -1 88 if lastword == -1
64 let s:prepended = '' 89 let s:prepended = ''
65 return start 90 return start
66 endif 91 endif
67 let s:prepended = strpart(line, start, lastword - start) 92 let s:prepended = strpart(line, start, (col('.') - 1) - start)
68 return lastword 93 return start
69 endif 94 endif
70 95
71 let base = s:prepended . a:base 96 " let base = s:prepended . a:base
97 let base = s:prepended
72 98
73 let filetype = substitute(&filetype, '\.', '_', 'g') 99 let filetype = substitute(&filetype, '\.', '_', 'g')
74 let list_idx = index(s:cache_name, filetype, 0, &ignorecase) 100 let list_idx = index(s:cache_name, filetype, 0, &ignorecase)
75 if list_idx > -1 101 if list_idx > -1
76 let compl_list = s:cache_list[list_idx] 102 let compl_list = s:cache_list[list_idx]
80 let s:cache_list = add( s:cache_list, compl_list ) 106 let s:cache_list = add( s:cache_list, compl_list )
81 endif 107 endif
82 108
83 " Return list of matches. 109 " Return list of matches.
84 110
85 if base =~ '\w' 111 if base != ''
86 let compstr = join(compl_list, ' ') 112 " let compstr = join(compl_list, ' ')
87 let expr = (g:omni_syntax_ignorecase==0?'\C':'').'\<\%('.base.'\)\@!\w\+\s*' 113 " let expr = (b:omni_syntax_ignorecase==0?'\C':'').'\<\%('.base.'\)\@!\w\+\s*'
88 let compstr = substitute(compstr, expr, '', 'g') 114 " let compstr = substitute(compstr, expr, '', 'g')
89 let compl_list = split(compstr, '\s\+') 115 " let compl_list = split(compstr, '\s\+')
116
117 " Filter the list based on the first few characters the user
118 " entered
119 let expr = 'v:val '.(g:omni_syntax_ignorecase==1?'=~?':'=~#')." '^".escape(base, '\\/.*$^~[]').".*'"
120 let compl_list = filter(deepcopy(compl_list), expr)
90 endif 121 endif
91 122
92 return compl_list 123 return compl_list
93 endfunc 124 endfunc
94 125
97 " a list will be returned. 128 " a list will be returned.
98 " let use_dictionary = 1 129 " let use_dictionary = 1
99 " if a:0 > 0 && a:1 != '' 130 " if a:0 > 0 && a:1 != ''
100 " let use_dictionary = a:1 131 " let use_dictionary = a:1
101 " endif 132 " endif
133
134 " Only display items in the completion window that are at least
135 " this many characters in length
136 if !exists('b:omni_syntax_use_iskeyword')
137 if exists('g:omni_syntax_use_iskeyword')
138 let b:omni_syntax_use_iskeyword = g:omni_syntax_use_iskeyword
139 else
140 let b:omni_syntax_use_iskeyword = 1
141 endif
142 endif
143
144 " Only display items in the completion window that are at least
145 " this many characters in length
146 if !exists('b:omni_syntax_minimum_length')
147 if exists('g:omni_syntax_minimum_length')
148 let b:omni_syntax_minimum_length = g:omni_syntax_minimum_length
149 else
150 let b:omni_syntax_minimum_length = 0
151 endif
152 endif
102 153
103 let saveL = @l 154 let saveL = @l
104 155
105 " Loop through all the syntax groupnames, and build a 156 " Loop through all the syntax groupnames, and build a
106 " syntax file which contains these names. This can 157 " syntax file which contains these names. This can
292 let syn_list = substitute( 343 let syn_list = substitute(
293 \ syn_list, '\%(^\|\n\)\@<=\s*\<\(contained\)' 344 \ syn_list, '\%(^\|\n\)\@<=\s*\<\(contained\)'
294 \ , "", 'g' 345 \ , "", 'g'
295 \ ) 346 \ )
296 347
297 " There are a number of items which have non-word characters in 348 if b:omni_syntax_use_iskeyword == 0
298 " them, *'T_F1'*. vim.vim is one such file. 349 " There are a number of items which have non-word characters in
299 " This will replace non-word characters with spaces. 350 " them, *'T_F1'*. vim.vim is one such file.
300 let syn_list = substitute( syn_list, '[^0-9A-Za-z_ ]', ' ', 'g' ) 351 " This will replace non-word characters with spaces.
352 let syn_list = substitute( syn_list, '[^0-9A-Za-z_ ]', ' ', 'g' )
353 else
354 let accept_chars = ','.&iskeyword.','
355 " Remove all character ranges
356 let accept_chars = substitute(accept_chars, ',[^,]\+-[^,]\+,', ',', 'g')
357 " Remove all numeric specifications
358 let accept_chars = substitute(accept_chars, ',\d\{-},', ',', 'g')
359 " Remove all commas
360 let accept_chars = substitute(accept_chars, ',', '', 'g')
361 " Escape special regex characters
362 let accept_chars = escape(accept_chars, '\\/.*$^~[]' )
363 " Remove all characters that are not acceptable
364 let syn_list = substitute( syn_list, '[^0-9A-Za-z_ '.accept_chars.']', ' ', 'g' )
365 endif
366
367 if b:omni_syntax_minimum_length > 0
368 " If the user specified a minimum length, enforce it
369 let syn_list = substitute(' '.syn_list.' ', ' \S\{,'.b:omni_syntax_minimum_length.'}\ze ', ' ', 'g')
370 endif
301 else 371 else
302 let syn_list = '' 372 let syn_list = ''
303 endif 373 endif
304 374
305 return syn_list 375 return syn_list
306 endfunction 376 endfunction
307