filters.vim 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "=============================================================================
  2. " FILE: filters.vim
  3. " AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
  4. " License: MIT license {{{
  5. " Permission is hereby granted, free of charge, to any person obtaining
  6. " a copy of this software and associated documentation files (the
  7. " "Software"), to deal in the Software without restriction, including
  8. " without limitation the rights to use, copy, modify, merge, publish,
  9. " distribute, sublicense, and/or sell copies of the Software, and to
  10. " permit persons to whom the Software is furnished to do so, subject to
  11. " the following conditions:
  12. "
  13. " The above copyright notice and this permission notice shall be included
  14. " in all copies or substantial portions of the Software.
  15. "
  16. " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  17. " OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  19. " IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  20. " CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  21. " TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  22. " SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. " }}}
  24. "=============================================================================
  25. let s:save_cpo = &cpo
  26. set cpo&vim
  27. function! neocomplete#filters#fuzzy_escape(string) abort "{{{
  28. " Escape string for lua regexp.
  29. let string = substitute(neocomplete#filters#escape(a:string),
  30. \ '\w', '\0.*', 'g')
  31. if g:neocomplete#enable_camel_case && string =~ '\u'
  32. let string = substitute(string, '\l', '[\0\u\0\E]', 'g')
  33. endif
  34. return string
  35. endfunction"}}}
  36. function! neocomplete#filters#escape(string) abort "{{{
  37. " Escape string for lua regexp.
  38. return substitute(a:string,
  39. \ '[%\[\]().*+?^$-]', '%\0', 'g')
  40. endfunction"}}}
  41. let &cpo = s:save_cpo
  42. unlet s:save_cpo
  43. " vim: foldmethod=marker