From 537c2ff01a4ea7e5c5148e6527d510eb5ce27f46 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Wed, 16 Jul 2014 00:43:16 +0900 Subject: [PATCH] Update vital & vital-over --- autoload/vital/_easymotion.vim | 66 ++++++++++++------- .../_easymotion/Over/Commandline/Base.vim | 8 ++- autoload/vital/easymotion.vital | 2 +- 3 files changed, 49 insertions(+), 27 deletions(-) diff --git a/autoload/vital/_easymotion.vim b/autoload/vital/_easymotion.vim index dd02388..d65da5e 100644 --- a/autoload/vital/_easymotion.vim +++ b/autoload/vital/_easymotion.vim @@ -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(':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 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 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('')) diff --git a/autoload/vital/_easymotion/Over/Commandline/Base.vim b/autoload/vital/_easymotion/Over/Commandline/Base.vim index 03d4a80..abf0cca 100644 --- a/autoload/vital/_easymotion/Over/Commandline/Base.vim +++ b/autoload/vital/_easymotion/Over/Commandline/Base.vim @@ -603,13 +603,15 @@ let s:special_keys = [ \ "\", \ "\", \] - -" \ "\", -> conflict with 4 -" \ "\", -> conflict with 7 +" Issues #45 +" \ "\", +" \ "\", function! s:_split_keys(str) return s:_split_keystring(a:str, s:special_keys) endfunction + + let &cpo = s:save_cpo unlet s:save_cpo diff --git a/autoload/vital/easymotion.vital b/autoload/vital/easymotion.vital index 66e2156..892ec63 100644 --- a/autoload/vital/easymotion.vital +++ b/autoload/vital/easymotion.vital @@ -1,5 +1,5 @@ easymotion -fb554d1 +439e6d2 Over.Commandline.Base Over.Commandline.Modules.Cancel