ctrlp.vim 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. " MIT License. Copyright (c) 2013-2021 Bailey Ling et al.
  2. " Plugin: https://github.com/ctrlpvim/ctrlp.vim
  3. " vim: et ts=2 sts=2 sw=2
  4. scriptencoding utf-8
  5. if !get(g:, 'loaded_ctrlp', 0)
  6. finish
  7. endif
  8. let s:color_template = get(g:, 'airline#extensions#ctrlp#color_template', 'insert')
  9. function! airline#extensions#ctrlp#generate_color_map(dark, light, white)
  10. return {
  11. \ 'CtrlPdark' : a:dark,
  12. \ 'CtrlPlight' : a:light,
  13. \ 'CtrlPwhite' : a:white,
  14. \ 'CtrlParrow1' : [ a:light[1] , a:white[1] , a:light[3] , a:white[3] , '' ] ,
  15. \ 'CtrlParrow2' : [ a:white[1] , a:light[1] , a:white[3] , a:light[3] , '' ] ,
  16. \ 'CtrlParrow3' : [ a:light[1] , a:dark[1] , a:light[3] , a:dark[3] , '' ] ,
  17. \ }
  18. endfunction
  19. function! airline#extensions#ctrlp#load_theme(palette)
  20. if exists('a:palette.ctrlp')
  21. let theme = a:palette.ctrlp
  22. else
  23. let s:color_template = has_key(a:palette, s:color_template) ? s:color_template : 'insert'
  24. let theme = airline#extensions#ctrlp#generate_color_map(
  25. \ a:palette[s:color_template]['airline_c'],
  26. \ a:palette[s:color_template]['airline_b'],
  27. \ a:palette[s:color_template]['airline_a'])
  28. endif
  29. for key in keys(theme)
  30. call airline#highlighter#exec(key, theme[key])
  31. endfor
  32. endfunction
  33. " Arguments: focus, byfname, regexp, prv, item, nxt, marked
  34. function! airline#extensions#ctrlp#ctrlp_airline(...)
  35. let b = airline#builder#new({'active': 1})
  36. if a:2 == 'file'
  37. call b.add_section_spaced('CtrlPlight', 'by fname')
  38. endif
  39. if a:3
  40. call b.add_section_spaced('CtrlPlight', 'regex')
  41. endif
  42. if get(g:, 'airline#extensions#ctrlp#show_adjacent_modes', 1)
  43. call b.add_section_spaced('CtrlPlight', a:4)
  44. call b.add_section_spaced('CtrlPwhite', a:5)
  45. call b.add_section_spaced('CtrlPlight', a:6)
  46. else
  47. call b.add_section_spaced('CtrlPwhite', a:5)
  48. endif
  49. call b.add_section_spaced('CtrlPdark', a:7)
  50. call b.split()
  51. call b.add_section_spaced('CtrlPdark', a:1)
  52. call b.add_section_spaced('CtrlPdark', a:2)
  53. call b.add_section_spaced('CtrlPlight', '%{getcwd()}')
  54. return b.build()
  55. endfunction
  56. " Argument: len
  57. function! airline#extensions#ctrlp#ctrlp_airline_status(...)
  58. let len = '%#CtrlPdark# '.a:1
  59. let dir = '%=%<%#CtrlParrow3#'.g:airline_right_sep.'%#CtrlPlight# '.getcwd().' %*'
  60. return len.dir
  61. endfunction
  62. function! airline#extensions#ctrlp#apply(...)
  63. " disable statusline overwrite if ctrlp already did it
  64. return match(&statusline, 'CtrlPwhite') >= 0 ? -1 : 0
  65. endfunction
  66. function! airline#extensions#ctrlp#init(ext)
  67. let g:ctrlp_status_func = {
  68. \ 'main': 'airline#extensions#ctrlp#ctrlp_airline',
  69. \ 'prog': 'airline#extensions#ctrlp#ctrlp_airline_status',
  70. \ }
  71. call a:ext.add_statusline_func('airline#extensions#ctrlp#apply')
  72. call a:ext.add_theme_func('airline#extensions#ctrlp#load_theme')
  73. endfunction