Skip to content

Commit

Permalink
Version 1.11
Browse files Browse the repository at this point in the history
- tlib#vcs#FindVCS(filename): Wrong parameters to fnamemodifiy if filename is a directory- Some system-related functions (e.g. facilitate use of cygwin tools)- tlib#arg#StringAsKeyArgsEqual(), tlib#arg#StringAsKeyArgs(): Support "key=val" type argument lists- tlib#vcs#Executable()- scripts/create_crc_table.rb- tlib#var#Get(): For namespaces other than global, replace "#" with "_"MD5 checksum: 4a33f2f23e1fc6600b32e7f8323e001e
  • Loading branch information
tomtom authored and vim-scripts committed Jul 6, 2014
1 parent 530bac3 commit 51fce93
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 37 deletions.
47 changes: 24 additions & 23 deletions autoload/tlib/arg.vim
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
" arg.vim
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2007-06-30.
" @Last Change: 2009-02-15.
" @Revision: 0.0.50

if &cp || exists("loaded_tlib_arg_autoload")
finish
endif
let loaded_tlib_arg_autoload = 1
" @Last Change: 2014-07-01.
" @Revision: 63


" :def: function! tlib#arg#Get(n, var, ?default="", ?test='')
Expand Down Expand Up @@ -50,32 +43,40 @@ function! tlib#arg#Key(list, ...) "{{{3
endf


" :def: function! tlib#arg#StringAsKeyArgs(string, ?keys=[], ?evaluate=0)
" :def: function! tlib#arg#StringAsKeyArgs(string, ?keys=[], ?evaluate=0, ?sep=':')
function! tlib#arg#StringAsKeyArgs(string, ...) "{{{1
TVarArg ['keys', {}], ['evaluate', 0]
TVarArg ['keys', {}], ['evaluate', 0], ['sep', ':']
let keyargs = {}
let args = split(a:string, '\\\@<! ')
let arglist = map(args, 'matchlist(v:val, ''^\(\w\+\):\(.*\)$'')')
let arglist = map(args, 'matchlist(v:val, ''^\%(\(\w\+\)'. sep .'\(.*\)\|\(.*\)\)$'')')
" TLogVAR a:string, args, arglist
let pos = 0
for matchlist in arglist
if len(matchlist) < 3
throw 'Malformed key arguments: '. string(matchlist) .' in '. a:string
endif
let [match, key, val; rest] = matchlist
if empty(keys) || has_key(keys, key)
let val = substitute(val, '\\\\', '\\', 'g')
if evaluate
let val = eval(val)
endif
let keyargs[key] = val
if !empty(matchlist[3])
let keyargs[pos] = matchlist[3]
let pos += 1
else
echom 'Unknown key: '. key .'='. val
let [match, key, val; rest] = matchlist
if empty(keys) || has_key(keys, key)
let val = substitute(val, '\\\\', '\\', 'g')
if evaluate
let val = eval(val)
endif
let keyargs[key] = val
else
echom 'Unknown key: '. key .'='. val
endif
endif
endfor
return keyargs
endf


function! tlib#arg#StringAsKeyArgsEqual(string) "{{{1
return tlib#arg#StringAsKeyArgs(a:string, [], 0, '=')
endf



