Update vital & vital-over

This commit is contained in:
haya14busa 2014-07-16 00:43:16 +09:00
parent 5cd205a016
commit 537c2ff01a
3 changed files with 49 additions and 27 deletions

View File

@ -64,10 +64,7 @@ function! s:exists(name)
endfunction
function! s:search(pattern)
let target = substitute(a:pattern, '\.', '/', 'g')
let tailpath = printf('autoload/vital/%s/%s.vim', s:self_version, target)
let paths = s:_runtime_files(tailpath)
let paths = s:_vital_files(a:pattern)
let modules = sort(map(paths, 's:_file2module(v:val)'))
return s:_uniq(modules)
endfunction
@ -104,7 +101,7 @@ function! s:_import(name)
if path ==# ''
throw 'vital: module not found: ' . a:name
endif
let sid = get(s:_scripts(), path, 0)
let sid = s:_get_sid_by_script(path)
if !sid
try
execute 'source' fnameescape(path)
@ -114,40 +111,38 @@ function! s:_import(name)
" Ignore.
endtry
let sid = s:_scripts()[path]
let sid = s:_get_sid_by_script(path)
endif
return s:_build_module(sid)
endfunction
function! s:_get_module_path(name)
if s:_is_absolute_path(a:name) && filereadable(a:name)
return s:_unify_path(a:name)
return a:name
endif
if a:name ==# ''
let tailpath = printf('autoload/vital/%s.vim', s:self_version)
let paths = [s:self_file]
elseif a:name =~# '\v^\u\w*%(\.\u\w*)*$'
let target = substitute(a:name, '\W\+', '/', 'g')
let tailpath = printf('autoload/vital/%s/%s.vim', s:self_version, target)
let paths = s:_vital_files(a:name)
else
throw 'vital: Invalid module name: ' . a:name
endif
let paths = s:_runtime_files(tailpath)
call filter(paths, 'filereadable(v:val)')
call filter(paths, 'filereadable(expand(v:val))')
let path = get(paths, 0, '')
return path !=# '' ? s:_unify_path(path) : ''
return path !=# '' ? path : ''
endfunction
function! s:_scripts()
let scripts = {}
function! s:_get_sid_by_script(path)
let path = s:_unify_path(a:path)
for line in filter(split(s:_redir('scriptnames'), "\n"),
\ 'stridx(v:val, s:self_version) > 0')
let list = matchlist(line, '^\s*\(\d\+\):\s\+\(.\+\)\s*$')
if !empty(list)
let scripts[s:_unify_path(list[2])] = list[1] - 0
if !empty(list) && s:_unify_path(list[2]) ==# path
return list[1] - 0
endif
endfor
return scripts
return 0
endfunction
function! s:_file2module(file)
@ -157,12 +152,19 @@ function! s:_file2module(file)
endfunction
if filereadable(expand('<sfile>:r') . '.VIM')
" resolve() is slow, so we cache results.
let s:_unify_path_cache = {}
" Note: On windows, vim can't expand path names from 8.3 formats.
" So if getting full path via <sfile> and $HOME was set as 8.3 format,
" vital load duplicated scripts. Below's :~ avoid this issue.
function! s:_unify_path(path)
" Note: On windows, vim can't expand path names from 8.3 formats.
" So if getting full path via <sfile> and $HOME was set as 8.3 format,
" vital load duplicated scripts. Below's :~ avoid this issue.
return tolower(fnamemodify(resolve(fnamemodify(
\ a:path, ':p')), ':~:gs?[\\/]\+?/?'))
if has_key(s:_unify_path_cache, a:path)
return s:_unify_path_cache[a:path]
endif
let value = tolower(fnamemodify(resolve(fnamemodify(
\ a:path, ':p')), ':~:gs?[\\/]\+?/?'))
let s:_unify_path_cache[a:path] = value
return value
endfunction
else
function! s:_unify_path(path)
@ -180,6 +182,22 @@ else
endfunction
endif
let s:_vital_files_cache_runtimepath = ''
let s:_vital_files_cache = []
function! s:_vital_files(pattern)
if s:_vital_files_cache_runtimepath !=# &runtimepath
let path = printf('autoload/vital/%s/**/*.vim', s:self_version)
let s:_vital_files_cache = s:_runtime_files(path)
let mod = ':p:gs?[\\/]\+?/?'
call map(s:_vital_files_cache, 'fnamemodify(v:val, mod)')
let s:_vital_files_cache_runtimepath = &runtimepath
endif
let target = substitute(a:pattern, '\.', '/', 'g')
let target = substitute(target, '\*', '[^/]*', 'g')
let regexp = printf('autoload/vital/%s/%s.vim', s:self_version, target)
return filter(copy(s:_vital_files_cache), 'v:val =~# regexp')
endfunction
" Copy from System.Filepath
if has('win16') || has('win32') || has('win64')
function! s:_is_absolute_path(path)
@ -282,3 +300,5 @@ endfunction
function! vital#{s:self_version}#new()
return s:_import('')
endfunction
let s:self_file = s:_unify_path(expand('<sfile>'))

View File

@ -603,13 +603,15 @@ let s:special_keys = [
\ "\<S-F12>",
\ "\<S-Tab>",
\]
" \ "\<S-Delete>", -> conflict with 4
" \ "\<S-End>", -> conflict with 7
" Issues #45
" \ "\<S-End>",
" \ "\<S-Delete>",
function! s:_split_keys(str)
return s:_split_keystring(a:str, s:special_keys)
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo

View File

@ -1,5 +1,5 @@
easymotion
fb554d1
439e6d2
Over.Commandline.Base
Over.Commandline.Modules.Cancel