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.
 
 

90 lines
2.7 KiB

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