Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Version 0.27

- NEW: tlib#normal#WithRegister()
- FIX: Try not to change numbered registers
- FIX: Cosmetic bug, wrong packaging (thanks Nathan Neff)
- Meaning of World#filter_format changed; new World#filter_options
- Filtering didn't work as advertised
  • Loading branch information...
commit 3731cc39dc685d0b3ef33a0041fc9b522f0abcc5 1 parent a9db093
@tomtom tomtom authored committed
View
13 autoload/tlib/Object.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: 2008-08-20.
-" @Revision: 0.1.118
+" @Last Change: 2008-10-16.
+" @Revision: 0.1.120
" :filedoc:
" Provides a prototype plus some OO-like methods.
@@ -147,13 +147,16 @@ function! s:prototype.Super(method, arglist) dict "{{{3
endf
-function! s:prototype.Methods() dict "{{{3
+function! s:prototype.Methods(...) dict "{{{3
+ TVarArg ['pattern', '\d\+']
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]
+ let id = matchstr(string(e[1]), pattern)
+ if !empty(id)
+ let acc[id] = e[0]
+ endif
endfor
return acc
endf
View
67 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: 2008-10-04.
-" @Revision: 0.1.471
+" @Last Change: 2008-10-16.
+" @Revision: 0.1.518
" :filedoc:
" A prototype used by |tlib#input#List|.
@@ -26,6 +26,7 @@ let s:prototype = tlib#Object#New({
\ 'display_format': '',
\ 'filter': [['']],
\ 'filter_format': '',
+ \ 'filter_options': '\c',
\ 'follow_cursor': '',
\ 'index_table': [],
\ 'initial_filter': [['']],
@@ -34,6 +35,7 @@ let s:prototype = tlib#Object#New({
\ 'initialized': 0,
\ 'key_handlers': [],
\ 'list': [],
+ \ 'match_mode': 'strings',
\ 'next_state': '',
\ 'numeric_chars': tlib#var#Get('tlib_numeric_chars', 'bg'),
\ 'offset': 1,
@@ -210,6 +212,12 @@ function! s:prototype.GetRx0(...) dict "{{{3
endf
+function! s:prototype.FormatName(format, value) dict "{{{3
+ let world = self
+ return eval(call(function("printf"), self.FormatArgs(a:format, a:value)))
+endf
+
+
function! s:prototype.GetItem(idx) dict "{{{3
return self.list[a:idx - 1]
endf
@@ -283,7 +291,7 @@ endf
function! s:prototype.SetFilter() dict "{{{3
" let mrx = '\V'. (a:0 >= 1 && a:1 ? '\C' : '')
- let mrx = '\V'. self.filter_format
+ let mrx = '\V'. self.filter_options
let self.filter_pos = []
let self.filter_neg = []
for filter in self.filter
@@ -301,13 +309,39 @@ function! s:prototype.SetFilter() dict "{{{3
endf
+function! s:prototype.IsValidFilter() dict "{{{3
+ let last = '\V\('. self.filter[0][0] .'\)'
+ " TLogVAR last
+ try
+ let a = match("", last)
+ return 1
+ catch
+ return 0
+ endtry
+endf
+
+
+function! s:prototype.SetMatchMode() dict "{{{3
+ let match_mode = tlib#var#Get('tlib_inputlist_match', 'bg')
+ if !empty(match_mode)
+ if index(['strings', 'chars'], match_mode) != -1
+ let self.match_mode = match_mode
+ else
+ throw 'tlib: Unknown mode for tlib_inputlist_match: '. match_mode
+ endif
+ endif
+endf
+
+
function! s:prototype.Match(text, ...) dict "{{{3
for rx in self.filter_neg
+ " TLogVAR rx
if a:text =~ rx
return 0
endif
endfor
for rx in self.filter_pos
+ " TLogVAR rx
if a:text !~ rx
return 0
endif
@@ -334,8 +368,9 @@ endf
function! s:prototype.MatchBaseIdx(idx) dict "{{{3
let text = self.GetBaseItem(a:idx)
if !empty(self.filter_format)
- let text = eval(call(function("printf"), self.FormatArgs(self.filter_format, text)))
+ let text = self.FormatName(self.filter_format, text)
endif
+ " TLogVAR text
return self.Match(text)
endf
@@ -388,9 +423,16 @@ endf
function! s:prototype.DisplayFilter() dict "{{{3
" TLogVAR self.filter
- let filter1 = map(deepcopy(self.filter), '"(". join(reverse(v:val), " OR ") .")"')
+ let filter1 = deepcopy(self.filter)
+ call filter(filter1, 'v:val != [""]')
" TLogVAR filter1
- return join(reverse(filter1), ' AND ')
+ if self.match_mode == 'strings'
+ call map(filter1, '"(". join(reverse(v:val), " OR ") .")"')
+ return join(reverse(filter1), ' AND ')
+ elseif self.match_mode == 'chars'
+ call map(filter1, 'v:val[0]')
+ return '['. join(reverse(filter1), '') .']'
+ end
endf
@@ -515,9 +557,12 @@ function! s:prototype.DisplayHelp() dict "{{{3
\ '',
\ 'Press any key to continue.',
\ ]
- norm! ggdG
+ " call tlib#normal#WithRegister('gg"tdG', 't')
+ call tlib#buffer#DeleteRange('1', '$')
call append(0, help)
- norm! Gddgg
+ " call tlib#normal#WithRegister('G"tddgg', 't')
+ call tlib#buffer#DeleteRange('$', '$')
+ 1
call self.Resize(len(help), 0)
endf
@@ -562,14 +607,14 @@ function! s:prototype.DisplayList(query, ...) dict "{{{3
let resize = min([resize, (&lines * g:tlib_inputlist_pct / 100)])
" TLogVAR resize, ll, &lines
call self.Resize(resize, get(self, 'resize_vertical', 0))
- norm! ggdG
+ call tlib#normal#WithRegister('gg"tdG', 't')
let w = winwidth(0) - &fdc
" let w = winwidth(0) - &fdc - 1
let lines = copy(list)
let lines = map(lines, 'printf("%-'. w .'.'. w .'s", substitute(v:val, ''[[:cntrl:][:space:]]'', " ", "g"))')
" TLogVAR lines
call append(0, lines)
- norm! Gddgg
+ call tlib#normal#WithRegister('G"tddgg', 't')
endif
" TLogVAR self.prefidx
let base_pref = self.GetBaseIdx(self.prefidx)
@@ -603,7 +648,7 @@ function! s:prototype.DisplayList(query, ...) dict "{{{3
if !empty(g:tlib_inputlist_higroup)
if empty(rx0)
match none
- else
+ elseif self.IsValidFilter()
exec 'match '. g:tlib_inputlist_higroup .' /\c'. escape(rx0, '/') .'/'
endif
endif
View
13 autoload/tlib/buffer.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: 2008-08-19.
-" @Revision: 0.0.252
+" @Last Change: 2008-10-06.
+" @Revision: 0.0.255
if &cp || exists("loaded_tlib_buffer_autoload")
finish
@@ -183,7 +183,12 @@ endf
" Delete the lines in the current buffer. Wrapper for |:delete|.
function! tlib#buffer#DeleteRange(line1, line2) "{{{3
- exec a:line1.','.a:line2.'delete'
+ let r = @t
+ try
+ exec a:line1.','.a:line2.'delete t'
+ finally
+ let @t = r
+ endtry
endf
@@ -282,7 +287,7 @@ function! tlib#buffer#InsertText(text, ...) "{{{3
" TLogVAR text
endif
" exec 'norm! '. lineno .'Gdd'
- norm! dd
+ call tlib#normal#WithRegister('"tdd', 't')
call append(lineno - 1, text)
let tlen = len(text)
let posshift = matchstr(pos, '\d\+')
View
183 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: 2008-10-04.
-" @Revision: 0.0.503
+" @Last Change: 2008-10-16.
+" @Revision: 0.0.534
if &cp || exists("loaded_tlib_input_autoload")
finish
@@ -130,6 +130,7 @@ function! tlib#input#ListW(world, ...) "{{{3
let @/ = ''
let &laststatus = 2
let world.initial_display = 1
+ call world.SetMatchMode()
try
while !empty(world.state) && world.state !~ '^exit' && (world.show_empty || !empty(world.base))
@@ -173,8 +174,77 @@ function! tlib#input#ListW(world, ...) "{{{3
endif
" TLogVAR world.filter
if world.state =~ 'display'
- if world.state =~ '^display'
- let dlist = s:GetDList(world)
+ if world.IsValidFilter() && world.state =~ '^display'
+
+ call world.BuildTable()
+ " TLogDBG 2
+ " TLogDBG len(world.table)
+ " TLogVAR world.table
+ let world.list = map(copy(world.table), 'world.GetBaseItem(v:val)')
+ " TLogDBG 3
+ let world.llen = len(world.list)
+ " 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
+ " TLogDBG 'ReduceFilter'
+ continue
+ else
+ if world.llen == 1
+ let world.last_item = world.list[0]
+ if world.pick_last_item
+ echom 'Pick last item: '. world.list[0]
+ let world.prefidx = '1'
+ " TLogDBG 'pick last item'
+ throw 'pick'
+ endif
+ else
+ let world.last_item = ''
+ 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
+ let pref = sort(range(1, world.llen), 's:SortPrefs')
+ let world.prefidx = get(pref, 0, world.initial_index)
+ 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
+ " TLogVAR world.initial_index, world.prefidx
+ " TLogDBG 5
+ " TLogDBG len(world.list)
+ " TLogVAR world.list
+ let dlist = copy(world.list)
+ if !empty(world.display_format)
+ let display_format = world.display_format
+ " TLogVAR display_format
+ call map(dlist, 'world.FormatName(display_format, v:val)')
+ endif
+ " TLogVAR world.prefidx
+ " TLogDBG 6
+ 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]')
+ " TLogVAR dlist
+
endif
" TLogDBG 7
" TLogVAR world.prefidx, world.offset
@@ -238,6 +308,8 @@ function! tlib#input#ListW(world, ...) "{{{3
" continue
elseif c == 13
throw 'pick'
+ elseif c == 27
+ let world.state = 'exit empty'
elseif c == "\<LeftMouse>"
let line = getline(v:mouse_lnum)
let world.prefidx = substitute(matchstr(line, '^\d\+\ze[*:]'), '^0\+', '', '')
@@ -265,12 +337,30 @@ function! tlib#input#ListW(world, ...) "{{{3
let world.idx = ''
" TLogVAR world.filter
if world.llen > g:tlib_inputlist_livesearch_threshold
- let world.filter[0][0] = input('Filter: ', world.filter[0][0] . nr2char(c))
- echo
+ let pattern = input('Filter: ', world.filter[0][0] . nr2char(c))
+ if empty(pattern)
+ let world.state = 'exit empty'
+ else
+ if world.match_mode == 'strings'
+ let world.filter[0] = split(pattern, '\s*|\s*') + world.filter[0][1 : -1]
+ elseif world.match_mode == 'chars'
+ let world.filter = map(split(pattern, '\zs'), '[v:val]') + world.filter[1 : -1]
+ endif
+ echo
+ endif
+ elseif c == 124
+ call insert(world.filter[0], [])
else
- let world.filter[0][0] .= nr2char(c)
+ if world.match_mode == 'strings'
+ let world.filter[0][0] .= nr2char(c)
+ elseif world.match_mode == 'chars'
+ call insert(world.filter, [nr2char(c)])
+ endif
endif
" continue
+ if c == 45 && world.filter[0][0] == '-'
+ let world.state = 'redisplay'
+ end
endif
else
let world.state = 'redisplay'
@@ -394,80 +484,6 @@ function! s:Init(world, cmd) "{{{3
endf
-function! s:GetDList(world) "{{{3
- call a:world.BuildTable()
- " TLogDBG 2
- " TLogDBG len(a:world.table)
- " TLogVAR a:world.table
- let a:world.list = map(copy(a:world.table), 'a:world.GetBaseItem(v:val)')
- " TLogDBG 3
- let a:world.llen = len(a:world.list)
- " TLogVAR a:world.index_table
- if empty(a:world.index_table)
- let dindex = range(1, a:world.llen)
- let a:world.index_width = len(a:world.llen)
- else
- let dindex = a:world.index_table
- let a:world.index_width = len(max(dindex))
- endif
- if a:world.llen == 0 && !a:world.show_empty
- call a:world.ReduceFilter()
- let a:world.offset = 1
- " TLogDBG 'ReduceFilter'
- continue
- else
- if a:world.llen == 1
- let a:world.last_item = a:world.list[0]
- if a:world.pick_last_item
- echom 'Pick last item: '. a:world.list[0]
- let a:world.prefidx = '1'
- " TLogDBG 'pick last item'
- throw 'pick'
- endif
- else
- let a:world.last_item = ''
- endif
- endif
- " TLogDBG 4
- " TLogVAR a:world.idx, a:world.llen, a:world.state
- " TLogDBG a:world.FilterIsEmpty()
- if a:world.state == 'display'
- if a:world.idx == '' && a:world.llen < g:tlib_sortprefs_threshold && !a:world.FilterIsEmpty()
- let s:world = a:world
- let pref = sort(range(1, a:world.llen), 's:SortPrefs')
- let a:world.prefidx = get(pref, 0, a:world.initial_index)
- else
- let a:world.prefidx = a:world.idx == '' ? a:world.initial_index : a:world.idx
- endif
- if a:world.prefidx > a:world.llen
- let a:world.prefidx = a:world.llen
- elseif a:world.prefidx < 1
- let a:world.prefidx = 1
- endif
- endif
- " TLogVAR a:world.initial_index, a:world.prefidx
- " TLogDBG 5
- " TLogDBG len(a:world.list)
- " TLogVAR a:world.list
- let dlist = copy(a:world.list)
- if !empty(a:world.display_format)
- let display_format = a:world.display_format
- let world = a:world
- " TLogVAR display_format
- call map(dlist, 'eval(call(function("printf"), a:world.FormatArgs(display_format, v:val)))')
- endif
- " TLogVAR a:world.prefidx
- " TLogDBG 6
- if a:world.offset_horizontal > 0
- call map(dlist, 'v:val[a:world.offset_horizontal:-1]')
- endif
- " TLogVAR dindex
- let dlist = map(range(0, a:world.llen - 1), 'printf("%0'. a:world.index_width .'d", dindex[v:val]) .": ". dlist[v:val]')
- " TLogVAR dlist
- return dlist
-endf
-
-
function! s:AssessName(name) "{{{3
let xa = 0
for fltl in s:world.filter
@@ -615,7 +631,8 @@ function! tlib#input#Edit(name, value, callback, ...) "{{{3
imap <buffer> <c-s> <c-o>call <SID>EditCallback(1)<cr>
map <buffer> <c-w><cr> :call <SID>EditCallback(1)<cr>
imap <buffer> <c-w><cr> <c-o>call <SID>EditCallback(1)<cr>
- norm! ggdG
+ call tlib#normal#WithRegister('gg"tdG', 't')
+ norm
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)
@@ -623,7 +640,7 @@ function! tlib#input#Edit(name, value, callback, ...) "{{{3
" hr3.hrm.hr3
let hd = ['Keys: <c-s>, <c-w><cr> ... save/accept; <c-w>c ... cancel', s:horizontal_line]
call append(1, hd)
- norm! ggdd
+ call tlib#normal#WithRegister('gg"tdd', 't')
syntax match TlibEditComment /^\%1l.*/
syntax match TlibEditComment /^```.*/
hi link TlibEditComment Comment
View
26 autoload/tlib/normal.vim
@@ -0,0 +1,26 @@
+" normal.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: 2008-10-06.
+" @Last Change: 2008-10-06.
+" @Revision: 9
+
+let s:save_cpo = &cpo
+set cpo&vim
+
+
+function! tlib#normal#WithRegister(cmd, ...) "{{{3
+ TVarArg ['register', 't'], ['norm_cmd', 'norm!']
+ exec 'let reg = @'. register
+ try
+ exec norm_cmd .' '. a:cmd
+ exec 'return @'. register
+ finally
+ exec 'let @'. register .' = reg'
+ endtry
+endf
+
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
View
28 doc/tlib.txt
@@ -42,6 +42,7 @@ Contents~
g:tlib_inputlist_higroup ................ |g:tlib_inputlist_higroup|
g:tlib_inputlist_livesearch_threshold ... |g:tlib_inputlist_livesearch_threshold|
g:tlib_inputlist_filename_indicators .... |g:tlib_inputlist_filename_indicators|
+ g:tlib_inputlist_match .................. |g:tlib_inputlist_match|
g:tlib_tags_extra ....................... |g:tlib_tags_extra|
g:tlib_tag_substitute ................... |g:tlib_tag_substitute|
g:tlib_filename_sep ..................... |g:tlib_filename_sep|
@@ -76,6 +77,7 @@ Contents~
prototype.FormatArgs
prototype.GetRx
prototype.GetRx0
+ prototype.FormatName
prototype.GetItem
prototype.GetListIdx
prototype.GetBaseIdx
@@ -84,6 +86,8 @@ Contents~
prototype.GetCurrentItem
prototype.CurrentItem
prototype.SetFilter
+ prototype.IsValidFilter
+ prototype.SetMatchMode
prototype.Match
prototype.MatchBaseIdx
prototype.BuildTable
@@ -232,6 +236,8 @@ Contents~
tlib#list#RemoveAll ..................... |tlib#list#RemoveAll()|
tlib#list#Zip ........................... |tlib#list#Zip()|
tlib#list#Uniq .......................... |tlib#list#Uniq()|
+ autoload/tlib/normal.vim
+ tlib#normal#WithRegister ................ |tlib#normal#WithRegister()|
autoload/tlib/notify.vim
tlib#notify#Echo ........................ |tlib#notify#Echo()|
tlib#notify#TrimMessage ................. |tlib#notify#TrimMessage()|
@@ -392,6 +398,12 @@ g:tlib_inputlist_filename_indicators (default: 0)
This is disabled by default because vim checks also for the file on
disk when doing this.
+ *g:tlib_inputlist_match*
+g:tlib_inputlist_match (default: 'strings')
+ Can be "strings" or "chars".
+ strings :: substrings
+ chars :: match characters
+
*g:tlib_tags_extra*
g:tlib_tags_extra (default: '')
Extra tags for |tlib#tag#Retrieve()| (see there). Can also be buffer-local.
@@ -558,6 +570,9 @@ prototype.GetRx
prototype.GetRx0
+prototype.FormatName
+
+
prototype.GetItem
@@ -582,6 +597,12 @@ prototype.CurrentItem
prototype.SetFilter
+prototype.IsValidFilter
+
+
+prototype.SetMatchMode
+
+
prototype.Match
@@ -1221,6 +1242,13 @@ tlib#list#Uniq(list, ...)
========================================================================
+autoload/tlib/normal.vim~
+
+ *tlib#normal#WithRegister()*
+tlib#normal#WithRegister(cmd, ...)
+
+
+========================================================================
autoload/tlib/notify.vim~
*tlib#notify#Echo()*
View
20 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: 2008-10-04.
-" @Revision: 470
+" @Last Change: 2008-10-16.
+" @Revision: 478
" GetLatestVimScripts: 1863 1 tlib.vim
"
" Please see also ../test/tlib.vim for usage examples.
@@ -28,7 +28,7 @@ if v:version < 700 "{{{2
echoerr "tlib requires Vim >= 7"
finish
endif
-let loaded_tlib = 25
+let loaded_tlib = 26
let s:save_cpo = &cpo
set cpo&vim
@@ -126,6 +126,11 @@ TLet g:tlib_inputlist_livesearch_threshold = 500
" disk when doing this.
TLet g:tlib_inputlist_filename_indicators = 0
+" Can be "strings" or "chars".
+" strings :: substrings
+" chars :: match characters
+TLet g:tlib_inputlist_match = 'strings'
+
" Extra tags for |tlib#tag#Retrieve()| (see there). Can also be buffer-local.
TLet g:tlib_tags_extra = ''
@@ -457,3 +462,12 @@ messages (contributed by Erik Falor)
- FIX: World.CloseScratch(): Set window
- FIX: tlib#input#ListW(): Set initial_display = 1 on reset
+0.26
+- NEW: tlib#normal#WithRegister()
+- FIX: Try not to change numbered registers
+
+0.27
+- FIX: Cosmetic bug, wrong packaging (thanks Nathan Neff)
+- Meaning of World#filter_format changed; new World#filter_options
+- Filtering didn't work as advertised
+
Please sign in to comment.
Something went wrong with that request. Please try again.