""" Command line {{{1

Expand Down
127 changes: 127 additions & 0 deletions autoload/tlib/sys.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Last Change: 2014-06-30.
" @Revision: 25


if !exists('g:tlib#sys#windows')
let g:tlib#sys#windows = &shell !~ 'sh' && (has('win16') || has('win32') || has('win64')) "{{{2
endif


if !exists('g:tlib#sys#null')
let g:tlib#sys#null = g:tlib#sys#windows ? 'NUL' : (filereadable('/dev/null') ? '/dev/null' : '') "{{{2
endif


let s:executables = {}

function! tlib#sys#IsExecutable(cmd, ...) "{{{3
" TLogVAR a:cmd
" echom "DBG has_key(s:executables, a:cmd)" has_key(s:executables, a:cmd)
if !has_key(s:executables, a:cmd)
let executable = executable(a:cmd)
" TLogVAR 1, executable
let ignore_cyg = a:0 >= 1 ? a:1 : !g:tlib#sys#windows
if !executable && !ignore_cyg
let executable = tlib#sys#IsCygwinBin(a:cmd)
" TLogVAR 2, executable
endif
let s:executables[a:cmd] = executable
endif
" echom "DBG s:executables[a:cmd]" s:executables[a:cmd]
return s:executables[a:cmd]
endf


if !exists('g:tlib#sys#check_cygpath')
" If true, check whether we have to convert a path via cyppath --
" see |tlib#sys#MaybeUseCygpath|
let g:tlib#sys#check_cygpath = g:tlib#sys#windows && tlib#sys#IsExecutable('cygpath') "{{{2
endif


if !exists('g:tlib#sys#cygwin_path_rx')
" If a full windows filename (with slashes instead of backslashes)
" matches this |regexp|, it is assumed to be a cygwin executable.
let g:tlib#sys#cygwin_path_rx = '/cygwin/' "{{{2
endif


if !exists('g:tlib#sys#cygwin_expr')
" For cygwin binaries, convert command calls using this vim
" expression.
let g:tlib#sys#cygwin_expr = '"bash -c ''". escape(%s, "''\\") ."''"' "{{{2
endif


let s:cygwin = {}

function! tlib#sys#IsCygwinBin(cmd) "{{{3
" TLogVAR a:cmd
if !g:tlib#sys#windows
return 0
elseif has_key(s:cygwin, a:cmd)
let rv = s:cygwin[a:cmd]
else
if !tlib#sys#IsExecutable('cygpath', 1) || !tlib#sys#IsExecutable('which', 1)
let rv = 0
else
let which = substitute(system('which '. shellescape(a:cmd)), '\n$', '', '')
" echom "DBG which:" which
if which =~ '^/'
let filename = system('cygpath -ma '. shellescape(which))
" echom "DBG filename:" filename
let rv = filename =~ g:tlib#sys#cygwin_path_rx
else
let rv = 0
endif
endif
let s:cygwin[a:cmd] = rv
endif
" TLogVAR rv
return rv
endf


function! tlib#sys#GetCmd(cmd) "{{{3
if !empty(g:tlib#sys#cygwin_expr) && tlib#sys#IsCygwinBin(matchstr(a:cmd, '^\S\+'))
let cmd = eval(printf(g:tlib#sys#cygwin_expr, string(a:cmd)))
" TLogVAR cmd
return cmd
else
return a:cmd
endif
endf


" If cmd seems to be a cygwin executable, use cygpath to convert
" filenames. This assumes that cygwin's which command returns full
" filenames for non-cygwin executables.
function! tlib#sys#MaybeUseCygpath(cmd) "{{{3
" echom "DBG" a:cmd
if g:tlib#sys#check_cygpath && tlib#sys#IsCygwinBin(a:cmd)
return 'cygpath -u "%s"'
endif
return ''
endf


function! tlib#sys#ConvertPath(converter, filename) "{{{3
return tlib#string#Chomp(system(printf(a:converter, shellescape(a:filename))))
endf


let s:native_filenames = {}

function! tlib#sys#FileArgs(cmd, files) "{{{3
let cygpath = tlib#sys#MaybeUseCygpath(a:cmd)
" TLogVAR cygpath
if empty(cygpath)
return a:files
else
let files = map(copy(a:files), 'has_key(s:native_filenames, v:val) ? s:native_filenames[v:val] : tlib#sys#CygPath(v:val)')
return files
endif
endf

10 changes: 6 additions & 4 deletions autoload/tlib/var.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2007-06-30.
" @Last Change: 2009-02-15.
" @Revision: 0.0.23
" @Last Change: 2014-07-03.
" @Revision: 0.0.26

if &cp || exists("loaded_tlib_var_autoload")
finish
Expand Down Expand Up @@ -58,10 +58,12 @@ endf
" echo tlib#var#Get('foo', 'bg') => 2
" echo tlib#var#Get('foo', 'wbg') => 3
function! tlib#var#Get(var, namespace, ...) "{{{3
let var_ = substitute(a:var, '#', '_', 'g')
for namespace in split(a:namespace, '\zs')
let var = namespace .':'. a:var
let vname = namespace == 'g' ? a:var : var_
let var = namespace .':'. vname
if exists(var)
return eval(var)
return {var}
endif
endfor
return a:0 >= 1 ? a:1 : ''
Expand Down
17 changes: 11 additions & 6 deletions autoload/tlib/vcs.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2012-03-08.
" @Last Change: 2012-09-10.
" @Revision: 122
" @Last Change: 2014-07-01.
" @Revision: 131


" A dictionarie of supported VCS (currently: git, hg, svn, bzr).
Expand Down Expand Up @@ -49,16 +49,21 @@ if !empty(g:tlib#vcs#check)
let g:tlib#vcs#executables[s:cmd] = executable(s:cmd1) ? s:cmd1 : ''
endif
endfor
unlet! s:cmd s:def s:cmd1
endif


function! tlib#vcs#Executable(type) "{{{3
return get(g:tlib#vcs#executables, a:type, '')
endf


function! tlib#vcs#FindVCS(filename) "{{{3
let type = ''
let dir = ''
" let path = escape(fnamemodify(a:filename, ':p'), ',:') .';'
let filename = fnamemodify(a:filename, isdirectory(a:filename) ? ':p:h' : ':p')
let path = escape(filename, ';') .';'
" TLogVAR a:filename, path
let dirname = fnamemodify(a:filename, isdirectory(a:filename) ? ':p' : ':p:h')
let path = escape(dirname, ';') .';'
" TLogVAR a:filename, dirname, path
let depth = -1
for vcs in keys(g:tlib#vcs#def)
let subdir = g:tlib#vcs#def[vcs].dir
Expand Down
67 changes: 66 additions & 1 deletion doc/tlib.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Contents~
g:tlib#vcs#def ......................... |g:tlib#vcs#def|
g:tlib#vcs#executables ................. |g:tlib#vcs#executables|
g:tlib#vcs#check ....................... |g:tlib#vcs#check|
tlib#vcs#Executable .................... |tlib#vcs#Executable()|
tlib#vcs#FindVCS ....................... |tlib#vcs#FindVCS()|
tlib#vcs#Ls ............................ |tlib#vcs#Ls()|
tlib#vcs#Diff .......................... |tlib#vcs#Diff()|
Expand Down Expand Up @@ -240,6 +241,17 @@ Contents~
tlib#file#Relative ..................... |tlib#file#Relative()|
tlib#file#Absolute ..................... |tlib#file#Absolute()|
tlib#file#With ......................... |tlib#file#With()|
g:tlib#sys#windows ..................... |g:tlib#sys#windows|
g:tlib#sys#null ........................ |g:tlib#sys#null|
tlib#sys#IsExecutable .................. |tlib#sys#IsExecutable()|
g:tlib#sys#check_cygpath ............... |g:tlib#sys#check_cygpath|
g:tlib#sys#cygwin_path_rx .............. |g:tlib#sys#cygwin_path_rx|
g:tlib#sys#cygwin_expr ................. |g:tlib#sys#cygwin_expr|
tlib#sys#IsCygwinBin ................... |tlib#sys#IsCygwinBin()|
tlib#sys#GetCmd ........................ |tlib#sys#GetCmd()|
tlib#sys#MaybeUseCygpath ............... |tlib#sys#MaybeUseCygpath()|
tlib#sys#ConvertPath ................... |tlib#sys#ConvertPath()|
tlib#sys#FileArgs ...................... |tlib#sys#FileArgs()|
tlib#paragraph#GetMetric ............... |tlib#paragraph#GetMetric()|
tlib#paragraph#Move .................... |tlib#paragraph#Move()|
g:tlib_inputlist_pct ................... |g:tlib_inputlist_pct|
Expand Down Expand Up @@ -269,6 +281,7 @@ Contents~
tlib#arg#Let ........................... |tlib#arg#Let()|
tlib#arg#Key ........................... |tlib#arg#Key()|
tlib#arg#StringAsKeyArgs ............... |tlib#arg#StringAsKeyArgs()|
tlib#arg#StringAsKeyArgsEqual .......... |tlib#arg#StringAsKeyArgsEqual()|
tlib#arg#Ex ............................ |tlib#arg#Ex()|
tlib#fixes#Winpos ...................... |tlib#fixes#Winpos()|
g:tlib#dir#sep ......................... |g:tlib#dir#sep|
Expand Down Expand Up @@ -747,6 +760,9 @@ g:tlib#vcs#check (default: has('win16') || has('win32') || has('wi
If non-empty, use it as a format string to check whether a VCS is
installed on your computer.

*tlib#vcs#Executable()*
tlib#vcs#Executable(type)

*tlib#vcs#FindVCS()*
tlib#vcs#FindVCS(filename)

Expand Down Expand Up @@ -1575,6 +1591,52 @@ tlib#file#Absolute(filename, ...)
tlib#file#With(fcmd, bcmd, files, ?world={})


========================================================================
autoload/tlib/sys.vim~

*g:tlib#sys#windows*
g:tlib#sys#windows (default: &shell !~ 'sh' && (has('win16') || has('win32') || has('win64')))

*g:tlib#sys#null*
g:tlib#sys#null (default: g:tlib#sys#windows ? 'NUL' : (filereadable('/dev/null') ? '/dev/null' : ''))

*tlib#sys#IsExecutable()*
tlib#sys#IsExecutable(cmd, ...)

*g:tlib#sys#check_cygpath*
g:tlib#sys#check_cygpath (default: g:tlib#sys#windows && tlib#sys#IsExecutable('cygpath'))
If true, check whether we have to convert a path via cyppath --
see |tlib#sys#MaybeUseCygpath|

*g:tlib#sys#cygwin_path_rx*
g:tlib#sys#cygwin_path_rx (default: '/cygwin/')
If a full windows filename (with slashes instead of backslashes)
matches this |regexp|, it is assumed to be a cygwin executable.

*g:tlib#sys#cygwin_expr*
g:tlib#sys#cygwin_expr (default: '"bash -c ''". escape(%s, "''\\") ."''"')
For cygwin binaries, convert command calls using this vim
expression.

*tlib#sys#IsCygwinBin()*
tlib#sys#IsCygwinBin(cmd)

*tlib#sys#GetCmd()*
tlib#sys#GetCmd(cmd)

*tlib#sys#MaybeUseCygpath()*
tlib#sys#MaybeUseCygpath(cmd)
If cmd seems to be a cygwin executable, use cygpath to convert
filenames. This assumes that cygwin's which command returns full
filenames for non-cygwin executables.

*tlib#sys#ConvertPath()*
tlib#sys#ConvertPath(converter, filename)

*tlib#sys#FileArgs()*
tlib#sys#FileArgs(cmd, files)


========================================================================
autoload/tlib/paragraph.vim~

Expand Down Expand Up @@ -1734,7 +1796,10 @@ tlib#arg#Key(dict, list, ?default='')
See |:TKeyArg|.

*tlib#arg#StringAsKeyArgs()*
tlib#arg#StringAsKeyArgs(string, ?keys=[], ?evaluate=0)
tlib#arg#StringAsKeyArgs(string, ?keys=[], ?evaluate=0, ?sep=':')

*tlib#arg#StringAsKeyArgsEqual()*
tlib#arg#StringAsKeyArgsEqual(string)

*tlib#arg#Ex()*
tlib#arg#Ex(arg, ?chars='%#! ')
Expand Down
6 changes: 3 additions & 3 deletions plugin/02tlib.vim
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
" @Created: 2007-04-10.
" @Last Change: 2013-09-25.
" @Last Change: 2014-07-03.
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Revision: 751
" @Revision: 752
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" GetLatestVimScripts: 1863 1 tlib.vim
" tlib.vim -- Some utility functions
Expand All @@ -14,7 +14,7 @@ if v:version < 700 "{{{2
echoerr "tlib requires Vim >= 7"
finish
endif
let loaded_tlib = 110
let loaded_tlib = 111

let s:save_cpo = &cpo
set cpo&vim
Expand Down

0 comments on commit 51fce93

Please sign in to comment.