Skip to content

Commit

Permalink
Version 0.42
Browse files Browse the repository at this point in the history
- tlib#input#List: <s-space> inserts a *-like wildcard (represented as "__")- Check if a cache file cannot be created because a directory of the same name exists (display a message if so)- tlib#cache#Filename: Removed check if a directory of the same name exists (due to inconsistent use)- Minor improvements related to buffer handling (scratch_split)- .gitignore- docs (thanks to blueyed)- There is no "edit" answer possibility.- Fix first purge: do nothing if no timestamp file.- g:tlib_pick_single_item- Removed pick_single_item. Changed the default behavour when a list has only 1 item. See doc for g:tlib_pick_last_item.- Updated help for tlib#input#List(); help_extra attribute- EXPERIMENTAL: cache_var, restore_from_cache, on_leave properties; #Initialize(), #Leave()- added tlib#cmd#BrowseOutputWithCallback function and :TBrowseScriptnames command- tlib#cmd#BrowseOutputWithCallback function and :TBrowseScriptnames command documentation- s:prototype.Initialize(): unlet self.cache_var after restoring values- tlib#input#List: filter-specific help- Removed the seq filter (use cnfd or fuzzy instead)- tlib#input#List: temp_prompt (for help message)MD5 checksum: aa8b5a4602235cc1a5bc9ee45d801b81
  • Loading branch information
tomtom authored and vim-scripts committed Jun 3, 2011
1 parent 0dde5f9 commit c19f9d7
Show file tree
Hide file tree
Showing 19 changed files with 335 additions and 414 deletions.
5 changes: 4 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ tlib#input#List(), tlib#input#ListW()
- Do stuff
- Developers can define keys that trigger some action with the
selected items
- Demo: http://vimsomnia.blogspot.com/2010/11/selecting-items-from-list-with-tlibs.html

tlib#input#EditList
+ Edit a list (copy, cut, paste, delete, edit ...)
Expand Down Expand Up @@ -50,16 +51,18 @@ TBrowseOutput COMMAND

