Skip to content

Commit

Permalink
Version 0.23
Browse files Browse the repository at this point in the history
- FIX: very magic mode for tlib#rx#Escape()
- FIX: tlib#arg#Ex: escape "!"
- Respect the setting of g:tlib_inputlist_filename_indicators
- tlib#input#List(): Reset syntax on resume; option to make list window "sticky"
- tlib#agent#ToggleStickyList()
- Simplified tlib#url#Decode()
- tlib#arg#Ex(): use fnameescape() if available
  • Loading branch information
tomtom authored and vim-scripts committed Oct 18, 2010
1 parent f1775e4 commit 9eade85
Show file tree
Hide file tree
Showing 12 changed files with 245 additions and 143 deletions.
59 changes: 36 additions & 23 deletions autoload/tlib/World.vim
Expand Up @@ -3,8 +3,8 @@
" @Website: http://members.a1.net/t.link/
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2007-05-01.
" @Last Change: 2007-11-19.
" @Revision: 0.1.421
" @Last Change: 2008-03-08.
" @Revision: 0.1.431

" :filedoc:
" A prototype used by |tlib#input#List|.
Expand Down Expand Up @@ -52,6 +52,7 @@ let s:prototype = tlib#Object#New({
\ 'show_empty': 0,
\ 'state': 'display',
\ 'state_handlers': [],
\ 'sticky': 0,
\ 'timeout': 0,
\ 'timeout_resolution': 2,
\ 'type': '',
Expand All @@ -77,15 +78,15 @@ endf

function! s:prototype.Set_highlight_filename() dict "{{{3
let self.tlib_UseInputListScratch = 'call world.Highlight_filename()'
" \ 'syn match TLibMarker /\%>'. (1 + eval(g:tlib_inputlist_width_filename)) .'c |.\{-}| / | hi def link TLibMarker Special'
" let self.tlib_UseInputListScratch .= '| syn match TLibDir /\%>'. (4 + eval(g:tlib_inputlist_width_filename)) .'c\S\{-}[\/].*$/ | hi def link TLibDir Directory'
" \ 'syntax match TLibMarker /\%>'. (1 + eval(g:tlib_inputlist_width_filename)) .'c |.\{-}| / | hi def link TLibMarker Special'
" let self.tlib_UseInputListScratch .= '| syntax match TLibDir /\%>'. (4 + eval(g:tlib_inputlist_width_filename)) .'c\S\{-}[\/].*$/ | hi def link TLibDir Directory'
endf


