136 lines
4.2 KiB
VimL
136 lines
4.2 KiB
VimL
"=============================================================================
|
|
" FILE: commands.vim
|
|
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
|
|
" Last Modified: 19 Nov 2013.
|
|
" License: MIT license {{{
|
|
" Permission is hereby granted, free of charge, to any person obtaining
|
|
" a copy of this software and associated documentation files (the
|
|
" "Software"), to deal in the Software without restriction, including
|
|
" without limitation the rights to use, copy, modify, merge, publish,
|
|
" distribute, sublicense, and/or sell copies of the Software, and to
|
|
" permit persons to whom the Software is furnished to do so, subject to
|
|
" the following conditions:
|
|
"
|
|
" The above copyright notice and this permission notice shall be included
|
|
" in all copies or substantial portions of the Software.
|
|
"
|
|
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
" }}}
|
|
"=============================================================================
|
|
|
|
let s:save_cpo = &cpo
|
|
set cpo&vim
|
|
|
|
" Variables "{{{
|
|
let s:edit_options = [
|
|
\ '-runtime',
|
|
\ '-vertical', '-horizontal', '-direction=', '-split',
|
|
\]
|
|
"}}}
|
|
|
|
function! neosnippet#commands#_edit(args) "{{{
|
|
if neosnippet#util#is_sudo()
|
|
call neosnippet#util#print_error(
|
|
\ '"sudo vim" is detected. This feature is disabled.')
|
|
return
|
|
endif
|
|
|
|
call neosnippet#init#check()
|
|
|
|
let [args, options] = neosnippet#util#parse_options(
|
|
\ a:args, s:edit_options)
|
|
|
|
let filetype = get(args, 0, '')
|
|
if filetype == ''
|
|
let filetype = neosnippet#get_filetype()
|
|
endif
|
|
|
|
let options = s:initialize_options(options)
|
|
let snippet_dir = (options.runtime ?
|
|
\ get(neosnippet#get_runtime_snippets_directory(), 0, '') :
|
|
\ get(neosnippet#get_user_snippets_directory(), -1, ''))
|
|
|
|
if snippet_dir == ''
|
|
call neosnippet#util#print_error('Snippet directory is not found.')
|
|
return
|
|
endif
|
|
|
|
" Edit snippet file.
|
|
let filename = snippet_dir .'/'.filetype
|
|
|
|
if isdirectory(filename)
|
|
" Edit in snippet directory.
|
|
let filename .= '/'.filetype
|
|
endif
|
|
|
|
if filename !~ '\.snip*$'
|
|
let filename .= '.snip'
|
|
endif
|
|
|
|
if options.split
|
|
" Split window.
|
|
execute options.direction
|
|
\ (options.vertical ? 'vsplit' : 'split')
|
|
endif
|
|
|
|
try
|
|
edit `=filename`
|
|
catch /^Vim\%((\a\+)\)\=:E749/
|
|
endtry
|
|
endfunction"}}}
|
|
|
|
function! neosnippet#commands#_make_cache(filetype) "{{{
|
|
call neosnippet#init#check()
|
|
|
|
let filetype = a:filetype == '' ?
|
|
\ &filetype : a:filetype
|
|
if filetype ==# ''
|
|
let filetype = 'nothing'
|
|
endif
|
|
|
|
let snippets = neosnippet#variables#get_snippets()
|
|
if has_key(snippets, filetype)
|
|
return
|
|
endif
|
|
|
|
let snippets_dir = neosnippet#get_snippets_directory()
|
|
let snippet = {}
|
|
let snippets_files =
|
|
\ split(globpath(join(snippets_dir, ','),
|
|
\ filetype . '.snip*'), '\n')
|
|
\ + split(globpath(join(snippets_dir, ','),
|
|
\ filetype . '_*.snip*'), '\n')
|
|
\ + split(globpath(join(snippets_dir, ','),
|
|
\ filetype . '/**/*.snip*'), '\n')
|
|
for snippets_file in reverse(snippets_files)
|
|
call neosnippet#_parse_snippets_file(snippet, snippets_file)
|
|
endfor
|
|
|
|
let snippets = neosnippet#variables#get_snippets()
|
|
let snippets[filetype] = snippet
|
|
endfunction"}}}
|
|
|
|
function! neosnippet#commands#_source(filename) "{{{
|
|
call neosnippet#init#check()
|
|
|
|
let neosnippet = neosnippet#get_current_neosnippet()
|
|
call neosnippet#_parse_snippets_file(neosnippet.snippets, a:filename)
|
|
endfunction"}}}
|
|
|
|
function! neosnippet#commands#_edit_complete(arglead, cmdline, cursorpos) "{{{
|
|
return filter(s:edit_options +
|
|
\ neosnippet#filetype_complete(a:arglead, a:cmdline, a:cursorpos),
|
|
\ 'stridx(v:val, a:arglead) == 0')
|
|
endfunction"}}}
|
|
|
|
let &cpo = s:save_cpo
|
|
unlet s:save_cpo
|
|
|
|
" vim: foldmethod=marker
|