denite.vim 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. " MIT License. Copyright (c) 2017-2021 Thomas Dy et al.
  2. " Plugin: https://github.com/Shougo/denite.nvim
  3. " vim: et ts=2 sts=2 sw=2
  4. scriptencoding utf-8
  5. if !get(g:, 'loaded_denite', 0)
  6. finish
  7. endif
  8. let s:denite_ver = (exists('*denite#get_status_mode') ? 2 : 3)
  9. " Denite does not use vim's built-in modal editing but has a custom prompt
  10. " that implements its own insert/normal mode so we have to handle changing the
  11. " highlight
  12. function! airline#extensions#denite#check_denite_mode(bufnr) abort
  13. if &filetype !=# 'denite' && &filetype !=# 'denite-filter'
  14. return ''
  15. endif
  16. if s:denite_ver == 3
  17. let mode = split(denite#get_status("mode"), ' ')
  18. else
  19. let mode = split(denite#get_status_mode(), ' ')
  20. endif
  21. let mode = tolower(get(mode, 1, ''))
  22. if !exists('b:denite_mode_cache') || mode != b:denite_mode_cache
  23. call airline#highlighter#highlight([mode], a:bufnr)
  24. let b:denite_mode_cache = mode
  25. endif
  26. return ''
  27. endfunction
  28. function! airline#extensions#denite#apply(...) abort
  29. if &filetype ==# 'denite' || &filetype ==# 'denite-filter'
  30. let w:airline_skip_empty_sections = 0
  31. call a:1.add_section('airline_a', ' Denite %{airline#extensions#denite#check_denite_mode('.a:2['bufnr'].')}')
  32. if s:denite_ver == 3
  33. call a:1.add_section('airline_c', ' %{denite#get_status("sources")}')
  34. call a:1.split()
  35. call a:1.add_section('airline_y', ' %{denite#get_status("path")} ')
  36. call a:1.add_section('airline_z', ' %{denite#get_status("linenr")} ')
  37. else
  38. call a:1.add_section('airline_c', ' %{denite#get_status_sources()}')
  39. call a:1.split()
  40. call a:1.add_section('airline_y', ' %{denite#get_status_path()} ')
  41. call a:1.add_section('airline_z', ' %{denite#get_status_linenr()} ')
  42. endif
  43. return 1
  44. endif
  45. endfunction
  46. function! airline#extensions#denite#init(ext) abort
  47. call denite#custom#option('_', 'statusline', 0)
  48. call a:ext.add_statusline_func('airline#extensions#denite#apply')
  49. endfunction