- Updated vital.

This commit is contained in:
Shougo Matsushita 2012-12-25 22:58:04 +09:00
parent 23677b98b9
commit b1ac2eb3ed
3 changed files with 83 additions and 68 deletions

View File

@ -3,22 +3,31 @@ let s:self_version = expand('<sfile>:t:r')
let s:loaded = {}
function! s:import(name, ...)
let module = {}
let debug = 0
let target = {}
let functions = []
for a in a:000
if type(a) == type({})
let module = a
elseif type(a) == type(0)
let debug = a
let target = a
elseif type(a) == type([])
let functions = a
endif
unlet a
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
function! s:load(...) dict
let scripts = s:_scripts()
let debug = has_key(self, 'debug') && self.debug
for arg in a:000
let [name; as] = type(arg) == type([]) ? arg[: 1] : [arg, arg]
let target = split(join(as, ''), '\W\+')
@ -37,7 +46,7 @@ function! s:load(...) dict
endwhile
if exists('dict')
call extend(dict, s:_import(name, scripts, debug))
call extend(dict, s:_import(name, scripts))
endif
unlet arg
endfor
@ -48,9 +57,9 @@ function! s:unload()
let s:loaded = {}
endfunction
function! s:_import(name, scripts, debug)
function! s:_import(name, scripts)
if type(a:name) == type(0)
return s:_build_module(a:name, a:debug)
return s:_build_module(a:name)
endif
if a:name =~# '^[^A-Z]' || a:name =~# '\W[^A-Z]'
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)
if !sid
try
source `=path`
execute 'source' fnameescape(path)
catch /^Vim\%((\a\+)\)\?:E484/
throw 'vital: module not found: ' . a:name
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 a:scripts[path] = sid
endif
return s:_build_module(sid, a:debug)
return s:_build_module(sid)
endfunction
function! s:_scripts()
@ -108,7 +117,7 @@ else
endfunction
endif
function! s:_build_module(sid, debug)
function! s:_build_module(sid)
if has_key(s:loaded, a:sid)
return copy(s:loaded[a:sid])
endif
@ -134,7 +143,7 @@ function! s:_build_module(sid, debug)
" FIXME: Show an error message for debug.
endtry
endif
if !a:debug
if !get(g:, 'vital_debug', 0)
call filter(module, 'v:key =~# "^\\a"')
endif
let s:loaded[a:sid] = module
@ -142,12 +151,15 @@ function! s:_build_module(sid, debug)
endfunction
function! s:_redir(cmd)
let oldverbosefile = &verbosefile
set verbosefile=
redir => res
silent! execute a:cmd
redir END
let &verbosefile = oldverbosefile
return res
endfunction
function! vital#{s:self_version}#new()
return s:_import('', s:_scripts(), 0).load(['Prelude', ''])
return s:_import('', s:_scripts()).load(['Prelude', ''])
endfunction

View File

