Permalink
Browse files

Update Vital and follow a latest Guard

  • Loading branch information...
1 parent 1dad594 commit 791a439cd75569b8d802f82c96595e843e25b327 @lambdalisue committed Sep 21, 2016
Showing with 1,042 additions and 430 deletions.
  1. +1 −1 autoload/gista/util.vim
  2. +1 −1 autoload/vital.vim
  3. +3 −287 autoload/vital/_vim_gista.vim
  4. +15 −0 autoload/vital/_vim_gista/ArgumentParser.vim
  5. +15 −0 autoload/vital/_vim_gista/Data/Base64.vim
  6. +15 −0 autoload/vital/_vim_gista/Data/Dict.vim
  7. +15 −0 autoload/vital/_vim_gista/Data/List.vim
  8. +97 −4 autoload/vital/_vim_gista/Data/String.vim
  9. +15 −0 autoload/vital/_vim_gista/DateTime.vim
  10. +32 −8 autoload/vital/_vim_gista/Prelude.vim
  11. +15 −0 autoload/vital/_vim_gista/Process.vim
  12. +15 −0 autoload/vital/_vim_gista/System/Cache.vim
  13. +15 −0 autoload/vital/_vim_gista/System/Cache/Base.vim
  14. +15 −0 autoload/vital/_vim_gista/System/Cache/Dummy.vim
  15. +15 −0 autoload/vital/_vim_gista/System/Cache/File.vim
  16. +15 −0 autoload/vital/_vim_gista/System/Cache/Memory.vim
  17. +15 −0 autoload/vital/_vim_gista/System/Cache/SingleFile.vim
  18. +111 −4 autoload/vital/_vim_gista/System/File.vim
  19. +15 −0 autoload/vital/_vim_gista/System/Filepath.vim
  20. +17 −1 autoload/vital/_vim_gista/Vim/Buffer.vim
  21. +30 −9 autoload/vital/_vim_gista/Vim/Buffer/Anchor.vim
  22. +15 −15 autoload/vital/_vim_gista/Vim/BufferManager.vim
  23. +39 −17 autoload/vital/_vim_gista/Vim/Compat.vim
  24. +17 −2 autoload/vital/_vim_gista/Vim/Guard.vim
  25. +95 −76 autoload/vital/_vim_gista/Vim/Prompt.vim
  26. +15 −0 autoload/vital/_vim_gista/Vim/Python.vim
  27. +15 −0 autoload/vital/_vim_gista/Web/HTTP.vim
  28. +15 −0 autoload/vital/_vim_gista/Web/JSON.vim
  29. +339 −0 autoload/vital/vim_gista.vim
  30. +1 −1 autoload/vital/vim_gista.vital
  31. +2 −2 test/gista/client.vimspec
  32. +2 −2 test/gista/resource/local.vimspec
