1
0

mixed.vim 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. " =============================================================================
  2. " File: autoload/ctrlp/mixed.vim
  3. " Description: Mixing Files + MRU + Buffers
  4. " Author: Kien Nguyen <github.com/kien>
  5. " =============================================================================
  6. " Init {{{1
  7. if exists('g:loaded_ctrlp_mixed') && g:loaded_ctrlp_mixed
  8. fini
  9. en
  10. let [g:loaded_ctrlp_mixed, g:ctrlp_newmix] = [1, 0]
  11. cal add(g:ctrlp_ext_vars, {
  12. \ 'init': 'ctrlp#mixed#init(s:compare_lim)',
  13. \ 'accept': 'ctrlp#acceptfile',
  14. \ 'lname': 'fil + mru + buf',
  15. \ 'sname': 'mix',
  16. \ 'type': 'path',
  17. \ 'opmul': 1,
  18. \ 'specinput': 1,
  19. \ })
  20. let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
  21. " Utilities {{{1
  22. fu! s:newcache(cwd)
  23. if g:ctrlp_newmix || !has_key(g:ctrlp_allmixes, 'data') | retu 1 | en
  24. retu g:ctrlp_allmixes['cwd'] != a:cwd
  25. \ || g:ctrlp_allmixes['filtime'] < getftime(ctrlp#utils#cachefile())
  26. \ || g:ctrlp_allmixes['mrutime'] < getftime(ctrlp#mrufiles#cachefile())
  27. \ || g:ctrlp_allmixes['bufs'] < len(ctrlp#mrufiles#bufs())
  28. endf
  29. fu! s:getnewmix(cwd, clim)
  30. if g:ctrlp_newmix
  31. cal ctrlp#mrufiles#refresh('raw')
  32. let g:ctrlp_newcache = 1
  33. en
  34. let g:ctrlp_lines = copy(ctrlp#files())
  35. cal ctrlp#progress('Mixing...')
  36. let mrufs = copy(ctrlp#mrufiles#list('raw'))
  37. if exists('+ssl') && &ssl
  38. cal map(mrufs, 'tr(v:val, "\\", "/")')
  39. en
  40. let allbufs = map(ctrlp#buffers(), 'fnamemodify(v:val, ":p")')
  41. let [bufs, ubufs] = [[], []]
  42. for each in allbufs
  43. cal add(filereadable(each) ? bufs : ubufs, each)
  44. endfo
  45. let mrufs = bufs + filter(mrufs, 'index(bufs, v:val) < 0')
  46. if len(mrufs) > len(g:ctrlp_lines)
  47. cal filter(mrufs, 'stridx(v:val, a:cwd)')
  48. el
  49. let cwd_mrufs = filter(copy(mrufs), '!stridx(v:val, a:cwd)')
  50. let cwd_mrufs = ctrlp#rmbasedir(cwd_mrufs)
  51. for each in cwd_mrufs
  52. let id = index(g:ctrlp_lines, each)
  53. if id >= 0 | cal remove(g:ctrlp_lines, id) | en
  54. endfo
  55. en
  56. let mrufs += ubufs
  57. cal map(mrufs, 'fnamemodify(v:val, ":.")')
  58. let g:ctrlp_lines = len(mrufs) > len(g:ctrlp_lines)
  59. \ ? g:ctrlp_lines + mrufs : mrufs + g:ctrlp_lines
  60. if len(g:ctrlp_lines) <= a:clim
  61. cal sort(g:ctrlp_lines, 'ctrlp#complen')
  62. en
  63. let g:ctrlp_allmixes = { 'filtime': getftime(ctrlp#utils#cachefile()),
  64. \ 'mrutime': getftime(ctrlp#mrufiles#cachefile()), 'cwd': a:cwd,
  65. \ 'bufs': len(ctrlp#mrufiles#bufs()), 'data': g:ctrlp_lines }
  66. endf
  67. " Public {{{1
  68. fu! ctrlp#mixed#init(clim)
  69. let cwd = getcwd()
  70. if s:newcache(cwd)
  71. cal s:getnewmix(cwd, a:clim)
  72. el
  73. let g:ctrlp_lines = g:ctrlp_allmixes['data']
  74. en
  75. let g:ctrlp_newmix = 0
  76. retu g:ctrlp_lines
  77. endf
  78. fu! ctrlp#mixed#id()
  79. retu s:id
  80. endf
  81. "}}}
  82. " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2