@ -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
" and 'wildignore' does not affect
@ -76,7 +76,7 @@ function! s:is_dict(Value)
return type(a:Value) ==# s:__TYPE_DICT
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)
if width <= a:max
let ret = a:str
@ -87,9 +87,9 @@ function! s:truncate_smart(str, max, footer_width, separator) "{{{
endif
return s:truncate(ret, a:max)
endfunction"}}}
endfunction
function! s:truncate(str, width) "{{{
function! s:truncate(str, width)
" Original function is from mattn.
" http://github.com/mattn/googlereader-vim/tree/master
@ -110,13 +110,13 @@ function! s:truncate(str, width) "{{{
endif
return ret
endfunction"}}}
endfunction
function! s:strchars(str) "{{{
function! s:strchars(str)
return len(substitute(a:str, '.', 'x', 'g'))
endfunction"}}}
endfunction
function! s:strwidthpart(str, width) "{{{
function! s:strwidthpart(str, width)
if a:width <= 0
return ''
endif
@ -129,8 +129,8 @@ function! s:strwidthpart(str, width) "{{{
endwhile
return ret
endfunction"}}}
function! s:strwidthpart_reverse(str, width) "{{{
endfunction
function! s:strwidthpart_reverse(str, width)
if a:width <= 0
return ''
endif
@ -143,15 +143,15 @@ function! s:strwidthpart_reverse(str, width) "{{{
endwhile
return ret
endfunction"}}}
endfunction
if v:version >= 703
" Use builtin function.
function! s:wcswidth(str) "{{{
function! s:wcswidth(str)
return strwidth(a:str)
endfunction"}}}
endfunction
else
function! s:wcswidth(str) "{{{
function! s:wcswidth(str)
if a:str =~# '^[\x00-\x7f]*$'
return strlen(a:str)
end
@ -168,10 +168,10 @@ else
let str = substitute(str, mx_first, '', '')
endwhile
return width
endfunction"}}}
endfunction
" UTF-8 only.
function! s:_wcwidth(ucs) "{{{
function! s:_wcwidth(ucs)
let ucs = a:ucs
if (ucs >= 0x1100
\ && (ucs <= 0x115f
@ -190,42 +190,42 @@ else
return 2
endif
return 1
endfunction"}}}
endfunction
endif
let s:is_windows = has('win16') || has('win32') || has('win64')
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') ||
\ (!executable('xdg-open') && system('uname') =~? '^darwin'))
function! s:is_windows() "{{{
\ (!isdirectory('/proc') && executable('sw_vers')))
function! s:is_windows()
return s:is_windows
endfunction"}}}
function! s:is_cygwin() "{{{
endfunction
function! s:is_cygwin()
return s:is_cygwin
endfunction"}}}
function! s:is_mac() "{{{
endfunction
function! s:is_mac()
return s:is_mac
endfunction"}}}
endfunction
function! s:print_error(message) "{{{
function! s:print_error(message)
echohl ErrorMsg
for m in split(a:message, "\n")
echomsg m
endfor
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`')
endfunction"}}}
endfunction
function! s:escape_file_searching(buffer_name) "{{{
function! s:escape_file_searching(buffer_name)
return escape(a:buffer_name, '*[]?{}, ')
endfunction"}}}
function! s:escape_pattern(str) "{{{
endfunction
function! s:escape_pattern(str)
return escape(a:str, '~"\.^$[]*')
endfunction"}}}
endfunction
" iconv() wrapper for safety.
function! s:iconv(expr, from, to)
if a:from == '' || a:to == '' || a:from ==? a:to
@ -265,25 +265,25 @@ function! s:input_helper(funcname, args)
endtry
endfunction
function! s:set_default(var, val) "{{{
function! s:set_default(var, val)
if !exists(a:var) || type({a:var}) != type(a:val)
let {a:var} = a:val
endif
endfunction"}}}
function! s:set_dictionary_helper(variable, keys, pattern) "{{{
endfunction
function! s:set_dictionary_helper(variable, keys, pattern)
for key in split(a:keys, '\s*,\s*')
if !has_key(a:variable, key)
let a:variable[key] = a:pattern
endif
endfor
endfunction"}}}
function! s:substitute_path_separator(path) "{{{
endfunction
function! s:substitute_path_separator(path)
return s:is_windows ? substitute(a:path, '\\', '/', 'g') : a:path
endfunction"}}}
function! s:path2directory(path) "{{{
endfunction
function! s:path2directory(path)
return s:substitute_path_separator(isdirectory(a:path) ? a:path : fnamemodify(a:path, ':p:h'))
endfunction"}}}
function! s:path2project_directory(path, ...) "{{{
endfunction
function! s:path2project_directory(path, ...)
let is_allow_empty = get(a:000, 0, 0)
let search_directory = s:path2directory(a:path)
let directory = ''
@ -323,9 +323,9 @@ function! s:path2project_directory(path, ...) "{{{
endif
return s:substitute_path_separator(directory)
endfunction"}}}
" Check vimproc. "{{{
function! s:has_vimproc() "{{{
endfunction
" Check vimproc.
function! s:has_vimproc()
if !exists('s:exists_vimproc')
try
call vimproc#version()
@ -335,9 +335,9 @@ function! s:has_vimproc() "{{{
endtry
endif
return s:exists_vimproc
endfunction"}}}
"}}}
function! s:system(str, ...) "{{{
endfunction
function! s:system(str, ...)
let command = a:str
let input = a:0 >= 1 ? a:1 : ''
let command = s:iconv(command, &encoding, 'char')
@ -358,10 +358,13 @@ function! s:system(str, ...) "{{{
let output = s:iconv(output, 'char', &encoding)
return output
endfunction"}}}
function! s:get_last_status() "{{{
endfunction
function! s:get_last_status()
return s:has_vimproc() ?
\ 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:

View File

@ -1,3 +1,3 @@
fa9e4af
08a462e
Prelude