comparison runtime/autoload/syntaxcomplete.vim @ 24569:e3ec2ec8841a

Update runtime files Commit: https://github.com/vim/vim/commit/4c295027a426986566cd7a76c47a6d3a529727e7 Author: Bram Moolenaar <Bram@vim.org> Date: Sun May 2 17:19:11 2021 +0200 Update runtime files
author Bram Moolenaar <Bram@vim.org>
date Sun, 02 May 2021 17:30:05 +0200
parents ef454a7f485d
children
comparison
equal deleted inserted replaced
24568:3671ff322103 24569:e3ec2ec8841a
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 <dfishburn dot vim at gmail dot com> 3 " Maintainer: David Fishburn <dfishburn dot vim at gmail dot com>
4 " Version: 14.0 4 " Version: 15.0
5 " Last Change: 2020 Dec 30 5 " Last Change: 2021 Apr 27
6 " Usage: For detailed help, ":help ft-syntax-omni" 6 " Usage: For detailed help, ":help ft-syntax-omni"
7 7
8 " History 8 " History
9 "
10 " Version 15.0
11 " - SyntaxComplete ignored all buffer specific overrides, always used global
12 " https://github.com/vim/vim/issues/8153
9 " 13 "
10 " Version 14.0 14 " Version 14.0
11 " - Fixed issue with single quotes and is_keyword 15 " - Fixed issue with single quotes and is_keyword
12 " https://github.com/vim/vim/issues/7463 16 " https://github.com/vim/vim/issues/7463
13 " 17 "
40 " This introduces a new option, since the character ranges 44 " This introduces a new option, since the character ranges
41 " specified could be multibyte: 45 " specified could be multibyte:
42 " let g:omni_syntax_use_single_byte = 1 46 " let g:omni_syntax_use_single_byte = 1
43 " - This by default will only allow single byte ASCII 47 " - This by default will only allow single byte ASCII
44 " characters to be added and an additional check to ensure 48 " characters to be added and an additional check to ensure
45 " the charater is printable (see documentation for isprint). 49 " the character is printable (see documentation for isprint).
46 " 50 "
47 " Version 9.0 51 " Version 9.0
48 " - Add the check for cpo. 52 " - Add the check for cpo.
49 " 53 "
50 " Version 8.0 54 " Version 8.0
88 endif 92 endif
89 93
90 if exists('g:loaded_syntax_completion') 94 if exists('g:loaded_syntax_completion')
91 finish 95 finish
92 endif 96 endif
93 let g:loaded_syntax_completion = 130 97 let g:loaded_syntax_completion = 150
94 98
95 " Turn on support for line continuations when creating the script 99 " Turn on support for line continuations when creating the script
96 let s:cpo_save = &cpo 100 let s:cpo_save = &cpo
97 set cpo&vim 101 set cpo&vim
98 102
143 let s:prepended = '' 147 let s:prepended = ''
144 148
145 " This function is used for the 'omnifunc' option. 149 " This function is used for the 'omnifunc' option.
146 function! syntaxcomplete#Complete(findstart, base) 150 function! syntaxcomplete#Complete(findstart, base)
147 151
148 " Only display items in the completion window that are at least 152 " Allow user to override ignorecase per buffer
149 " this many characters in length 153 let l:omni_syntax_ignorecase = g:omni_syntax_ignorecase
150 if !exists('b:omni_syntax_ignorecase') 154 if exists('b:omni_syntax_ignorecase')
151 if exists('g:omni_syntax_ignorecase') 155 let l:omni_syntax_ignorecase = b:omni_syntax_ignorecase
152 let b:omni_syntax_ignorecase = g:omni_syntax_ignorecase
153 else
154 let b:omni_syntax_ignorecase = &ignorecase
155 endif
156 endif 156 endif
157 157
158 if a:findstart 158 if a:findstart
159 " Locate the start of the item, including "." 159 " Locate the start of the item, including "."
160 let line = getline('.') 160 let line = getline('.')
181 let s:prepended = strpart(line, start, (col('.') - 1) - start) 181 let s:prepended = strpart(line, start, (col('.') - 1) - start)
182 return start 182 return start
183 endif 183 endif
184 184
185 " let base = s:prepended . a:base 185 " let base = s:prepended . a:base
186 " let base = s:prepended
187 let base = substitute(s:prepended, "'", "''", 'g') 186 let base = substitute(s:prepended, "'", "''", 'g')
188 187
189 let filetype = substitute(&filetype, '\.', '_', 'g') 188 let filetype = substitute(&filetype, '\.', '_', 'g')
190 let list_idx = index(s:cache_name, filetype, 0, &ignorecase) 189 let list_idx = index(s:cache_name, filetype, 0, &ignorecase)
191 if list_idx > -1 190 if list_idx > -1
198 197
199 " Return list of matches. 198 " Return list of matches.
200 199
201 if base != '' 200 if base != ''
202 " let compstr = join(compl_list, ' ') 201 " let compstr = join(compl_list, ' ')
203 " let expr = (b:omni_syntax_ignorecase==0?'\C':'').'\<\%('.base.'\)\@!\w\+\s*' 202 " let expr = (l:omni_syntax_ignorecase==0?'\C':'').'\<\%('.base.'\)\@!\w\+\s*'
204 " let compstr = substitute(compstr, expr, '', 'g') 203 " let compstr = substitute(compstr, expr, '', 'g')
205 " let compl_list = split(compstr, '\s\+') 204 " let compl_list = split(compstr, '\s\+')
206 205
207 " Filter the list based on the first few characters the user 206 " Filter the list based on the first few characters the user
208 " entered 207 " entered
209 let expr = 'v:val '.(g:omni_syntax_ignorecase==1?'=~?':'=~#')." '^".escape(base, '\\/.*$^~[]').".*'" 208 let expr = 'v:val '.(l:omni_syntax_ignorecase==1?'=~?':'=~#')." '^".escape(base, '\\/.*$^~[]').".*'"
210 let compl_list = filter(deepcopy(compl_list), expr) 209 let compl_list = filter(deepcopy(compl_list), expr)
211 endif 210 endif
212 211
213 return compl_list 212 return compl_list
214 endfunc 213 endfunc
225 else 224 else
226 return OmniSyntaxList() 225 return OmniSyntaxList()
227 endif 226 endif
228 endfunc 227 endfunc
229 228
229 function! syntaxcomplete#OmniSyntaxClearCache()
230 let s:cache_name = []
231 let s:cache_list = []
232 endfunction
233
234 " To retrieve all syntax items regardless of syntax group:
235 " echo OmniSyntaxList( [] )
236 "
237 " To retrieve only the syntax items for the sqlOperator syntax group:
238 " echo OmniSyntaxList( ['sqlOperator'] )
239 "
240 " To retrieve all syntax items for both the sqlOperator and sqlType groups:
241 " echo OmniSyntaxList( ['sqlOperator', 'sqlType'] )
242 "
243 " A regular expression can also be used:
244 " echo OmniSyntaxList( ['sql\w\+'] )
245 "
246 " From within a plugin, you would typically assign the output to a List: >
247 " let myKeywords = []
248 " let myKeywords = OmniSyntaxList( ['sqlKeyword'] )
230 function! OmniSyntaxList(...) 249 function! OmniSyntaxList(...)
231 let list_parms = [] 250 let list_parms = []
232 if a:0 > 0 251 if a:0 > 0
233 if 3 == type(a:1) 252 if 3 == type(a:1)
234 let list_parms = a:1 253 let list_parms = a:1
242 " let use_dictionary = 1 261 " let use_dictionary = 1
243 " if a:0 > 0 && a:1 != '' 262 " if a:0 > 0 && a:1 != ''
244 " let use_dictionary = a:1 263 " let use_dictionary = a:1
245 " endif 264 " endif
246 265
247 " Only display items in the completion window that are at least
248 " this many characters in length
249 if !exists('b:omni_syntax_use_iskeyword')
250 if exists('g:omni_syntax_use_iskeyword')
251 let b:omni_syntax_use_iskeyword = g:omni_syntax_use_iskeyword
252 else
253 let b:omni_syntax_use_iskeyword = 1
254 endif
255 endif
256
257 " Only display items in the completion window that are at least
258 " this many characters in length
259 if !exists('b:omni_syntax_minimum_length')
260 if exists('g:omni_syntax_minimum_length')
261 let b:omni_syntax_minimum_length = g:omni_syntax_minimum_length
262 else
263 let b:omni_syntax_minimum_length = 0
264 endif
265 endif
266
267 let saveL = @l 266 let saveL = @l
268 let filetype = substitute(&filetype, '\.', '_', 'g') 267 let filetype = substitute(&filetype, '\.', '_', 'g')
269 268
270 if empty(list_parms) 269 if empty(list_parms)
270 " Allow user to override per buffer
271 if exists('g:omni_syntax_group_include_'.filetype)
272 let l:omni_syntax_group_include_{filetype} = g:omni_syntax_group_include_{filetype}
273 endif
274 if exists('b:omni_syntax_group_include_'.filetype)
275 let l:omni_syntax_group_include_{filetype} = b:omni_syntax_group_include_{filetype}
276 endif
277
271 " Default the include group to include the requested syntax group 278 " Default the include group to include the requested syntax group
272 let syntax_group_include_{filetype} = '' 279 let syntax_group_include_{filetype} = ''
273 " Check if there are any overrides specified for this filetype 280 " Check if there are any overrides specified for this filetype
274 if exists('g:omni_syntax_group_include_'.filetype) 281 if exists('l:omni_syntax_group_include_'.filetype)
275 let syntax_group_include_{filetype} = 282 let syntax_group_include_{filetype} =
276 \ substitute( g:omni_syntax_group_include_{filetype},'\s\+','','g') 283 \ substitute( l:omni_syntax_group_include_{filetype},'\s\+','','g')
277 let list_parms = split(g:omni_syntax_group_include_{filetype}, ',') 284 let list_parms = split(l:omni_syntax_group_include_{filetype}, ',')
278 if syntax_group_include_{filetype} =~ '\w' 285 if syntax_group_include_{filetype} =~ '\w'
279 let syntax_group_include_{filetype} = 286 let syntax_group_include_{filetype} =
280 \ substitute( syntax_group_include_{filetype}, 287 \ substitute( syntax_group_include_{filetype},
281 \ '\s*,\s*', '\\|', 'g' 288 \ '\s*,\s*', '\\|', 'g'
282 \ ) 289 \ )
327 if a:0 > 0 334 if a:0 > 0
328 " Do nothing since we have specific a specific list of groups 335 " Do nothing since we have specific a specific list of groups
329 else 336 else
330 " Default the exclude group to nothing 337 " Default the exclude group to nothing
331 let syntax_group_exclude_{filetype} = '' 338 let syntax_group_exclude_{filetype} = ''
339
340 " Allow user to override per buffer
341 if exists('g:omni_syntax_group_exclude_'.filetype)
342 let l:omni_syntax_group_exclude_{filetype} = g:omni_syntax_group_exclude_{filetype}
343 endif
344 if exists('b:omni_syntax_group_exclude_'.filetype)
345 let l:omni_syntax_group_exclude_{filetype} = b:omni_syntax_group_exclude_{filetype}
346 endif
347
332 " Check if there are any overrides specified for this filetype 348 " Check if there are any overrides specified for this filetype
333 if exists('g:omni_syntax_group_exclude_'.filetype) 349 if exists('l:omni_syntax_group_exclude_'.filetype)
334 let syntax_group_exclude_{filetype} = 350 let syntax_group_exclude_{filetype} =
335 \ substitute( g:omni_syntax_group_exclude_{filetype},'\s\+','','g') 351 \ substitute( l:omni_syntax_group_exclude_{filetype},'\s\+','','g')
336 let list_exclude_groups = split(g:omni_syntax_group_exclude_{filetype}, ',') 352 let list_exclude_groups = split(l:omni_syntax_group_exclude_{filetype}, ',')
337 if syntax_group_exclude_{filetype} =~ '\w' 353 if syntax_group_exclude_{filetype} =~ '\w'
338 let syntax_group_exclude_{filetype} = 354 let syntax_group_exclude_{filetype} =
339 \ substitute( syntax_group_exclude_{filetype}, 355 \ substitute( syntax_group_exclude_{filetype},
340 \ '\s*,\s*', '\\|', 'g' 356 \ '\s*,\s*', '\\|', 'g'
341 \ ) 357 \ )
526 return compl_list 542 return compl_list
527 endif 543 endif
528 endfunction 544 endfunction
529 545
530 function! s:SyntaxCSyntaxGroupItems( group_name, syntax_full ) 546 function! s:SyntaxCSyntaxGroupItems( group_name, syntax_full )
547
548 " Allow user to override iskeyword per buffer
549 let l:omni_syntax_use_iskeyword = g:omni_syntax_use_iskeyword
550 if exists('b:omni_syntax_use_iskeyword')
551 let l:omni_syntax_use_iskeyword = b:omni_syntax_use_iskeyword
552 endif
553
554 " Allow user to override iskeyword_numeric per buffer
555 let l:omni_syntax_use_iskeyword_numeric = g:omni_syntax_use_iskeyword_numeric
556 if exists('b:omni_syntax_use_iskeyword_numeric')
557 let l:omni_syntax_use_iskeyword_numeric = b:omni_syntax_use_iskeyword_numeric
558 endif
559
560 " Allow user to override iskeyword_numeric per buffer
561 let l:omni_syntax_use_single_byte = g:omni_syntax_use_single_byte
562 if exists('b:omni_syntax_use_single_byte')
563 let l:omni_syntax_use_single_byte = b:omni_syntax_use_single_byte
564 endif
565
566 " Allow user to override minimum_length per buffer
567 let l:omni_syntax_minimum_length = g:omni_syntax_minimum_length
568 if exists('b:omni_syntax_minimum_length')
569 let l:omni_syntax_minimum_length = b:omni_syntax_minimum_length
570 endif
531 571
532 let syn_list = "" 572 let syn_list = ""
533 573
534 " From the full syntax listing, strip out the portion for the 574 " From the full syntax listing, strip out the portion for the
535 " request group. 575 " request group.
645 " Now remove the remainder of the nextgroup=@someName lines 685 " Now remove the remainder of the nextgroup=@someName lines
646 let syn_list = substitute( 686 let syn_list = substitute(
647 \ syn_list, '\%(^\|\n\)\@<=\s*\(@\w\+\)' 687 \ syn_list, '\%(^\|\n\)\@<=\s*\(@\w\+\)'
648 \ , "", 'g' 688 \ , "", 'g'
649 \ ) 689 \ )
650 690
651 if b:omni_syntax_use_iskeyword == 0 691 if l:omni_syntax_use_iskeyword == 0
652 " There are a number of items which have non-word characters in 692 " There are a number of items which have non-word characters in
653 " them, *'T_F1'*. vim.vim is one such file. 693 " them, *'T_F1'*. vim.vim is one such file.
654 " This will replace non-word characters with spaces. 694 " This will replace non-word characters with spaces.
695 " setlocal filetype=forth
696 " let g:omni_syntax_use_iskeyword = 1
697 " let g:omni_syntax_use_iskeyword_numeric = 1
698 " You will see entries like
699 " #>>
700 " (.local)
701 " These were found doing a grep in vim82\syntax
702 " grep iskeyword *
703 " forth.vim:setlocal iskeyword=!,@,33-35,%,$,38-64,A-Z,91-96,a-z,123-126,128-255
655 let syn_list = substitute( syn_list, '[^0-9A-Za-z_ ]', ' ', 'g' ) 704 let syn_list = substitute( syn_list, '[^0-9A-Za-z_ ]', ' ', 'g' )
656 else 705 else
657 if g:omni_syntax_use_iskeyword_numeric == 1 706 if l:omni_syntax_use_iskeyword_numeric == 1
658 " iskeyword can contain value like this 707 " iskeyword can contain value like this
659 " 38,42,43,45,47-58,60-62,64-90,97-122,_,+,-,*,/,%,<,=,>,:,$,?,!,@-@,94 708 " 38,42,43,45,47-58,60-62,64-90,97-122,_,+,-,*,/,%,<,=,>,:,$,?,!,@-@,94
660 " Numeric values convert to their ASCII equivalent using the 709 " Numeric values convert to their ASCII equivalent using the
661 " nr2char() function. 710 " nr2char() function.
662 " & 38 711 " & 38
672 if item =~ '\d-\d' 721 if item =~ '\d-\d'
673 " This is a character range (ie 47-58), 722 " This is a character range (ie 47-58),
674 " cycle through each character within the range 723 " cycle through each character within the range
675 let [b:start, b:end] = split(item, '-') 724 let [b:start, b:end] = split(item, '-')
676 for range_item in range( b:start, b:end ) 725 for range_item in range( b:start, b:end )
677 if range_item <= 127 || g:omni_syntax_use_single_byte == 0 726 if range_item <= 127 || l:omni_syntax_use_single_byte == 0
678 if nr2char(range_item) =~ '\p' 727 if nr2char(range_item) =~ '\p'
679 let accepted_chars = accepted_chars . nr2char(range_item) 728 let accepted_chars = accepted_chars . nr2char(range_item)
680 endif 729 endif
681 endif 730 endif
682 endfor 731 endfor
683 elseif item =~ '^\d\+$' 732 elseif item =~ '^\d\+$'
684 " Only numeric, translate to a character 733 " Only numeric, translate to a character
685 if item < 127 || g:omni_syntax_use_single_byte == 0 734 if item < 127 || l:omni_syntax_use_single_byte == 0
686 if nr2char(item) =~ '\p' 735 if nr2char(item) =~ '\p'
687 let accepted_chars = accepted_chars . nr2char(item) 736 let accepted_chars = accepted_chars . nr2char(item)
688 endif 737 endif
689 endif 738 endif
690 else 739 else
691 if char2nr(item) < 127 || g:omni_syntax_use_single_byte == 0 740 if char2nr(item) < 127 || l:omni_syntax_use_single_byte == 0
692 if item =~ '\p' 741 if item =~ '\p'
693 let accepted_chars = accepted_chars . item 742 let accepted_chars = accepted_chars . item
694 endif 743 endif
695 endif 744 endif
696 endif 745 endif
722 " Remove all characters that are not acceptable 771 " Remove all characters that are not acceptable
723 let syn_list = substitute( syn_list, '[^0-9A-Za-z_'.accept_chars.']', ' ', 'g' ) 772 let syn_list = substitute( syn_list, '[^0-9A-Za-z_'.accept_chars.']', ' ', 'g' )
724 endif 773 endif
725 endif 774 endif
726 775
727 if b:omni_syntax_minimum_length > 0 776 if l:omni_syntax_minimum_length > 0
728 " If the user specified a minimum length, enforce it 777 " If the user specified a minimum length, enforce it
729 let syn_list = substitute(' '.syn_list.' ', ' \S\{,'.b:omni_syntax_minimum_length.'}\ze ', ' ', 'g') 778 let syn_list = substitute(' '.syn_list.' ', ' \S\{,'.l:omni_syntax_minimum_length.'}\ze ', ' ', 'g')
730 endif 779 endif
731 else 780 else
732 let syn_list = '' 781 let syn_list = ''
733 endif 782 endif
734 783
754 endif 803 endif
755 endif 804 endif
756 endfor 805 endfor
757 return join(map(result, 'nr2char(v:val)'), ', ') 806 return join(map(result, 'nr2char(v:val)'), ', ')
758 endfunction 807 endfunction
808
759 let &cpo = s:cpo_save 809 let &cpo = s:cpo_save
760 unlet s:cpo_save 810 unlet s:cpo_save