commands.vim 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. "=============================================================================
  2. " FILE: commands.vim
  3. " AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
  4. " License: MIT license {{{
  5. " Permission is hereby granted, free of charge, to any person obtaining
  6. " a copy of this software and associated documentation files (the
  7. " "Software"), to deal in the Software without restriction, including
  8. " without limitation the rights to use, copy, modify, merge, publish,
  9. " distribute, sublicense, and/or sell copies of the Software, and to
  10. " permit persons to whom the Software is furnished to do so, subject to
  11. " the following conditions:
  12. "
  13. " The above copyright notice and this permission notice shall be included
  14. " in all copies or substantial portions of the Software.
  15. "
  16. " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  17. " OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  19. " IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  20. " CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  21. " TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  22. " SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. " }}}
  24. "=============================================================================
  25. let s:save_cpo = &cpo
  26. set cpo&vim
  27. function! neocomplete#commands#_initialize() abort "{{{
  28. command! -nargs=1 NeoCompleteAutoCompletionLength
  29. \ call s:set_auto_completion_length(<args>)
  30. endfunction"}}}
  31. function! neocomplete#commands#_toggle_lock() abort "{{{
  32. if !neocomplete#is_enabled()
  33. call neocomplete#init#enable()
  34. return
  35. endif
  36. if neocomplete#get_current_neocomplete().lock
  37. echo 'neocomplete is unlocked!'
  38. call neocomplete#commands#_unlock()
  39. else
  40. echo 'neocomplete is locked!'
  41. call neocomplete#commands#_lock()
  42. endif
  43. endfunction"}}}
  44. function! neocomplete#commands#_lock() abort "{{{
  45. let neocomplete = neocomplete#get_current_neocomplete()
  46. let neocomplete.lock = 1
  47. endfunction"}}}
  48. function! neocomplete#commands#_unlock() abort "{{{
  49. let neocomplete = neocomplete#get_current_neocomplete()
  50. let neocomplete.lock = 0
  51. endfunction"}}}
  52. function! neocomplete#commands#_clean() abort "{{{
  53. " Delete cache files.
  54. let data_directory = neocomplete#get_data_directory()
  55. for directory in filter(neocomplete#util#glob(
  56. \ data_directory.'/*'), 'isdirectory(v:val)')
  57. if has('patch-7.4.1120')
  58. call delete(data_directory, 'rf')
  59. else
  60. for filename in filter(neocomplete#util#glob(directory.'/*'),
  61. \ '!isdirectory(v:val)')
  62. call delete(filename)
  63. endfor
  64. endif
  65. endfor
  66. echo 'Cleaned cache files in: ' . data_directory
  67. endfunction"}}}
  68. function! neocomplete#commands#_set_file_type(filetype) abort "{{{
  69. let neocomplete = neocomplete#get_current_neocomplete()
  70. let neocomplete.context_filetype = a:filetype
  71. endfunction"}}}
  72. function! s:rand(max) abort "{{{
  73. if !has('reltime')
  74. " Same value.
  75. return 0
  76. endif
  77. let time = reltime()[1]
  78. return (time < 0 ? -time : time)% (a:max + 1)
  79. endfunction"}}}
  80. function! s:set_auto_completion_length(len) abort "{{{
  81. let neocomplete = neocomplete#get_current_neocomplete()
  82. let neocomplete.completion_length = a:len
  83. endfunction"}}}
  84. let &cpo = s:save_cpo
  85. unlet s:save_cpo
  86. " vim: foldmethod=marker