Vitalize.
This commit is contained in:
parent
39cd6d1f28
commit
157863b7cb
@ -61,21 +61,10 @@ function! s:_import(name, scripts)
|
|||||||
if type(a:name) == type(0)
|
if type(a:name) == type(0)
|
||||||
return s:_build_module(a:name)
|
return s:_build_module(a:name)
|
||||||
endif
|
endif
|
||||||
if a:name =~# '^[^A-Z]' || a:name =~# '\W[^A-Z]'
|
let path = s:_get_module_path(a:name)
|
||||||
throw 'vital: module name must start with capital letter: ' . a:name
|
if path ==# ''
|
||||||
|
throw 'vital: module not found: ' . a:name
|
||||||
endif
|
endif
|
||||||
let target = a:name ==# '' ? '' : '/' . substitute(a:name, '\W\+', '/', 'g')
|
|
||||||
let target = substitute(target, '\l\zs\ze\u', '_', 'g') " OrderedSet -> Ordered_Set
|
|
||||||
let target = substitute(target, '[/_]\zs\u', '\l\0', 'g') " Ordered_Set -> ordered_set
|
|
||||||
let tailpath = printf('autoload/vital/%s%s.vim', s:self_version, target)
|
|
||||||
|
|
||||||
" Note: The extra argument to globpath() was added in Patch 7.2.051.
|
|
||||||
if v:version > 702 || v:version == 702 && has('patch51')
|
|
||||||
let paths = split(globpath(&runtimepath, tailpath, 1), "\n")
|
|
||||||
else
|
|
||||||
let paths = split(globpath(&runtimepath, tailpath), "\n")
|
|
||||||
endif
|
|
||||||
let path = s:_unify_path(get(paths, 0, ''))
|
|
||||||
let sid = get(a:scripts, path, 0)
|
let sid = get(a:scripts, path, 0)
|
||||||
if !sid
|
if !sid
|
||||||
try
|
try
|
||||||
@ -92,6 +81,29 @@ function! s:_import(name, scripts)
|
|||||||
return s:_build_module(sid)
|
return s:_build_module(sid)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:_get_module_path(name)
|
||||||
|
if filereadable(a:name)
|
||||||
|
return s:_unify_path(a:name)
|
||||||
|
endif
|
||||||
|
if a:name ==# ''
|
||||||
|
let tailpath = printf('autoload/vital/%s.vim', s:self_version)
|
||||||
|
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)
|
||||||
|
else
|
||||||
|
let tailpath = a:name
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Note: The extra argument to globpath() was added in Patch 7.2.051.
|
||||||
|
if v:version > 702 || v:version == 702 && has('patch51')
|
||||||
|
let paths = split(globpath(&runtimepath, tailpath, 1), "\n")
|
||||||
|
else
|
||||||
|
let paths = split(globpath(&runtimepath, tailpath), "\n")
|
||||||
|
endif
|
||||||
|
call filter(paths, 'filereadable(v:val)')
|
||||||
|
return s:_unify_path(get(paths, 0, ''))
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:_scripts()
|
function! s:_scripts()
|
||||||
let scripts = {}
|
let scripts = {}
|
||||||
for line in split(s:_redir('scriptnames'), "\n")
|
for line in split(s:_redir('scriptnames'), "\n")
|
||||||
@ -151,12 +163,12 @@ function! s:_build_module(sid)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:_redir(cmd)
|
function! s:_redir(cmd)
|
||||||
let oldverbosefile = &verbosefile
|
let [save_verbose, save_verbosefile] = [&verbose, &verbosefile]
|
||||||
set verbosefile=
|
set verbose=0 verbosefile=
|
||||||
redir => res
|
redir => res
|
||||||
silent! execute a:cmd
|
silent! execute a:cmd
|
||||||
redir END
|
redir END
|
||||||
let &verbosefile = oldverbosefile
|
let [&verbose, &verbosefile] = [save_verbose, save_verbosefile]
|
||||||
return res
|
return res
|
||||||
endfunction
|
endfunction
|
||||||
|
|
@ -15,6 +15,7 @@ else
|
|||||||
return split(R, '\n')
|
return split(R, '\n')
|
||||||
endfunction
|
endfunction
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" globpath() wrapper which returns List
|
" globpath() wrapper which returns List
|
||||||
" and 'suffixes' and 'wildignore' does not affect
|
" and 'suffixes' and 'wildignore' does not affect
|
||||||
" this function's return value.
|
" this function's return value.
|
||||||
@ -30,15 +31,13 @@ let [
|
|||||||
\ s:__TYPE_FUNCREF,
|
\ s:__TYPE_FUNCREF,
|
||||||
\ s:__TYPE_LIST,
|
\ s:__TYPE_LIST,
|
||||||
\ s:__TYPE_DICT,
|
\ s:__TYPE_DICT,
|
||||||
\ s:__TYPE_FLOAT
|
\ s:__TYPE_FLOAT] = [
|
||||||
\] = [
|
\ type(3),
|
||||||
\ type(3),
|
\ type(""),
|
||||||
\ type(""),
|
\ type(function('tr')),
|
||||||
\ type(function('tr')),
|
\ type([]),
|
||||||
\ type([]),
|
\ type({}),
|
||||||
\ type({}),
|
\ has('float') ? type(str2float('0')) : -1]
|
||||||
\ has('float') ? type(str2float('0')) : -1
|
|
||||||
\]
|
|
||||||
" __TYPE_FLOAT = -1 when -float
|
" __TYPE_FLOAT = -1 when -float
|
||||||
" This doesn't match to anything.
|
" This doesn't match to anything.
|
||||||
|
|
||||||
@ -48,13 +47,17 @@ function! s:is_numeric(Value)
|
|||||||
return _ ==# s:__TYPE_NUMBER
|
return _ ==# s:__TYPE_NUMBER
|
||||||
\ || _ ==# s:__TYPE_FLOAT
|
\ || _ ==# s:__TYPE_FLOAT
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Number
|
" Number
|
||||||
function! s:is_integer(Value)
|
function! s:is_integer(Value)
|
||||||
return type(a:Value) ==# s:__TYPE_NUMBER
|
echoerr 'Prelude.is_integer() is obsolete. Use its is_number() instead; they are equivalent.'
|
||||||
|
return s:is_number(a:Value)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:is_number(Value)
|
function! s:is_number(Value)
|
||||||
return type(a:Value) ==# s:__TYPE_NUMBER
|
return type(a:Value) ==# s:__TYPE_NUMBER
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Float
|
" Float
|
||||||
function! s:is_float(Value)
|
function! s:is_float(Value)
|
||||||
return type(a:Value) ==# s:__TYPE_FLOAT
|
return type(a:Value) ==# s:__TYPE_FLOAT
|
||||||
@ -77,6 +80,11 @@ function! s:is_dict(Value)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:truncate_smart(str, max, footer_width, separator)
|
function! s:truncate_smart(str, max, footer_width, separator)
|
||||||
|
echoerr 'Prelude.truncate_smart() is obsolete. Use its truncate_skipping() instead; they are equivalent.'
|
||||||
|
return s:truncate_skipping(a:str, a:max, a:footer_width, a:separator)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:truncate_skipping(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
|
||||||
@ -112,10 +120,6 @@ function! s:truncate(str, width)
|
|||||||
return ret
|
return ret
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:strchars(str)
|
|
||||||
return len(substitute(a:str, '.', 'x', 'g'))
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:strwidthpart(str, width)
|
function! s:strwidthpart(str, width)
|
||||||
if a:width <= 0
|
if a:width <= 0
|
||||||
return ''
|
return ''
|
||||||
@ -193,21 +197,29 @@ else
|
|||||||
endfunction
|
endfunction
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let s:is_windows = has('win16') || has('win32') || has('win64')
|
let s:is_windows = has('win16') || has('win32') || has('win64') || has('win95')
|
||||||
let s:is_cygwin = has('win32unix')
|
let s:is_cygwin = has('win32unix')
|
||||||
let s:is_mac = !s:is_windows
|
let s:is_mac = !s:is_windows && !s:is_cygwin
|
||||||
\ && (has('mac') || has('macunix') || has('gui_macvim') ||
|
\ && (has('mac') || has('macunix') || has('gui_macvim') ||
|
||||||
\ (!isdirectory('/proc') && executable('sw_vers')))
|
\ (!isdirectory('/proc') && executable('sw_vers')))
|
||||||
|
let s:is_unix = has('unix')
|
||||||
|
|
||||||
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:is_unix()
|
||||||
|
return s:is_unix
|
||||||
|
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")
|
||||||
@ -223,9 +235,11 @@ 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
|
||||||
@ -234,22 +248,26 @@ function! s:iconv(expr, from, to)
|
|||||||
let result = iconv(a:expr, a:from, a:to)
|
let result = iconv(a:expr, a:from, a:to)
|
||||||
return result != '' ? result : a:expr
|
return result != '' ? result : a:expr
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Like builtin getchar() but returns string always.
|
" Like builtin getchar() but returns string always.
|
||||||
function! s:getchar(...)
|
function! s:getchar(...)
|
||||||
let c = call('getchar', a:000)
|
let c = call('getchar', a:000)
|
||||||
return type(c) == type(0) ? nr2char(c) : c
|
return type(c) == type(0) ? nr2char(c) : c
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Like builtin getchar() but returns string always.
|
" Like builtin getchar() but returns string always.
|
||||||
" and do inputsave()/inputrestore() before/after getchar().
|
" and do inputsave()/inputrestore() before/after getchar().
|
||||||
function! s:getchar_safe(...)
|
function! s:getchar_safe(...)
|
||||||
let c = s:input_helper('getchar', a:000)
|
let c = s:input_helper('getchar', a:000)
|
||||||
return type(c) == type("") ? c : nr2char(c)
|
return type(c) == type("") ? c : nr2char(c)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Like builtin getchar() but
|
" Like builtin getchar() but
|
||||||
" do inputsave()/inputrestore() before/after input().
|
" do inputsave()/inputrestore() before/after input().
|
||||||
function! s:input_safe(...)
|
function! s:input_safe(...)
|
||||||
return s:input_helper('input', a:000)
|
return s:input_helper('input', a:000)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Do inputsave()/inputrestore() before/after calling a:funcname.
|
" Do inputsave()/inputrestore() before/after calling a:funcname.
|
||||||
function! s:input_helper(funcname, args)
|
function! s:input_helper(funcname, args)
|
||||||
let success = 0
|
let success = 0
|
||||||
@ -270,6 +288,7 @@ function! s:set_default(var, 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)
|
||||||
@ -277,23 +296,41 @@ function! s:set_dictionary_helper(variable, keys, 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 = ''
|
||||||
|
|
||||||
" Search VCS directory.
|
" Search VCS directory.
|
||||||
for d in ['.git', '.bzr', '.hg']
|
for vcs in ['.git', '.bzr', '.hg', '.svn']
|
||||||
let d = finddir(d, s:escape_file_searching(search_directory) . ';')
|
let find_directory = s:escape_file_searching(search_directory)
|
||||||
if d != ''
|
let d = finddir(vcs, find_directory . ';')
|
||||||
|
if d == ''
|
||||||
|
continue
|
||||||
|
endif
|
||||||
|
|
||||||
let directory = fnamemodify(d, ':p:h:h')
|
let directory = fnamemodify(d, ':p:h:h')
|
||||||
break
|
|
||||||
|
if vcs ==# '.svn'
|
||||||
|
" Search parent directories.
|
||||||
|
let parent_directory = s:path2directory(
|
||||||
|
\ fnamemodify(directory, ':h'))
|
||||||
|
|
||||||
|
if parent_directory != ''
|
||||||
|
let d = finddir(vcs, parent_directory . ';')
|
||||||
|
if d != ''
|
||||||
|
let directory = s:path2project_directory(parent_directory)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
@ -324,6 +361,7 @@ function! s:path2project_directory(path, ...)
|
|||||||
|
|
||||||
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')
|
||||||
@ -359,6 +397,7 @@ function! s:system(str, ...)
|
|||||||
|
|
||||||
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
|
@ -1,3 +1,3 @@
|
|||||||
08a462e
|
de83b96
|
||||||
|
|
||||||
Prelude
|
Prelude
|
||||||
|
Loading…
Reference in New Issue
Block a user