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