annotate runtime/autoload/syntaxcomplete.vim @ 1854:a58806285f20 v7.2.152

updated for version 7.2-152
author vimboss
date Wed, 22 Apr 2009 12:44:48 +0000
parents 73fe8baea242
children 4a1bcdd9ea55
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
1 " Vim completion script
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
2 " Language: All languages, uses existing syntax highlighting rules
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
3 " Maintainer: David Fishburn <dfishburn.vim@gmail.com>
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
4 " Version: 4.0
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
5 " Last Change: Fri 26 Oct 2007 05:27:03 PM Eastern Daylight Time
871
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
6 " Usage: For detailed help, ":help ft-syntax-omni"
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
7
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
8 " Set completion with CTRL-X CTRL-O to autoloaded function.
785
fd60bacf955b updated for version 7.0229
vimboss
parents: 702
diff changeset
9 " This check is in place in case this script is
fd60bacf955b updated for version 7.0229
vimboss
parents: 702
diff changeset
10 " sourced directly instead of using the autoload feature.
702
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
11 if exists('+omnifunc')
785
fd60bacf955b updated for version 7.0229
vimboss
parents: 702
diff changeset
12 " Do not set the option if already set since this
fd60bacf955b updated for version 7.0229
vimboss
parents: 702
diff changeset
13 " results in an E117 warning.
fd60bacf955b updated for version 7.0229
vimboss
parents: 702
diff changeset
14 if &omnifunc == ""
fd60bacf955b updated for version 7.0229
vimboss
parents: 702
diff changeset
15 setlocal omnifunc=syntaxcomplete#Complete
fd60bacf955b updated for version 7.0229
vimboss
parents: 702
diff changeset
16 endif
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
17 endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
18
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
19 if exists('g:loaded_syntax_completion')
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
20 finish
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
21 endif
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
22 let g:loaded_syntax_completion = 40
871
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
23
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
24 " Set ignorecase to the ftplugin standard
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
25 " This is the default setting, but if you define a buffer local
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
26 " variable you can override this on a per filetype.
871
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
27 if !exists('g:omni_syntax_ignorecase')
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
28 let g:omni_syntax_ignorecase = &ignorecase
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
29 endif
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
30
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
31 " Indicates whether we should use the iskeyword option to determine
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
32 " how to split words.
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
33 " This is the default setting, but if you define a buffer local
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
34 " variable you can override this on a per filetype.
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
35 if !exists('g:omni_syntax_use_iskeyword')
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
36 let g:omni_syntax_use_iskeyword = 1
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
37 endif
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
38
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
39 " Only display items in the completion window that are at least
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
40 " this many characters in length.
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
41 " This is the default setting, but if you define a buffer local
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
42 " variable you can override this on a per filetype.
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
43 if !exists('g:omni_syntax_minimum_length')
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
44 let g:omni_syntax_minimum_length = 0
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
45 endif
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
46
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
47 " This script will build a completion list based on the syntax
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
48 " elements defined by the files in $VIMRUNTIME/syntax.
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
49 let s:syn_remove_words = 'match,matchgroup=,contains,'.
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
50 \ 'links to,start=,end=,nextgroup='
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
51
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
52 let s:cache_name = []
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
53 let s:cache_list = []
785
fd60bacf955b updated for version 7.0229
vimboss
parents: 702
diff changeset
54 let s:prepended = ''
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
55
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
56 " This function is used for the 'omnifunc' option.
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
57 function! syntaxcomplete#Complete(findstart, base)
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
58
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
59 " Only display items in the completion window that are at least
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
60 " this many characters in length
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
61 if !exists('b:omni_syntax_ignorecase')
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
62 if exists('g:omni_syntax_ignorecase')
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
63 let b:omni_syntax_ignorecase = g:omni_syntax_ignorecase
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
64 else
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
65 let b:omni_syntax_ignorecase = &ignorecase
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
66 endif
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
67 endif
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
68
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
69 if a:findstart
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
70 " Locate the start of the item, including "."
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
71 let line = getline('.')
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
72 let start = col('.') - 1
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
73 let lastword = -1
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
74 while start > 0
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
75 " if line[start - 1] =~ '\S'
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
76 " let start -= 1
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
77 " elseif line[start - 1] =~ '\.'
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
78 if line[start - 1] =~ '\k'
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
79 let start -= 1
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
80 let lastword = a:findstart
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
81 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
82 break
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
83 endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
84 endwhile
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
85
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
86 " Return the column of the last word, which is going to be changed.
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
87 " Remember the text that comes before it in s:prepended.
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
88 if lastword == -1
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
89 let s:prepended = ''
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
90 return start
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
91 endif
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
92 let s:prepended = strpart(line, start, (col('.') - 1) - start)
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
93 return start
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
94 endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
95
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
96 " let base = s:prepended . a:base
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
97 let base = s:prepended
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
98
871
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
99 let filetype = substitute(&filetype, '\.', '_', 'g')
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
100 let list_idx = index(s:cache_name, filetype, 0, &ignorecase)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
101 if list_idx > -1
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
102 let compl_list = s:cache_list[list_idx]
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
103 else
871
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
104 let compl_list = OmniSyntaxList()
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
105 let s:cache_name = add( s:cache_name, filetype )
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
106 let s:cache_list = add( s:cache_list, compl_list )
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
107 endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
108
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
109 " Return list of matches.
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
110
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
111 if base != ''
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
112 " let compstr = join(compl_list, ' ')
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
113 " let expr = (b:omni_syntax_ignorecase==0?'\C':'').'\<\%('.base.'\)\@!\w\+\s*'
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
114 " let compstr = substitute(compstr, expr, '', 'g')
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
115 " let compl_list = split(compstr, '\s\+')
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
116
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
117 " Filter the list based on the first few characters the user
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
118 " entered
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
119 let expr = 'v:val '.(g:omni_syntax_ignorecase==1?'=~?':'=~#')." '^".escape(base, '\\/.*$^~[]').".*'"
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
120 let compl_list = filter(deepcopy(compl_list), expr)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
121 endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
122
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
123 return compl_list
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
124 endfunc
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
125
702
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
126 function! OmniSyntaxList()
871
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
127 " Default to returning a dictionary, if use_dictionary is set to 0
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
128 " a list will be returned.
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
129 " let use_dictionary = 1
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
130 " if a:0 > 0 && a:1 != ''
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
131 " let use_dictionary = a:1
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
132 " endif
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
133
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
134 " Only display items in the completion window that are at least
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
135 " this many characters in length
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
136 if !exists('b:omni_syntax_use_iskeyword')
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
137 if exists('g:omni_syntax_use_iskeyword')
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
138 let b:omni_syntax_use_iskeyword = g:omni_syntax_use_iskeyword
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
139 else
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
140 let b:omni_syntax_use_iskeyword = 1
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
141 endif
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
142 endif
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
143
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
144 " Only display items in the completion window that are at least
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
145 " this many characters in length
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
146 if !exists('b:omni_syntax_minimum_length')
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
147 if exists('g:omni_syntax_minimum_length')
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
148 let b:omni_syntax_minimum_length = g:omni_syntax_minimum_length
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
149 else
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
150 let b:omni_syntax_minimum_length = 0
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
151 endif
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
152 endif
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
153
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
154 let saveL = @l
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
155
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
156 " Loop through all the syntax groupnames, and build a
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
157 " syntax file which contains these names. This can
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
158 " work generically for any filetype that does not already
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
159 " have a plugin defined.
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
160 " This ASSUMES the syntax groupname BEGINS with the name
702
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
161 " of the filetype. From my casual viewing of the vim7\syntax
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
162 " directory.
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
163 redir @l
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
164 silent! exec 'syntax list '
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
165 redir END
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
166
702
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
167 let syntax_full = "\n".@l
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
168 let @l = saveL
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
169
702
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
170 if syntax_full =~ 'E28'
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
171 \ || syntax_full =~ 'E411'
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
172 \ || syntax_full =~ 'E415'
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
173 \ || syntax_full =~ 'No Syntax items'
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
174 return []
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
175 endif
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
176
871
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
177 let filetype = substitute(&filetype, '\.', '_', 'g')
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
178
702
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
179 " Default the include group to include the requested syntax group
871
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
180 let syntax_group_include_{filetype} = ''
702
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
181 " Check if there are any overrides specified for this filetype
871
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
182 if exists('g:omni_syntax_group_include_'.filetype)
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
183 let syntax_group_include_{filetype} =
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
184 \ substitute( g:omni_syntax_group_include_{filetype},'\s\+','','g')
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
185 if syntax_group_include_{filetype} =~ '\w'
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
186 let syntax_group_include_{filetype} =
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
187 \ substitute( syntax_group_include_{filetype},
702
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
188 \ '\s*,\s*', '\\|', 'g'
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
189 \ )
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
190 endif
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
191 endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
192
702
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
193 " Default the exclude group to nothing
871
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
194 let syntax_group_exclude_{filetype} = ''
702
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
195 " Check if there are any overrides specified for this filetype
871
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
196 if exists('g:omni_syntax_group_exclude_'.filetype)
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
197 let syntax_group_exclude_{filetype} =
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
198 \ substitute( g:omni_syntax_group_exclude_{filetype},'\s\+','','g')
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
199 if syntax_group_exclude_{filetype} =~ '\w'
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
200 let syntax_group_exclude_{filetype} =
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
201 \ substitute( syntax_group_exclude_{filetype},
702
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
202 \ '\s*,\s*', '\\|', 'g'
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
203 \ )
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
204 endif
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
205 endif
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
206
871
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
207 " Sometimes filetypes can be composite names, like c.doxygen
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
208 " Loop through each individual part looking for the syntax
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
209 " items specific to each individual filetype.
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
210 let syn_list = ''
871
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
211 let ftindex = 0
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
212 let ftindex = match(&filetype, '\w\+', ftindex)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
213
871
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
214 while ftindex > -1
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
215 let ft_part_name = matchstr( &filetype, '\w\+', ftindex )
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
216
871
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
217 " Syntax rules can contain items for more than just the current
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
218 " filetype. They can contain additional items added by the user
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
219 " via autocmds or their vimrc.
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
220 " Some syntax files can be combined (html, php, jsp).
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
221 " We want only items that begin with the filetype we are interested in.
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
222 let next_group_regex = '\n' .
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
223 \ '\zs'.ft_part_name.'\w\+\ze'.
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
224 \ '\s\+xxx\s\+'
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
225 let index = 0
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
226 let index = match(syntax_full, next_group_regex, index)
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
227
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
228 while index > -1
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
229 let group_name = matchstr( syntax_full, '\w\+', index )
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
230
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
231 let get_syn_list = 1
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
232 " if syntax_group_include_{&filetype} == ''
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
233 " if syntax_group_exclude_{&filetype} != ''
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
234 " if '\<'.syntax_group_exclude_{&filetype}.'\>' =~ '\<'.group_name.'\>'
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
235 " let get_syn_list = 0
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
236 " endif
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
237 " endif
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
238 " else
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
239 " if '\<'.syntax_group_include_{&filetype}.'\>' !~ '\<'.group_name.'\>'
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
240 " let get_syn_list = 0
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
241 " endif
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
242 " endif
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
243 if syntax_group_exclude_{filetype} != ''
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
244 if '\<'.syntax_group_exclude_{filetype}.'\>' =~ '\<'.group_name.'\>'
702
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
245 let get_syn_list = 0
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
246 endif
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
247 endif
871
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
248
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
249 if get_syn_list == 1
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
250 if syntax_group_include_{filetype} != ''
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
251 if '\<'.syntax_group_include_{filetype}.'\>' !~ '\<'.group_name.'\>'
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
252 let get_syn_list = 0
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
253 endif
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
254 endif
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
255 endif
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
256
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
257 if get_syn_list == 1
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
258 " Pass in the full syntax listing, plus the group name we
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
259 " are interested in.
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
260 let extra_syn_list = s:SyntaxCSyntaxGroupItems(group_name, syntax_full)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
261
871
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
262 " if !empty(extra_syn_list)
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
263 " for elem in extra_syn_list
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
264 " let item = {'word':elem, 'kind':'t', 'info':group_name}
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
265 " let compl_list += [item]
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
266 " endfor
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
267 " endif
702
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
268
871
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
269 let syn_list = syn_list . extra_syn_list . "\n"
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
270 endif
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
271
871
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
272 let index = index + strlen(group_name)
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
273 let index = match(syntax_full, next_group_regex, index)
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
274 endwhile
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
275
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
276 let ftindex = ftindex + len(ft_part_name)
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
277 let ftindex = match( &filetype, '\w\+', ftindex )
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
278 endwhile
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
279
702
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
280 " Convert the string to a List and sort it.
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
281 let compl_list = sort(split(syn_list))
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
282
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
283 if &filetype == 'vim'
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
284 let short_compl_list = []
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
285 for i in range(len(compl_list))
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
286 if i == len(compl_list)-1
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
287 let next = i
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
288 else
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
289 let next = i + 1
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
290 endif
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
291 if compl_list[next] !~ '^'.compl_list[i].'.$'
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
292 let short_compl_list += [compl_list[i]]
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
293 endif
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
294 endfor
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
295
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
296 return short_compl_list
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
297 else
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
298 return compl_list
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
299 endif
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
300 endfunction
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
301
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 785
diff changeset
302 function! s:SyntaxCSyntaxGroupItems( group_name, syntax_full )
702
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
303
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
304 let syn_list = ""
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
305
702
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
306 " From the full syntax listing, strip out the portion for the
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
307 " request group.
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
308 " Query:
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
309 " \n - must begin with a newline
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
310 " a:group_name - the group name we are interested in
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
311 " \s\+xxx\s\+ - group names are always followed by xxx
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
312 " \zs - start the match
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
313 " .\{-} - everything ...
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
314 " \ze - end the match
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
315 " \n\w - at the first newline starting with a character
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
316 let syntax_group = matchstr(a:syntax_full,
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
317 \ "\n".a:group_name.'\s\+xxx\s\+\zs.\{-}\ze'."\n".'\w'
871
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
318 \ )
702
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
319
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
320 if syntax_group != ""
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
321 " let syn_list = substitute( @l, '^.*xxx\s*\%(contained\s*\)\?', "", '' )
702
8a99b25de218 updated for version 7.0212
vimboss
parents: 625
diff changeset
322 " let syn_list = substitute( @l, '^.*xxx\s*', "", '' )
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
323
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
324 " We only want the words for the lines begining with
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
325 " containedin, but there could be other items.
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
326
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
327 " Tried to remove all lines that do not begin with contained
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
328 " but this does not work in all cases since you can have
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
329 " contained nextgroup=...
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
330 " So this will strip off the ending of lines with known
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
331 " keywords.
871
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
332 let syn_list = substitute(
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
333 \ syntax_group, '\<\('.
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
334 \ substitute(
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
335 \ escape(s:syn_remove_words, '\\/.*$^~[]')
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
336 \ , ',', '\\|', 'g'
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
337 \ ).
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
338 \ '\).\{-}\%($\|'."\n".'\)'
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
339 \ , "\n", 'g'
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
340 \ )
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
341
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
342 " Now strip off the newline + blank space + contained
871
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
343 let syn_list = substitute(
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
344 \ syn_list, '\%(^\|\n\)\@<=\s*\<\(contained\)'
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
345 \ , "", 'g'
c301dba834d0 updated for version 7.0g05
vimboss
parents: 818
diff changeset
346 \ )
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
347
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
348 if b:omni_syntax_use_iskeyword == 0
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
349 " There are a number of items which have non-word characters in
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
350 " them, *'T_F1'*. vim.vim is one such file.
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
351 " This will replace non-word characters with spaces.
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
352 let syn_list = substitute( syn_list, '[^0-9A-Za-z_ ]', ' ', 'g' )
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
353 else
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
354 let accept_chars = ','.&iskeyword.','
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
355 " Remove all character ranges
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
356 " let accept_chars = substitute(accept_chars, ',[^,]\+-[^,]\+,', ',', 'g')
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
357 let accept_chars = substitute(accept_chars, ',\@<=[^,]\+-[^,]\+,', '', 'g')
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
358 " Remove all numeric specifications
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
359 " let accept_chars = substitute(accept_chars, ',\d\{-},', ',', 'g')
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
360 let accept_chars = substitute(accept_chars, ',\@<=\d\{-},', '', 'g')
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
361 " Remove all commas
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
362 let accept_chars = substitute(accept_chars, ',', '', 'g')
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
363 " Escape special regex characters
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
364 let accept_chars = escape(accept_chars, '\\/.*$^~[]' )
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
365 " Remove all characters that are not acceptable
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
366 let syn_list = substitute( syn_list, '[^0-9A-Za-z_ '.accept_chars.']', ' ', 'g' )
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
367 endif
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
368
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
369 if b:omni_syntax_minimum_length > 0
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
370 " If the user specified a minimum length, enforce it
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
371 let syn_list = substitute(' '.syn_list.' ', ' \S\{,'.b:omni_syntax_minimum_length.'}\ze ', ' ', 'g')
e63691e7c504 updated for version 7.1a
vimboss
parents: 871
diff changeset
372 endif
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
373 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
374 let syn_list = ''
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
375 endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
376
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
377 return syn_list
81fe2ccc1207 updated for version 7.0179
vimboss
parents:
diff changeset
378 endfunction