@@ -10,7 +10,7 @@ function! gista#util#clip(content) abort
endfunction
function! gista#util#doautocmd(name, ...) abort
- let guard = s:Guard.store('g:gista#avars')
+ let guard = s:Guard.store(['g:gista#avars'])
let g:gista#avars = extend(
\ get(g:, 'gista#avars', {}),
\ get(a:000, 0, {})
View
@@ -1,5 +1,5 @@
function! vital#of(name) abort
- let files = globpath(&runtimepath, 'autoload/vital/' . a:name . '.vital')
+ let files = globpath(&runtimepath, 'autoload/vital/' . a:name . '.vital', 1)
let file = split(files, "\n")
if empty(file)
throw 'vital: version file not found: ' . a:name
@@ -1,289 +1,5 @@
-let s:self_version = expand('<sfile>:t:r')
-let s:self_file = expand('<sfile>')
-let s:base_dir = expand('<sfile>:h')
+let s:_plugin_name = expand('<sfile>:t:r')
-let s:loaded = {}
-let s:cache_module_path = {}
-let s:cache_sid = {}
-
-let s:_unify_path_cache = {}
-
-function! s:plugin_name() abort
- return s:self_version[1 :]
-endfunction
-
-function! s:vital_files() abort
- if !exists('s:vital_files')
- let s:vital_files =
- \ map(
- \ s:plugin_name() ==# '_latest__'
- \ ? s:_global_vital_files()
- \ : s:_self_vital_files(),
- \ 'fnamemodify(v:val, ":p:gs?[\\\\/]?/?")')
- endif
- return copy(s:vital_files)
-endfunction
-
-function! s:import(name, ...) abort
- let target = {}
- let functions = []
- for a in a:000
- if type(a) == type({})
- let target = a
- elseif type(a) == type([])
- let functions = a
- endif
- unlet a
- endfor
- let module = s:_import(a:name)
- 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 abort
- for arg in a:000
- let [name; as] = type(arg) == type([]) ? arg[: 1] : [arg, arg]
- let target = split(join(as, ''), '\W\+')
- let dict = self
- let dict_type = type({})
- while !empty(target)
- let ns = remove(target, 0)
- if !has_key(dict, ns)
- let dict[ns] = {}
- endif
- if type(dict[ns]) == dict_type
- let dict = dict[ns]
- else
- unlet dict
- break
- endif
- endwhile
-
- if exists('dict')
- call extend(dict, s:_import(name))
- endif
- unlet arg
- endfor
- return self
-endfunction
-
-function! s:unload() abort
- let s:loaded = {}
- let s:cache_sid = {}
- let s:cache_module_path = {}
- unlet! s:vital_files
-endfunction
-
-function! s:exists(name) abort
- return s:_get_module_path(a:name) !=# ''
-endfunction
-
-function! s:search(pattern) abort
- let paths = s:_extract_files(a:pattern, s:vital_files())
- let modules = sort(map(paths, 's:_file2module(v:val)'))
- return s:_uniq(modules)
-endfunction
-
-function! s:_import(name) abort
- if type(a:name) == type(0)
- return s:_build_module(a:name)
- endif
- let path = s:_get_module_path(a:name)
- if path ==# ''
- throw 'vital: module not found: ' . a:name
- endif
- let sid = s:_get_sid_by_script(path)
- if !sid
- try
- execute 'source' fnameescape(path)
- catch /^Vim\%((\a\+)\)\?:E484/
- throw 'vital: module not found: ' . a:name
- catch /^Vim\%((\a\+)\)\?:E127/
- " Ignore.
- endtry
-
- let sid = s:_get_sid_by_script(path)
- endif
- return s:_build_module(sid)
-endfunction
-
-function! s:_get_module_path(name) abort
- let key = a:name . '_'
- if has_key(s:cache_module_path, key)
- return s:cache_module_path[key]
- endif
- if s:_is_absolute_path(a:name) && filereadable(a:name)
- return a:name
- endif
- if a:name =~# '\v^\u\w*%(\.\u\w*)*$'
- let paths = s:_extract_files(a:name, s:vital_files())
- else
- throw 'vital: Invalid module name: ' . a:name
- endif
-
- call filter(paths, 'filereadable(expand(v:val, 1))')
- let path = get(paths, 0, '')
- let s:cache_module_path[key] = path
- return path
-endfunction
-
-function! s:_get_sid_by_script(path) abort
- if has_key(s:cache_sid, a:path)
- return s:cache_sid[a:path]
- endif
-
- let path = s:_unify_path(a:path)
- let p = 'stridx(v:val, s:self_version) > 0 || v:val =~# "__\\w\\+__"'
- for line in filter(split(s:_redir('scriptnames'), "\n"), p)
- let list = matchlist(line, '^\s*\(\d\+\):\s\+\(.\+\)\s*$')
- if !empty(list) && s:_unify_path(list[2]) ==# path
- let s:cache_sid[a:path] = list[1] - 0
- return s:cache_sid[a:path]
- endif
- endfor
- return 0
-endfunction
-
-function! s:_file2module(file) abort
- let filename = fnamemodify(a:file, ':p:gs?[\\/]?/?')
- let tail = matchstr(filename, 'autoload/vital/_\w\+/\zs.*\ze\.vim$')
- return join(split(tail, '[\\/]\+'), '.')
-endfunction
-
-if filereadable(expand('<sfile>:r') . '.VIM')
- " resolve() is slow, so we cache results.
- " 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) abort
- 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) abort
- return resolve(fnamemodify(a:path, ':p:gs?[\\/]?/?'))
- endfunction
-endif
-
-function! s:_self_vital_files() abort
- let name = s:plugin_name()
- let builtin = printf('%s/__%s__/**/*.vim', s:base_dir, name)
- let installed = printf('%s/_%s/**/*.vim', s:base_dir, name)
- return split(glob(builtin, 1), "\n") + split(glob(installed, 1), "\n")
-endfunction
-
-function! s:_global_vital_files() abort
- let pattern = 'autoload/vital/__*__/**/*.vim'
- return split(globpath(&runtimepath, pattern, 1), "\n")
-endfunction
-
-function! s:_extract_files(pattern, files) abort
- let tr = {'.': '/', '*': '[^/]*', '**': '.*'}
- let target = substitute(a:pattern, '\.\|\*\*\?', '\=tr[submatch(0)]', 'g')
- let regexp = printf('autoload/vital/[^/]\+/%s.vim$', target)
- return filter(a:files, 'v:val =~# regexp')
-endfunction
-
-" Copy from System.Filepath
-if has('win16') || has('win32') || has('win64')
- function! s:_is_absolute_path(path) abort
- return a:path =~? '^[a-z]:[/\\]'
- endfunction
-else
- function! s:_is_absolute_path(path) abort
- return a:path[0] ==# '/'
- endfunction
-endif
-
-function! s:_build_module(sid) abort
- if has_key(s:loaded, a:sid)
- return copy(s:loaded[a:sid])
- endif
- let functions = s:_get_functions(a:sid)
-
- let prefix = '<SNR>' . a:sid . '_'
- let module = {}
- for func in functions
- let module[func] = function(prefix . func)
- endfor
- if has_key(module, '_vital_created')
- call module._vital_created(module)
- endif
- let export_module = filter(copy(module), 'v:key =~# "^\\a"')
- " Cache module before calling module.vital_debug() to avoid cyclic
- " dependences but remove the cache if module._vital_loaded() fails.
- let s:loaded[a:sid] = get(g:, 'vital_debug', 0) ? module : export_module
- if has_key(module, '_vital_loaded')
- try
- let V = vital#{s:self_version}#new()
- call module._vital_loaded(V)
- catch
- unlet s:loaded[a:sid]
- throw 'vital: fail to call ._vital_loaded(): ' . v:exception
- endtry
- endif
- return copy(s:loaded[a:sid])
-endfunction
-
-if exists('+regexpengine')
- function! s:_get_functions(sid) abort
- let funcs = s:_redir(printf("function /\\%%#=2^\<SNR>%d_", a:sid))
- let map_pat = '<SNR>' . a:sid . '_\zs\w\+'
- return map(split(funcs, "\n"), 'matchstr(v:val, map_pat)')
- endfunction
-else
- function! s:_get_functions(sid) abort
- let prefix = '<SNR>' . a:sid . '_'
- let funcs = s:_redir('function')
- let filter_pat = '^\s*function ' . prefix
- let map_pat = prefix . '\zs\w\+'
- return map(filter(split(funcs, "\n"),
- \ 'stridx(v:val, prefix) > 0 && v:val =~# filter_pat'),
- \ 'matchstr(v:val, map_pat)')
- endfunction
-endif
-
-if exists('*uniq')
- function! s:_uniq(list) abort
- return uniq(a:list)
- endfunction
-else
- function! s:_uniq(list) abort
- let i = len(a:list) - 1
- while 0 < i
- if a:list[i] ==# a:list[i - 1]
- call remove(a:list, i)
- endif
- let i -= 1
- endwhile
- return a:list
- endfunction
-endif
-
-function! s:_redir(cmd) abort
- let [save_verbose, save_verbosefile] = [&verbose, &verbosefile]
- set verbose=0 verbosefile=
- redir => res
- silent! execute a:cmd
- redir END
- let [&verbose, &verbosefile] = [save_verbose, save_verbosefile]
- return res
-endfunction
-
-function! vital#{s:self_version}#new() abort
- let sid = s:_get_sid_by_script(s:self_file)
- return s:_build_module(sid)
+function! vital#{s:_plugin_name}#new() abort
+ return vital#{s:_plugin_name[1:]}#new()
endfunction
@@ -1,3 +1,18 @@
+" ___vital___
+" NOTE: lines between '" ___vital___' is generated by :Vitalize.
+" Do not mofidify the code nor insert new lines before '" ___vital___'
+if v:version > 703 || v:version == 703 && has('patch1170')
+ function! vital#_vim_gista#ArgumentParser#import() abort
+ return map({'_vital_depends': '', 'complete_choices': '', 'splitargs': '', '_vital_created': '', 'complete_files': '', 'complete_dummy': '', 'new_argument': '', 'strip_quotes': '', 'new': '', '_vital_loaded': ''}, 'function("s:" . v:key)')
+ endfunction
+else
+ function! s:_SID() abort
+ return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
+ endfunction
+ execute join(['function! vital#_vim_gista#ArgumentParser#import() abort', printf("return map({'_vital_depends': '', 'complete_choices': '', 'splitargs': '', '_vital_created': '', 'complete_files': '', 'complete_dummy': '', 'new_argument': '', 'strip_quotes': '', 'new': '', '_vital_loaded': ''}, \"function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
+ delfunction s:_SID
+endif
+" ___vital___
let s:save_cpo = &cpo
set cpo&vim
@@ -1,3 +1,18 @@
+" ___vital___
+" NOTE: lines between '" ___vital___' is generated by :Vitalize.
+" Do not mofidify the code nor insert new lines before '" ___vital___'
+if v:version > 703 || v:version == 703 && has('patch1170')
+ function! vital#_vim_gista#Data#Base64#import() abort
+ return map({'decode': '', 'encodebin': '', 'encode': ''}, 'function("s:" . v:key)')
+ endfunction
+else
+ function! s:_SID() abort
+ return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
+ endfunction
+ execute join(['function! vital#_vim_gista#Data#Base64#import() abort', printf("return map({'decode': '', 'encodebin': '', 'encode': ''}, \"function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
+ delfunction s:_SID
+endif
+" ___vital___
" Utilities for Base64.
let s:save_cpo = &cpo
@@ -1,3 +1,18 @@
+" ___vital___
+" NOTE: lines between '" ___vital___' is generated by :Vitalize.
+" Do not mofidify the code nor insert new lines before '" ___vital___'
+if v:version > 703 || v:version == 703 && has('patch1170')
+ function! vital#_vim_gista#Data#Dict#import() abort
+ return map({'pick': '', 'clear': '', 'max_by': '', 'foldl': '', 'swap': '', 'omit': '', 'min_by': '', 'foldr': '', 'make_index': '', 'make': ''}, 'function("s:" . v:key)')
+ endfunction
+else
+ function! s:_SID() abort
+ return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
+ endfunction
+ execute join(['function! vital#_vim_gista#Data#Dict#import() abort', printf("return map({'pick': '', 'clear': '', 'max_by': '', 'foldl': '', 'swap': '', 'omit': '', 'min_by': '', 'foldr': '', 'make_index': '', 'make': ''}, \"function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
+ delfunction s:_SID
+endif
+" ___vital___
" Utilities for dictionary.
let s:save_cpo = &cpo
@@ -1,3 +1,18 @@
+" ___vital___
+" NOTE: lines between '" ___vital___' is generated by :Vitalize.
+" Do not mofidify the code nor insert new lines before '" ___vital___'
+if v:version > 703 || v:version == 703 && has('patch1170')
+ function! vital#_vim_gista#Data#List#import() abort
+ return map({'combinations': '', 'and': '', 'sort_by': '', 'foldr1': '', 'sort': '', 'flatten': '', 'has_index': '', 'find_indices': '', 'any': '', 'unshift': '', 'span': '', 'pop': '', 'binary_search': '', 'uniq_by': '', 'or': '', 'all': '', 'zip': '', 'find_last_index': '', 'find': '', 'partition': '', 'map_accum': '', 'permutations': '', 'break': '', 'max_by': '', 'foldl': '', 'foldr': '', 'find_index': '', 'group_by': '', 'take_while': '', 'conj': '', 'push': '', 'char_range': '', 'cons': '', 'foldl1': '', 'intersect': '', 'concat': '', 'shift': '', 'clear': '', 'has_common_items': '', 'product': '', 'zip_fill': '', 'uniq': '', 'has': '', 'min_by': '', 'with_index': ''}, 'function("s:" . v:key)')
+ endfunction
+else
+ function! s:_SID() abort
+ return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
+ endfunction
+ execute join(['function! vital#_vim_gista#Data#List#import() abort', printf("return map({'combinations': '', 'and': '', 'sort_by': '', 'foldr1': '', 'sort': '', 'flatten': '', 'has_index': '', 'find_indices': '', 'any': '', 'unshift': '', 'span': '', 'pop': '', 'binary_search': '', 'uniq_by': '', 'or': '', 'all': '', 'zip': '', 'find_last_index': '', 'find': '', 'partition': '', 'map_accum': '', 'permutations': '', 'break': '', 'max_by': '', 'foldl': '', 'foldr': '', 'find_index': '', 'group_by': '', 'take_while': '', 'conj': '', 'push': '', 'char_range': '', 'cons': '', 'foldl1': '', 'intersect': '', 'concat': '', 'shift': '', 'clear': '', 'has_common_items': '', 'product': '', 'zip_fill': '', 'uniq': '', 'has': '', 'min_by': '', 'with_index': ''}, \"function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
+ delfunction s:_SID
+endif
+" ___vital___
" Utilities for list.
let s:save_cpo = &cpo
Oops, something went wrong.

0 comments on commit 791a439

Please sign in to comment.