function! s:prototype.Highlight_filename() dict "{{{3
" exec 'syn match TLibDir /\%>'. (3 + eval(g:tlib_inputlist_width_filename)) .'c \(\S:\)\?[\/].*$/ contained containedin=TLibMarker'
exec 'syn match TLibDir /\(\a:\|\.\.\.\S\{-}\)\?[\/][^&<>*|]*$/ contained containedin=TLibMarker'
exec 'syn match TLibMarker /\%>'. (1 + eval(g:tlib_inputlist_width_filename)) .'c |\( \|[[:alnum:]%*+-]*\)| \S.*$/ contains=TLibDir'
" exec 'syntax match TLibDir /\%>'. (3 + eval(g:tlib_inputlist_width_filename)) .'c \(\S:\)\?[\/].*$/ contained containedin=TLibMarker'
exec 'syntax match TLibDir /\(\a:\|\.\.\..\{-}\)\?[\/][^&<>*|]*$/ contained containedin=TLibMarker'
exec 'syntax match TLibMarker /\%>'. (1 + eval(g:tlib_inputlist_width_filename)) .'c |\( \|[[:alnum:]%*+-]*\)| \S.*$/ contains=TLibDir'
hi def link TLibMarker Special
hi def link TLibDir Directory
endf
Expand All @@ -104,24 +105,28 @@ function! s:prototype.FormatFilename(file) dict "{{{3
let dname = '...'. strpart(fnamemodify(a:file, ":h"), len(dname) - dnmax)
endif
let marker = []
let bnr = bufnr(a:file)
" TLogVAR a:file, bnr, self.bufnr
if bnr != -1
if bnr == self.bufnr
call add(marker, '%')
elseif buflisted(a:file)
if getbufvar(a:file, "&mod")
call add(marker, '+')
if g:tlib_inputlist_filename_indicators
let bnr = bufnr(a:file)
" TLogVAR a:file, bnr, self.bufnr
if bnr != -1
if bnr == self.bufnr
call add(marker, '%')
else
call add(marker, 'B')
call add(marker, ' ')
" elseif buflisted(a:file)
" if getbufvar(a:file, "&mod")
" call add(marker, '+')
" else
" call add(marker, 'B')
" endif
" elseif bufloaded(a:file)
" call add(marker, 'h')
" else
" call add(marker, 'u')
endif
elseif bufloaded(a:file)
call add(marker, 'h')
else
call add(marker, 'u')
call add(marker, ' ')
endif
else
call add(marker, ' ')
endif
call insert(marker, '|')
call add(marker, '|')
Expand Down Expand Up @@ -487,7 +492,7 @@ function! s:prototype.DisplayHelp() dict "{{{3
let help += [
\ '',
\ 'Warning:',
\ 'Please don''t try to resize the window with the mouse.',
\ 'Please don''t resize the window with the mouse.',
\ '',
\ 'Note on filtering:',
\ 'The filter is prepended with "\V". Basically, filtering is case-insensitive.',
Expand Down Expand Up @@ -587,7 +592,15 @@ function! s:prototype.DisplayList(query, ...) dict "{{{3
exec 'match '. g:tlib_inputlist_higroup .' /\c'. escape(rx0, '/') .'/'
endif
endif
let &statusline = a:query
let query = a:query
let options = []
if self.sticky
call add(options, 's')
endif
if !empty(options)
let query .= printf(' [%s]', join(options))
endif
let &statusline = query
endif
redraw
endf
Expand Down
11 changes: 9 additions & 2 deletions autoload/tlib/agent.vim
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-24.
" @Last Change: 2007-10-05.
" @Revision: 0.1.137
" @Last Change: 2008-03-08.
" @Revision: 0.1.140

if &cp || exists("loaded_tlib_agent_autoload") "{{{2
finish
Expand Down Expand Up @@ -261,6 +261,13 @@ function! tlib#agent#SelectAll(world, selected) "{{{3
endf


function! tlib#agent#ToggleStickyList(world, selected) "{{{3
let a:world.sticky = !a:world.sticky
let a:world.state = 'display keepcursor'
return a:world
endf



" EditList related {{{1

Expand Down
22 changes: 14 additions & 8 deletions autoload/tlib/arg.vim
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: 2007-10-04.
" @Revision: 0.0.45
" @Last Change: 2008-06-15.
" @Revision: 0.0.49

if &cp || exists("loaded_tlib_arg_autoload")
finish
Expand Down Expand Up @@ -79,18 +79,24 @@ endf

""" Command line {{{1

" :def: function! tlib#arg#Ex(arg, ?chars='%# ')
" :def: function! tlib#arg#Ex(arg, ?chars='%#! ')
" Escape some characters in a string.
"
" Use |fnamescape()| if available.
"
" EXAMPLES: >
" exec 'edit '. tlib#arg#Ex('foo%#bar.txt')
function! tlib#arg#Ex(arg, ...) "{{{3
" let chars = '%# \'
let chars = '%# '
if a:0 >= 1
let chars .= a:1
if exists('*fnameescape') && a:0 == 0
return fnameescape(a:arg)
else
" let chars = '%# \'
let chars = '%#! '
if a:0 >= 1
let chars .= a:1
endif
return escape(a:arg, chars)
endif
return escape(a:arg, chars)
endf


12 changes: 10 additions & 2 deletions autoload/tlib/cmd.vim
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-08-23.
" @Last Change: 2007-10-12.
" @Revision: 0.0.14
" @Last Change: 2008-03-06.
" @Revision: 0.0.20

if &cp || exists("loaded_tlib_cmd_autoload")
finish
Expand All @@ -13,6 +13,7 @@ let loaded_tlib_cmd_autoload = 1


function! tlib#cmd#OutputAsList(command) "{{{3
" let lines = ''
redir => lines
silent! exec a:command
redir END
Expand Down Expand Up @@ -46,3 +47,10 @@ function! tlib#cmd#UseVertical(...) "{{{3
endf


" Print the time in seconds a command takes.
function! tlib#cmd#Time(cmd) "{{{3
let start = localtime()
exec a:cmd
echom 'Time: '. (localtime() - start) .'s: '. a:cmd
endf

4 changes: 2 additions & 2 deletions autoload/tlib/file.vim
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: 2007-11-01.
" @Revision: 0.0.51
" @Last Change: 2007-12-03.
" @Revision: 0.0.56

if &cp || exists("loaded_tlib_file_autoload")
finish
Expand Down
22 changes: 15 additions & 7 deletions autoload/tlib/input.vim
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: 2007-11-14.
" @Revision: 0.0.437
" @Last Change: 2008-03-08.
" @Revision: 0.0.449

if &cp || exists("loaded_tlib_input_autoload")
finish
Expand Down Expand Up @@ -113,6 +113,7 @@ function! tlib#input#ListW(world, ...) "{{{3
TVarArg 'cmd'
let world = a:world
if cmd =~ '^resume'
call world.UseInputListScratch()
let world.initial_index = line('.')
call world.Retrieve(1)
elseif !world.initialized
Expand Down Expand Up @@ -425,11 +426,18 @@ function! tlib#input#ListW(world, ...) "{{{3
silent! let @/ = lastsearch
" TLogDBG 'finally 2'
if world.state !~ '\<suspend\>'
" TLogVAR world.state, world.win_wnr, world.bufnr
call world.CloseScratch()
call world.SwitchWindow('win')
" TLogVAR world.winview
call tlib#win#SetLayout(world.winview)
if world.sticky
if bufwinnr(world.bufnr) == -1
call world.UseScratch()
endif
let world = tlib#agent#SuspendToParentWindow(world, world.GetSelectedItems(world.rv))
else
" TLogVAR world.state, world.win_wnr, world.bufnr
call world.CloseScratch()
call world.SwitchWindow('win')
" TLogVAR world.winview
call tlib#win#SetLayout(world.winview)
endif
endif
" for i in range(0,5)
" call getchar(0)
Expand Down
15 changes: 8 additions & 7 deletions autoload/tlib/rx.vim
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-07-20.
" @Last Change: 2007-10-10.
" @Revision: 0.0.13
" @Last Change: 2007-11-23.
" @Revision: 0.0.15

if &cp || exists("loaded_tlib_rx_autoload")
finish
Expand All @@ -21,17 +21,18 @@ function! tlib#rx#Escape(text, ...) "{{{3
let magic = 'm'
endif
if magic ==# 'm'
let chars = '^$.*\[]~'
return escape(a:text, '^$.*\[]~')
elseif magic ==# 'M'
" echoerr 'tlib: Unsupported magic type'
let chars = '^$\'
return escape(a:text, '^$\')
elseif magic ==# 'V'
let chars = '\'
return escape(a:text, '\')
elseif magic ==# 'v'
let chars = '^$.*+\()|{}[]~'
" let chars = '^$.*+\()|{}[]~'
return substitute(a:text, '[^0-9a-zA-Z_]', '\\&', 'g')
else
echoerr 'tlib: Unsupported magic type'
return a:text
endif
return escape(a:text, chars)
endf

88 changes: 63 additions & 25 deletions autoload/tlib/string.vim
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: 2007-10-02.
" @Revision: 0.0.48
" @Last Change: 2008-03-08.
" @Revision: 0.0.58

if &cp || exists("loaded_tlib_string_autoload")
finish
Expand Down Expand Up @@ -33,32 +33,70 @@ endf
" %{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')
let s = split(a:format, '%.\zs')
" TLogVAR s
return join(map(s, 's:PrintFormat(v:val, a:string)'), '')
endf

function! s:PrintFormat(format, string) "{{{3
let cut = match(a:format, '%\({.\{-}}\|.\)$')
if cut == -1
return a:format
else
let a = repeat([a:string], n)
return call('printf', insert(a, f))
let head = cut > 0 ? a:format[0 : cut - 1] : ''
let tail = a:format[cut : -1]
" TLogVAR head, tail
if tail == '%{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 tail = join(frx, '')
elseif tail == '%{rx}'
let tail = tlib#rx#Escape(a:string)
elseif tail == '%%'
let tail = '%'
elseif tail == '%s'
let tail = a:string
endif
" TLogVAR tail
return head . tail
endif
endf
" 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
Expand Down

0 comments on commit 9eade85

Please sign in to comment.