neosnippet.vim/autoload/neosnippet/util.vim

118 lines
4.0 KiB
VimL
Raw Normal View History

2012-09-30 08:04:46 +00:00
"=============================================================================
" FILE: util.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
2013-03-02 09:27:24 +00:00
" Last Modified: 02 Mar 2013.
2012-09-30 08:04:46 +00:00
" 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
2012-09-30 08:06:28 +00:00
let s:V = vital#of('neosnippet')
2012-09-30 08:04:46 +00:00
2012-12-13 08:34:20 +00:00
function! neosnippet#util#substitute_path_separator(...) "{{{
2012-09-30 08:04:46 +00:00
return call(s:V.substitute_path_separator, a:000)
endfunction"}}}
2012-12-13 08:34:20 +00:00
function! neosnippet#util#system(...) "{{{
2012-09-30 08:04:46 +00:00
return call(s:V.system, a:000)
endfunction"}}}
2012-12-13 08:34:20 +00:00
function! neosnippet#util#has_vimproc(...) "{{{
2012-09-30 08:04:46 +00:00
return call(s:V.has_vimproc, a:000)
endfunction"}}}
2012-12-13 08:34:20 +00:00
function! neosnippet#util#is_windows(...) "{{{
2012-09-30 08:04:46 +00:00
return call(s:V.is_windows, a:000)
endfunction"}}}
2012-12-13 08:34:20 +00:00
function! neosnippet#util#is_mac(...) "{{{
2012-09-30 08:04:46 +00:00
return call(s:V.is_mac, a:000)
endfunction"}}}
2012-12-13 08:34:20 +00:00
function! neosnippet#util#get_last_status(...) "{{{
2012-09-30 08:04:46 +00:00
return call(s:V.get_last_status, a:000)
endfunction"}}}
2012-12-13 08:34:20 +00:00
function! neosnippet#util#escape_pattern(...) "{{{
2012-09-30 08:04:46 +00:00
return call(s:V.escape_pattern, a:000)
endfunction"}}}
2012-12-13 08:34:20 +00:00
function! neosnippet#util#iconv(...) "{{{
2012-09-30 08:04:46 +00:00
return call(s:V.iconv, a:000)
endfunction"}}}
2013-03-02 09:27:24 +00:00
function! neosnippet#util#truncate(...) "{{{
return call(s:V.truncate, a:000)
endfunction"}}}
2013-03-02 09:31:05 +00:00
function! neosnippet#util#strwidthpart(...) "{{{
return call(s:V.strwidthpart, a:000)
endfunction"}}}
2012-09-30 08:04:46 +00:00
2012-12-13 08:34:20 +00:00
function! neosnippet#util#expand(path) "{{{
2012-11-16 23:49:18 +00:00
return neosnippet#util#substitute_path_separator(
\ expand(escape(a:path, '*?[]"={}'), 1))
endfunction"}}}
2012-09-30 08:17:31 +00:00
function! neosnippet#util#set_default(var, val, ...) "{{{
if !exists(a:var) || type({a:var}) != type(a:val)
let alternate_var = get(a:000, 0, '')
let {a:var} = exists(alternate_var) ?
\ {alternate_var} : a:val
endif
endfunction"}}}
2012-12-13 08:34:20 +00:00
function! neosnippet#util#set_dictionary_helper(...) "{{{
2012-09-30 08:04:46 +00:00
return call(s:V.set_dictionary_helper, a:000)
endfunction"}}}
2012-12-13 08:34:20 +00:00
function! neosnippet#util#get_cur_text() "{{{
2012-09-30 08:21:47 +00:00
return
\ (mode() ==# 'i' ? (col('.')-1) : col('.')) >= len(getline('.')) ?
\ getline('.') :
\ matchstr(getline('.'),
\ '^.*\%' . col('.') . 'c' . (mode() ==# 'i' ? '' : '.'))
endfunction"}}}
2012-12-13 08:34:20 +00:00
function! neosnippet#util#print_error(string) "{{{
echohl Error | echomsg a:string | echohl None
endfunction"}}}
2012-09-30 08:21:47 +00:00
2012-12-13 08:34:20 +00:00
function! neosnippet#util#parse_options(args, options_list) "{{{
2012-09-30 10:10:25 +00:00
let args = []
let options = {}
for arg in split(a:args, '\%(\\\@<!\s\)\+')
let arg = substitute(arg, '\\\( \)', '\1', 'g')
let matched_list = filter(copy(a:options_list),
\ 'stridx(arg, v:val) == 0')
for option in matched_list
let key = substitute(substitute(option, '-', '_', 'g'), '=$', '', '')[1:]
let options[key] = (option =~ '=$') ?
\ arg[len(option) :] : 1
break
endfor
if empty(matched_list)
call add(args, arg)
endif
endfor
return [args, options]
endfunction"}}}
2012-09-30 08:04:46 +00:00
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker