Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Version 0.12

NEW:
    - tlib/tab.vim
CHANGES:
    - Renamed tlib#win#SetWin() to tlib#win#Set()
IMPROVEMENTS:
    - tlib#input#List(): <left>, <right> keys work in some lists
    - tlib#input#List(): If an index_table is provided this will be used
    instead of the item's list index.
FIXES:
    - tlib#input#List(): Problem with scrolling, when the list was
    shorter than the window (eg when using a vertical window).
    - tlib#cache#Filename(): Don't rewrite name as relative filename if
    explicitly given as argument. Avoid double (back)slashes.
    - TLet: simplified
  • Loading branch information...
commit 0dd2b686864e705ce89d0d5c8a2c57a833882501 1 parent 0df04c8
@tomtom tomtom authored committed
View
6 autoload/tlib.vim
@@ -1,10 +1,10 @@
" tlib.vim
-" @Author: Thomas Link (mailto:samul AT web de?subject=[vim])
+" @Author: Thomas Link (mailto: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-07-17.
-" @Last Change: 2007-07-17.
-" @Revision: 0.0.2
+" @Last Change: 2007-08-27.
+" @Revision: 0.0.3
if &cp || exists("loaded_tlib_autoload")
finish
View
18 autoload/tlib/Object.vim
@@ -1,10 +1,10 @@
" Object.vim -- Prototype objects?
-" @Author: Thomas Link (mailto:samul AT web de?subject=[vim])
+" @Author: Thomas Link (mailto:micathom AT gmail com?subject=[vim])
" @Website: http://members.a1.net/t.link/
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2007-05-01.
-" @Last Change: 2007-08-18.
-" @Revision: 0.1.110
+" @Last Change: 2007-09-02.
+" @Revision: 0.1.115
" :filedoc:
" Provides a prototype plus some OO-like methods.
@@ -145,3 +145,15 @@ function! s:prototype.Super(method, arglist) dict "{{{3
echoerr 'tlib#Object: Does not respond to '. a:method .': '. string(self)
endf
+
+function! s:prototype.Methods() dict "{{{3
+ let o = items(self)
+ call filter(o, 'type(v:val[1]) == 2 && string(v:val[1]) =~ "^function(''\\d\\+'')"')
+ let acc = {}
+ for e in o
+ let id = matchstr(string(e[1]), '\d\+')
+ let acc[id] = e[0]
+ endfor
+ return acc
+endf
+
View
6 autoload/tlib/Test.vim
@@ -1,10 +1,10 @@
" Test.vim -- A test class
-" @Author: Thomas Link (mailto:samul AT web de?subject=[vim])
+" @Author: Thomas Link (mailto:micathom AT gmail com?subject=[vim])
" @Website: http://members.a1.net/t.link/
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2007-05-01.
-" @Last Change: 2007-07-28.
-" @Revision: 0.1.6
+" @Last Change: 2007-08-27.
+" @Revision: 0.1.7
" :enddoc:
View
6 autoload/tlib/TestChild.vim
@@ -1,10 +1,10 @@
" TestChild.vim
-" @Author: Thomas Link (mailto:samul AT web de?subject=[vim])
+" @Author: Thomas Link (mailto:micathom AT gmail com?subject=[vim])
" @Website: http://members.a1.net/t.link/
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2007-05-18.
-" @Last Change: 2007-07-28.
-" @Revision: 0.1.10
+" @Last Change: 2007-08-27.
+" @Revision: 0.1.11
" :enddoc:
View
48 autoload/tlib/World.vim
@@ -1,10 +1,10 @@
" World.vim -- The World prototype for tlib#input#List()
-" @Author: Thomas Link (mailto:samul AT web de?subject=[vim])
+" @Author: Thomas Link (mailto:micathom AT gmail com?subject=[vim])
" @Website: http://members.a1.net/t.link/
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2007-05-01.
-" @Last Change: 2007-08-26.
-" @Revision: 0.1.259
+" @Last Change: 2007-09-02.
+" @Revision: 0.1.305
" :filedoc:
" A prototype used by |tlib#input#List|.
@@ -25,11 +25,14 @@ let s:prototype = tlib#Object#New({
\ 'bufnr': -1,
\ 'display_format': '',
\ 'filter_format': '',
+ \ 'index_table': [],
\ 'initial_index': 1,
\ 'initialized': 0,
\ 'key_handlers': [],
\ 'list': [],
\ 'numeric_chars': tlib#var#Get('tlib_numeric_chars', 'bg'),
+ \ 'offset': 1,
+ \ 'offset_horizontal': 0,
\ 'pick_last_item': tlib#var#Get('tlib_pick_last_item', 'bg'),
\ 'post_handlers': [],
\ 'query': '',
@@ -61,8 +64,8 @@ function! s:prototype.Set_display_format(value) dict "{{{3
if a:value == 'filename'
let self.display_format = 's:FormatFilename(world, %s)'
let self.tlib_UseInputListScratch =
- \ 'syn match TLibMarker /\%>'. (2 + g:tlib_inputlist_width_filename) .'c |.\{-}| / | hi def link TLibMarker Special'
- let self.tlib_UseInputListScratch .= '| syn match TLibDir /\%>'. (4 + g:tlib_inputlist_width_filename) .'c\S\{-}[\/].*$/ | hi def link TLibDir Directory'
+ \ 'syn match TLibMarker /\%>'. (2 + 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'
else
let self.display_format = a:value
endif
@@ -82,6 +85,13 @@ function! s:prototype.GetSelectedItems(current) dict "{{{3
endif
call insert(rv, a:current)
endif
+ if stridx(self.type, 'i') != -1
+ if !empty(self.index_table)
+ " TLogVAR rv, self.index_table
+ call map(rv, 'self.index_table[v:val - 1]')
+ " TLogVAR rv
+ endif
+ endif
return rv
endf
@@ -143,12 +153,21 @@ endf
function! s:prototype.GetListIdx(baseidx) dict "{{{3
- return index(self.table, a:baseidx)
+ " if empty(self.index_table)
+ let baseidx = a:baseidx
+ " else
+ " let baseidx = 0 + self.index_table[a:baseidx - 1]
+ " " TLogVAR a:baseidx, baseidx, self.index_table
+ " endif
+ let rv = index(self.table, baseidx)
+ " TLogVAR rv, self.table
+ return rv
endf
function! s:prototype.GetBaseIdx(idx) dict "{{{3
- if !empty(self.table) && a:idx > 0
+ " TLogVAR a:idx, self.table, self.index_table
+ if !empty(self.table) && a:idx > 0 && a:idx <= len(self.table)
return self.table[a:idx - 1]
else
return ''
@@ -398,8 +417,10 @@ function! s:prototype.DisplayList(world, query, ...) dict "{{{3
elseif self.state == 'help'
call self.DisplayHelp(a:world)
else
- let ll = len(list)
- let x = len(ll) + 1
+ " let ll = len(list)
+ let ll = a:world.llen
+ " let x = len(ll) + 1
+ let x = a:world.index_width + 1
" TLogVAR ll
if self.state =~ '\<display\>'
let resize = get(self, 'resize', 0)
@@ -411,7 +432,8 @@ function! s:prototype.DisplayList(world, query, ...) dict "{{{3
norm! ggdG
let w = winwidth(0) - &fdc
" let w = winwidth(0) - &fdc - 1
- let lines = map(copy(list), 'printf("%-'. w .'.'. w .'s", substitute(v:val, ''[[:cntrl:][:space:]]'', " ", "g"))')
+ let lines = copy(list)
+ let lines = map(lines, 'printf("%-'. w .'.'. w .'s", substitute(v:val, ''[[:cntrl:][:space:]]'', " ", "g"))')
call append(0, lines)
norm! Gddgg
endif
@@ -462,6 +484,9 @@ function! s:prototype.SetOffset() dict "{{{3
" TLogDBG winheight(0)
" TLogDBG self.prefidx > self.offset + winheight(0) - 1
let listtop = len(self.list) - winheight(0) + 1
+ if listtop < 1
+ let listtop = 1
+ endif
if self.prefidx > listtop
let self.offset = listtop
elseif self.prefidx > self.offset + winheight(0) - 1
@@ -474,6 +499,7 @@ function! s:prototype.SetOffset() dict "{{{3
elseif self.prefidx < self.offset
let self.offset = self.prefidx
endif
+ " TLogVAR self.offset
endf
@@ -496,7 +522,7 @@ endf
function! s:prototype.SwitchWindow(where) dict "{{{3
let wnr = get(self, a:where.'_wnr')
" TLogVAR wnr
- return tlib#win#SetWin(wnr)
+ return tlib#win#Set(wnr)
endf
View
32 autoload/tlib/agent.vim
@@ -1,10 +1,10 @@
" agent.vim
-" @Author: Thomas Link (mailto:samul AT web de?subject=[vim])
+" @Author: Thomas Link (mailto: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-24.
-" @Last Change: 2007-08-26.
-" @Revision: 0.1.114
+" @Last Change: 2007-09-02.
+" @Revision: 0.1.122
if &cp || exists("loaded_tlib_agent_autoload") "{{{2
finish
@@ -86,6 +86,23 @@ function! tlib#agent#DownN(world, selected) "{{{3
endf
+function! tlib#agent#ShiftLeft(world, selected) "{{{3
+ let a:world.offset_horizontal -= (winwidth(0) / 2)
+ if a:world.offset_horizontal < 0
+ let a:world.offset_horizontal = 0
+ endif
+ let a:world.state = 'display shift'
+ return a:world
+endf
+
+
+function! tlib#agent#ShiftRight(world, selected) "{{{3
+ let a:world.offset_horizontal += (winwidth(0) / 2)
+ let a:world.state = 'display shift'
+ return a:world
+endf
+
+
function! tlib#agent#Reset(world, selected) "{{{3
let a:world.state = 'reset'
return a:world
@@ -328,12 +345,9 @@ endf
" Files related {{{1
function! tlib#agent#ViewFile(world, selected) "{{{3
- if a:world.SwitchWindow('win')
- call tlib#file#With('edit', 'buffer', a:selected, a:world)
- if !a:world.SwitchWindow('list')
- throw 'tlib: Cannot switch back to list window: '. string(a:world)
- end
- endif
+ let back = a:world.SwitchWindow('win')
+ call tlib#file#With('edit', 'buffer', a:selected, a:world)
+ exec back
let a:world.state = 'display'
return a:world
endf
View
6 autoload/tlib/arg.vim
@@ -1,10 +1,10 @@
" arg.vim
-" @Author: Thomas Link (mailto:samul AT web de?subject=[vim])
+" @Author: Thomas Link (mailto: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: 2007-08-21.
-" @Revision: 0.0.18
+" @Last Change: 2007-08-27.
+" @Revision: 0.0.19
if &cp || exists("loaded_tlib_arg_autoload")
finish
View
12 autoload/tlib/buffer.vim
@@ -1,10 +1,10 @@
" buffer.vim
-" @Author: Thomas Link (mailto:samul AT web de?subject=[vim])
+" @Author: Thomas Link (mailto: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: 2007-08-24.
-" @Revision: 0.0.47
+" @Last Change: 2007-09-02.
+" @Revision: 0.0.58
if &cp || exists("loaded_tlib_buffer_autoload")
finish
@@ -91,8 +91,14 @@ function! tlib#buffer#GetList(...)
redir END
let buffer_list = split(bfs, '\n')
let buffer_nr = map(copy(buffer_list), 'matchstr(v:val, ''\s*\zs\d\+\ze'')')
+ " TLogVAR buffer_list
call map(buffer_list, 'matchstr(v:val, ''\s*\d\+\zs.\{-}\ze\s\+line \d\+\s*$'')')
+ " call map(buffer_list, 'matchstr(v:val, ''\s*\d\+.\{-}\ze\s\+line \d\+\s*$'')')
+ " TLogVAR buffer_list
+ " call map(buffer_list, 'matchstr(v:val, ''^.\{-}\ze\s\+line \d\+\s*$'')')
+ " TLogVAR buffer_list
call map(buffer_list, 'matchstr(v:val, ''^[^"]\+''). printf("%-20s %s", fnamemodify(matchstr(v:val, ''"\zs.\{-}\ze"$''), ":t"), fnamemodify(matchstr(v:val, ''"\zs.\{-}\ze"$''), ":h"))')
+ " TLogVAR buffer_list
return [buffer_nr, buffer_list]
endf
View
26 autoload/tlib/cache.vim
@@ -1,10 +1,10 @@
" cache.vim
-" @Author: Thomas Link (mailto:samul AT web de?subject=[vim])
+" @Author: Thomas Link (mailto: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: 2007-07-27.
-" @Revision: 0.1.9
+" @Last Change: 2007-09-02.
+" @Revision: 0.1.17
if &cp || exists("loaded_tlib_cache_autoload")
finish
@@ -15,22 +15,28 @@ let loaded_tlib_cache_autoload = 1
" :def: function! tlib#cache#Filename(type, ?file=%, ?mkdir=0)
function! tlib#cache#Filename(type, ...) "{{{3
" TLogDBG 'bufname='. bufname('.')
- if empty(expand('%:t'))
- return ''
+ let dir = tlib#dir#MyRuntime()
+ if a:0 >= 1 && !empty(a:1)
+ let file = a:1
+ else
+ if empty(expand('%:t'))
+ return ''
+ endif
+ let file = expand('%:p')
+ let file = tlib#file#Relative(file, dir)
endif
- let file = a:0 >= 1 && !empty(a:1) ? a:1 : expand('%:p')
let mkdir = a:0 >= 2 ? a:2 : 0
- let dir = tlib#dir#MyRuntime()
- let file = tlib#file#Relative(file, dir)
let file = substitute(file, '\.\.\|[:&<>]\|//\+\|\\\\\+', '_', 'g')
- let dir = tlib#file#Join([dir, 'cache', a:type, fnamemodify(file, ':h')])
+ let dir = tlib#dir#PlainName(tlib#file#Join([dir, 'cache', a:type, fnamemodify(file, ':h')]))
let file = fnamemodify(file, ':t')
" TLogVAR dir
" TLogVAR file
if mkdir && !isdirectory(dir)
call mkdir(dir, 'p')
endif
- retur tlib#file#Join([dir, file])
+ let cache_file = tlib#file#Join([dir, file])
+ " TLogVAR cache_file
+ return cache_file
endf
View
6 autoload/tlib/char.vim
@@ -1,10 +1,10 @@
" char.vim
-" @Author: Thomas Link (mailto:samul AT web de?subject=[vim])
+" @Author: Thomas Link (mailto: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: 2007-07-29.
-" @Revision: 0.0.10
+" @Last Change: 2007-08-27.
+" @Revision: 0.0.11
if &cp || exists("loaded_tlib_char_autoload")
finish
View
24 autoload/tlib/cmd.vim
@@ -1,16 +1,17 @@
" cmd.vim
-" @Author: Thomas Link (mailto:samul AT web de?subject=[vim])
+" @Author: Thomas Link (mailto: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-08-23.
-" @Last Change: 2007-08-23.
-" @Revision: 0.0.3
+" @Last Change: 2007-08-29.
+" @Revision: 0.0.10
if &cp || exists("loaded_tlib_cmd_autoload")
finish
endif
let loaded_tlib_cmd_autoload = 1
+
function! tlib#cmd#OutputAsList(command) "{{{3
redir => lines
silent! exec a:command
@@ -18,3 +19,20 @@ function! tlib#cmd#OutputAsList(command) "{{{3
return split(lines, '\n')
endf
+
+" :def: function! tlib#cmd#UseVertical(?rx='')
+" Look at the history whether the command was called with vertical. If
+" an rx is provided check first if the last entry in the history matches
+" this rx.
+function! tlib#cmd#UseVertical(...) "{{{3
+ TVarArg ['rx']
+ let h0 = histget(':')
+ let rx0 = '\C\<vert\%[ical]\>\s\+'
+ if !empty(rx)
+ let rx0 .= '.\{-}'.rx
+ endif
+ " TLogVAR h0, rx0
+ return h0 =~ rx0
+endf
+
+
View
14 autoload/tlib/dir.vim
@@ -1,10 +1,10 @@
" dir.vim
-" @Author: Thomas Link (mailto:samul AT web de?subject=[vim])
+" @Author: Thomas Link (mailto: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: 2007-08-21.
-" @Revision: 0.0.19
+" @Last Change: 2007-09-02.
+" @Revision: 0.0.21
if &cp || exists("loaded_tlib_dir_autoload")
finish
@@ -24,6 +24,14 @@ function! tlib#dir#CanonicName(dirname) "{{{3
endf
+" EXAMPLES: >
+" tlib#dir#PlainName('foo/bar/')
+" => 'foo/bar'
+function! tlib#dir#PlainName(dirname) "{{{3
+ return substitute(a:dirname, tlib#rx#Escape(g:tlib_filename_sep).'\+$', '', '')
+endf
+
+
" Create a directory if it doesn't already exist.
function! tlib#dir#Ensure(dir) "{{{3
if !isdirectory(a:dir)
View
9 autoload/tlib/file.vim
@@ -1,10 +1,10 @@
" file.vim
-" @Author: Thomas Link (mailto:samul AT web de?subject=[vim])
+" @Author: Thomas Link (mailto: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: 2007-08-21.
-" @Revision: 0.0.34
+" @Last Change: 2007-09-02.
+" @Revision: 0.0.39
if &cp || exists("loaded_tlib_file_autoload")
finish
@@ -40,6 +40,9 @@ endf
" tlib#file#Join(['foo', 'bar', 'filename.txt'])
" => 'foo/bar/filename.txt'
function! tlib#file#Join(filename_parts) "{{{3
+ " let rx = tlib#rx#Escape(g:tlib_filename_sep) .'$'
+ " let parts = map(copy(a:filename_parts), 'substitute(v:val, rx, "", "")')
+ " return join(parts, g:tlib_filename_sep)
return join(a:filename_parts, g:tlib_filename_sep)
endf
View
6 autoload/tlib/hook.vim
@@ -1,10 +1,10 @@
" hook.vim
-" @Author: Thomas Link (mailto:samul AT web de?subject=[vim])
+" @Author: Thomas Link (mailto: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-08-21.
-" @Last Change: 2007-08-24.
-" @Revision: 0.0.6
+" @Last Change: 2007-08-27.
+" @Revision: 0.0.7
if &cp || exists("loaded_tlib_hook_autoload")
finish
View
53 autoload/tlib/input.vim
@@ -1,10 +1,10 @@
" input.vim
-" @Author: Thomas Link (mailto:samul AT web de?subject=[vim])
+" @Author: Thomas Link (mailto: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: 2007-08-25.
-" @Revision: 0.0.267
+" @Last Change: 2007-09-02.
+" @Revision: 0.0.323
if &cp || exists("loaded_tlib_input_autoload")
finish
@@ -74,7 +74,8 @@ function! tlib#input#List(type, ...) "{{{3
endif
let world.scratch_vertical = tlib#list#Find(handlers, 'has_key(v:val, "scratch_vertical")', 0, 'v:val.scratch_vertical')
call world.Set_display_format(tlib#list#Find(handlers, 'has_key(v:val, "display_format")', '', 'v:val.display_format'))
- let world.initial_index = tlib#list#Find(handlers, 'has_key(v:val, "initial_index")', 1, 'v:val.initial_index')
+ let world.initial_index = tlib#list#Find(handlers, 'has_key(v:val, "initial_index")', 1, 'v:val.initial_index')
+ let world.index_table = tlib#list#Find(handlers, 'has_key(v:val, "index_table")', [], 'v:val.index_table')
let world.state_handlers = filter(copy(handlers), 'has_key(v:val, "state")')
let world.post_handlers = filter(copy(handlers), 'has_key(v:val, "postprocess")')
let world.filter_format = tlib#list#Find(handlers, 'has_key(v:val, "filter_format")', '', 'v:val.filter_format')
@@ -174,7 +175,14 @@ function! tlib#input#ListW(world, ...) "{{{3
let world.list = map(copy(world.table), 'world.GetBaseItem(v:val)')
" TLogDBG 3
let world.llen = len(world.list)
- let world.index_width = len(world.llen)
+ " TLogVAR world.index_table
+ if empty(world.index_table)
+ let dindex = range(1, world.llen)
+ let world.index_width = len(world.llen)
+ else
+ let dindex = world.index_table
+ let world.index_width = len(max(dindex))
+ endif
if world.llen == 0 && !world.show_empty
call world.ReduceFilter()
let world.offset = 1
@@ -200,6 +208,11 @@ function! tlib#input#ListW(world, ...) "{{{3
else
let world.prefidx = world.idx == '' ? world.initial_index : world.idx
endif
+ if world.prefidx > world.llen
+ let world.prefidx = world.llen
+ elseif world.prefidx < 1
+ let world.prefidx = 1
+ endif
endif
" TLogDBG 5
let dlist = copy(world.list)
@@ -209,7 +222,11 @@ function! tlib#input#ListW(world, ...) "{{{3
endif
" TLogVAR world.prefidx
" TLogDBG 6
- let dlist = map(range(1, world.llen), 'printf("%0'. world.index_width .'d", v:val) .": ". dlist[v:val - 1]')
+ if world.offset_horizontal > 0
+ call map(dlist, 'v:val[world.offset_horizontal:-1]')
+ endif
+ " TLogVAR dindex
+ let dlist = map(range(0, world.llen - 1), 'printf("%0'. world.index_width .'d", dindex[v:val]) .": ". dlist[v:val]')
endif
" TLogDBG 7
" TLogVAR world.prefidx, world.offset
@@ -348,6 +365,8 @@ function! tlib#input#ListW(world, ...) "{{{3
return world
elseif stridx(world.type, 'm') != -1
return world.GetSelectedItems(world.rv)
+ elseif stridx(world.type, 'i') != -1 && !empty(world.index_table)
+ return world.index_table[world.rv - 1]
else
return world.rv
endif
@@ -440,7 +459,7 @@ function! s:FormatFilename(world, file) "{{{3
" let fname .='/'
" endif
let dname = fnamemodify(a:file, ":h")
- let dnmax = &co - max([g:tlib_inputlist_width_filename, len(fname)]) - 11 - a:world.index_width - &fdc
+ let dnmax = &co - max([eval(g:tlib_inputlist_width_filename), len(fname)]) - 11 - a:world.index_width - &fdc
if len(dname) > dnmax
let dname = '...'. strpart(fnamemodify(a:file, ":h"), len(dname) - dnmax)
endif
@@ -469,7 +488,7 @@ function! s:FormatFilename(world, file) "{{{3
call add(marker, '|')
" let fname .= ' '. join(marker, '')
endif
- return printf("%-". g:tlib_inputlist_width_filename ."s %s %s", fname, join(marker, ''), dname)
+ return printf("%-". eval(g:tlib_inputlist_width_filename) ."s %s %s", fname, join(marker, ''), dname)
endf
@@ -556,16 +575,25 @@ function! tlib#input#Edit(name, value, callback, ...) "{{{3
imap <buffer> <c-w>c <c-o>call <SID>EditCallback(0)<cr>
map <buffer> <c-s> :call <SID>EditCallback(1)<cr>
imap <buffer> <c-s> <c-o>call <SID>EditCallback(1)<cr>
- echohl MoreMsg
- echom 'Press <c-s> to enter, <c-w>c to cancel editing.'
- echohl NONE
norm! ggdG
call append(1, split(a:value, "\<c-j>", 1))
+ " let hrm = 'DON''T DELETE THIS HEADER'
+ " let hr3 = repeat('"', (tlib#win#Width(0) - len(hrm)) / 2)
+ let s:horizontal_line = repeat('`', tlib#win#Width(0))
+ " hr3.hrm.hr3
+ let hd = ['``` Keys: <c-s> ... save/accept; <c-w>c ... cancel', s:horizontal_line]
+ call append(1, hd)
norm! ggdd
+ syntax match TlibEditComment /^```.*/
+ hi link TlibEditComment Comment
+ exec len(hd) + 1
let b:tlib_scratch_edit_callback = a:callback
let b:tlib_scratch_edit_args = args
let b:tlib_scratch_edit_scratch = sargs
" exec 'autocmd BufDelete,BufHidden,BufUnload <buffer> call s:EditCallback('. string(a:name) .')'
+ " echohl MoreMsg
+ " echom 'Press <c-s> to enter, <c-w>c to cancel editing.'
+ " echohl NONE
endf
@@ -576,7 +604,8 @@ function! s:EditCallback(...) "{{{3
if ok == -1
let ok = confirm('Use value')
endif
- let text = ok ? join(getline(1, '$'), "\n") : ''
+ let start = getline(2) == s:horizontal_line ? 3 : 1
+ let text = ok ? join(getline(start, '$'), "\n") : ''
let cb = b:tlib_scratch_edit_callback
let args = b:tlib_scratch_edit_args
call tlib#scratch#CloseScratch(b:tlib_scratch_edit_scratch)
View
6 autoload/tlib/list.vim
@@ -1,10 +1,10 @@
" list.vim
-" @Author: Thomas Link (mailto:samul AT web de?subject=[vim])
+" @Author: Thomas Link (mailto: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: 2007-08-18.
-" @Revision: 0.0.23
+" @Last Change: 2007-08-27.
+" @Revision: 0.0.24
if &cp || exists("loaded_tlib_list_autoload")
finish
View
6 autoload/tlib/rx.vim
@@ -1,10 +1,10 @@
" rx.vim
-" @Author: Thomas Link (mailto:samul AT web de?subject=[vim])
+" @Author: Thomas Link (mailto: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-07-20.
-" @Last Change: 2007-07-27.
-" @Revision: 0.0.10
+" @Last Change: 2007-08-27.
+" @Revision: 0.0.11
if &cp || exists("loaded_tlib_rx_autoload")
finish
View
8 autoload/tlib/scratch.vim
@@ -1,10 +1,10 @@
" scratch.vim
-" @Author: Thomas Link (mailto:samul AT web de?subject=[vim])
+" @Author: Thomas Link (mailto: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-07-18.
-" @Last Change: 2007-08-25.
-" @Revision: 0.0.107
+" @Last Change: 2007-08-27.
+" @Revision: 0.0.109
if &cp || exists("loaded_tlib_scratch_autoload")
finish
@@ -78,7 +78,7 @@ function! tlib#scratch#CloseScratch(keyargs, ...) "{{{3
" TLogVAR wn
if wn != -1
" TLogDBG winnr()
- let wb = tlib#win#SetWin(wn)
+ let wb = tlib#win#Set(wn)
wincmd c
" exec wb
" redraw
View
6 autoload/tlib/string.vim
@@ -1,10 +1,10 @@
" string.vim
-" @Author: Thomas Link (mailto:samul AT web de?subject=[vim])
+" @Author: Thomas Link (mailto: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: 2007-07-27.
-" @Revision: 0.0.10
+" @Last Change: 2007-08-27.
+" @Revision: 0.0.11
if &cp || exists("loaded_tlib_string_autoload")
finish
View
55 autoload/tlib/tab.vim
@@ -0,0 +1,55 @@
+" tab.vim
+" @Author: Thomas Link (mailto: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-08-27.
+" @Last Change: 2007-08-27.
+" @Revision: 0.0.27
+
+if &cp || exists("loaded_tlib_tab_autoload")
+ finish
+endif
+let loaded_tlib_tab_autoload = 1
+
+
+" Return a dictionary of bufnumbers => [[tabpage, winnr] ...]
+function! tlib#tab#BufMap() "{{{3
+ let acc = {}
+ for t in range(tabpagenr('$'))
+ let bb = tabpagebuflist(t + 1)
+ for b in range(len(bb))
+ let bn = bb[b]
+ let bd = [t + 1, b + 1]
+ if has_key(acc, bn)
+ call add(acc[bn], bd)
+ else
+ let acc[bn] = [bd]
+ endif
+ endfor
+ endfor
+ return acc
+endf
+
+
+" Find a buffer's window at some tab page.
+function! tlib#tab#TabWinNr(buffer) "{{{3
+ let bn = bufnr(a:buffer)
+ let bt = tlib#tab#BufMap()
+ let tn = tabpagenr()
+ let wn = winnr()
+ let bc = get(bt, bn)
+ if !empty(bc)
+ for [t, w] in bc
+ if t == tn
+ return [t, w]
+ endif
+ endfor
+ return bc[0]
+ endif
+endf
+
+
+function! tlib#tab#Set(tabnr) "{{{3
+ exec a:tabnr .'tabnext'
+endf
+
View
15 autoload/tlib/url.vim
@@ -1,10 +1,10 @@
" url.vim
-" @Author: Thomas Link (mailto:samul AT web de?subject=[vim])
+" @Author: Thomas Link (mailto: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: 2007-07-25.
-" @Revision: 0.0.4
+" @Last Change: 2007-09-01.
+" @Revision: 0.0.12
if &cp || exists("loaded_tlib_url_autoload")
finish
@@ -59,8 +59,13 @@ endf
" Encode an url.
-function! tlib#url#Encode(url) "{{{3
- return substitute(a:url, '\([^a-zA-Z0-9_.-]\)', '\=tlib#url#EncodeChar(submatch(1))', 'g')
+function! tlib#url#Encode(url, ...) "{{{3
+ TVarArg ['extrachars', '']
+ let rx = '\([^a-zA-Z0-9_.'. extrachars .'-]\)'
+ " TLogVAR a:url, rx
+ let rv = substitute(a:url, rx, '\=tlib#url#EncodeChar(submatch(1))', 'g')
+ " TLogVAR rv
+ return rv
endf
View
6 autoload/tlib/var.vim
@@ -1,10 +1,10 @@
" var.vim
-" @Author: Thomas Link (mailto:samul AT web de?subject=[vim])
+" @Author: Thomas Link (mailto: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: 2007-07-29.
-" @Revision: 0.0.17
+" @Last Change: 2007-08-27.
+" @Revision: 0.0.18
if &cp || exists("loaded_tlib_var_autoload")
finish
View
28 autoload/tlib/win.vim
@@ -1,10 +1,10 @@
" win.vim
-" @Author: Thomas Link (mailto:samul AT web de?subject=[vim])
+" @Author: Thomas Link (mailto: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-08-24.
-" @Last Change: 2007-08-25.
-" @Revision: 0.0.27
+" @Last Change: 2007-08-29.
+" @Revision: 0.0.31
if &cp || exists("loaded_tlib_win_autoload")
finish
@@ -13,7 +13,7 @@ let loaded_tlib_win_autoload = 1
" Return vim code to jump back to the original window.
-function! tlib#win#SetWin(winnr) "{{{3
+function! tlib#win#Set(winnr) "{{{3
if a:winnr > 0
" TLogDBG winnr()
if winnr() != a:winnr && winbufnr(a:winnr) != -1
@@ -33,10 +33,10 @@ function! tlib#win#GetLayout(...) "{{{3
if save_view
let winnr = winnr()
for w in range(1, winnr('$'))
- call tlib#win#SetWin(w)
+ call tlib#win#Set(w)
let views[w] = winsaveview()
endfor
- call tlib#win#SetWin(winnr)
+ call tlib#win#Set(winnr)
endif
return [winnr('$'), winrestcmd(), views]
endf
@@ -49,10 +49,10 @@ function! tlib#win#SetLayout(layout) "{{{3
if !empty(views)
let winnr = winnr()
for [w, v] in items(views)
- call tlib#win#SetWin(w)
+ call tlib#win#Set(w)
call winrestview(v)
endfor
- call tlib#win#SetWin(winnr)
+ call tlib#win#Set(winnr)
endif
return 1
endif
@@ -70,12 +70,12 @@ endf
" for w in range(1, winnr('$'))
" let def = {'h': winheight(w), 'w': winwidth(w)}
" if save_view
-" call tlib#win#SetWin(w)
+" call tlib#win#Set(w)
" let def.view = winsaveview()
" endif
" let acc[w] = def
" endfor
-" call tlib#win#SetWin(winnr)
+" call tlib#win#Set(winnr)
" return acc
" endf
"
@@ -87,7 +87,7 @@ endf
" endif
" let winnr = winnr()
" for [w, def] in items(a:layout)
-" if tlib#win#SetWin(w)
+" if tlib#win#Set(w)
" exec 'resize '. def.h
" exec 'vertical resize '. def.w
" if has_key(def, 'view')
@@ -97,8 +97,12 @@ endf
" break
" endif
" endfor
-" call tlib#win#SetWin(winnr)
+" call tlib#win#Set(winnr)
" return 1
" endf
+function! tlib#win#Width(wnr) "{{{3
+ return winwidth(a:wnr) - &fdc
+endf
+
View
68 doc/tlib.txt
@@ -1,6 +1,6 @@
-*tlib.txt* tlib -- A library of vim functions
+*tlib.txt* tlib -- A library of vim functions
+ Author: Thomas Link, micathom at gmail com
-Author: Thomas Link, samul AT web.de
This library provides some utility functions. There isn't much need to
install it unless another plugin requires you to do so.
@@ -52,6 +52,7 @@ Contents~
prototype.IsRelated
prototype.RespondTo
prototype.Super
+ prototype.Methods
autoload/tlib/World.vim
tlib#World#New ..................... |tlib#World#New|
prototype.Set_display_format
@@ -93,6 +94,8 @@ Contents~
tlib#agent#Down .................... |tlib#agent#Down|
tlib#agent#UpN ..................... |tlib#agent#UpN|
tlib#agent#DownN ................... |tlib#agent#DownN|
+ tlib#agent#ShiftLeft ............... |tlib#agent#ShiftLeft|
+ tlib#agent#ShiftRight .............. |tlib#agent#ShiftRight|
tlib#agent#Reset ................... |tlib#agent#Reset|
tlib#agent#Input ................... |tlib#agent#Input|
tlib#agent#SuspendToParentWindow ... |tlib#agent#SuspendToParentWindow|
@@ -144,8 +147,10 @@ Contents~
tlib#char#Get ...................... |tlib#char#Get|
autoload/tlib/cmd.vim
tlib#cmd#OutputAsList .............. |tlib#cmd#OutputAsList|
+ tlib#cmd#UseVertical ............... |tlib#cmd#UseVertical|
autoload/tlib/dir.vim
tlib#dir#CanonicName ............... |tlib#dir#CanonicName|
+ tlib#dir#PlainName ................. |tlib#dir#PlainName|
tlib#dir#Ensure .................... |tlib#dir#Ensure|
tlib#dir#MyRuntime ................. |tlib#dir#MyRuntime|
tlib#dir#CD ........................ |tlib#dir#CD|
@@ -183,6 +188,10 @@ Contents~
tlib#scratch#CloseScratch .......... |tlib#scratch#CloseScratch|
autoload/tlib/string.vim
tlib#string#RemoveBackslashes ...... |tlib#string#RemoveBackslashes|
+ autoload/tlib/tab.vim
+ tlib#tab#BufMap .................... |tlib#tab#BufMap|
+ tlib#tab#TabWinNr .................. |tlib#tab#TabWinNr|
+ tlib#tab#Set ....................... |tlib#tab#Set|
autoload/tlib/url.vim
tlib#url#Decode .................... |tlib#url#Decode|
tlib#url#EncodeChar ................ |tlib#url#EncodeChar|
@@ -192,9 +201,10 @@ Contents~
tlib#var#EGet ...................... |tlib#var#EGet|
tlib#var#Get ....................... |tlib#var#Get|
autoload/tlib/win.vim
- tlib#win#SetWin .................... |tlib#win#SetWin|
+ tlib#win#Set ....................... |tlib#win#Set|
tlib#win#GetLayout ................. |tlib#win#GetLayout|
tlib#win#SetLayout ................. |tlib#win#SetLayout|
+ tlib#win#Width ..................... |tlib#win#Width|
------------------------------------------------------------------------
@@ -212,6 +222,10 @@ plugin/02tlib.vim~
Open a scratch buffer (a buffer without a file). >
TScratch ... use split window
TScratch! ... use the whole frame
+ This command takes an (inner) dictionnary as optional argument.
+ EXAMPLES: >
+ TScratch 'scratch': '__FOO__'
+ => Open a scratch buffer named __FOO__
<
*:TVarArg*
@@ -244,7 +258,7 @@ g:tlib_inputlist_pct (default: 70)
Size of the input list window (in percent) from the main size (of &lines).
*g:tlib_inputlist_width_filename*
-g:tlib_inputlist_width_filename (default: &co / 3)
+g:tlib_inputlist_width_filename (default: '&co / 3')
Size of filename columns when listing filenames
*g:tlib_inputlist_higroup*
@@ -365,6 +379,9 @@ prototype.RespondTo(name)
prototype.Super(method, arglist)
+prototype.Methods()
+
+
------------------------------------------------------------------------
autoload/tlib/World.vim~
A prototype used by |tlib#input#List|.
@@ -492,6 +509,12 @@ tlib#agent#UpN(world, selected)
*tlib#agent#DownN*
tlib#agent#DownN(world, selected)
+ *tlib#agent#ShiftLeft*
+tlib#agent#ShiftLeft(world, selected)
+
+ *tlib#agent#ShiftRight*
+tlib#agent#ShiftRight(world, selected)
+
*tlib#agent#Reset*
tlib#agent#Reset(world, selected)
@@ -685,6 +708,12 @@ autoload/tlib/cmd.vim~
*tlib#cmd#OutputAsList*
tlib#cmd#OutputAsList(command)
+ *tlib#cmd#UseVertical*
+tlib#cmd#UseVertical(?rx='')
+ Look at the history whether the command was called with vertical. If
+ an rx is provided check first if the last entry in the history matches
+ this rx.
+
------------------------------------------------------------------------
autoload/tlib/dir.vim~
@@ -696,6 +725,13 @@ tlib#dir#CanonicName(dirname)
=> 'foo/bar/'
<
+ *tlib#dir#PlainName*
+tlib#dir#PlainName(dirname)
+ EXAMPLES: >
+ tlib#dir#PlainName('foo/bar/')
+ => 'foo/bar'
+<
+
*tlib#dir#Ensure*
tlib#dir#Ensure(dir)
Create a directory if it doesn't already exist.
@@ -937,6 +973,21 @@ tlib#string#RemoveBackslashes(text, ?chars=' ')
------------------------------------------------------------------------
+autoload/tlib/tab.vim~
+
+ *tlib#tab#BufMap*
+tlib#tab#BufMap()
+ Return a dictionary of bufnumbers => [[tabpage, winnr] ...]
+
+ *tlib#tab#TabWinNr*
+tlib#tab#TabWinNr(buffer)
+ Find a buffer's window at some tab page.
+
+ *tlib#tab#Set*
+tlib#tab#Set(tabnr)
+
+
+------------------------------------------------------------------------
autoload/tlib/url.vim~
*tlib#url#Decode*
@@ -948,7 +999,7 @@ tlib#url#EncodeChar(char)
Encode a single character.
*tlib#url#Encode*
-tlib#url#Encode(url)
+tlib#url#Encode(url, ...)
Encode an url.
@@ -995,8 +1046,8 @@ tlib#var#Get(var, namespace, ?default='')
------------------------------------------------------------------------
autoload/tlib/win.vim~
- *tlib#win#SetWin*
-tlib#win#SetWin(winnr)
+ *tlib#win#Set*
+tlib#win#Set(winnr)
Return vim code to jump back to the original window.
*tlib#win#GetLayout*
@@ -1005,4 +1056,7 @@ tlib#win#GetLayout(?save_view=0)
*tlib#win#SetLayout*
tlib#win#SetLayout(layout)
+ *tlib#win#Width*
+tlib#win#Width(wnr)
+
View
39 plugin/02tlib.vim
@@ -1,15 +1,16 @@
" tlib.vim -- Some utility functions
-" @Author: Thomas Link (mailto:samul AT web de?subject=[vim])
+" @Author: Thomas Link (mailto: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-04-10.
-" @Last Change: 2007-08-26.
-" @Revision: 0.11.308
+" @Last Change: 2007-09-05.
+" @Revision: 0.12.338
" GetLatestVimScripts: 1863 1 tlib.vim
"
" Please see also ../test/tlib.vim for usage examples.
"
" TODO:
+" - tlib#cache#Purge(): delete old cache files (for the moment use find)
" - tlib#file#Relative(): currently relies on cwd to be set
" - tlib#input#EditList(): Disable selection by index number
" - tlib#input#List(): Some kind of command line to edit some
@@ -23,7 +24,7 @@ if v:version < 700 "{{{2
echoerr "tlib requires Vim >= 7"
finish
endif
-let loaded_tlib = 11
+let loaded_tlib = 12
let s:save_cpo = &cpo
set cpo&vim
@@ -36,15 +37,16 @@ set cpo&vim
" Set a variable only if it doesn't already exist.
" EXAMPLES: >
" TLet foo = 1
-command! -nargs=+ TLet let s:tllet_var = matchstr(<q-args>, '^\S\+')
- \ | let s:tllet_val = matchstr(<q-args>, '=\s*\zs.*')
- \ | exec printf('if !exists(%s) | let %s = %s | endif', string(s:tllet_var), s:tllet_var, s:tllet_val)
- " \ | unlet s:tllet_var s:tllet_val
+command! -nargs=+ TLet exec printf('if !exists("%s") | let %s | endif', matchstr(<q-args>, '^[^=[:space:]]\+'), <q-args>)
" Open a scratch buffer (a buffer without a file). >
" TScratch ... use split window
" TScratch! ... use the whole frame
+" This command takes an (inner) dictionnary as optional argument.
+" EXAMPLES: >
+" TScratch 'scratch': '__FOO__'
+" => Open a scratch buffer named __FOO__
command! -bar -nargs=* -bang TScratch call tlib#scratch#UseScratch({'scratch_split': '<bang>' != '!', <args>})
@@ -77,7 +79,7 @@ TLet g:tlib_scratch_pos = 'botright'
TLet g:tlib_inputlist_pct = 70
" Size of filename columns when listing filenames
-TLet g:tlib_inputlist_width_filename = &co / 3
+TLet g:tlib_inputlist_width_filename = '&co / 3'
" TLet g:tlib_inputlist_width_filename = 25
" The highlight group to use for showing matches in the input list window.
@@ -138,6 +140,8 @@ TLet g:tlib_keyagents_InputList_s = {
\ "\<Down>": 'tlib#agent#Down',
\ "\<c-Up>": 'tlib#agent#UpN',
\ "\<c-Down>": 'tlib#agent#DownN',
+ \ "\<Left>": 'tlib#agent#ShiftLeft',
+ \ "\<Right>": 'tlib#agent#ShiftRight',
\ 18: 'tlib#agent#Reset',
\ 242: 'tlib#agent#Reset',
\ 17: 'tlib#agent#Input',
@@ -184,6 +188,7 @@ TLet g:tlib_handlers_EditList = [
\ {'return_agent': 'tlib#agent#EditReturnValue'},
\ ]
+
augroup TLib
autocmd!
augroup END
@@ -298,3 +303,19 @@ FIXES:
number of windows hasn't changed)
- tlib#arg#Ex(): Don't escape backslashes by default
+0.12
+NEW:
+ - tlib/tab.vim
+CHANGES:
+ - Renamed tlib#win#SetWin() to tlib#win#Set()
+IMPROVEMENTS:
+ - tlib#input#List(): <left>, <right> keys work in some lists
+ - tlib#input#List(): If an index_table is provided this will be used
+ instead of the item's list index.
+FIXES:
+ - tlib#input#List(): Problem with scrolling, when the list was
+ shorter than the window (eg when using a vertical window).
+ - tlib#cache#Filename(): Don't rewrite name as relative filename if
+ explicitly given as argument. Avoid double (back)slashes.
+ - TLet: simplified
+
View
6 test/tlib.vim
@@ -1,10 +1,10 @@
" tLib.vim
-" @Author: Thomas Link (mailto:samul AT web de?subject=vim-tLib)
+" @Author: Thomas Link (mailto:micathom AT gmail com?subject=vim-tLib)
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2006-12-17.
-" @Last Change: 2007-08-04.
-" @Revision: 115
+" @Last Change: 2007-08-27.
+" @Revision: 116
if !exists("loaded_tassert")
echoerr 'tAssert (vimscript #1730) is required'
Please sign in to comment.
Something went wrong with that request. Please try again.