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.
 
 

88 lines
2.8 KiB

  1. "=============================================================================
  2. " FILE: variables.vim
  3. " AUTHOR: Shougo Matsushita <Shougo.Matsu at gmail.com>
  4. " License: MIT license
  5. "=============================================================================
  6. function! neosnippet#variables#current_neosnippet() abort
  7. if !exists('b:neosnippet')
  8. let b:neosnippet = {
  9. \ 'snippets' : {},
  10. \ 'selected_text' : '',
  11. \ 'target' : '',
  12. \ 'trigger' : 0,
  13. \ 'optional_tabstop' : 0,
  14. \ 'unnamed_register' : '',
  15. \}
  16. endif
  17. return b:neosnippet
  18. endfunction
  19. function! neosnippet#variables#expand_stack() abort
  20. if !exists('s:expand_stack')
  21. let s:expand_stack = []
  22. endif
  23. return s:expand_stack
  24. endfunction
  25. function! neosnippet#variables#pop_expand_stack() abort
  26. let s:expand_stack = s:expand_stack[: -2]
  27. endfunction
  28. function! neosnippet#variables#clear_expand_stack() abort
  29. let s:expand_stack = []
  30. endfunction
  31. function! neosnippet#variables#snippets() abort
  32. if !exists('s:snippets')
  33. let s:snippets= {}
  34. endif
  35. return s:snippets
  36. endfunction
  37. function! neosnippet#variables#set_snippets(list) abort
  38. if !exists('s:snippets')
  39. let s:snippets= {}
  40. endif
  41. let s:snippets = a:list
  42. endfunction
  43. function! neosnippet#variables#snippets_dir() abort
  44. " Set snippets_dir.
  45. let snippets_dir = map(neosnippet#util#option2list(
  46. \ g:neosnippet#snippets_directory),
  47. \ 'neosnippet#util#expand(v:val)')
  48. return map(snippets_dir, 'substitute(v:val, "[\\\\/]$", "", "")')
  49. endfunction
  50. function! neosnippet#variables#runtime_dir() abort
  51. " Set runtime dir.
  52. let runtime_dir = split(globpath(&runtimepath, 'neosnippets'), '\n')
  53. if empty(runtime_dir) && empty(g:neosnippet#disable_runtime_snippets)
  54. call neosnippet#util#print_error(
  55. \ 'neosnippet default snippets cannot be loaded.')
  56. call neosnippet#util#print_error(
  57. \ 'You must install neosnippet-snippets or disable runtime snippets.')
  58. endif
  59. if g:neosnippet#enable_snipmate_compatibility
  60. " Load snipMate snippet directories.
  61. let runtime_dir += split(globpath(&runtimepath,
  62. \ 'snippets'), '\n')
  63. if exists('g:snippets_dir')
  64. let runtime_dir += neosnippet#util#option2list(g:snippets_dir)
  65. endif
  66. endif
  67. return map(runtime_dir, 'substitute(v:val, "[\\\\/]$", "", "")')
  68. endfunction
  69. function! neosnippet#variables#data_dir() abort
  70. let g:neosnippet#data_directory =
  71. \ substitute(fnamemodify(get(
  72. \ g:, 'neosnippet#data_directory',
  73. \ ($XDG_CACHE_HOME != '' ?
  74. \ $XDG_CACHE_HOME . '/neosnippet' : expand('~/.cache/neosnippet'))),
  75. \ ':p'), '\\', '/', 'g')
  76. if !isdirectory(g:neosnippet#data_directory)
  77. call mkdir(g:neosnippet#data_directory, 'p')
  78. endif
  79. return g:neosnippet#data_directory
  80. endfunction