Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Version 0.18

NEW:
    - tlib/time.vim
    - g:tlib_inputlist_livesearch_threshold (useful on slower systems)
CHANGES:
    - tlib#input#ListD(), World: Don't redisplay the list while typing
    new letters; calculate filter regexps only once before filtering the
    list.
    - World.vim: Minor changes to how filenames are handled.
  • Loading branch information...
commit b7e236ee5d9ad03f2e75d05ced24b07b0bee9b0b 1 parent 72a2901
@tomtom tomtom authored committed
View
152 autoload/tlib/World.vim
@@ -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-09-29.
-" @Revision: 0.1.320
+" @Last Change: 2007-10-21.
+" @Revision: 0.1.374
" :filedoc:
" A prototype used by |tlib#input#List|.
@@ -51,6 +51,7 @@ let s:prototype = tlib#Object#New({
\ 'state': 'display',
\ 'state_handlers': [],
\ 'timeout': 0,
+ \ 'timeout_resolution': 2,
\ 'type': '',
\ 'win_wnr': -1,
\ })
@@ -64,16 +65,70 @@ endf
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 + 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'
+ call self.Set_highlight_filename()
+ let self.display_format = 'world.FormatFilename(%s)'
else
let self.display_format = a:value
endif
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'
+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'
+ hi def link TLibMarker Special
+ hi def link TLibDir Directory
+endf
+
+
+function! s:prototype.FormatFilename(file) dict "{{{3
+ let fname = fnamemodify(a:file, ":p:t")
+ " let fname = fnamemodify(a:file, ":t")
+ " if isdirectory(a:file)
+ " let fname .='/'
+ " endif
+ let dname = fnamemodify(a:file, ":h")
+ let dnmax = &co - max([eval(g:tlib_inputlist_width_filename), len(fname)]) - 11 - self.index_width - &fdc
+ if len(dname) > dnmax
+ 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, '+')
+ else
+ call add(marker, 'B')
+ endif
+ elseif bufloaded(a:file)
+ call add(marker, 'b')
+ else
+ call add(marker, '-')
+ endif
+ else
+ call add(marker, ' ')
+ endif
+ if !empty(marker)
+ call insert(marker, '|')
+ call add(marker, '|')
+ " let fname .= ' '. join(marker, '')
+ endif
+ return printf("%-". eval(g:tlib_inputlist_width_filename) ."s %s %s", fname, join(marker, ''), dname)
+endf
+
+
function! s:prototype.GetSelectedItems(current) dict "{{{3
if stridx(self.type, 'i') != -1
let rv = copy(self.sel_idx)
@@ -201,34 +256,68 @@ function! s:prototype.GetCurrentItem() dict "{{{3
endf
-function! s:prototype.Match(text, ...) dict "{{{3
- let mrx = '\V'. (a:0 >= 1 && a:1 ? '\C' : '')
+function! s:prototype.SetFilter() dict "{{{3
+ " let mrx = '\V'. (a:0 >= 1 && a:1 ? '\C' : '')
+ let mrx = '\V'. self.filter_format
+ let self.filter_pos = []
+ let self.filter_neg = []
for filter in self.filter
" TLogVAR filter
let rx = join(reverse(filter(copy(filter), '!empty(v:val)')), '\|')
" TLogVAR rx
if rx[0] == g:tlib_inputlist_not
- if len(rx) > 1 && a:text =~ mrx .'\('. rx[1:-1] .'\)'
- return 0
+ if len(rx) > 1
+ call add(self.filter_neg, mrx .'\('. rx[1:-1] .'\)')
endif
- elseif a:text !~ mrx .'\('. rx .'\)'
+ else
+ call add(self.filter_pos, mrx .'\('. rx .'\)')
+ endif
+ endfor
+endf
+
+
+function! s:prototype.Match(text, ...) dict "{{{3
+ for rx in self.filter_neg
+ if a:text =~ rx
+ return 0
+ endif
+ endfor
+ for rx in self.filter_pos
+ if a:text !~ rx
return 0
endif
- " if a:text !~ mrx. self.GetRx(filter)
- " return 0
- " endif
endfor
+ " for filter in self.filter
+ " " TLogVAR filter
+ " let rx = join(reverse(filter(copy(filter), '!empty(v:val)')), '\|')
+ " " TLogVAR rx
+ " if rx[0] == g:tlib_inputlist_not
+ " if len(rx) > 1 && a:text =~ mrx .'\('. rx[1:-1] .'\)'
+ " return 0
+ " endif
+ " elseif a:text !~ mrx .'\('. rx .'\)'
+ " return 0
+ " endif
+ " " if a:text !~ mrx. self.GetRx(filter)
+ " " return 0
+ " " endif
+ " endfor
return 1
endf
-function! s:prototype.MatchBaseIdx(filter_format, idx, ...) dict "{{{3
- let mrx = '\V'. (a:0 >= 1 && a:1 ? '\C' : '')
+function! s:prototype.MatchBaseIdx(idx) dict "{{{3
let text = self.GetBaseItem(a:idx)
- if !empty(a:filter_format)
- let text = eval(call(function("printf"), self.FormatArgs(a:filter_format, text)))
+ if !empty(self.filter_format)
+ let text = eval(call(function("printf"), self.FormatArgs(self.filter_format, text)))
endif
- return self.Match(text, mrx)
+ return self.Match(text)
+endf
+
+
+function! s:prototype.BuildTable() dict "{{{3
+ call self.SetFilter()
+ let self.table = filter(range(1, len(self.base)), 'self.MatchBaseIdx(v:val)')
endf
@@ -244,6 +333,11 @@ function! s:prototype.ReduceFilter() dict "{{{3
endf
+function! s:prototype.SetInitialFilter(filter) dict "{{{3
+ let self.initial_filter = [[''], [a:filter]]
+endf
+
+
function! s:prototype.PopFilter() dict "{{{3
" TLogVAR self.filter
if len(self.filter[0]) > 1
@@ -330,7 +424,7 @@ function! s:prototype.Retrieve(anyway) dict "{{{3
let ra = self.retrieve_eval
" TLogVAR ra
if !empty(ra)
- let back = self.SwitchWindow('win')
+ let back = self.SwitchWindow('win')
let world = self
let self.base = eval(ra)
" TLogVAR self.base
@@ -342,7 +436,7 @@ function! s:prototype.Retrieve(anyway) dict "{{{3
endf
-function! s:prototype.DisplayHelp(world) dict "{{{3
+function! s:prototype.DisplayHelp() dict "{{{3
let help = [
\ 'Help:',
\ 'Mouse ... Pick an item Letter ... Filter the list',
@@ -354,12 +448,12 @@ function! s:prototype.DisplayHelp(world) dict "{{{3
\ '<Esc> ... Abort',
\ ]
- if a:world.allow_suspend
+ if self.allow_suspend
call add(help,
\ '<c|m-z> ... Suspend/Resume <c-o> ... Switch to origin')
endif
- if stridx(a:world.type, 'm') != -1
+ if stridx(self.type, 'm') != -1
let help += [
\ '#, <c-space> ... (Un)Select the current item',
\ '<c|m-a> ... (Un)Select all currently visible items',
@@ -367,7 +461,7 @@ function! s:prototype.DisplayHelp(world) dict "{{{3
\ ]
" \ '<c-\> ... Show only selected',
endif
- for handler in a:world.key_handlers
+ for handler in self.key_handlers
let key = get(handler, 'key_name', '')
if !empty(key)
let desc = get(handler, 'help', '')
@@ -406,8 +500,8 @@ function! s:prototype.Resize(hsize, vsize) dict "{{{3
endf
-" :def: function! s:prototype.DisplayList(world, query, ?list)
-function! s:prototype.DisplayList(world, query, ...) dict "{{{3
+" :def: function! s:prototype.DisplayList(query, ?list)
+function! s:prototype.DisplayList(query, ...) dict "{{{3
" TLogVAR a:query
" TLogVAR self.state
let list = a:0 >= 1 ? a:1 : []
@@ -417,12 +511,12 @@ function! s:prototype.DisplayList(world, query, ...) dict "{{{3
if self.state == 'scroll'
exec 'norm! '. self.offset .'zt'
elseif self.state == 'help'
- call self.DisplayHelp(a:world)
+ call self.DisplayHelp()
else
" let ll = len(list)
- let ll = a:world.llen
+ let ll = self.llen
" let x = len(ll) + 1
- let x = a:world.index_width + 1
+ let x = self.index_width + 1
" TLogVAR ll
if self.state =~ '\<display\>'
let resize = get(self, 'resize', 0)
View
43 autoload/tlib/char.vim
@@ -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-11.
-" @Revision: 0.0.12
+" @Last Change: 2007-10-21.
+" @Revision: 0.0.29
if &cp || exists("loaded_tlib_char_autoload")
finish
@@ -19,20 +19,39 @@ let loaded_tlib_char_autoload = 1
" echo tlib#char#Get()
" echo tlib#char#Get(5)
function! tlib#char#Get(...) "{{{3
- let timeout = a:0 >= 1 ? a:1 : 0
- if timeout == 0
+ TVarArg ['timeout', 0], ['resolution', 0]
+ if timeout == 0 || !has('reltime')
return getchar()
else
- let start = localtime()
- while 1
- let c = getchar(0)
- if c != 0
- return c
- elseif localtime() - start > timeout
+ return tlib#char#GetWithTimeout(timeout, resolution)
+ endif
+ return -1
+endf
+
+
+function! tlib#char#IsAvailable() "{{{3
+ let ch = getchar(1)
+ return type(ch) == 0 && ch != 0
+endf
+
+
+function! tlib#char#GetWithTimeout(timeout, ...) "{{{3
+ TVarArg ['resolution', 2]
+ " TLogVAR a:timeout, resolution
+ let start = tlib#time#MSecs()
+ while 1
+ let c = getchar(0)
+ if type(c) != 0 || c != 0
+ return c
+ else
+ let now = tlib#time#MSecs()
+ let diff = tlib#time#DiffMSecs(now, start, resolution)
+ " TLogVAR diff
+ if diff > a:timeout
return -1
endif
- endwh
- endif
+ endif
+ endwh
return -1
endf
View
5 autoload/tlib/hook.vim
@@ -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-21.
-" @Last Change: 2007-09-11.
-" @Revision: 0.0.8
+" @Last Change: 2007-10-15.
+" @Revision: 0.0.9
if &cp || exists("loaded_tlib_hook_autoload")
finish
@@ -24,6 +24,7 @@ function! tlib#hook#Run(hook, ...) "{{{3
if empty(hook)
return 0
else
+ let world = dict
exec hook
return 1
endif
View
73 autoload/tlib/input.vim
@@ -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-07.
-" @Revision: 0.0.352
+" @Last Change: 2007-10-21.
+" @Revision: 0.0.381
if &cp || exists("loaded_tlib_input_autoload")
finish
@@ -123,6 +123,7 @@ function! tlib#input#ListW(world, ...) "{{{3
let world.winview = tlib#win#GetLayout()
call world.Reset(1)
endif
+ " TLogVAR world.initial_index
let key_agents = copy(g:tlib_keyagents_InputList_s)
if stridx(world.type, 'm') != -1
call extend(key_agents, g:tlib_keyagents_InputList_m, 'force')
@@ -182,7 +183,7 @@ function! tlib#input#ListW(world, ...) "{{{3
" TLogVAR world.filter
if world.state =~ 'display'
if world.state =~ '^display'
- let world.table = filter(range(1, len(world.base)), 'world.MatchBaseIdx(world.filter_format, v:val)')
+ call world.BuildTable()
" TLogDBG 2
" TLogVAR world.table
let world.list = map(copy(world.table), 'world.GetBaseItem(v:val)')
@@ -213,6 +214,8 @@ function! tlib#input#ListW(world, ...) "{{{3
endif
endif
" TLogDBG 4
+ " TLogVAR world.idx, world.llen, world.state
+ " TLogDBG world.FilterIsEmpty()
if world.state == 'display'
if world.idx == '' && world.llen < g:tlib_sortprefs_threshold && !world.FilterIsEmpty()
let s:world = world
@@ -227,10 +230,12 @@ function! tlib#input#ListW(world, ...) "{{{3
let world.prefidx = 1
endif
endif
+ " TLogVAR world.initial_index, world.prefidx
" TLogDBG 5
let dlist = copy(world.list)
if !empty(world.display_format)
let display_format = world.display_format
+ " TLogVAR display_format
call map(dlist, 'eval(call(function("printf"), world.FormatArgs(display_format, v:val)))')
endif
" TLogVAR world.prefidx
@@ -256,15 +261,16 @@ function! tlib#input#ListW(world, ...) "{{{3
" let world.offset = world.prefidx
" endif
" TLogDBG 8
- call world.DisplayList(world, world.query .' (filter: '. world.DisplayFilter() .'; press "?" for help)', dlist)
- " TLogDBG 9
+ if !tlib#char#IsAvailable()
+ call world.DisplayList(world.query .' (filter: '. world.DisplayFilter() .'; press "?" for help)', dlist)
+ " TLogDBG 9
+ endif
let world.state = ''
-
else
" if world.state == 'scroll'
" let world.prefidx = world.offset
" endif
- call world.DisplayList(world, '')
+ call world.DisplayList('')
if world.state == 'help'
let world.state = 'display'
else
@@ -275,7 +281,7 @@ function! tlib#input#ListW(world, ...) "{{{3
let world.list_wnr = winnr()
" TLogVAR world.timeout
- let c = tlib#char#Get(world.timeout)
+ let c = tlib#char#Get(world.timeout, world.timeout_resolution)
if world.state != ''
" continue
elseif has_key(key_agents, c)
@@ -310,7 +316,12 @@ function! tlib#input#ListW(world, ...) "{{{3
else
let world.idx = ''
" TLogVAR world.filter
- let world.filter[0][0] .= nr2char(c)
+ if world.llen > g:tlib_inputlist_livesearch_threshold
+ let world.filter[0][0] = input('Filter: ', world.filter[0][0] . nr2char(c))
+ echo
+ else
+ let world.filter[0][0] .= nr2char(c)
+ endif
" continue
endif
else
@@ -469,46 +480,6 @@ function! s:CheckAgentReturnValue(name, value) "{{{3
endf
-function! s:FormatFilename(world, file) "{{{3
- let fname = fnamemodify(a:file, ":p:t")
- " let fname = fnamemodify(a:file, ":t")
- " if isdirectory(a:file)
- " let fname .='/'
- " endif
- let dname = fnamemodify(a:file, ":h")
- 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
- let marker = []
- let bnr = bufnr(a:file)
- " TLogVAR a:file, bnr, a:world.bufnr
- if bnr != -1
- if bnr == a:world.bufnr
- 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, 'b')
- else
- call add(marker, '-')
- endif
- else
- call add(marker, ' ')
- endif
- if !empty(marker)
- call insert(marker, '|')
- call add(marker, '|')
- " let fname .= ' '. join(marker, '')
- endif
- return printf("%-". eval(g:tlib_inputlist_width_filename) ."s %s %s", fname, join(marker, ''), dname)
-endf
-
-
" Functions related to tlib#input#EditList(type, ...) "{{{2
" :def: function! tlib#input#EditList(query, list, ?timeout=0)
@@ -545,8 +516,8 @@ endf
" its output.
"
" EXAMPLE: >
-" exec 'norm! `'. matchstr(tlib#input#CommandSelect('marks'), '^ \+\zs.')
-" exec 'norm i'. matchstr(tlib#input#CommandSelect('abbrev'), '^\S\+\s\+\zs\S\+')
+" command! TMarks exec 'norm! `'. matchstr(tlib#input#CommandSelect('marks'), '^ \+\zs.')
+" command! TAbbrevs exec 'norm i'. matchstr(tlib#input#CommandSelect('abbrev'), '^\S\+\s\+\zs\S\+')
function! tlib#input#CommandSelect(command, ...) "{{{3
TVarArg ['args', {}]
if has_key(args, 'retrieve')
View
60 autoload/tlib/time.vim
@@ -0,0 +1,60 @@
+" time.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-10-17.
+" @Last Change: 2007-10-17.
+" @Revision: 0.0.27
+
+if &cp || exists("loaded_tlib_time_autoload")
+ finish
+endif
+let loaded_tlib_time_autoload = 1
+
+
+function! tlib#time#MSecs() "{{{3
+ let rts = reltimestr(reltime())
+ return substitute(rts, '\.', '', '')
+endf
+
+
+function! tlib#time#Now() "{{{3
+ let rts = reltimestr(reltime())
+ let rtl = split(rts, '\.')
+ return rtl
+endf
+
+
+function! tlib#time#Diff(a, b, ...) "{{{3
+ TVarArg ['resolution', 2]
+ let [as, am] = a:a
+ let [bs, bm] = a:b
+ let rv = 0 + (as - bs)
+ if resolution > 0
+ let rv .= repeat('0', resolution))
+ let am = am[0 : resolution - 1]
+ let bm = bm[0 : resolution - 1]
+ let rv += (am - bm)
+ endif
+ return rv
+endf
+
+
+function! tlib#time#DiffMSecs(a, b, ...) "{{{3
+ TVarArg ['resolution', 2]
+ if a:a == a:b
+ return 0
+ endif
+ let a = printf('%30s', a:a[0 : -(7 - resolution)])
+ let b = printf('%30s', a:b[0 : -(7 - resolution)])
+ for i in range(0, 29)
+ if a[i] != b[i]
+ let a = a[i : -1]
+ let b = b[i : -1]
+ return a - b
+ endif
+ endfor
+ return 0
+endf
+
+
View
21 plugin/02tlib.vim
@@ -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-10-12.
-" @Revision: 0.17.380
+" @Last Change: 2007-10-21.
+" @Revision: 0.18.390
" 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 = 17
+let loaded_tlib = 18
let s:save_cpo = &cpo
set cpo&vim
@@ -111,6 +111,11 @@ TLet g:tlib_inputlist_width_filename = '&co / 3'
" The highlight group to use for showing matches in the input list window.
TLet g:tlib_inputlist_higroup = 'IncSearch'
+" If a list contains more items, don't do an incremental "live search",
+" but use |input()| the quere the user for a filter. This is useful on
+" slower machines or with very long lists.
+TLet g:tlib_inputlist_livesearch_threshold = 500
+
TLet g:tlib_filename_sep = '/'
" TLet g:tlib_filename_sep = exists('+shellslash') && !&shellslash ? '\' : '/' " {{{2
@@ -378,3 +383,13 @@ NEW:
- TBrowseOutput
- Some minor changes
+0.18
+NEW:
+ - tlib/time.vim
+ - g:tlib_inputlist_livesearch_threshold
+CHANGES:
+ - tlib#input#ListD(), World: Don't redisplay the list while typing
+ new letters; calculate filter regexps only once before filtering the
+ list.
+ - World.vim: Minor changes to how filenames are handled.
+
Please sign in to comment.
Something went wrong with that request. Please try again.