Related (small) plugins that utilize tlib and thus provide some degree of uniform user experience:
tbibtools (vimscript #1915): bibtex-related utilities (sort, reformat, list contents ...)
tmarks (vimscript #2594): Browse, place, & delete marks
tmboxbrowser (vimscript #1906): A mbox browser -- Read your e-mails with vim
tmru (vimscript #1864): Most Recently Used Files
trag (vimscript #2033): A slightly language-aware alternative to grep
tregisters (vimscript #2017): List, edit, and run/execute registers/clipboards
tselectbuffer (vimscript #1866): A quick buffer selector/switcher
tselectfile (vimscript #1865): A quick file selector/browser/explorer (sort of)
tselectfiles (vimscript #1865): A quick file selector/browser/explorer (sort of)
ttagecho (vimscript #2055): Show current tag information
ttagcomplete (vimscript #2069): Context-sensitive tags-based completion and code skeletons
ttags (vimscript #2018): Tag list browser (List, filter, preview, jump to tags)
ttoc (vimscript #2014): A regexp-based table of contents of the current buffer
vikitasks (vimscript #2894): Search viki files for tasks and display them in a list


For full details, please see:
Expand Down
12 changes: 9 additions & 3 deletions autoload/tlib/Filter_cnf.vim
Original file line number Diff line number Diff line change
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: 2008-11-25.
" @Last Change: 2010-10-10.
" @Revision: 0.0.74
" @Last Change: 2010-11-20.
" @Revision: 0.0.79

let s:prototype = tlib#Object#New({'_class': ['Filter_cnf'], 'name': 'cnf'}) "{{{2
let s:prototype.highlight = g:tlib_inputlist_higroup
Expand Down Expand Up @@ -109,11 +109,17 @@ endf
" :nodoc:
function! s:prototype.DisplayFilter(filter) dict "{{{3
let filter1 = deepcopy(a:filter)
call map(filter1, '"(". join(reverse(v:val), " OR ") .")"')
call map(filter1, '"(". join(reverse(s:Pretty(v:val)), " OR ") .")"')
return join(reverse(filter1), ' AND ')
endf


function! s:Pretty(filter) "{{{3
call map(a:filter, 'substitute(v:val, ''\\\.\\{-}'', ''__'', ''g'')')
return a:filter
endf


" :nodoc:
function! s:prototype.SetFrontFilter(world, pattern) dict "{{{3
let a:world.filter[0] = reverse(split(a:pattern, '\s*|\s*')) + a:world.filter[0][1 : -1]
Expand Down
12 changes: 9 additions & 3 deletions autoload/tlib/Filter_seq.vim
Original file line number Diff line number Diff line change
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: 2008-11-25.
" @Last Change: 2010-09-15.
" @Revision: 0.0.24
" @Last Change: 2010-11-20.
" @Revision: 0.0.30

let s:prototype = tlib#Filter_cnf#New({'_class': ['Filter_seq'], 'name': 'seq'}) "{{{2
let s:prototype.highlight = g:tlib_inputlist_higroup
Expand Down Expand Up @@ -46,11 +46,17 @@ endf
" :nodoc:
function! s:prototype.DisplayFilter(filter) dict "{{{3
let filter1 = deepcopy(a:filter)
call map(filter1, '"(". join(reverse(v:val), "_") .")"')
call map(filter1, '"(". join(reverse(s:Pretty(v:val)), "_") .")"')
return join(reverse(filter1), ' OR ')
endf


function! s:Pretty(filter) "{{{3
call map(a:filter, 's:prototype.CleanFilter(v:val)')
return a:filter
endf


" :nodoc:
function! s:prototype.SetFrontFilter(world, pattern) dict "{{{3
let a:world.filter[0] = map(reverse(split(a:pattern, '\s*|\s*')), 'join(split(v:val, ''\.''), ''.\{-}'')') + a:world.filter[0][1 : -1]
Expand Down
8 changes: 4 additions & 4 deletions autoload/tlib/Object.vim
Original file line number Diff line number Diff line change
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-05-01.
" @Last Change: 2010-09-05.
" @Revision: 0.1.124
" @Last Change: 2011-03-10.
" @Revision: 0.1.126

" :filedoc:
" Provides a prototype plus some OO-like methods.
Expand All @@ -20,9 +20,9 @@ let s:prototype = {'_class': ['object'], '_super': [], '_id': 0} "{{{2

" :def: function! tlib#Object#New(?fields={})
" This function creates a prototype that provides some kind of
" inheritance mechanism and a way to call parent/super's methods.
" inheritance mechanism and a way to call parent/super methods.
"
" The usage demonstrated in the following example works best, when every
" The usage demonstrated in the following example works best when every
" class/prototype is defined in a file of its own.
"
" The reason for why there is a dedicated constructor function is that
Expand Down
68 changes: 54 additions & 14 deletions autoload/tlib/World.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2007-05-01.
" @Last Change: 2010-10-31.
" @Revision: 0.1.887
" @Last Change: 2011-04-01.
" @Revision: 0.1.915

" :filedoc:
" A prototype used by |tlib#input#List|.
" Inherits from |tlib#Object#New|.


" Known keys & values:
" scratch_split ... See |tlib#scratch#UseScratch()|
let s:prototype = tlib#Object#New({
\ '_class': 'World',
\ 'name': 'world',
\ 'allow_suspend': 1,
\ 'base': [],
\ 'bufnr': -1,
\ 'cache_var': '',
\ 'display_format': '',
\ 'fileencoding': &fileencoding,
\ 'fmt_display': {},
Expand All @@ -27,6 +30,7 @@ let s:prototype = tlib#Object#New({
\ 'filter_options': '',
\ 'follow_cursor': '',
\ 'has_menu': 0,
\ 'help_extra': [],
\ 'index_table': [],
\ 'initial_filter': [['']],
\ 'initial_index': 1,
Expand All @@ -39,17 +43,20 @@ let s:prototype = tlib#Object#New({
\ 'numeric_chars': tlib#var#Get('tlib_numeric_chars', 'bg'),
\ 'offset': 1,
\ 'offset_horizontal': 0,
\ 'on_leave': [],
\ 'pick_last_item': tlib#var#Get('tlib_pick_last_item', 'bg'),
\ 'post_handlers': [],
\ 'query': '',
\ 'resize': 0,
\ 'resize_vertical': 0,
\ 'restore_from_cache': [],
\ 'retrieve_eval': '',
\ 'return_agent': '',
\ 'rv': '',
\ 'scratch': '__InputList__',
\ 'scratch_filetype': 'tlibInputList',
\ 'scratch_vertical': 0,
\ 'scratch_split': 1,
\ 'sel_idx': [],
\ 'show_empty': 0,
\ 'state': 'display',
Expand Down Expand Up @@ -588,6 +595,31 @@ function! s:prototype.CloseScratch(...) dict "{{{3
endf


" :nodoc:
function! s:prototype.Initialize() dict "{{{3
let self.initialized = 1
call self.SetOrigin(1)
call self.Reset(1)
if !empty(self.cache_var) && exists(self.cache_var)
for prop in self.restore_from_cache
exec 'let self[prop] = get('. self.cache_var .', prop, self[prop])'
endfor
exec 'unlet '. self.cache_var
endif
endf


" :nodoc:
function! s:prototype.Leave() dict "{{{3
if !empty(self.cache_var)
exec 'let '. self.cache_var .' = self'
endif
for handler in self.on_leave
call call(handler, [self])
endfor
endf


" :nodoc:
function! s:prototype.UseInputListScratch() dict "{{{3
let scratch = self.UseScratch()
Expand Down Expand Up @@ -660,7 +692,7 @@ function! s:prototype.DisplayHelp() dict "{{{3
" \ 'Help:',
let help = [
\ 'Mouse ... Pick an item Letter ... Filter the list',
\ printf('Number ... Pick an item "%s", "%s", %sWORD ... AND, OR, NOT',
\ printf('<m-Number> ... Pick an item "%s", "%s", %sWORD ... AND, OR, NOT',
\ g:tlib_inputlist_and, g:tlib_inputlist_or, g:tlib_inputlist_not),
\ 'Enter ... Pick the current item <bs>, <c-bs> ... Reduce filter',
\ '<c|m-r> ... Reset the display Up/Down ... Next/previous item',
Expand Down Expand Up @@ -688,6 +720,9 @@ function! s:prototype.DisplayHelp() dict "{{{3
call add(help, printf('%-12s ... %s', key, desc))
endif
endfor
if !empty(self.help_extra)
let help += self.help_extra
endif
let help += [
\ '',
\ 'Exact matches and matches at word boundaries is given more weight.',
Expand All @@ -709,17 +744,21 @@ endf
function! s:prototype.Resize(hsize, vsize) dict "{{{3
" TLogVAR self.scratch_vertical, a:hsize, a:vsize
let world_resize = ''
if self.scratch_vertical
if a:vsize
let world_resize = 'vert resize '. a:vsize
" let w:winresize = {'v': a:vsize}
setlocal winfixwidth
endif
else
if a:hsize
let world_resize = 'resize '. a:hsize
" let w:winresize = {'h': a:hsize}
setlocal winfixheight
let scratch_split = get(self, 'scratch_split', 1)
" TLogVAR scratch_split
if scratch_split > 0
if self.scratch_vertical
if a:vsize
let world_resize = 'vert resize '. a:vsize
" let w:winresize = {'v': a:vsize}
setlocal winfixwidth
endif
else
if a:hsize
let world_resize = 'resize '. a:hsize
" let w:winresize = {'h': a:hsize}
setlocal winfixheight
endif
endif
endif
if !empty(world_resize)
Expand Down Expand Up @@ -928,6 +967,7 @@ function! s:prototype.SetOrigin(...) dict "{{{3
let self.win_width = winwidth(self.win_wnr)
" TLogVAR self.win_wnr, self.win_height, self.win_width
let self.bufnr = bufnr('%')
let self.tabpagenr = tabpagenr()
let self.cursor = getpos('.')
if winview
let self.winview = tlib#win#GetLayout()
Expand Down
20 changes: 18 additions & 2 deletions autoload/tlib/agent.vim
Original file line number Diff line number Diff line change
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: 2010-09-16.
" @Revision: 0.1.181
" @Last Change: 2010-11-20.
" @Revision: 0.1.185


" :filedoc:
Expand Down Expand Up @@ -496,3 +496,19 @@ function! tlib#agent#DoAtLine(world, selected) "{{{3
return a:world
endf


function! tlib#agent#Wildcard(world, selected) "{{{3
if !empty(a:world.filter[0])
let rx_type = a:world.matcher.FilterRxPrefix()
let flt0 = a:world.CleanFilter(a:world.filter[0][0])
if rx_type == '\V'
let flt0 .= '\.\{-}'
else
let flt0 .= '.\{-}'
endif
call a:world.SetFrontFilter(flt0)
endif
let a:world.state = 'redisplay'
return a:world
endf

20 changes: 14 additions & 6 deletions autoload/tlib/cache.vim
Original file line number Diff line number Diff line change
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: 2010-08-10.
" @Revision: 0.1.165
" @Last Change: 2011-03-10.
" @Revision: 0.1.182


" |tlib#cache#Purge()|: Remove cache files older than N days.
Expand All @@ -31,7 +31,7 @@ TLet g:tlib#cache#dont_purge = ['[\/]\.last_purge$']


" :display: tlib#cache#Dir(?mode = 'bg')
" The default cache directory
" The default cache directory.
function! tlib#cache#Dir(...) "{{{3
TVarArg ['mode', 'bg']
let dir = tlib#var#Get('tlib_cache', mode)
Expand Down Expand Up @@ -70,7 +70,15 @@ function! tlib#cache#Filename(type, ...) "{{{3
let file = fnamemodify(file, ':t')
" TLogVAR file, dir, mkdir
if mkdir && !isdirectory(dir)
call mkdir(dir, 'p')
try
call mkdir(dir, 'p')
catch /^Vim\%((\a\+)\)\=:E739:/
if filereadable(dir) && !isdirectory(dir)
echoerr 'TLib: Cannot create directory for cache file because a file with the same name exists (please delete it):' dir
" call delete(dir)
" call mkdir(dir, 'p')
endif
endtry
endif
let cache_file = tlib#file#Join([dir, file])
" TLogVAR cache_file
Expand Down Expand Up @@ -110,14 +118,14 @@ endf
let threshold = localtime() - g:tlib#cache#purge_every_days * g:tlib#date#dayshift
let should_purge = getftime(last_purge) < threshold
else
let should_purge = !empty(glob(tlib#file#Join([dir, '**'])))
let should_purge = 0 " should ignore empty dirs, like the tmru one: !empty(glob(tlib#file#Join([dir, '**'])))
endif
if should_purge
if last_purge_exists
let yn = 'y'
else
let txt = "TLib: The cache directory '". dir ."' should be purged of old files.\nDelete files older than ". g:tlib#cache#purge_days ." days now?"
let yn = tlib#input#Dialog(txt, ['yes', 'no', 'edit'], 'no')
let yn = tlib#input#Dialog(txt, ['yes', 'no'], 'no')
endif
if yn =~ '^y\%[es]$'
call tlib#cache#Purge()
Expand Down

0 comments on commit c19f9d7

Please sign in to comment.