Skip to content

Commit

Permalink
- Updated vital.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Aug 18, 2013
1 parent 27ed9ed commit 29c9966
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 62 deletions.
13 changes: 12 additions & 1 deletion autoload/vital/_a20a988.vim → autoload/vital/_13055f8.vim
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function! s:_import(name, scripts)
endfunction

function! s:_get_module_path(name)
if filereadable(a:name)
if s:_is_absolute_path(a:name) && filereadable(a:name)
return s:_unify_path(a:name)
endif
if a:name ==# ''
Expand Down Expand Up @@ -129,6 +129,17 @@ else
endfunction
endif

" Copy from System.Filepath
if has('win16') || has('win32') || has('win64')
function! s:_is_absolute_path(path)
return a:path =~? '^[a-z]:[/\\]'
endfunction
else
function! s:_is_absolute_path(path)
return a:path[0] ==# '/'
endfunction
endif

function! s:_build_module(sid)
if has_key(s:loaded, a:sid)
return copy(s:loaded[a:sid])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ function! s:unshift(list, val)
return insert(a:list, a:val)
endfunction

function! s:cons(x, xs)
return [a:x] + a:xs
endfunction

" TODO spec
function! s:conj(xs, x)
return a:xs + [a:x]
endfunction

" Removes duplicates from a list.
function! s:uniq(list, ...)
let list = a:0 ? map(copy(a:list), printf('[v:val, %s]', a:1)) : copy(a:list)
Expand Down Expand Up @@ -96,23 +105,33 @@ function! s:sort_by(list, expr)
\ 'a:a[1] ==# a:b[1] ? 0 : a:a[1] ># a:b[1] ? 1 : -1'), 'v:val[0]')
endfunction

function! s:max(list, expr)
echoerr 'Data.List.max() is obsolete. Use its max_by() instead.'
return s:max_by(a:list, a:expr)
endfunction

" Returns a maximum value in {list} through given {expr}.
" Returns 0 if {list} is empty.
" v:val is used in {expr}
function! s:max(list, expr)
function! s:max_by(list, expr)
if empty(a:list)
return 0
endif
let list = map(copy(a:list), a:expr)
return a:list[index(list, max(list))]
endfunction

function! s:min(list, expr)
echoerr 'Data.List.min() is obsolete. Use its min_by() instead.'
return s:min_by(a:list, a:expr)
endfunction

" Returns a minimum value in {list} through given {expr}.
" Returns 0 if {list} is empty.
" v:val is used in {expr}
" FIXME: -0x80000000 == 0x80000000
function! s:min(list, expr)
return s:max(a:list, '-(' . a:expr . ')')
function! s:min_by(list, expr)
return s:max_by(a:list, '-(' . a:expr . ')')
endfunction

" Returns List of character sequence between [a:from, a:to]
Expand All @@ -124,10 +143,10 @@ function! s:char_range(from, to)
\)
endfunction

" Returns true if a:list has a:Value.
" Returns true if a:list has a:value.
" Returns false otherwise.
function! s:has(list, Value)
return index(a:list, a:Value) isnot -1
function! s:has(list, value)
return index(a:list, a:value) isnot -1
endfunction

" Returns true if a:list[a:index] exists.
Expand Down Expand Up @@ -232,12 +251,42 @@ function! s:zip(...)
return map(range(min(map(copy(a:000), 'len(v:val)'))), "map(copy(a:000), 'v:val['.v:val.']')")
endfunction

" similar to zip(), but goes until the longer one.
function! s:zip_fill(xs, ys, filler)
if empty(a:xs) && empty(a:ys)
return []
elseif empty(a:ys)
return s:cons([a:xs[0], a:filler], s:zip_fill(a:xs[1 :], [], a:filler))
elseif empty(a:xs)
return s:cons([a:filler, a:ys[0]], s:zip_fill([], a:ys[1 :], a:filler))
else
return s:cons([a:xs[0], a:ys[0]], s:zip_fill(a:xs[1 :], a:ys[1: ], a:filler))
endif
endfunction

" Inspired by Ruby's with_index method.
function! s:with_index(list, ...)
let base = a:0 > 0 ? a:1 : 0
return s:zip(a:list, range(base, len(a:list)+base-1))
endfunction

" similar to Ruby's detect or Haskell's find.
" TODO spec and doc
function! s:find(list, default, f)
for x in a:list
if eval(substitute(a:f, 'v:val', string(x), 'g'))
return x
endif
endfor
return a:default
endfunction

" Return non-zero if a:list1 and a:list2 have any common item(s).
" Return zero otherwise.
function! s:has_common_items(list1, list2)
return !empty(filter(copy(a:list1), 'index(a:list2, v:val) isnot -1'))
endfunction

