pymatcher.vim 1015 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. " Python Matcher
  2. if !has('python') && !has('python3')
  3. echo 'In order to use pymatcher plugin, you need +python or +python3 compiled vim'
  4. endif
  5. let s:plugin_path = escape(expand('<sfile>:p:h'), '\')
  6. if has('python3')
  7. execute 'py3file ' . s:plugin_path . '/pymatcher.py'
  8. else
  9. execute 'pyfile ' . s:plugin_path . '/pymatcher.py'
  10. endif
  11. function! pymatcher#PyMatch(items, str, limit, mmode, ispath, crfile, regex)
  12. call clearmatches()
  13. if a:str == ''
  14. let arr = a:items[0:a:limit]
  15. if !exists('g:ctrlp_match_current_file') && a:ispath && !empty(a:crfile)
  16. call remove(arr, index(arr, a:crfile))
  17. endif
  18. return arr
  19. endif
  20. let s:rez = []
  21. let s:regex = ''
  22. execute 'python' . (has('python3') ? '3' : '') . ' CtrlPPyMatch()'
  23. let s:matchregex = '\v\c'
  24. if a:mmode == 'filename-only'
  25. let s:matchregex .= '[\^\/]*'
  26. endif
  27. let s:matchregex .= s:regex
  28. call matchadd('CtrlPMatch', s:matchregex)
  29. return s:rez
  30. endfunction