diff --git a/autoload/neosnippet/util.vim b/autoload/neosnippet/util.vim index 00ba8ee..9b3de8c 100644 --- a/autoload/neosnippet/util.vim +++ b/autoload/neosnippet/util.vim @@ -1,7 +1,7 @@ "============================================================================= " FILE: util.vim " AUTHOR: Shougo Matsushita -" Last Modified: 13 Nov 2013. +" Last Modified: 15 Feb 2014. " License: MIT license {{{ " Permission is hereby granted, free of charge, to any person obtaining " a copy of this software and associated documentation files (the @@ -28,36 +28,57 @@ let s:save_cpo = &cpo set cpo&vim let s:V = vital#of('neosnippet') +function! neosnippet#util#get_vital() "{{{ + return s:V +endfunction"}}} +function! s:get_prelude() "{{{ + if !exists('s:Prelude') + let s:Prelude = neosnippet#util#get_vital().import('Prelude') + endif + return s:Prelude +endfunction"}}} +function! s:get_list() "{{{ + if !exists('s:List') + let s:List = neosnippet#util#get_vital().import('Data.List') + endif + return s:List +endfunction"}}} +function! s:get_process() "{{{ + if !exists('s:Process') + let s:Process = neosnippet#util#get_vital().import('Process') + endif + return s:Process +endfunction"}}} function! neosnippet#util#substitute_path_separator(...) "{{{ - return call(s:V.substitute_path_separator, a:000) + return call(s:get_prelude().substitute_path_separator, a:000) endfunction"}}} function! neosnippet#util#system(...) "{{{ - return call(s:V.system, a:000) + return call(s:get_process().system, a:000) endfunction"}}} function! neosnippet#util#has_vimproc(...) "{{{ - return call(s:V.has_vimproc, a:000) + return call(s:get_process().has_vimproc, a:000) endfunction"}}} function! neosnippet#util#is_windows(...) "{{{ - return call(s:V.is_windows, a:000) + return call(s:get_prelude().is_windows, a:000) endfunction"}}} function! neosnippet#util#is_mac(...) "{{{ - return call(s:V.is_mac, a:000) + return call(s:get_prelude().is_mac, a:000) endfunction"}}} function! neosnippet#util#get_last_status(...) "{{{ - return call(s:V.get_last_status, a:000) + return call(s:get_process().get_last_status, a:000) endfunction"}}} function! neosnippet#util#escape_pattern(...) "{{{ - return call(s:V.escape_pattern, a:000) + return call(s:get_prelude().escape_pattern, a:000) endfunction"}}} function! neosnippet#util#iconv(...) "{{{ - return call(s:V.iconv, a:000) + return call(s:get_process().iconv, a:000) endfunction"}}} function! neosnippet#util#truncate(...) "{{{ - return call(s:V.truncate, a:000) + return call(s:get_prelude().truncate, a:000) endfunction"}}} function! neosnippet#util#strwidthpart(...) "{{{ - return call(s:V.strwidthpart, a:000) + return call(s:get_prelude().strwidthpart, a:000) endfunction"}}} function! neosnippet#util#expand(path) "{{{ @@ -70,7 +91,7 @@ function! neosnippet#util#set_default(var, val, ...) "{{{ endif endfunction"}}} function! neosnippet#util#set_dictionary_helper(...) "{{{ - return call(s:V.set_dictionary_helper, a:000) + return call(s:get_prelude().set_dictionary_helper, a:000) endfunction"}}} function! neosnippet#util#get_cur_text() "{{{ diff --git a/autoload/vital/_9bfba96.vim b/autoload/vital/_neosnippet.vim similarity index 99% rename from autoload/vital/_9bfba96.vim rename to autoload/vital/_neosnippet.vim index 3ba9dc9..6a0aac3 100644 --- a/autoload/vital/_9bfba96.vim +++ b/autoload/vital/_neosnippet.vim @@ -199,5 +199,5 @@ function! s:_redir(cmd) endfunction function! vital#{s:self_version}#new() - return s:_import('').load(['Prelude', '']) + return s:_import('') endfunction diff --git a/autoload/vital/_9bfba96/Data/List.vim b/autoload/vital/_neosnippet/Data/List.vim similarity index 89% rename from autoload/vital/_9bfba96/Data/List.vim rename to autoload/vital/_neosnippet/Data/List.vim index 226f55a..cdbd49b 100644 --- a/autoload/vital/_9bfba96/Data/List.vim +++ b/autoload/vital/_neosnippet/Data/List.vim @@ -24,18 +24,22 @@ 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) +function! s:uniq(list) + return s:uniq_by(a:list, 'v:val') +endfunction + +" Removes duplicates from a list. +function! s:uniq_by(list, f) + let list = map(copy(a:list), printf('[v:val, %s]', a:f)) let i = 0 let seen = {} while i < len(list) - let key = string(a:0 ? list[i][1] : list[i]) + let key = string(list[i][1]) if has_key(seen, key) call remove(list, i) else @@ -43,7 +47,7 @@ function! s:uniq(list, ...) let i += 1 endif endwhile - return a:0 ? map(list, 'v:val[0]') : list + return map(list, 'v:val[0]') endfunction function! s:clear(list) @@ -56,30 +60,29 @@ endfunction " Concatenates a list of lists. " XXX: Should we verify the input? function! s:concat(list) - let list = [] + let memo = [] for Value in a:list - let list += Value + let memo += Value endfor - return list + return memo endfunction -" Flattens a list. +" Take each elements from lists to a new list. function! s:flatten(list, ...) let limit = a:0 > 0 ? a:1 : -1 - let list = [] + let memo = [] if limit == 0 return a:list endif let limit -= 1 for Value in a:list - if type(Value) == type([]) - let list += s:flatten(Value, limit) - else - call add(list, Value) - endif + let memo += + \ type(Value) == type([]) ? + \ s:flatten(Value, limit) : + \ [Value] unlet! Value endfor - return list + return memo endfunction " Sorts a list with expression to compare each two values. @@ -105,11 +108,6 @@ 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} @@ -121,11 +119,6 @@ function! s:max_by(list, 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} diff --git a/autoload/vital/_9bfba96/Prelude.vim b/autoload/vital/_neosnippet/Prelude.vim similarity index 80% rename from autoload/vital/_9bfba96/Prelude.vim rename to autoload/vital/_neosnippet/Prelude.vim index 7c1425f..9a076bc 100644 --- a/autoload/vital/_9bfba96/Prelude.vim +++ b/autoload/vital/_neosnippet/Prelude.vim @@ -49,11 +49,6 @@ function! s:is_numeric(Value) endfunction " Number -function! s:is_integer(Value) - echoerr 'Prelude.is_integer() is obsolete. Use its is_number() instead; they are equivalent.' - return s:is_number(a:Value) -endfunction - function! s:is_number(Value) return type(a:Value) ==# s:__TYPE_NUMBER endfunction @@ -220,7 +215,14 @@ function! s:is_unix() return s:is_unix endfunction +function! s:_deprecated(fname, newname) + echomsg printf("Vital.Prelude.%s is deprecated! Please use %s instead.", + \ a:fname, a:newname) +endfunction + function! s:print_error(message) + call s:_deprecated('print_error', 'Vital.Vim.Message.error') + echohl ErrorMsg for m in split(a:message, "\n") echomsg m @@ -240,47 +242,32 @@ function! s:escape_pattern(str) return escape(a:str, '~"\.^$[]*') endfunction -" iconv() wrapper for safety. -function! s:iconv(expr, from, to) - if a:from == '' || a:to == '' || a:from ==? a:to - return a:expr - endif - let result = iconv(a:expr, a:from, a:to) - return result != '' ? result : a:expr -endfunction - -" Like builtin getchar() but returns string always. function! s:getchar(...) let c = call('getchar', a:000) return type(c) == type(0) ? nr2char(c) : c endfunction -" Like builtin getchar() but returns string always. -" and do inputsave()/inputrestore() before/after getchar(). function! s:getchar_safe(...) let c = s:input_helper('getchar', a:000) return type(c) == type("") ? c : nr2char(c) endfunction -" Like builtin getchar() but -" do inputsave()/inputrestore() before/after input(). function! s:input_safe(...) - return s:input_helper('input', a:000) + return s:input_helper('input', a:000) endfunction -" Do inputsave()/inputrestore() before/after calling a:funcname. function! s:input_helper(funcname, args) - let success = 0 - if inputsave() !=# success - throw 'inputsave() failed' + let success = 0 + if inputsave() !=# success + throw 'inputsave() failed' + endif + try + return call(a:funcname, a:args) + finally + if inputrestore() !=# success + throw 'inputrestore() failed' endif - try - return call(a:funcname, a:args) - finally - if inputrestore() !=# success - throw 'inputrestore() failed' - endif - endtry + endtry endfunction function! s:set_default(var, val) @@ -380,8 +367,9 @@ function! s:path2project_directory(path, ...) " Search project file. if directory == '' - for d in ['build.xml', 'prj.el', '.project', 'pom.xml', - \ 'Makefile', 'configure', 'Rakefile', 'NAnt.build', 'tags', 'gtags'] + for d in ['build.xml', 'prj.el', '.project', 'pom.xml', 'package.json', + \ 'Makefile', 'configure', 'Rakefile', 'NAnt.build', + \ 'P4CONFIG', 'tags', 'gtags'] let d = findfile(d, s:escape_file_searching(search_directory) . ';') if d != '' let directory = fnamemodify(d, ':p:h') @@ -406,47 +394,6 @@ function! s:path2project_directory(path, ...) return s:substitute_path_separator(directory) endfunction -" Check vimproc. -function! s:has_vimproc() - if !exists('s:exists_vimproc') - try - call vimproc#version() - let s:exists_vimproc = 1 - catch - let s:exists_vimproc = 0 - endtry - endif - return s:exists_vimproc -endfunction - -function! s:system(str, ...) - let command = a:str - let input = a:0 >= 1 ? a:1 : '' - let command = s:iconv(command, &encoding, 'char') - let input = s:iconv(input, &encoding, 'char') - - if a:0 == 0 - let output = s:has_vimproc() ? - \ vimproc#system(command) : system(command) - elseif a:0 == 1 - let output = s:has_vimproc() ? - \ vimproc#system(command, input) : system(command, input) - else - " ignores 3rd argument unless you have vimproc. - let output = s:has_vimproc() ? - \ vimproc#system(command, input, a:2) : system(command, input) - endif - - let output = s:iconv(output, 'char', &encoding) - - return output -endfunction - -function! s:get_last_status() - return s:has_vimproc() ? - \ vimproc#get_last_status() : v:shell_error -endfunction - let &cpo = s:save_cpo unlet s:save_cpo diff --git a/autoload/vital/_neosnippet/Process.vim b/autoload/vital/_neosnippet/Process.vim new file mode 100644 index 0000000..f2dc640 --- /dev/null +++ b/autoload/vital/_neosnippet/Process.vim @@ -0,0 +1,154 @@ +" TODO: move all comments to doc file. +" +" +" FIXME: This module name should be Vital.System ? +" But the name has been already taken. + +let s:save_cpo = &cpo +set cpo&vim + + +" FIXME: Unfortunately, can't use s:_vital_loaded() for this purpose. +" Because these variables are used when this script file is loaded. +let s:is_windows = has('win16') || has('win32') || has('win64') || has('win95') +let s:is_unix = has('unix') + + +" Execute program in the background from Vim. +" Return an empty string always. +" +" If a:expr is a List, shellescape() each argument. +" If a:expr is a String, the arguments are passed as-is. +" +" Windows: +" Using :!start , execute program without via cmd.exe. +" Spawning 'expr' with 'noshellslash' +" keep special characters from unwanted expansion. +" (see :help shellescape()) +" +" Unix: +" using :! , execute program in the background by shell. +function! s:spawn(expr, ...) + if s:is_windows + let shellslash = &l:shellslash + setlocal noshellslash + endif + try + if type(a:expr) is type([]) + let special = 1 + let cmdline = join(map(a:expr, 'shellescape(v:val, special)'), ' ') + elseif type(a:expr) is type("") + let cmdline = a:expr + if a:0 && a:1 + " for :! command + let cmdline = substitute(cmdline, '\([!%#]\|<[^<>]\+>\)', '\\\1', 'g') + endif + else + throw 'Process.spawn(): invalid argument (value type:'.type(a:expr).')' + endif + if s:is_windows + silent execute '!start' cmdline + else + silent execute '!' cmdline '&' + endif + finally + if s:is_windows + let &l:shellslash = shellslash + endif + endtry + return '' +endfunction + +" iconv() wrapper for safety. +function! s:iconv(expr, from, to) + if a:from == '' || a:to == '' || a:from ==? a:to + return a:expr + endif + let result = iconv(a:expr, a:from, a:to) + return result != '' ? result : a:expr +endfunction + +" Check vimproc. +function! s:has_vimproc() + if !exists('s:exists_vimproc') + try + call vimproc#version() + let s:exists_vimproc = 1 + catch + let s:exists_vimproc = 0 + endtry + endif + return s:exists_vimproc +endfunction + +" * {command} [, {input} [, {timeout}]] +" * {command} [, {dict}] +" {dict} = { +" use_vimproc: bool, +" input: string, +" timeout: bool, +" } +function! s:system(str, ...) + if type(a:str) is type([]) + let command = join(map(copy(a:str), 's:shellescape(v:val)'), ' ') + elseif type(a:str) is type("") + let command = a:str + else + throw 'Process.system(): invalid argument (value type:'.type(a:str).')' + endif + let command = s:iconv(command, &encoding, 'char') + let input = '' + let use_vimproc = s:has_vimproc() + let args = [command] + if a:0 ==# 1 + if type(a:1) is type({}) + if has_key(a:1, 'use_vimproc') + let use_vimproc = a:1.use_vimproc + endif + if has_key(a:1, 'input') + let args += [s:iconv(a:1.input, &encoding, 'char')] + endif + if use_vimproc && has_key(a:1, 'timeout') + " ignores timeout unless you have vimproc. + let args += [a:1.timeout] + endif + endif + elseif a:0 >= 2 + let [input; rest] = a:000 + let input = s:iconv(a:1, &encoding, 'char') + let args += [input] + rest + endif + + if use_vimproc + " vimproc's parser seems to treat # as a comment + let args[0] = escape(args[0], '#') + let funcname = 'vimproc#system' + else + let funcname = 'system' + endif + let output = call(funcname, args) + let output = s:iconv(output, 'char', &encoding) + + return output +endfunction + +function! s:get_last_status() + return s:has_vimproc() ? + \ vimproc#get_last_status() : v:shell_error +endfunction + +if s:is_windows + function! s:shellescape(command) + return substitute(a:command, '[&()[\]{}^=;!''+,`~]', '^\0', 'g') + endfunction +else + function! s:shellescape(...) + return call('shellescape', a:000) + endfunction +endif + + +let &cpo = s:save_cpo +unlet s:save_cpo + +" vim:set et ts=2 sts=2 sw=2 tw=0: diff --git a/autoload/vital/neosnippet.vital b/autoload/vital/neosnippet.vital index d4022aa..a63048f 100644 --- a/autoload/vital/neosnippet.vital +++ b/autoload/vital/neosnippet.vital @@ -1,3 +1,6 @@ -9bfba96 +neosnippet +450727f +Prelude Data.List +Process