Permalink
Browse files

Version 0.16: - tlib#string#Printf1()

  • Loading branch information...
1 parent a394ab8 commit 93e792bb5119929a7478d06c0ab632ab9593bd66 @tomtom tomtom committed with Oct 7, 2007
View
@@ -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-24.
-" @Last Change: 2007-09-15.
-" @Revision: 0.1.136
+" @Last Change: 2007-10-05.
+" @Revision: 0.1.137
if &cp || exists("loaded_tlib_agent_autoload") "{{{2
finish
@@ -437,7 +437,7 @@ endf
function! tlib#agent#DoAtLine(world, selected) "{{{3
if !empty(a:selected)
- let cmd = input('Command: ')
+ let cmd = input('Command: ', '', 'command')
if !empty(cmd)
call a:world.SwitchWindow('win')
let pos = getpos('.')
View
@@ -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: 2007-09-14.
-" @Revision: 0.0.32
+" @Last Change: 2007-10-04.
+" @Revision: 0.0.45
if &cp || exists("loaded_tlib_arg_autoload")
finish
@@ -50,6 +50,32 @@ function! tlib#arg#Key(list, ...) "{{{3
endf
+" :def: function! tlib#arg#StringAsKeyArgs(string, ?keys=[], ?evaluate=0)
+function! tlib#arg#StringAsKeyArgs(string, ...) "{{{1
+ TVarArg ['keys', {}], ['evaluate', 0]
+ let keyargs = {}
+ let args = split(a:string, '\\\@<! ')
+ let arglist = map(args, 'matchlist(v:val, ''^\(\w\+\):\(.*\)$'')')
+ " TLogVAR a:string, args, arglist
+ 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
+ else
+ echom 'Unknown key: '. key .'='. val
+ endif
+ endfor
+ return keyargs
+endf
+
+
""" Command line {{{1
View
@@ -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: 2007-09-28.
-" @Revision: 0.0.351
+" @Last Change: 2007-10-07.
+" @Revision: 0.0.352
if &cp || exists("loaded_tlib_input_autoload")
finish
@@ -152,7 +152,7 @@ function! tlib#input#ListW(world, ...) "{{{3
exec ea
else
let agent = get(handler, 'agent', '')
- let world = call(agent, [world])
+ let world = call(agent, [world, world.GetSelectedItems(world.GetCurrentItem())])
call s:CheckAgentReturnValue(agent, world)
endif
endif
@@ -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-09-30.
-" @Last Change: 2007-09-30.
-" @Revision: 0.0.32
+" @Last Change: 2007-10-01.
+" @Revision: 0.0.33
if &cp || exists("loaded_tlib_progressbar_autoload")
finish
@@ -38,7 +38,7 @@ function! tlib#progressbar#Init(max, ...) "{{{3
call insert(s:width, width)
call insert(s:value, -1)
let &laststatus = 2
- let s:timestamp = -1
+ let s:timestamp = localtime()
endf
@@ -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-07-18.
-" @Last Change: 2007-09-11.
-" @Revision: 0.0.111
+" @Last Change: 2007-10-07.
+" @Revision: 0.0.117
if &cp || exists("loaded_tlib_scratch_autoload")
finish
@@ -22,6 +22,8 @@ function! tlib#scratch#UseScratch(...) "{{{3
let id = get(keyargs, 'scratch', '__Scratch__')
" TLogVAR id
" TLogDBG winnr()
+ " TLogDBG bufnr(id)
+ " TLogDBG bufwinnr(id)
" TLogDBG bufnr('%')
if id =~ '^\d\+$' && bufwinnr(id) != -1
if bufnr('%') != id
View
@@ -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: 2007-09-29.
-" @Revision: 0.0.17
+" @Last Change: 2007-10-02.
+" @Revision: 0.0.48
if &cp || exists("loaded_tlib_string_autoload")
finish
@@ -28,6 +28,45 @@ function! tlib#string#Chomp(string) "{{{3
endf
+" This function deviates from |printf()| in certain ways.
+" Additional items:
+" %{rx} ... insert escaped regexp
+" %{fuzzyrx} ... insert typo-tolerant regexp
+function! tlib#string#Printf1(format, string) "{{{3
+ let n = len(split(a:format, '%\@<!%s', 1)) - 1
+ let f = a:format
+ if f =~ '%\@<!%{fuzzyrx}'
+ let frx = []
+ for i in range(len(a:string))
+ if i > 0
+ let pb = i - 1
+ else
+ let pb = 0
+ endif
+ let slice = tlib#rx#Escape(a:string[pb : i + 1])
+ call add(frx, '['. slice .']')
+ call add(frx, '.\?')
+ endfor
+ let f = s:RewriteFormatString(f, '%{fuzzyrx}', join(frx, ''))
+ endif
+ if f =~ '%\@<!%{rx}'
+ let f = s:RewriteFormatString(f, '%{rx}', tlib#rx#Escape(a:string))
+ endif
+ if n == 0
+ return substitute(f, '%%', '%', 'g')
+ else
+ let a = repeat([a:string], n)
+ return call('printf', insert(a, f))
+ endif
+endf
+
+
+function! s:RewriteFormatString(format, pattern, string) "{{{3
+ let string = substitute(a:string, '%', '%%', 'g')
+ return substitute(a:format, tlib#rx#Escape(a:pattern), escape(string, '\'), 'g')
+endf
+
+
function! tlib#string#TrimLeft(string) "{{{3
return substitute(a:string, '^\s\+', '', '')
endf
View
@@ -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-04-10.
-" @Last Change: 2007-09-30.
-" @Revision: 0.15.367
+" @Last Change: 2007-10-02.
+" @Revision: 0.16.369
" GetLatestVimScripts: 1863 1 tlib.vim
"
" Please see also ../test/tlib.vim for usage examples.
@@ -24,7 +24,7 @@ if v:version < 700 "{{{2
echoerr "tlib requires Vim >= 7"
finish
endif
-let loaded_tlib = 15
+let loaded_tlib = 16
let s:save_cpo = &cpo
set cpo&vim
@@ -354,3 +354,7 @@ NEW:
- tlib#string#TrimLeft(), tlib#string#TrimRight(), tlib#string#Strip()
- Progress bar
+0.16
+NEW:
+ - tlib#string#Printf1()
+

0 comments on commit 93e792b

Please sign in to comment.