let &cpo = s:save_cpo
unlet s:save_cpo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,23 @@ endfunction
" Substitute a:from => a:to by string.
" To substitute by pattern, use substitute() instead.
function! s:replace(str, from, to)
if a:str ==# '' || a:from ==# ''
return a:str
endif
let str = a:str
let idx = stridx(str, a:from)
while idx !=# -1
let left = idx ==# 0 ? '' : str[: idx - 1]
let right = str[idx + strlen(a:from) :]
let str = left . a:to . right
let idx = stridx(str, a:from, idx + strlen(a:to))
endwhile
return str
return s:_replace(a:str, a:from, a:to, 'g')
endfunction

" Substitute a:from => a:to only once.
" cf. s:replace()
function! s:replace_once(str, from, to)
if a:str ==# '' || a:from ==# ''
return a:str
endif
let idx = stridx(a:str, a:from)
if idx ==# -1
return a:str
else
let left = idx ==# 0 ? '' : a:str[: idx - 1]
let right = a:str[idx + strlen(a:from) :]
return left . a:to . right
endif
function! s:replace_first(str, from, to)
return s:_replace(a:str, a:from, a:to, '')
endfunction

" implement of replace() and replace_first()
function! s:_replace(str, from, to, flags)
return substitute(a:str, '\V'.escape(a:from, '\'), escape(a:to, '\'), a:flags)
endfunction

function! s:scan(str, pattern)
let list = []
let pos = 0
let len = len(a:str)
while 0 <= pos && pos < len
let matched = matchstr(a:str, a:pattern, pos)
let pos = matchend(a:str, a:pattern, pos)
if !empty(matched)
call add(list, matched)
endif
endwhile
call substitute(a:str, a:pattern, '\=add(list, submatch(0)) == [] ? "" : ""', 'g')
return list
endfunction

Expand All @@ -67,15 +43,13 @@ function! s:common_head(strs)
if empty(a:strs)
return ''
endif
let head = a:strs[0]
for str in a:strs[1 :]
let pat = substitute(str, '.', '[\0]', 'g')
let head = matchstr(head, '^\%[' . pat . ']')
if head ==# ''
break
endif
endfor
return head
let len = len(a:strs)
if len == 1
return a:strs[0]
endif
let strs = len == 2 ? a:strs : sort(copy(a:strs))
let pat = substitute(strs[0], '.', '[\0]', 'g')
return pat == '' ? '' : matchstr(strs[-1], '^\%[' . pat . ']')
endfunction

" Split to two elements of List. ([left, right])
Expand All @@ -101,7 +75,7 @@ function! s:split3(expr, pattern)
endfunction

" Slices into strings determines the number of substrings.
" e.g.: s:splitn("neo compl cache", 2, '\s') returns ['neo', 'compl cache']
" e.g.: s:nsplit("neo compl cache", 2, '\s') returns ['neo', 'compl cache']
function! s:nsplit(expr, n, ...)
let pattern = get(a:000, 0, '\s')
let keepempty = get(a:000, 1, 1)
Expand Down Expand Up @@ -197,7 +171,7 @@ endfunction
function! s:wrap(str,...)
let _columns = a:0 > 0 ? a:1 : &columns
return s:L.concat(
\ map(split(a:str, '\r\?\n'), 's:_split_by_wcswidth(v:val, _columns - 1)'))
\ map(split(a:str, '\r\n\|[\r\n]'), 's:_split_by_wcswidth(v:val, _columns - 1)'))
endfunction

function! s:nr2byte(nr)
Expand Down Expand Up @@ -234,22 +208,19 @@ endfunction
" If a ==# b, returns -1.
" If a !=# b, returns first index of diffrent character.
function! s:diffidx(a, b)
let [a, b] = [split(a:a, '\zs'), split(a:b, '\zs')]
let [al, bl] = [len(a), len(b)]
let l = max([al, bl])
for i in range(l)
" if `i` is out of range, a[i] returns empty string.
if i >= al || i >= bl || a[i] !=# b[i]
return i > 0 ? strlen(join(a[:i-1], '')) : 0
endif
endfor
return -1
return a:a ==# a:b ? -1 : strlen(s:common_head([a:a, a:b]))
endfunction

function! s:substitute_last(expr, pat, sub)
return substitute(a:expr, printf('.*\zs%s', a:pat), a:sub, '')
endfunction

function! s:dstring(expr)
let x = substitute(string(a:expr), "^'\\|'$", '', 'g')
let x = substitute(x, "''", "'", 'g')
return printf('"%s"', escape(x, '"'))
endfunction

let &cpo = s:save_cpo
unlet s:save_cpo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ function! s:is_dict(Value)
endfunction

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)
if width <= a:max
let ret = a:str
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion autoload/vital/neocomplcache.vital
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
a20a988
13055f8

Data.String
Data.List
Expand Down

0 comments on commit 29c9966

Please sign in to comment.