syntaxcomplete.vim 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  1. " Vim completion script
  2. " Language: All languages, uses existing syntax highlighting rules
  3. " Maintainer: David Fishburn <dfishburn dot vim at gmail dot com>
  4. " Version: 15.0
  5. " Last Change: 2021 Apr 27
  6. " Usage: For detailed help, ":help ft-syntax-omni"
  7. " History
  8. "
  9. " Version 15.0
  10. " - SyntaxComplete ignored all buffer specific overrides, always used global
  11. " https://github.com/vim/vim/issues/8153
  12. "
  13. " Version 14.0
  14. " - Fixed issue with single quotes and is_keyword
  15. " https://github.com/vim/vim/issues/7463
  16. "
  17. " Version 13.0
  18. " - Extended the option omni_syntax_group_include_{filetype}
  19. " to accept a comma separated list of regex's rather than
  20. " string. For example, for the javascript filetype you could
  21. " use:
  22. " let g:omni_syntax_group_include_javascript = 'javascript\w\+,jquery\w\+'
  23. " - Some syntax files (perl.vim) use the match // syntax as a mechanism
  24. " to identify keywords. This update attempts to parse the
  25. " match syntax and pull out syntax items which are at least
  26. " 3 words or more.
  27. "
  28. " Version 12.0
  29. " - It is possible to have '-' as part of iskeyword, when
  30. " checking for character ranges, tighten up the regex.
  31. " E688: More targets than List items.
  32. "
  33. " Version 11.0
  34. " - Corrected which characters required escaping during
  35. " substitution calls.
  36. "
  37. " Version 10.0
  38. " - Cycle through all the character ranges specified in the
  39. " iskeyword option and build a list of valid word separators.
  40. " Prior to this change, only actual characters were used,
  41. " where for example ASCII "45" == "-". If "45" were used
  42. " in iskeyword the hyphen would not be picked up.
  43. " This introduces a new option, since the character ranges
  44. " specified could be multibyte:
  45. " let g:omni_syntax_use_single_byte = 1
  46. " - This by default will only allow single byte ASCII
  47. " characters to be added and an additional check to ensure
  48. " the character is printable (see documentation for isprint).
  49. "
  50. " Version 9.0
  51. " - Add the check for cpo.
  52. "
  53. " Version 8.0
  54. " - Updated SyntaxCSyntaxGroupItems()
  55. " - Some additional syntax items were also allowed
  56. " on nextgroup= lines which were ignored by default.
  57. " Now these lines are processed independently.
  58. "
  59. " Version 7.0
  60. " - Updated syntaxcomplete#OmniSyntaxList()
  61. " - Looking up the syntax groups defined from a syntax file
  62. " looked for only 1 format of {filetype}GroupName, but some
  63. " syntax writers use this format as well:
  64. " {b:current_syntax}GroupName
  65. " - OmniSyntaxList() will now check for both if the first
  66. " method does not find a match.
  67. "
  68. " Version 6.0
  69. " - Added syntaxcomplete#OmniSyntaxList()
  70. " - Allows other plugins to use this for their own
  71. " purposes.
  72. " - It will return a List of all syntax items for the
  73. " syntax group name passed in.
  74. " - XPTemplate for SQL will use this function via the
  75. " sqlcomplete plugin to populate a Choose box.
  76. "
  77. " Version 5.0
  78. " - Updated SyntaxCSyntaxGroupItems()
  79. " - When processing a list of syntax groups, the final group
  80. " was missed in function SyntaxCSyntaxGroupItems.
  81. "
  82. " Set completion with CTRL-X CTRL-O to autoloaded function.
  83. " This check is in place in case this script is
  84. " sourced directly instead of using the autoload feature.
  85. if exists('+omnifunc')
  86. " Do not set the option if already set since this
  87. " results in an E117 warning.
  88. if &omnifunc == ""
  89. setlocal omnifunc=syntaxcomplete#Complete
  90. endif
  91. endif
  92. if exists('g:loaded_syntax_completion')
  93. finish
  94. endif
  95. let g:loaded_syntax_completion = 150
  96. " Turn on support for line continuations when creating the script
  97. let s:cpo_save = &cpo
  98. set cpo&vim
  99. " Set ignorecase to the ftplugin standard
  100. " This is the default setting, but if you define a buffer local
  101. " variable you can override this on a per filetype.
  102. if !exists('g:omni_syntax_ignorecase')
  103. let g:omni_syntax_ignorecase = &ignorecase
  104. endif
  105. " Indicates whether we should use the iskeyword option to determine
  106. " how to split words.
  107. " This is the default setting, but if you define a buffer local
  108. " variable you can override this on a per filetype.
  109. if !exists('g:omni_syntax_use_iskeyword')
  110. let g:omni_syntax_use_iskeyword = 1
  111. endif
  112. " When using iskeyword, this setting controls whether the characters
  113. " should be limited to single byte characters.
  114. if !exists('g:omni_syntax_use_single_byte')
  115. let g:omni_syntax_use_single_byte = 1
  116. endif
  117. " When using iskeyword, this setting controls whether the characters
  118. " should be limited to single byte characters.
  119. if !exists('g:omni_syntax_use_iskeyword_numeric')
  120. let g:omni_syntax_use_iskeyword_numeric = 1
  121. endif
  122. " Only display items in the completion window that are at least
  123. " this many characters in length.
  124. " This is the default setting, but if you define a buffer local
  125. " variable you can override this on a per filetype.
  126. if !exists('g:omni_syntax_minimum_length')
  127. let g:omni_syntax_minimum_length = 0
  128. endif
  129. " This script will build a completion list based on the syntax
  130. " elements defined by the files in $VIMRUNTIME/syntax.
  131. " let s:syn_remove_words = 'match,matchgroup=,contains,'.
  132. let s:syn_remove_words = 'matchgroup=,contains,'.
  133. \ 'links to,start=,end='
  134. " \ 'links to,start=,end=,nextgroup='
  135. let s:cache_name = []
  136. let s:cache_list = []
  137. let s:prepended = ''
  138. " This function is used for the 'omnifunc' option.
  139. function! syntaxcomplete#Complete(findstart, base)
  140. " Allow user to override ignorecase per buffer
  141. let l:omni_syntax_ignorecase = g:omni_syntax_ignorecase
  142. if exists('b:omni_syntax_ignorecase')
  143. let l:omni_syntax_ignorecase = b:omni_syntax_ignorecase
  144. endif
  145. if a:findstart
  146. " Locate the start of the item, including "."
  147. let line = getline('.')
  148. let start = col('.') - 1
  149. let lastword = -1
  150. while start > 0
  151. " if line[start - 1] =~ '\S'
  152. " let start -= 1
  153. " elseif line[start - 1] =~ '\.'
  154. if line[start - 1] =~ '\k'
  155. let start -= 1
  156. let lastword = a:findstart
  157. else
  158. break
  159. endif
  160. endwhile
  161. " Return the column of the last word, which is going to be changed.
  162. " Remember the text that comes before it in s:prepended.
  163. if lastword == -1
  164. let s:prepended = ''
  165. return start
  166. endif
  167. let s:prepended = strpart(line, start, (col('.') - 1) - start)
  168. return start
  169. endif
  170. " let base = s:prepended . a:base
  171. let base = substitute(s:prepended, "'", "''", 'g')
  172. let filetype = substitute(&filetype, '\.', '_', 'g')
  173. let list_idx = index(s:cache_name, filetype, 0, &ignorecase)
  174. if list_idx > -1
  175. let compl_list = s:cache_list[list_idx]
  176. else
  177. let compl_list = OmniSyntaxList()
  178. let s:cache_name = add( s:cache_name, filetype )
  179. let s:cache_list = add( s:cache_list, compl_list )
  180. endif
  181. " Return list of matches.
  182. if base != ''
  183. " let compstr = join(compl_list, ' ')
  184. " let expr = (l:omni_syntax_ignorecase==0?'\C':'').'\<\%('.base.'\)\@!\w\+\s*'
  185. " let compstr = substitute(compstr, expr, '', 'g')
  186. " let compl_list = split(compstr, '\s\+')
  187. " Filter the list based on the first few characters the user
  188. " entered
  189. let expr = 'v:val '.(l:omni_syntax_ignorecase==1?'=~?':'=~#')." '^".escape(base, '\\/.*$^~[]').".*'"
  190. let compl_list = filter(deepcopy(compl_list), expr)
  191. endif
  192. return compl_list
  193. endfunc
  194. function! syntaxcomplete#OmniSyntaxList(...)
  195. if a:0 > 0
  196. let parms = []
  197. if 3 == type(a:1)
  198. let parms = a:1
  199. elseif 1 == type(a:1)
  200. let parms = split(a:1, ',')
  201. endif
  202. return OmniSyntaxList( parms )
  203. else
  204. return OmniSyntaxList()
  205. endif
  206. endfunc
  207. function! syntaxcomplete#OmniSyntaxClearCache()
  208. let s:cache_name = []
  209. let s:cache_list = []
  210. endfunction
  211. " To retrieve all syntax items regardless of syntax group:
  212. " echo OmniSyntaxList( [] )
  213. "
  214. " To retrieve only the syntax items for the sqlOperator syntax group:
  215. " echo OmniSyntaxList( ['sqlOperator'] )
  216. "
  217. " To retrieve all syntax items for both the sqlOperator and sqlType groups:
  218. " echo OmniSyntaxList( ['sqlOperator', 'sqlType'] )
  219. "
  220. " A regular expression can also be used:
  221. " echo OmniSyntaxList( ['sql\w\+'] )
  222. "
  223. " From within a plugin, you would typically assign the output to a List: >
  224. " let myKeywords = []
  225. " let myKeywords = OmniSyntaxList( ['sqlKeyword'] )
  226. function! OmniSyntaxList(...)
  227. let list_parms = []
  228. if a:0 > 0
  229. if 3 == type(a:1)
  230. let list_parms = a:1
  231. elseif 1 == type(a:1)
  232. let list_parms = split(a:1, ',')
  233. endif
  234. endif
  235. " Default to returning a dictionary, if use_dictionary is set to 0
  236. " a list will be returned.
  237. " let use_dictionary = 1
  238. " if a:0 > 0 && a:1 != ''
  239. " let use_dictionary = a:1
  240. " endif
  241. let saveL = @l
  242. let filetype = substitute(&filetype, '\.', '_', 'g')
  243. if empty(list_parms)
  244. " Allow user to override per buffer
  245. if exists('g:omni_syntax_group_include_'.filetype)
  246. let l:omni_syntax_group_include_{filetype} = g:omni_syntax_group_include_{filetype}
  247. endif
  248. if exists('b:omni_syntax_group_include_'.filetype)
  249. let l:omni_syntax_group_include_{filetype} = b:omni_syntax_group_include_{filetype}
  250. endif
  251. " Default the include group to include the requested syntax group
  252. let syntax_group_include_{filetype} = ''
  253. " Check if there are any overrides specified for this filetype
  254. if exists('l:omni_syntax_group_include_'.filetype)
  255. let syntax_group_include_{filetype} =
  256. \ substitute( l:omni_syntax_group_include_{filetype},'\s\+','','g')
  257. let list_parms = split(l:omni_syntax_group_include_{filetype}, ',')
  258. if syntax_group_include_{filetype} =~ '\w'
  259. let syntax_group_include_{filetype} =
  260. \ substitute( syntax_group_include_{filetype},
  261. \ '\s*,\s*', '\\|', 'g'
  262. \ )
  263. endif
  264. endif
  265. else
  266. " A specific list was provided, use it
  267. endif
  268. " Loop through all the syntax groupnames, and build a
  269. " syntax file which contains these names. This can
  270. " work generically for any filetype that does not already
  271. " have a plugin defined.
  272. " This ASSUMES the syntax groupname BEGINS with the name
  273. " of the filetype. From my casual viewing of the vim7\syntax
  274. " directory this is true for almost all syntax definitions.
  275. " As an example, the SQL syntax groups have this pattern:
  276. " sqlType
  277. " sqlOperators
  278. " sqlKeyword ...
  279. if !empty(list_parms) && empty(substitute(join(list_parms), '[a-zA-Z ]', '', 'g'))
  280. " If list_parms only includes word characters, use it to limit
  281. " the syntax elements.
  282. " If using regex syntax list will fail to find those items, so
  283. " simply grab the who syntax list.
  284. redir @l
  285. silent! exec 'syntax list '.join(list_parms)
  286. redir END
  287. else
  288. redir @l
  289. silent! exec 'syntax list'
  290. redir END
  291. endif
  292. let syntax_full = "\n".@l
  293. let @l = saveL
  294. if syntax_full =~ 'E28'
  295. \ || syntax_full =~ 'E411'
  296. \ || syntax_full =~ 'E415'
  297. \ || syntax_full =~ 'No Syntax items'
  298. return []
  299. endif
  300. let filetype = substitute(&filetype, '\.', '_', 'g')
  301. let list_exclude_groups = []
  302. if a:0 > 0
  303. " Do nothing since we have specific a specific list of groups
  304. else
  305. " Default the exclude group to nothing
  306. let syntax_group_exclude_{filetype} = ''
  307. " Allow user to override per buffer
  308. if exists('g:omni_syntax_group_exclude_'.filetype)
  309. let l:omni_syntax_group_exclude_{filetype} = g:omni_syntax_group_exclude_{filetype}
  310. endif
  311. if exists('b:omni_syntax_group_exclude_'.filetype)
  312. let l:omni_syntax_group_exclude_{filetype} = b:omni_syntax_group_exclude_{filetype}
  313. endif
  314. " Check if there are any overrides specified for this filetype
  315. if exists('l:omni_syntax_group_exclude_'.filetype)
  316. let syntax_group_exclude_{filetype} =
  317. \ substitute( l:omni_syntax_group_exclude_{filetype},'\s\+','','g')
  318. let list_exclude_groups = split(l:omni_syntax_group_exclude_{filetype}, ',')
  319. if syntax_group_exclude_{filetype} =~ '\w'
  320. let syntax_group_exclude_{filetype} =
  321. \ substitute( syntax_group_exclude_{filetype},
  322. \ '\s*,\s*', '\\|', 'g'
  323. \ )
  324. endif
  325. endif
  326. endif
  327. if empty(list_parms)
  328. let list_parms = [&filetype.'\w\+']
  329. endif
  330. let syn_list = ''
  331. let index = 0
  332. for group_regex in list_parms
  333. " Sometimes filetypes can be composite names, like c.doxygen
  334. " Loop through each individual part looking for the syntax
  335. " items specific to each individual filetype.
  336. " let ftindex = 0
  337. " let ftindex = match(syntax_full, group_regex, ftindex)
  338. " while ftindex > -1
  339. " let ft_part_name = matchstr( syntax_full, '\w\+', ftindex )
  340. " Syntax rules can contain items for more than just the current
  341. " filetype. They can contain additional items added by the user
  342. " via autocmds or their vimrc.
  343. " Some syntax files can be combined (html, php, jsp).
  344. " We want only items that begin with the filetype we are interested in.
  345. let next_group_regex = '\n' .
  346. \ '\zs'.group_regex.'\ze'.
  347. \ '\s\+xxx\s\+'
  348. let index = match(syntax_full, next_group_regex, index)
  349. " For the matched group name, strip off any of the regex special
  350. " characters and see if we get a match with the current syntax
  351. if index == -1 && exists('b:current_syntax') && substitute(group_regex, '[^a-zA-Z ]\+.*', '', 'g') !~ '^'.b:current_syntax
  352. " There appears to be two standards when writing syntax files.
  353. " Either items begin as:
  354. " syn keyword {filetype}Keyword values ...
  355. " let b:current_syntax = "sql"
  356. " let b:current_syntax = "sqlanywhere"
  357. " Or
  358. " syn keyword {syntax_filename}Keyword values ...
  359. " let b:current_syntax = "mysql"
  360. " So, we will make the format of finding the syntax group names
  361. " a bit more flexible and look for both if the first fails to
  362. " find a match.
  363. let next_group_regex = '\n' .
  364. \ '\zs'.b:current_syntax.'\w\+\ze'.
  365. \ '\s\+xxx\s\+'
  366. let index = 0
  367. let index = match(syntax_full, next_group_regex, index)
  368. endif
  369. while index > -1
  370. let group_name = matchstr( syntax_full, '\w\+', index )
  371. let get_syn_list = 1
  372. for exclude_group_name in list_exclude_groups
  373. if '\<'.exclude_group_name.'\>' =~ '\<'.group_name.'\>'
  374. let get_syn_list = 0
  375. endif
  376. endfor
  377. " This code is no longer needed in version 6.0 since we have
  378. " augmented the syntax list command to only retrieve the syntax
  379. " groups we are interested in.
  380. "
  381. " if get_syn_list == 1
  382. " if syntax_group_include_{filetype} != ''
  383. " if '\<'.syntax_group_include_{filetype}.'\>' !~ '\<'.group_name.'\>'
  384. " let get_syn_list = 0
  385. " endif
  386. " endif
  387. " endif
  388. if get_syn_list == 1
  389. " Pass in the full syntax listing, plus the group name we
  390. " are interested in.
  391. let extra_syn_list = s:SyntaxCSyntaxGroupItems(group_name, syntax_full)
  392. let syn_list = syn_list . extra_syn_list . "\n"
  393. endif
  394. let index = index + strlen(group_name)
  395. let index = match(syntax_full, next_group_regex, index)
  396. endwhile
  397. " let ftindex = ftindex + len(ft_part_name)
  398. " let ftindex = match( syntax_full, group_regex, ftindex )
  399. " endwhile
  400. endfor
  401. " " Sometimes filetypes can be composite names, like c.doxygen
  402. " " Loop through each individual part looking for the syntax
  403. " " items specific to each individual filetype.
  404. " let syn_list = ''
  405. " let ftindex = 0
  406. " let ftindex = match(&filetype, '\w\+', ftindex)
  407. " while ftindex > -1
  408. " let ft_part_name = matchstr( &filetype, '\w\+', ftindex )
  409. " " Syntax rules can contain items for more than just the current
  410. " " filetype. They can contain additional items added by the user
  411. " " via autocmds or their vimrc.
  412. " " Some syntax files can be combined (html, php, jsp).
  413. " " We want only items that begin with the filetype we are interested in.
  414. " let next_group_regex = '\n' .
  415. " \ '\zs'.ft_part_name.'\w\+\ze'.
  416. " \ '\s\+xxx\s\+'
  417. " let index = 0
  418. " let index = match(syntax_full, next_group_regex, index)
  419. " if index == -1 && exists('b:current_syntax') && ft_part_name != b:current_syntax
  420. " " There appears to be two standards when writing syntax files.
  421. " " Either items begin as:
  422. " " syn keyword {filetype}Keyword values ...
  423. " " let b:current_syntax = "sql"
  424. " " let b:current_syntax = "sqlanywhere"
  425. " " Or
  426. " " syn keyword {syntax_filename}Keyword values ...
  427. " " let b:current_syntax = "mysql"
  428. " " So, we will make the format of finding the syntax group names
  429. " " a bit more flexible and look for both if the first fails to
  430. " " find a match.
  431. " let next_group_regex = '\n' .
  432. " \ '\zs'.b:current_syntax.'\w\+\ze'.
  433. " \ '\s\+xxx\s\+'
  434. " let index = 0
  435. " let index = match(syntax_full, next_group_regex, index)
  436. " endif
  437. " while index > -1
  438. " let group_name = matchstr( syntax_full, '\w\+', index )
  439. " let get_syn_list = 1
  440. " for exclude_group_name in list_exclude_groups
  441. " if '\<'.exclude_group_name.'\>' =~ '\<'.group_name.'\>'
  442. " let get_syn_list = 0
  443. " endif
  444. " endfor
  445. " " This code is no longer needed in version 6.0 since we have
  446. " " augmented the syntax list command to only retrieve the syntax
  447. " " groups we are interested in.
  448. " "
  449. " " if get_syn_list == 1
  450. " " if syntax_group_include_{filetype} != ''
  451. " " if '\<'.syntax_group_include_{filetype}.'\>' !~ '\<'.group_name.'\>'
  452. " " let get_syn_list = 0
  453. " " endif
  454. " " endif
  455. " " endif
  456. " if get_syn_list == 1
  457. " " Pass in the full syntax listing, plus the group name we
  458. " " are interested in.
  459. " let extra_syn_list = s:SyntaxCSyntaxGroupItems(group_name, syntax_full)
  460. " let syn_list = syn_list . extra_syn_list . "\n"
  461. " endif
  462. " let index = index + strlen(group_name)
  463. " let index = match(syntax_full, next_group_regex, index)
  464. " endwhile
  465. " let ftindex = ftindex + len(ft_part_name)
  466. " let ftindex = match( &filetype, '\w\+', ftindex )
  467. " endwhile
  468. " Convert the string to a List and sort it.
  469. let compl_list = sort(split(syn_list))
  470. if &filetype == 'vim'
  471. let short_compl_list = []
  472. for i in range(len(compl_list))
  473. if i == len(compl_list)-1
  474. let next = i
  475. else
  476. let next = i + 1
  477. endif
  478. if compl_list[next] !~ '^'.compl_list[i].'.$'
  479. let short_compl_list += [compl_list[i]]
  480. endif
  481. endfor
  482. return short_compl_list
  483. else
  484. return compl_list
  485. endif
  486. endfunction
  487. function! s:SyntaxCSyntaxGroupItems( group_name, syntax_full )
  488. " Allow user to override iskeyword per buffer
  489. let l:omni_syntax_use_iskeyword = g:omni_syntax_use_iskeyword
  490. if exists('b:omni_syntax_use_iskeyword')
  491. let l:omni_syntax_use_iskeyword = b:omni_syntax_use_iskeyword
  492. endif
  493. " Allow user to override iskeyword_numeric per buffer
  494. let l:omni_syntax_use_iskeyword_numeric = g:omni_syntax_use_iskeyword_numeric
  495. if exists('b:omni_syntax_use_iskeyword_numeric')
  496. let l:omni_syntax_use_iskeyword_numeric = b:omni_syntax_use_iskeyword_numeric
  497. endif
  498. " Allow user to override iskeyword_numeric per buffer
  499. let l:omni_syntax_use_single_byte = g:omni_syntax_use_single_byte
  500. if exists('b:omni_syntax_use_single_byte')
  501. let l:omni_syntax_use_single_byte = b:omni_syntax_use_single_byte
  502. endif
  503. " Allow user to override minimum_length per buffer
  504. let l:omni_syntax_minimum_length = g:omni_syntax_minimum_length
  505. if exists('b:omni_syntax_minimum_length')
  506. let l:omni_syntax_minimum_length = b:omni_syntax_minimum_length
  507. endif
  508. let syn_list = ""
  509. " From the full syntax listing, strip out the portion for the
  510. " request group.
  511. " Query:
  512. " \n - must begin with a newline
  513. " a:group_name - the group name we are interested in
  514. " \s\+xxx\s\+ - group names are always followed by xxx
  515. " \zs - start the match
  516. " .\{-} - everything ...
  517. " \ze - end the match
  518. " \( - start a group or 2 potential matches
  519. " \n\w - at the first newline starting with a character
  520. " \| - 2nd potential match
  521. " \%$ - matches end of the file or string
  522. " \) - end a group
  523. let syntax_group = matchstr(a:syntax_full,
  524. \ "\n".a:group_name.'\s\+xxx\s\+\zs.\{-}\ze\(\n\w\|\%$\)'
  525. \ )
  526. if syntax_group != ""
  527. " let syn_list = substitute( @l, '^.*xxx\s*\%(contained\s*\)\?', "", '' )
  528. " let syn_list = substitute( @l, '^.*xxx\s*', "", '' )
  529. " We only want the words for the lines beginning with
  530. " containedin, but there could be other items.
  531. " Tried to remove all lines that do not begin with contained
  532. " but this does not work in all cases since you can have
  533. " contained nextgroup=...
  534. " So this will strip off the ending of lines with known
  535. " keywords.
  536. let syn_list = substitute(
  537. \ syntax_group, '\<\('.
  538. \ substitute(
  539. \ escape(s:syn_remove_words, '\\/.*$^~[]')
  540. \ , ',', '\\|', 'g'
  541. \ ).
  542. \ '\).\{-}\%($\|'."\n".'\)'
  543. \ , "\n", 'g'
  544. \ )
  545. " Attempt to deal with lines using the match syntax
  546. " javaScriptDocTags xxx match /@\(param\|argument\|requires\|file\)\>/
  547. " Though it can use any types of regex, so this plugin will attempt
  548. " to restrict it
  549. " 1. Only use \( or \%( constructs remove all else
  550. " 2 Remove and []s
  551. " 3. Account for match //constructs
  552. " \%(\%(ms\|me\|hs\|he\|rs\|re\|lc\)\S\+\)\?
  553. " 4. Hope for the best
  554. "
  555. "
  556. let syn_list_old = syn_list
  557. while syn_list =~ '\<match\>\s\+\/'
  558. if syn_list =~ 'perlElseIfError'
  559. let syn_list = syn_list
  560. endif
  561. " Check if the match has words at least 3 characters long
  562. if syn_list =~ '\<match \/\zs.\{-}\<\w\{3,}\>.\{-}\ze\\\@<!\/\%(\%(ms\|me\|hs\|he\|rs\|re\|lc\)\S\+\)\?\s\+'
  563. " Remove everything after / and before the first \(
  564. let syn_list = substitute( syn_list, '\<match \/\zs.\{-}\ze\\%\?(.\{-}\\\@<!\/\%(\%(ms\|me\|hs\|he\|rs\|re\|lc\)\S\+\)\?\s\+', '', 'g' )
  565. " Remove everything after \) and up to the ending /
  566. let syn_list = substitute( syn_list, '\<match \/.\{-}\\)\zs.\{-}\ze\/\%(\%(ms\|me\|hs\|he\|rs\|re\|lc\)\S\+\)\?\s\+', '', 'g' )
  567. " Remove any character classes
  568. " let syn_list = substitute( syn_list, '\<match /\zs.\{-}\[[^]]*\].\{-}\ze\/ ', '', 'g' )
  569. let syn_list = substitute( syn_list, '\%(\<match \/[^/]\{-}\)\@<=\[[^]]*\]\ze.\{-}\\\@<!\/\%(\%(ms\|me\|hs\|he\|rs\|re\|lc\)\S\+\)\?', '', 'g' )
  570. " Remove any words < 3 characters
  571. let syn_list = substitute( syn_list, '\%(\<match \/[^/]\{-}\)\@<=\<\w\{1,2}\>\ze.\{-}\\\@<!\/\%(\%(ms\|me\|hs\|he\|rs\|re\|lc\)\S\+\)\?\s\+', '', 'g' )
  572. " Remove all non-word characters
  573. " let syn_list = substitute( syn_list, '\<match /\zs.\{-}\<\W\+\>.\{-}\ze\/ ', "", 'g' )
  574. " let syn_list = substitute( syn_list, '\%(\<match \/[^/]\{-}\)\@<=\W\+\ze.\{-}\/ ', ' ', 'g' )
  575. " Do this by using the outer substitute() call to gather all
  576. " text between the match /.../ tags.
  577. " The inner substitute() call operates on the text selected
  578. " and replaces all non-word characters.
  579. let syn_list = substitute( syn_list, '\<match \/\zs\(.\{-}\)\ze\\\@<!\/\%(\%(ms\|me\|hs\|he\|rs\|re\|lc\)\S\+\)\?\s\+'
  580. \ , '\=substitute(submatch(1), "\\W\\+", " ", "g")'
  581. \ , 'g' )
  582. " Remove the match / / syntax
  583. let syn_list = substitute( syn_list, '\<match \/\(.\{-}\)\/\%(\%(ms\|me\|hs\|he\|rs\|re\|lc\)\S\+\)\?\s\+', '\1', 'g' )
  584. else
  585. " No words long enough, remove the match
  586. " Remove the match syntax
  587. " let syn_list = substitute( syn_list, '\<match \/[^\/]*\/\%(\%(ms\|me\|hs\|he\|rs\|re\|lc\)\S\+\)\?\s\+', '', 'g' )
  588. let syn_list = substitute( syn_list, '\<match \/\%(.\{-}\)\?\/\%(\%(ms\|me\|hs\|he\|rs\|re\|lc\)\S\+\)\?\s\+', '', 'g' )
  589. endif
  590. if syn_list =~ '\<match\>\s\+\/'
  591. " Problem removing the match / / tags
  592. let syn_list = ''
  593. endif
  594. endwhile
  595. " Now strip off the newline + blank space + contained.
  596. " Also include lines with nextgroup=@someName skip_key_words syntax_element
  597. " \ syn_list, '\%(^\|\n\)\@<=\s*\<\(contained\|nextgroup=\)'
  598. " \ syn_list, '\%(^\|\n\)\@<=\s*\<\(contained\|nextgroup=[@a-zA-Z,]*\)'
  599. let syn_list = substitute(
  600. \ syn_list, '\<\(contained\|nextgroup=[@a-zA-Z,]*\)'
  601. \ , "", 'g'
  602. \ )
  603. " This can leave lines like this
  604. " =@vimMenuList skipwhite onoremenu
  605. " Strip the special option keywords first
  606. " :h :syn-skipwhite*
  607. let syn_list = substitute(
  608. \ syn_list, '\<\(skipwhite\|skipnl\|skipempty\)\>'
  609. \ , "", 'g'
  610. \ )
  611. " Now remove the remainder of the nextgroup=@someName lines
  612. let syn_list = substitute(
  613. \ syn_list, '\%(^\|\n\)\@<=\s*\(@\w\+\)'
  614. \ , "", 'g'
  615. \ )
  616. if l:omni_syntax_use_iskeyword == 0
  617. " There are a number of items which have non-word characters in
  618. " them, *'T_F1'*. vim.vim is one such file.
  619. " This will replace non-word characters with spaces.
  620. " setlocal filetype=forth
  621. " let g:omni_syntax_use_iskeyword = 1
  622. " let g:omni_syntax_use_iskeyword_numeric = 1
  623. " You will see entries like
  624. " #>>
  625. " (.local)
  626. " These were found doing a grep in vim82\syntax
  627. " grep iskeyword *
  628. " forth.vim:setlocal iskeyword=!,@,33-35,%,$,38-64,A-Z,91-96,a-z,123-126,128-255
  629. let syn_list = substitute( syn_list, '[^0-9A-Za-z_ ]', ' ', 'g' )
  630. else
  631. if l:omni_syntax_use_iskeyword_numeric == 1
  632. " iskeyword can contain value like this
  633. " 38,42,43,45,47-58,60-62,64-90,97-122,_,+,-,*,/,%,<,=,>,:,$,?,!,@-@,94
  634. " Numeric values convert to their ASCII equivalent using the
  635. " nr2char() function.
  636. " & 38
  637. " * 42
  638. " + 43
  639. " - 45
  640. " ^ 94
  641. " Iterate through all numeric specifications and convert those
  642. " to their ascii equivalent ensuring the character is printable.
  643. " If so, add it to the list.
  644. let accepted_chars = ''
  645. for item in split(&iskeyword, ',')
  646. if item =~ '\d-\d'
  647. " This is a character range (ie 47-58),
  648. " cycle through each character within the range
  649. let [b:start, b:end] = split(item, '-')
  650. for range_item in range( b:start, b:end )
  651. if range_item <= 127 || l:omni_syntax_use_single_byte == 0
  652. if nr2char(range_item) =~ '\p'
  653. let accepted_chars = accepted_chars . nr2char(range_item)
  654. endif
  655. endif
  656. endfor
  657. elseif item =~ '^\d\+$'
  658. " Only numeric, translate to a character
  659. if item < 127 || l:omni_syntax_use_single_byte == 0
  660. if nr2char(item) =~ '\p'
  661. let accepted_chars = accepted_chars . nr2char(item)
  662. endif
  663. endif
  664. else
  665. if char2nr(item) < 127 || l:omni_syntax_use_single_byte == 0
  666. if item =~ '\p'
  667. let accepted_chars = accepted_chars . item
  668. endif
  669. endif
  670. endif
  671. endfor
  672. " Escape special regex characters
  673. " Looks like the wrong chars are escaped. In a collection,
  674. " :h /[]
  675. " only `]', `\', `-' and `^' are special:
  676. " let accepted_chars = escape(accepted_chars, '\\/.*$^~[]' )
  677. let accepted_chars = escape(accepted_chars, ']\-^' )
  678. " Remove all characters that are not acceptable
  679. let syn_list = substitute( syn_list, '[^A-Za-z'.accepted_chars.']', ' ', 'g' )
  680. else
  681. let accept_chars = ','.&iskeyword.','
  682. " Remove all character ranges
  683. " let accept_chars = substitute(accept_chars, ',[^,]\+-[^,]\+,', ',', 'g')
  684. let accept_chars = substitute(accept_chars, ',\@<=[^,]\+-[^,]\+,', '', 'g')
  685. " Remove all numeric specifications
  686. " let accept_chars = substitute(accept_chars, ',\d\{-},', ',', 'g')
  687. let accept_chars = substitute(accept_chars, ',\@<=\d\{-},', '', 'g')
  688. " Remove all commas
  689. let accept_chars = substitute(accept_chars, ',', '', 'g')
  690. " Escape special regex characters
  691. " Looks like the wrong chars are escaped. In a collection,
  692. " :h /[]
  693. " only `]', `\', `-' and `^' are special:
  694. " let accept_chars = escape(accept_chars, '\\/.*$^~[]' )
  695. let accept_chars = escape(accept_chars, ']\-^' )
  696. " Remove all characters that are not acceptable
  697. let syn_list = substitute( syn_list, '[^0-9A-Za-z_'.accept_chars.']', ' ', 'g' )
  698. endif
  699. endif
  700. if l:omni_syntax_minimum_length > 0
  701. " If the user specified a minimum length, enforce it
  702. let syn_list = substitute(' '.syn_list.' ', ' \S\{,'.l:omni_syntax_minimum_length.'}\ze ', ' ', 'g')
  703. endif
  704. else
  705. let syn_list = ''
  706. endif
  707. return syn_list
  708. endfunction
  709. function! OmniSyntaxShowChars(spec)
  710. let result = []
  711. for item in split(a:spec, ',')
  712. if len(item) > 1
  713. if item == '@-@'
  714. call add(result, char2nr(item))
  715. else
  716. call extend(result, call('range', split(item, '-')))
  717. endif
  718. else
  719. if item == '@' " assume this is [A-Za-z]
  720. for [c1, c2] in [['A', 'Z'], ['a', 'z']]
  721. call extend(result, range(char2nr(c1), char2nr(c2)))
  722. endfor
  723. else
  724. call add(result, char2nr(item))
  725. endif
  726. endif
  727. endfor
  728. return join(map(result, 'nr2char(v:val)'), ', ')
  729. endfunction
  730. let &cpo = s:cpo_save
  731. unlet s:cpo_save