- Updated vital.
This commit is contained in:
parent
23677b98b9
commit
b1ac2eb3ed
@ -3,22 +3,31 @@ let s:self_version = expand('<sfile>:t:r')
|
|||||||
let s:loaded = {}
|
let s:loaded = {}
|
||||||
|
|
||||||
function! s:import(name, ...)
|
function! s:import(name, ...)
|
||||||
let module = {}
|
let target = {}
|
||||||
let debug = 0
|
let functions = []
|
||||||
for a in a:000
|
for a in a:000
|
||||||
if type(a) == type({})
|
if type(a) == type({})
|
||||||
let module = a
|
let target = a
|
||||||
elseif type(a) == type(0)
|
elseif type(a) == type([])
|
||||||
let debug = a
|
let functions = a
|
||||||
endif
|
endif
|
||||||
unlet a
|
unlet a
|
||||||
endfor
|
endfor
|
||||||
return extend(module, s:_import(a:name, s:_scripts(), debug), 'keep')
|
let module = s:_import(a:name, s:_scripts())
|
||||||
|
if empty(functions)
|
||||||
|
call extend(target, module, 'keep')
|
||||||
|
else
|
||||||
|
for f in functions
|
||||||
|
if has_key(module, f) && !has_key(target, f)
|
||||||
|
let target[f] = module[f]
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
|
return target
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:load(...) dict
|
function! s:load(...) dict
|
||||||
let scripts = s:_scripts()
|
let scripts = s:_scripts()
|
||||||
let debug = has_key(self, 'debug') && self.debug
|
|
||||||
for arg in a:000
|
for arg in a:000
|
||||||
let [name; as] = type(arg) == type([]) ? arg[: 1] : [arg, arg]
|
let [name; as] = type(arg) == type([]) ? arg[: 1] : [arg, arg]
|
||||||
let target = split(join(as, ''), '\W\+')
|
let target = split(join(as, ''), '\W\+')
|
||||||
@ -37,7 +46,7 @@ function! s:load(...) dict
|
|||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
if exists('dict')
|
if exists('dict')
|
||||||
call extend(dict, s:_import(name, scripts, debug))
|
call extend(dict, s:_import(name, scripts))
|
||||||
endif
|
endif
|
||||||
unlet arg
|
unlet arg
|
||||||
endfor
|
endfor
|
||||||
@ -48,9 +57,9 @@ function! s:unload()
|
|||||||
let s:loaded = {}
|
let s:loaded = {}
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:_import(name, scripts, debug)
|
function! s:_import(name, scripts)
|
||||||
if type(a:name) == type(0)
|
if type(a:name) == type(0)
|
||||||
return s:_build_module(a:name, a:debug)
|
return s:_build_module(a:name)
|
||||||
endif
|
endif
|
||||||
if a:name =~# '^[^A-Z]' || a:name =~# '\W[^A-Z]'
|
if a:name =~# '^[^A-Z]' || a:name =~# '\W[^A-Z]'
|
||||||
throw 'vital: module name must start with capital letter: ' . a:name
|
throw 'vital: module name must start with capital letter: ' . a:name
|
||||||
@ -70,7 +79,7 @@ function! s:_import(name, scripts, debug)
|
|||||||
let sid = get(a:scripts, path, 0)
|
let sid = get(a:scripts, path, 0)
|
||||||
if !sid
|
if !sid
|
||||||
try
|
try
|
||||||
source `=path`
|
execute 'source' fnameescape(path)
|
||||||
catch /^Vim\%((\a\+)\)\?:E484/
|
catch /^Vim\%((\a\+)\)\?:E484/
|
||||||
throw 'vital: module not found: ' . a:name
|
throw 'vital: module not found: ' . a:name
|
||||||
catch /^Vim\%((\a\+)\)\?:E127/
|
catch /^Vim\%((\a\+)\)\?:E127/
|
||||||
@ -80,7 +89,7 @@ function! s:_import(name, scripts, debug)
|
|||||||
let sid = len(a:scripts) + 1 " We expect that the file newly read is +1.
|
let sid = len(a:scripts) + 1 " We expect that the file newly read is +1.
|
||||||
let a:scripts[path] = sid
|
let a:scripts[path] = sid
|
||||||
endif
|
endif
|
||||||
return s:_build_module(sid, a:debug)
|
return s:_build_module(sid)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:_scripts()
|
function! s:_scripts()
|
||||||
@ -108,7 +117,7 @@ else
|
|||||||
endfunction
|
endfunction
|
||||||
endif
|
endif
|
||||||
|
|
||||||
function! s:_build_module(sid, debug)
|
function! s:_build_module(sid)
|
||||||
if has_key(s:loaded, a:sid)
|
if has_key(s:loaded, a:sid)
|
||||||
return copy(s:loaded[a:sid])
|
return copy(s:loaded[a:sid])
|
||||||
endif
|
endif
|
||||||
@ -134,7 +143,7 @@ function! s:_build_module(sid, debug)
|
|||||||
" FIXME: Show an error message for debug.
|
" FIXME: Show an error message for debug.
|
||||||
endtry
|
endtry
|
||||||
endif
|
endif
|
||||||
if !a:debug
|
if !get(g:, 'vital_debug', 0)
|
||||||
call filter(module, 'v:key =~# "^\\a"')
|
call filter(module, 'v:key =~# "^\\a"')
|
||||||
endif
|
endif
|
||||||
let s:loaded[a:sid] = module
|
let s:loaded[a:sid] = module
|
||||||
@ -142,12 +151,15 @@ function! s:_build_module(sid, debug)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:_redir(cmd)
|
function! s:_redir(cmd)
|
||||||
|
let oldverbosefile = &verbosefile
|
||||||
|
set verbosefile=
|
||||||
redir => res
|
redir => res
|
||||||
silent! execute a:cmd
|
silent! execute a:cmd
|
||||||
redir END
|
redir END
|
||||||
|
let &verbosefile = oldverbosefile
|
||||||
return res
|
return res
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! vital#{s:self_version}#new()
|
function! vital#{s:self_version}#new()
|
||||||
return s:_import('', s:_scripts(), 0).load(['Prelude', ''])
|
return s:_import('', s:_scripts()).load(['Prelude', ''])
|
||||||
endfunction
|
endfunction
|
@ -1,5 +1,5 @@
|
|||||||
" vim:set et ts=2 sts=2 sw=2 tw=0:
|
let s:save_cpo = &cpo
|
||||||
|
set cpo&vim
|
||||||
|
|
||||||
" glob() wrapper which returns List
|
" glob() wrapper which returns List
|
||||||
" and 'wildignore' does not affect
|
" and 'wildignore' does not affect
|
||||||
@ -76,7 +76,7 @@ function! s:is_dict(Value)
|
|||||||
return type(a:Value) ==# s:__TYPE_DICT
|
return type(a:Value) ==# s:__TYPE_DICT
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:truncate_smart(str, max, footer_width, separator) "{{{
|
function! s:truncate_smart(str, max, footer_width, separator)
|
||||||
let width = s:wcswidth(a:str)
|
let width = s:wcswidth(a:str)
|
||||||
if width <= a:max
|
if width <= a:max
|
||||||
let ret = a:str
|
let ret = a:str
|
||||||
@ -87,9 +87,9 @@ function! s:truncate_smart(str, max, footer_width, separator) "{{{
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
return s:truncate(ret, a:max)
|
return s:truncate(ret, a:max)
|
||||||
endfunction"}}}
|
endfunction
|
||||||
|
|
||||||
function! s:truncate(str, width) "{{{
|
function! s:truncate(str, width)
|
||||||
" Original function is from mattn.
|
" Original function is from mattn.
|
||||||
" http://github.com/mattn/googlereader-vim/tree/master
|
" http://github.com/mattn/googlereader-vim/tree/master
|
||||||
|
|
||||||
@ -110,13 +110,13 @@ function! s:truncate(str, width) "{{{
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
endfunction"}}}
|
endfunction
|
||||||
|
|
||||||
function! s:strchars(str) "{{{
|
function! s:strchars(str)
|
||||||
return len(substitute(a:str, '.', 'x', 'g'))
|
return len(substitute(a:str, '.', 'x', 'g'))
|
||||||
endfunction"}}}
|
endfunction
|
||||||
|
|
||||||
function! s:strwidthpart(str, width) "{{{
|
function! s:strwidthpart(str, width)
|
||||||
if a:width <= 0
|
if a:width <= 0
|
||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
@ -129,8 +129,8 @@ function! s:strwidthpart(str, width) "{{{
|
|||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
endfunction"}}}
|
endfunction
|
||||||
function! s:strwidthpart_reverse(str, width) "{{{
|
function! s:strwidthpart_reverse(str, width)
|
||||||
if a:width <= 0
|
if a:width <= 0
|
||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
@ -143,15 +143,15 @@ function! s:strwidthpart_reverse(str, width) "{{{
|
|||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
endfunction"}}}
|
endfunction
|
||||||
|
|
||||||
if v:version >= 703
|
if v:version >= 703
|
||||||
" Use builtin function.
|
" Use builtin function.
|
||||||
function! s:wcswidth(str) "{{{
|
function! s:wcswidth(str)
|
||||||
return strwidth(a:str)
|
return strwidth(a:str)
|
||||||
endfunction"}}}
|
endfunction
|
||||||
else
|
else
|
||||||
function! s:wcswidth(str) "{{{
|
function! s:wcswidth(str)
|
||||||
if a:str =~# '^[\x00-\x7f]*$'
|
if a:str =~# '^[\x00-\x7f]*$'
|
||||||
return strlen(a:str)
|
return strlen(a:str)
|
||||||
end
|
end
|
||||||
@ -168,10 +168,10 @@ else
|
|||||||
let str = substitute(str, mx_first, '', '')
|
let str = substitute(str, mx_first, '', '')
|
||||||
endwhile
|
endwhile
|
||||||
return width
|
return width
|
||||||
endfunction"}}}
|
endfunction
|
||||||
|
|
||||||
" UTF-8 only.
|
" UTF-8 only.
|
||||||
function! s:_wcwidth(ucs) "{{{
|
function! s:_wcwidth(ucs)
|
||||||
let ucs = a:ucs
|
let ucs = a:ucs
|
||||||
if (ucs >= 0x1100
|
if (ucs >= 0x1100
|
||||||
\ && (ucs <= 0x115f
|
\ && (ucs <= 0x115f
|
||||||
@ -190,42 +190,42 @@ else
|
|||||||
return 2
|
return 2
|
||||||
endif
|
endif
|
||||||
return 1
|
return 1
|
||||||
endfunction"}}}
|
endfunction
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let s:is_windows = has('win16') || has('win32') || has('win64')
|
let s:is_windows = has('win16') || has('win32') || has('win64')
|
||||||
let s:is_cygwin = has('win32unix')
|
let s:is_cygwin = has('win32unix')
|
||||||
let s:is_mac = !s:is_windows && !s:is_cygwin
|
let s:is_mac = !s:is_windows
|
||||||
\ && (has('mac') || has('macunix') || has('gui_macvim') ||
|
\ && (has('mac') || has('macunix') || has('gui_macvim') ||
|
||||||
\ (!executable('xdg-open') && system('uname') =~? '^darwin'))
|
\ (!isdirectory('/proc') && executable('sw_vers')))
|
||||||
function! s:is_windows() "{{{
|
function! s:is_windows()
|
||||||
return s:is_windows
|
return s:is_windows
|
||||||
endfunction"}}}
|
endfunction
|
||||||
function! s:is_cygwin() "{{{
|
function! s:is_cygwin()
|
||||||
return s:is_cygwin
|
return s:is_cygwin
|
||||||
endfunction"}}}
|
endfunction
|
||||||
function! s:is_mac() "{{{
|
function! s:is_mac()
|
||||||
return s:is_mac
|
return s:is_mac
|
||||||
endfunction"}}}
|
endfunction
|
||||||
|
|
||||||
function! s:print_error(message) "{{{
|
function! s:print_error(message)
|
||||||
echohl ErrorMsg
|
echohl ErrorMsg
|
||||||
for m in split(a:message, "\n")
|
for m in split(a:message, "\n")
|
||||||
echomsg m
|
echomsg m
|
||||||
endfor
|
endfor
|
||||||
echohl None
|
echohl None
|
||||||
endfunction"}}}
|
endfunction
|
||||||
|
|
||||||
function! s:smart_execute_command(action, word) "{{{
|
function! s:smart_execute_command(action, word)
|
||||||
execute a:action . ' ' . (a:word == '' ? '' : '`=a:word`')
|
execute a:action . ' ' . (a:word == '' ? '' : '`=a:word`')
|
||||||
endfunction"}}}
|
endfunction
|
||||||
|
|
||||||
function! s:escape_file_searching(buffer_name) "{{{
|
function! s:escape_file_searching(buffer_name)
|
||||||
return escape(a:buffer_name, '*[]?{}, ')
|
return escape(a:buffer_name, '*[]?{}, ')
|
||||||
endfunction"}}}
|
endfunction
|
||||||
function! s:escape_pattern(str) "{{{
|
function! s:escape_pattern(str)
|
||||||
return escape(a:str, '~"\.^$[]*')
|
return escape(a:str, '~"\.^$[]*')
|
||||||
endfunction"}}}
|
endfunction
|
||||||
" iconv() wrapper for safety.
|
" iconv() wrapper for safety.
|
||||||
function! s:iconv(expr, from, to)
|
function! s:iconv(expr, from, to)
|
||||||
if a:from == '' || a:to == '' || a:from ==? a:to
|
if a:from == '' || a:to == '' || a:from ==? a:to
|
||||||
@ -265,25 +265,25 @@ function! s:input_helper(funcname, args)
|
|||||||
endtry
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:set_default(var, val) "{{{
|
function! s:set_default(var, val)
|
||||||
if !exists(a:var) || type({a:var}) != type(a:val)
|
if !exists(a:var) || type({a:var}) != type(a:val)
|
||||||
let {a:var} = a:val
|
let {a:var} = a:val
|
||||||
endif
|
endif
|
||||||
endfunction"}}}
|
endfunction
|
||||||
function! s:set_dictionary_helper(variable, keys, pattern) "{{{
|
function! s:set_dictionary_helper(variable, keys, pattern)
|
||||||
for key in split(a:keys, '\s*,\s*')
|
for key in split(a:keys, '\s*,\s*')
|
||||||
if !has_key(a:variable, key)
|
if !has_key(a:variable, key)
|
||||||
let a:variable[key] = a:pattern
|
let a:variable[key] = a:pattern
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
endfunction"}}}
|
endfunction
|
||||||
function! s:substitute_path_separator(path) "{{{
|
function! s:substitute_path_separator(path)
|
||||||
return s:is_windows ? substitute(a:path, '\\', '/', 'g') : a:path
|
return s:is_windows ? substitute(a:path, '\\', '/', 'g') : a:path
|
||||||
endfunction"}}}
|
endfunction
|
||||||
function! s:path2directory(path) "{{{
|
function! s:path2directory(path)
|
||||||
return s:substitute_path_separator(isdirectory(a:path) ? a:path : fnamemodify(a:path, ':p:h'))
|
return s:substitute_path_separator(isdirectory(a:path) ? a:path : fnamemodify(a:path, ':p:h'))
|
||||||
endfunction"}}}
|
endfunction
|
||||||
function! s:path2project_directory(path, ...) "{{{
|
function! s:path2project_directory(path, ...)
|
||||||
let is_allow_empty = get(a:000, 0, 0)
|
let is_allow_empty = get(a:000, 0, 0)
|
||||||
let search_directory = s:path2directory(a:path)
|
let search_directory = s:path2directory(a:path)
|
||||||
let directory = ''
|
let directory = ''
|
||||||
@ -323,9 +323,9 @@ function! s:path2project_directory(path, ...) "{{{
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
return s:substitute_path_separator(directory)
|
return s:substitute_path_separator(directory)
|
||||||
endfunction"}}}
|
endfunction
|
||||||
" Check vimproc. "{{{
|
" Check vimproc.
|
||||||
function! s:has_vimproc() "{{{
|
function! s:has_vimproc()
|
||||||
if !exists('s:exists_vimproc')
|
if !exists('s:exists_vimproc')
|
||||||
try
|
try
|
||||||
call vimproc#version()
|
call vimproc#version()
|
||||||
@ -335,9 +335,9 @@ function! s:has_vimproc() "{{{
|
|||||||
endtry
|
endtry
|
||||||
endif
|
endif
|
||||||
return s:exists_vimproc
|
return s:exists_vimproc
|
||||||
endfunction"}}}
|
endfunction
|
||||||
"}}}
|
|
||||||
function! s:system(str, ...) "{{{
|
function! s:system(str, ...)
|
||||||
let command = a:str
|
let command = a:str
|
||||||
let input = a:0 >= 1 ? a:1 : ''
|
let input = a:0 >= 1 ? a:1 : ''
|
||||||
let command = s:iconv(command, &encoding, 'char')
|
let command = s:iconv(command, &encoding, 'char')
|
||||||
@ -358,10 +358,13 @@ function! s:system(str, ...) "{{{
|
|||||||
let output = s:iconv(output, 'char', &encoding)
|
let output = s:iconv(output, 'char', &encoding)
|
||||||
|
|
||||||
return output
|
return output
|
||||||
endfunction"}}}
|
endfunction
|
||||||
function! s:get_last_status() "{{{
|
function! s:get_last_status()
|
||||||
return s:has_vimproc() ?
|
return s:has_vimproc() ?
|
||||||
\ vimproc#get_last_status() : v:shell_error
|
\ vimproc#get_last_status() : v:shell_error
|
||||||
endfunction"}}}
|
endfunction
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo
|
||||||
|
unlet s:save_cpo
|
||||||
|
|
||||||
" vim:set et ts=2 sts=2 sw=2 tw=0:
|
" vim:set et ts=2 sts=2 sw=2 tw=0:
|
@ -1,3 +1,3 @@
|
|||||||
fa9e4af
|
08a462e
|
||||||
|
|
||||||
Prelude
|
Prelude
|
||||||
|
Loading…
Reference in New Issue
Block a user