Permalink
Browse files

Update vital

1 parent 6474eb4 commit d0c5bef010237855b4de25863bc54895effe5d7a @Shougo committed Dec 13, 2016
@@ -25,7 +25,7 @@
function! vimshell#util#get_vital() abort "{{{
if !exists('s:V')
- let s:V = vital#vimshell#of()
+ let s:V = vital#vimshell#new()
endif
return s:V
endfunction"}}}
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,5 +1,5 @@
let s:_plugin_name = expand('<sfile>:t:r')
function! vital#{s:_plugin_name}#new() abort
- return vital#{s:_plugin_name[1:]}#of()
+ return vital#{s:_plugin_name[1:]}#new()
endfunction
@@ -3,13 +3,13 @@
" Do not mofidify the code nor insert new lines before '" ___vital___'
if v:version > 703 || v:version == 703 && has('patch1170')
function! vital#_vimshell#Data#String#import() abort
- return map({'starts_with': '', 'split3': '', 'chop': '', 'unescape': '', 'split_posix_text': '', 'replace': '', 'scan': '', 'strchars': '', 'strwidthpart': '', 'common_head': '', 'reverse': '', 'escape_pattern': '', 'trim_end': '', '_vital_depends': '', 'wrap': '', 'join_posix_lines': '', 'contains_multibyte': '', 'truncate_skipping': '', 'split_leftright': '', 'ends_with': '', 'nsplit': '', 'substitute_last': '', 'strwidthpart_reverse': '', 'unescape_pattern': '', 'levenshtein_distance': '', 'trim_start': '', 'nr2hex': '', 'remove_ansi_sequences': '', 'iconv': '', 'pad_left': '', 'nr2enc_char': '', 'lines': '', 'repair_posix_text': '', 'nr2byte': '', 'trim': '', 'diffidx': '', 'truncate': '', 'split_by_displaywidth': '', 'padding_by_displaywidth': '', 'hash': '', 'chomp': '', 'pad_between_letters': '', 'wcswidth': '', 'dstring': '', 'pad_both_sides': '', 'justify_equal_spacing': '', 'pad_right': '', 'replace_first': '', '_vital_loaded': ''}, 'function("s:" . v:key)')
+ return map({'starts_with': '', 'split3': '', 'replace_first': '', 'chop': '', 'unescape': '', 'split_posix_text': '', 'replace': '', 'scan': '', 'strwidthpart': '', 'common_head': '', 'reverse': '', 'escape_pattern': '', 'trim_end': '', '_vital_depends': '', 'wrap': '', 'join_posix_lines': '', 'contains_multibyte': '', 'truncate_skipping': '', 'split_leftright': '', 'ends_with': '', 'nsplit': '', 'strwidthpart_reverse': '', 'unescape_pattern': '', 'levenshtein_distance': '', 'trim_start': '', 'justify_equal_spacing': '', 'nr2hex': '', 'iconv': '', 'pad_left': '', 'nr2enc_char': '', 'lines': '', 'repair_posix_text': '', 'nr2byte': '', 'trim': '', 'diffidx': '', 'truncate': '', 'split_by_displaywidth': '', '_vital_created': '', 'padding_by_displaywidth': '', 'hash': '', 'chomp': '', 'pad_between_letters': '', 'dstring': '', 'pad_both_sides': '', 'substitute_last': '', 'pad_right': '', 'remove_ansi_sequences': '', '_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#_vimshell#Data#String#import() abort', printf("return map({'starts_with': '', 'split3': '', 'chop': '', 'unescape': '', 'split_posix_text': '', 'replace': '', 'scan': '', 'strchars': '', 'strwidthpart': '', 'common_head': '', 'reverse': '', 'escape_pattern': '', 'trim_end': '', '_vital_depends': '', 'wrap': '', 'join_posix_lines': '', 'contains_multibyte': '', 'truncate_skipping': '', 'split_leftright': '', 'ends_with': '', 'nsplit': '', 'substitute_last': '', 'strwidthpart_reverse': '', 'unescape_pattern': '', 'levenshtein_distance': '', 'trim_start': '', 'nr2hex': '', 'remove_ansi_sequences': '', 'iconv': '', 'pad_left': '', 'nr2enc_char': '', 'lines': '', 'repair_posix_text': '', 'nr2byte': '', 'trim': '', 'diffidx': '', 'truncate': '', 'split_by_displaywidth': '', 'padding_by_displaywidth': '', 'hash': '', 'chomp': '', 'pad_between_letters': '', 'wcswidth': '', 'dstring': '', 'pad_both_sides': '', 'justify_equal_spacing': '', 'pad_right': '', 'replace_first': '', '_vital_loaded': ''}, \"function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
+ execute join(['function! vital#_vimshell#Data#String#import() abort', printf("return map({'starts_with': '', 'split3': '', 'replace_first': '', 'chop': '', 'unescape': '', 'split_posix_text': '', 'replace': '', 'scan': '', 'strwidthpart': '', 'common_head': '', 'reverse': '', 'escape_pattern': '', 'trim_end': '', '_vital_depends': '', 'wrap': '', 'join_posix_lines': '', 'contains_multibyte': '', 'truncate_skipping': '', 'split_leftright': '', 'ends_with': '', 'nsplit': '', 'strwidthpart_reverse': '', 'unescape_pattern': '', 'levenshtein_distance': '', 'trim_start': '', 'justify_equal_spacing': '', 'nr2hex': '', 'iconv': '', 'pad_left': '', 'nr2enc_char': '', 'lines': '', 'repair_posix_text': '', 'nr2byte': '', 'trim': '', 'diffidx': '', 'truncate': '', 'split_by_displaywidth': '', '_vital_created': '', 'padding_by_displaywidth': '', 'hash': '', 'chomp': '', 'pad_between_letters': '', 'dstring': '', 'pad_both_sides': '', 'substitute_last': '', 'pad_right': '', 'remove_ansi_sequences': '', '_vital_loaded': ''}, \"function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
delfunction s:_SID
endif
" ___vital___
@@ -27,6 +27,16 @@ function! s:_vital_depends() abort
return ['Data.List']
endfunction
+function! s:_vital_created(module) abort
+ " Expose script-local funcref
+ if exists('s:strchars')
+ let a:module.strchars = s:strchars
+ endif
+ if exists('s:wcswidth')
+ let a:module.wcswidth = s:wcswidth
+ endif
+endfunction
+
" Substitute a:from => a:to by string.
" To substitute by pattern, use substitute() instead.
function! s:replace(str, from, to) abort
@@ -142,9 +152,7 @@ endfunction
" even if a:str contains multibyte character(s).
" s:strchars(str) {{{
if exists('*strchars')
- function! s:strchars(str) abort
- return strchars(a:str)
- endfunction
+ let s:strchars = function('strchars')
else
function! s:strchars(str) abort
return strlen(substitute(copy(a:str), '.', 'x', 'g'))
@@ -452,8 +460,9 @@ function! s:truncate(str, width) abort
" http://github.com/mattn/googlereader-vim/tree/master
if a:str =~# '^[\x00-\x7f]*$'
- return len(a:str) < a:width ?
- \ printf('%-'.a:width.'s', a:str) : strpart(a:str, 0, a:width)
+ return len(a:str) < a:width
+ \ ? printf('%-' . a:width . 's', a:str)
+ \ : strpart(a:str, 0, a:width)
endif
let ret = a:str
@@ -483,57 +492,20 @@ function! s:truncate_skipping(str, max, footer_width, separator) abort
endfunction
function! s:strwidthpart(str, width) abort
- if a:width <= 0
- return ''
- endif
- let strarr = split(a:str, '\zs')
- let width = s:wcswidth(a:str)
- let index = len(strarr)
- let diff = (index + 1) / 2
- let rightindex = index - 1
- while width > a:width
- let index = max([rightindex - diff + 1, 0])
- let partwidth = s:wcswidth(join(strarr[(index):(rightindex)], ''))
- if width - partwidth >= a:width || diff <= 1
- let width -= partwidth
- let rightindex = index - 1
- endif
- if diff > 1
- let diff = diff / 2
- endif
- endwhile
- return index ? join(strarr[:index - 1], '') : ''
+ let str = tr(a:str, "\t", ' ')
+ let vcol = a:width + 2
+ return matchstr(str, '.*\%<' . (vcol < 0 ? 0 : vcol) . 'v')
endfunction
function! s:strwidthpart_reverse(str, width) abort
- if a:width <= 0
- return ''
- endif
- let strarr = split(a:str, '\zs')
- let width = s:wcswidth(a:str)
- let strlen = len(strarr)
- let diff = (strlen + 1) / 2
- let leftindex = 0
- let index = -1
- while width > a:width
- let index = min([leftindex + diff, strlen]) - 1
- let partwidth = s:wcswidth(join(strarr[(leftindex):(index)], ''))
- if width - partwidth >= a:width || diff <= 1
- let width -= partwidth
- let leftindex = index + 1
- endif
- if diff > 1
- let diff = diff / 2
- endif
- endwhile
- return index < strlen ? join(strarr[(index + 1):], '') : ''
+ let str = tr(a:str, "\t", ' ')
+ let vcol = s:wcswidth(str) - a:width
+ return matchstr(str, '\%>' . (vcol < 0 ? 0 : vcol) . 'v.*')
endfunction
if v:version >= 703
" Use builtin function.
- function! s:wcswidth(str) abort
- return strwidth(a:str)
- endfunction
+ let s:wcswidth = function('strwidth')
else
function! s:wcswidth(str) abort
if a:str =~# '^[\x00-\x7f]*$'
@@ -577,7 +549,7 @@ else
endif
function! s:remove_ansi_sequences(text) abort
- return substitute(a:text, '\e\[\%(\%(\d;\)\?\d\{1,2}\)\?[mK]', '', 'g')
+ return substitute(a:text, '\e\[\%(\%(\d\+;\)*\d\+\)\?[mK]', '', 'g')
endfunction
function! s:escape_pattern(str) abort
@@ -16,39 +16,60 @@ endif
let s:save_cpo = &cpo
set cpo&vim
-if v:version ># 703 ||
-\ (v:version is 703 && has('patch465'))
+if v:version > 703 ||
+\ (v:version == 703 && has('patch465'))
function! s:glob(expr) abort
return glob(a:expr, 1, 1)
endfunction
else
function! s:glob(expr) abort
- let R = glob(a:expr, 1)
- return split(R, '\n')
+ return split(glob(a:expr, 1), '\n')
endfunction
endif
-function! s:globpath(path, expr) abort
- let R = globpath(a:path, a:expr, 1)
- return split(R, '\n')
-endfunction
+if v:version > 704 ||
+\ (v:version == 704 && has('patch279'))
+ function! s:globpath(path, expr) abort
+ return globpath(a:path, a:expr, 1, 1)
+ endfunction
+else
+ function! s:globpath(path, expr) abort
+ return split(globpath(a:path, a:expr, 1), '\n')
+ endfunction
+endif
" Wrapper functions for type().
-let [
-\ s:__TYPE_NUMBER,
-\ s:__TYPE_STRING,
-\ s:__TYPE_FUNCREF,
-\ s:__TYPE_LIST,
-\ s:__TYPE_DICT,
-\ s:__TYPE_FLOAT] = [
- \ type(3),
- \ type(''),
- \ type(function('tr')),
- \ type([]),
- \ type({}),
- \ has('float') ? type(str2float('0')) : -1]
-" __TYPE_FLOAT = -1 when -float
-" This doesn't match to anything.
+" NOTE: __TYPE_FLOAT = -1 when -float.
+" this doesn't match to anything.
+if has('patch-7.4.2071')
+ let [
+ \ s:__TYPE_NUMBER,
+ \ s:__TYPE_STRING,
+ \ s:__TYPE_FUNCREF,
+ \ s:__TYPE_LIST,
+ \ s:__TYPE_DICT,
+ \ s:__TYPE_FLOAT] = [
+ \ v:t_number,
+ \ v:t_string,
+ \ v:t_func,
+ \ v:t_list,
+ \ v:t_dict,
+ \ v:t_float]
+else
+ let [
+ \ s:__TYPE_NUMBER,
+ \ s:__TYPE_STRING,
+ \ s:__TYPE_FUNCREF,
+ \ s:__TYPE_LIST,
+ \ s:__TYPE_DICT,
+ \ s:__TYPE_FLOAT] = [
+ \ type(3),
+ \ type(''),
+ \ type(function('tr')),
+ \ type([]),
+ \ type({}),
+ \ has('float') ? type(str2float('0')) : -1]
+endif
" Number or Float
function! s:is_numeric(Value) abort
@@ -62,27 +83,32 @@ function! s:is_number(Value) abort
return type(a:Value) ==# s:__TYPE_NUMBER
endfunction
-" Float
-function! s:is_float(Value) abort
- return type(a:Value) ==# s:__TYPE_FLOAT
-endfunction
" String
function! s:is_string(Value) abort
return type(a:Value) ==# s:__TYPE_STRING
endfunction
+
" Funcref
function! s:is_funcref(Value) abort
return type(a:Value) ==# s:__TYPE_FUNCREF
endfunction
+
" List
function! s:is_list(Value) abort
return type(a:Value) ==# s:__TYPE_LIST
endfunction
+
" Dictionary
function! s:is_dict(Value) abort
return type(a:Value) ==# s:__TYPE_DICT
endfunction
+" Float
+function! s:is_float(Value) abort
+ return type(a:Value) ==# s:__TYPE_FLOAT
+endfunction
+
+
function! s:truncate_skipping(str, max, footer_width, separator) abort
call s:_warn_deprecated('truncate_skipping', 'Data.String.truncate_skipping')
@@ -3,13 +3,13 @@
" Do not mofidify the code nor insert new lines before '" ___vital___'
if v:version > 703 || v:version == 703 && has('patch1170')
function! vital#_vimshell#Vim#Buffer#import() abort
- return map({'_vital_depends': '', 'read_content': '', 'get_selected_text': '', 'is_cmdwin': '', 'edit_content': '', 'open': '', 'get_last_selected': '', '_vital_loaded': ''}, 'function("s:" . v:key)')
+ return map({'parse_cmdarg': '', '_vital_depends': '', 'read_content': '', 'get_selected_text': '', 'is_cmdwin': '', 'edit_content': '', 'open': '', 'get_last_selected': '', '_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#_vimshell#Vim#Buffer#import() abort', printf("return map({'_vital_depends': '', 'read_content': '', 'get_selected_text': '', 'is_cmdwin': '', 'edit_content': '', 'open': '', 'get_last_selected': '', '_vital_loaded': ''}, \"function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
+ execute join(['function! vital#_vimshell#Vim#Buffer#import() abort', printf("return map({'parse_cmdarg': '', '_vital_depends': '', 'read_content': '', 'get_selected_text': '', 'is_cmdwin': '', 'edit_content': '', 'open': '', 'get_last_selected': '', '_vital_loaded': ''}, \"function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
delfunction s:_SID
endif
" ___vital___
@@ -114,6 +114,7 @@ function! s:read_content(content, ...) abort
\ 'nobinary': 0,
\ 'bad': '',
\ 'edit': 0,
+ \ 'line': '',
\}, get(a:000, 0, {}))
let tempfile = empty(options.tempfile) ? tempname() : options.tempfile
let optnames = [
@@ -127,20 +128,22 @@ function! s:read_content(content, ...) abort
let optname = join(filter(optnames, '!empty(v:val)'))
try
call writefile(a:content, tempfile)
- execute printf('keepalt keepjumps read %s%s',
+ execute printf('keepalt keepjumps %sread %s%s',
+ \ options.line,
\ empty(optname) ? '' : optname . ' ',
\ fnameescape(tempfile),
\)
finally
call delete(tempfile)
+ execute 'bwipeout!' tempfile
endtry
endfunction
function! s:edit_content(content, ...) abort
let options = extend({
\ 'edit': 1,
\}, get(a:000, 0, {}))
- let guard = s:G.store('&l:modifiable')
+ let guard = s:G.store(['&l:modifiable'])
let saved_view = winsaveview()
try
let &l:modifiable=1
@@ -154,6 +157,30 @@ function! s:edit_content(content, ...) abort
setlocal nomodified
endfunction
+function! s:parse_cmdarg(...) abort
+ let cmdarg = get(a:000, 0, v:cmdarg)
+ let options = {}
+ if cmdarg =~# '++enc='
+ let options.encoding = matchstr(cmdarg, '++enc=\zs[^ ]\+\ze')
+ endif
+ if cmdarg =~# '++ff='
+ let options.fileformat = matchstr(cmdarg, '++ff=\zs[^ ]\+\ze')
+ endif
+ if cmdarg =~# '++bad='
+ let options.bad = matchstr(cmdarg, '++bad=\zs[^ ]\+\ze')
+ endif
+ if cmdarg =~# '++bin'
+ let options.binary = 1
+ endif
+ if cmdarg =~# '++nobin'
+ let options.nobinary = 1
+ endif
+ if cmdarg =~# '++edit'
+ let options.edit = 1
+ endif
+ return options
+endfunction
+
let &cpo = s:save_cpo
unlet s:save_cpo
@@ -100,7 +100,12 @@ function! s:_new_register(name) abort
return register
endfunction
function! s:register.restore() abort
- call setreg(self.name, self.value, self.type)
+ " https://github.com/vim/vim/commit/5a50c2255c447838d08d3b4895a3be3a41cd8eda
+ if has('patch-7.4.243') || self.name !=# '='
+ call setreg(self.name, self.value, self.type)
+ else
+ let @= = self.value
+ endif
endfunction
let s:environment = {}
@@ -185,9 +190,9 @@ function! s:instance.restore() abort
endfunction
let s:guard = {}
-function! s:store(...) abort
+function! s:store(targets) abort
let resources = []
- for meta in a:000
+ for meta in a:targets
if s:Prelude.is_list(meta)
if len(meta) == 1
call add(resources, s:_new_instance(meta[0]))
Oops, something went wrong.

0 comments on commit d0c5bef

Please sign in to comment.