You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

98 lines
2.9 KiB

  1. "=============================================================================
  2. " FILE: neosnippet_file.vim
  3. " AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
  4. " License: MIT license
  5. "=============================================================================
  6. let s:save_cpo = &cpo
  7. set cpo&vim
  8. function! unite#sources#neosnippet_file#define() abort "{{{
  9. return [s:source_user, s:source_runtime]
  10. endfunction "}}}
  11. " common action table
  12. let s:action_table = {}
  13. let s:action_table.neosnippet_source = {
  14. \ 'description' : 'neosnippet_source file',
  15. \ 'is_selectable' : 1,
  16. \ 'is_quit' : 1,
  17. \ }
  18. function! s:action_table.neosnippet_source.func(candidates) abort "{{{
  19. for candidate in a:candidates
  20. let snippet_name = candidate.action__path
  21. if snippet_name != ''
  22. call neosnippet#commands#_source(snippet_name)
  23. endif
  24. endfor
  25. endfunction"}}}
  26. " neosnippet source.
  27. let s:source_user = {
  28. \ 'name': 'neosnippet/user',
  29. \ 'description' : 'neosnippet user file',
  30. \ 'action_table' : copy(s:action_table),
  31. \ }
  32. function! s:source_user.gather_candidates(args, context) abort "{{{
  33. return s:get_snippet_candidates(
  34. \ neosnippet#get_user_snippets_directory())
  35. endfunction "}}}
  36. let s:source_user.action_table.unite__new_candidate = {
  37. \ 'description' : 'create new user snippet',
  38. \ 'is_invalidate_cache' : 1,
  39. \ 'is_quit' : 1,
  40. \ }
  41. function! s:source_user.action_table.unite__new_candidate.func(candidate) abort "{{{
  42. let filename = input(
  43. \ 'New snippet file name: ', neosnippet#helpers#get_filetype())
  44. if filename != ''
  45. call neosnippet#commands#_edit(filename)
  46. endif
  47. endfunction"}}}
  48. " neosnippet source.
  49. let s:source_runtime = {
  50. \ 'name': 'neosnippet/runtime',
  51. \ 'description' : 'neosnippet runtime file',
  52. \ 'action_table' : copy(s:action_table),
  53. \ }
  54. function! s:source_runtime.gather_candidates(args, context) abort "{{{
  55. return s:get_snippet_candidates(
  56. \ neosnippet#get_runtime_snippets_directory())
  57. endfunction "}}}
  58. let s:source_runtime.action_table.unite__new_candidate = {
  59. \ 'description' : 'create new runtime snippet',
  60. \ 'is_invalidate_cache' : 1,
  61. \ 'is_quit' : 1,
  62. \ }
  63. function! s:source_runtime.action_table.unite__new_candidate.func(candidate) abort "{{{
  64. let filename = input(
  65. \ 'New snippet file name: ', neosnippet#helpers#get_filetype())
  66. if filename != ''
  67. call neosnippet#commands#_edit('-runtime ' . filename)
  68. endif
  69. endfunction"}}}
  70. function! s:get_snippet_candidates(dirs) abort "{{{
  71. let _ = []
  72. for directory in a:dirs
  73. let _ += map(split(unite#util#substitute_path_separator(
  74. \ globpath(directory, '**/*.snip*')), '\n'), "{
  75. \ 'word' : v:val[len(directory)+1 :],
  76. \ 'action__path' : v:val,
  77. \ 'kind' : 'file',
  78. \ }")
  79. endfor
  80. return _
  81. endfunction "}}}
  82. let &cpo = s:save_cpo
  83. unlet s:save_cpo
  84. " vim: foldmethod=marker