Skip to content

Commit

Permalink
Version 0.13
Browse files Browse the repository at this point in the history
CHANGES:
    - Scratch: Set &fdc=0.
    - The cache directory can be configured via g:tlib_cache
    - Renamed tlib#buffer#SetBuffer() to tlib#buffer#Set().
FIXES:
    - tlib#input#List(): Select the active item per mouse.
    - TLet: simplified
  • Loading branch information
tomtom authored and vim-scripts committed Oct 18, 2010
1 parent 0dd2b68 commit 61ee933
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 47 deletions.
10 changes: 6 additions & 4 deletions autoload/tlib/World.vim
Original file line number Diff line number Diff line change
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-09-02.
" @Revision: 0.1.305
" @Last Change: 2007-09-10.
" @Revision: 0.1.314

" :filedoc:
" A prototype used by |tlib#input#List|.
Expand All @@ -24,8 +24,10 @@ let s:prototype = tlib#Object#New({
\ 'base': [],
\ 'bufnr': -1,
\ 'display_format': '',
\ 'filter': [['']],
\ 'filter_format': '',
\ 'index_table': [],
\ 'initial_filter': [['']],
\ 'initial_index': 1,
\ 'initialized': 0,
\ 'key_handlers': [],
Expand Down Expand Up @@ -256,7 +258,7 @@ endf

function! s:prototype.FilterIsEmpty() dict "{{{3
" TLogVAR self.filter
return self.filter == [['']]
return self.filter == copy(self.initial_filter)
endf


Expand Down Expand Up @@ -306,7 +308,7 @@ function! s:prototype.Reset(...) dict "{{{3
" TLogVAR initial
let self.state = 'display'
let self.offset = 1
let self.filter = [['']]
let self.filter = deepcopy(self.initial_filter)
let self.idx = ''
let self.prefidx = 0
call self.UseInputListScratch()
Expand Down
8 changes: 4 additions & 4 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: 2007-09-02.
" @Revision: 0.1.122
" @Last Change: 2007-09-10.
" @Revision: 0.1.124

if &cp || exists("loaded_tlib_agent_autoload") "{{{2
finish
Expand Down Expand Up @@ -151,7 +151,7 @@ function! tlib#agent#Suspend(world, selected) "{{{3
if a:world.allow_suspend
" TAssert IsNotEmpty(a:world.scratch)
" TLogDBG bufnr('%')
let br = tlib#buffer#SetBuffer(a:world.scratch)
let br = tlib#buffer#Set(a:world.scratch)
" TLogVAR br, a:world.bufnr, a:world.scratch
" TLogDBG bufnr('%')
let b:tlib_suspend = ['<m-z>', '<c-z>', '<cr>', '<space>', '<LeftMouse>']
Expand Down Expand Up @@ -378,7 +378,7 @@ endf

function! tlib#agent#EditFileInTab(world, selected) "{{{3
call a:world.CloseScratch()
call tlib#file#With('tabedit', 'tab buffer', a:selected, a:world)
call tlib#file#With('tabedit', 'tab sbuffer', a:selected, a:world)
return tlib#agent#Exit(a:world, a:selected)
endf

Expand Down
31 changes: 23 additions & 8 deletions autoload/tlib/buffer.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: 2007-09-02.
" @Revision: 0.0.58
" @Last Change: 2007-09-10.
" @Revision: 0.0.66

if &cp || exists("loaded_tlib_buffer_autoload")
finish
Expand All @@ -14,7 +14,7 @@ let loaded_tlib_buffer_autoload = 1

" Set the buffer to buffer and return a command as string that can be
" evaluated by |:execute| in order to restore the original view.
function! tlib#buffer#SetBuffer(buffer) "{{{3
function! tlib#buffer#Set(buffer) "{{{3
let lazyredraw = &lazyredraw
set lazyredraw
try
Expand Down Expand Up @@ -52,7 +52,7 @@ function! tlib#buffer#Eval(buffer, code) "{{{3
" let sb = sn != cb
let lazyredraw = &lazyredraw
set lazyredraw
let restore = tlib#buffer#SetBuffer(a:buffer)
let restore = tlib#buffer#Set(a:buffer)
try
exec a:code
" if sb
Expand Down Expand Up @@ -82,18 +82,21 @@ function! tlib#buffer#Eval(buffer, code) "{{{3
endf


" :def: function! tlib#buffer#GetList(?show_hidden=0)
" :def: function! tlib#buffer#GetList(?show_hidden=0, ?show_number=0)
function! tlib#buffer#GetList(...)
exec tlib#arg#Let(['show_hidden'])
TVarArg ['show_hidden', 0], ['show_number', 0]
let ls_bang = show_hidden ? '!' : ''
redir => bfs
exec 'silent ls'. ls_bang
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*$'')')
if show_number
call map(buffer_list, 'matchstr(v:val, ''\s*\d\+.\{-}\ze\s\+line \d\+\s*$'')')
else
call map(buffer_list, 'matchstr(v:val, ''\s*\d\+\zs.\{-}\ze\s\+line \d\+\s*$'')')
endif
" TLogVAR buffer_list
" call map(buffer_list, 'matchstr(v:val, ''^.\{-}\ze\s\+line \d\+\s*$'')')
" TLogVAR buffer_list
Expand Down Expand Up @@ -123,6 +126,11 @@ function! tlib#buffer#ViewLine(line, ...) "{{{3
endf


function! tlib#buffer#HighlightLine(line) "{{{3
exec 'match MatchParen /\V\%'. a:line .'l.*/'
endf


" Delete the lines in the current buffer. Wrapper for |:delete|.
function! tlib#buffer#DeleteRange(line1, line2) "{{{3
exec a:line1.','.a:line2.'delete'
Expand Down Expand Up @@ -154,3 +162,10 @@ function! tlib#buffer#ScratchEnd() "{{{3
endf


" Run exec on all buffers via bufdo and return to the original buffer.
function! tlib#buffer#BufDo(exec) "{{{3
let bn = bufnr('%')
exec 'bufdo '. a:exec
exec 'buffer! '. bn
endf

13 changes: 8 additions & 5 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: 2007-09-02.
" @Revision: 0.1.17
" @Last Change: 2007-09-09.
" @Revision: 0.1.20

if &cp || exists("loaded_tlib_cache_autoload")
finish
Expand All @@ -15,19 +15,22 @@ let loaded_tlib_cache_autoload = 1
" :def: function! tlib#cache#Filename(type, ?file=%, ?mkdir=0)
function! tlib#cache#Filename(type, ...) "{{{3
" TLogDBG 'bufname='. bufname('.')
let dir = tlib#dir#MyRuntime()
let dir = tlib#var#Get('tlib_cache', 'wbg')
if empty(dir)
let dir = tlib#file#Join([tlib#dir#MyRuntime(), 'cache'])
endif
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)
let file = tlib#file#Relative(file, tlib#file#Join([dir, '..']))
endif
let mkdir = a:0 >= 2 ? a:2 : 0
let file = substitute(file, '\.\.\|[:&<>]\|//\+\|\\\\\+', '_', 'g')
let dir = tlib#dir#PlainName(tlib#file#Join([dir, 'cache', a:type, fnamemodify(file, ':h')]))
let dir = tlib#dir#PlainName(tlib#file#Join([dir, a:type, fnamemodify(file, ':h')]))
let file = fnamemodify(file, ':t')
" TLogVAR dir
" TLogVAR file
Expand Down
4 changes: 2 additions & 2 deletions autoload/tlib/file.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: 2007-09-02.
" @Revision: 0.0.39
" @Last Change: 2007-09-11.
" @Revision: 0.0.41

if &cp || exists("loaded_tlib_file_autoload")
finish
Expand Down
38 changes: 25 additions & 13 deletions autoload/tlib/input.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: 2007-09-02.
" @Revision: 0.0.323
" @Last Change: 2007-09-11.
" @Revision: 0.0.343

if &cp || exists("loaded_tlib_input_autoload")
finish
Expand Down Expand Up @@ -87,6 +87,11 @@ function! tlib#input#List(type, ...) "{{{3
let world.numeric_chars = tlib#list#Find(handlers, 'has_key(v:val, "numeric_chars")',
\ tlib#var#Get('tlib_numeric_chars', 'bg'), 'v:val.numeric_chars')
let world.key_handlers = filter(copy(handlers), 'has_key(v:val, "key")')
let filter = tlib#list#Find(handlers, 'has_key(v:val, "filter")', '', 'v:val.filter')
if !empty(filter)
let world.initial_filter = [[filter], ['']]
" TLogVAR world.initial_filter
endif
endif
return tlib#input#ListW(world)
endf
Expand Down Expand Up @@ -167,6 +172,7 @@ function! tlib#input#ListW(world, ...) "{{{3
let world.prefidx = world.offset
let world.state = 'redisplay'
endif
" 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)')
Expand Down Expand Up @@ -267,15 +273,17 @@ function! tlib#input#ListW(world, ...) "{{{3
" continue
elseif has_key(key_agents, c)
let sr = @/
let @/ = lastsearch
silent! let @/ = lastsearch
let world = call(key_agents[c], [world, world.GetSelectedItems(world.GetCurrentItem())])
call s:CheckAgentReturnValue(c, world)
let @/ = sr
silent! let @/ = sr
" continue
elseif c == 13
throw 'pick'
elseif c == "\<LeftMouse>"
let world.prefidx = matchstr(getline(v:mouse_lnum), '^\d\+\ze:')
let line = getline(v:mouse_lnum)
" TLogVAR line
let world.prefidx = matchstr(line, '^\d\+\ze[*:]')
if empty(world.prefidx)
" call feedkeys(c, 't')
let c = tlib#char#Get(world.timeout)
Expand Down Expand Up @@ -374,7 +382,7 @@ function! tlib#input#ListW(world, ...) "{{{3
finally
let &statusline = statusline
let &laststatus = laststatus
let @/ = lastsearch
silent! let @/ = lastsearch
" TLogDBG 'finally 2'
if world.state !~ '\<suspend\>'
" TLogVAR world.state, world.win_wnr, world.bufnr
Expand Down Expand Up @@ -467,11 +475,11 @@ function! s:FormatFilename(world, file) "{{{3
let bnr = bufnr(a:file)
" TLogVAR a:file, bnr, a:world.bufnr
if bnr != -1
if buflisted(a:file)
if bnr == a:world.bufnr
call add(marker, '%')
elseif buflisted(a:file)
if getbufvar(a:file, "&mod")
call add(marker, '+')
elseif bnr == a:world.bufnr
call add(marker, '%')
else
call add(marker, 'B')
endif
Expand Down Expand Up @@ -555,10 +563,11 @@ endf

" :def: function! tlib#input#Edit(name, value, callback, ?cb_args=[])
"
" Edit value in a scratch buffer. Use name for identification. Call
" callback when done (or on cancel).
" Edit a value (asynchronously) in a scratch buffer. Use name for
" identification. Call callback when done (or on cancel).
" In the scratch buffer:
" Press <c-s> to enter, <c-w>c to cancel editing.
" Press <c-s> or <c-w><cr> to enter the new value, <c-w>c to cancel
" editing.
" EXAMPLES: >
" fun! FooContinue(success, text)
" if a:success
Expand All @@ -575,15 +584,18 @@ 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>
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 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]
let hd = ['Keys: <c-s>, <c-w><cr> ... save/accept; <c-w>c ... cancel', s:horizontal_line]
call append(1, hd)
norm! ggdd
syntax match TlibEditComment /^\%1l.*/
syntax match TlibEditComment /^```.*/
hi link TlibEditComment Comment
exec len(hd) + 1
Expand Down
5 changes: 3 additions & 2 deletions autoload/tlib/scratch.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-07-18.
" @Last Change: 2007-08-27.
" @Revision: 0.0.109
" @Last Change: 2007-09-08.
" @Revision: 0.0.110

if &cp || exists("loaded_tlib_scratch_autoload")
finish
Expand Down Expand Up @@ -57,6 +57,7 @@ function! tlib#scratch#UseScratch(...) "{{{3
setlocal nobuflisted
setlocal modifiable
setlocal foldmethod=manual
setlocal foldcolumn=0
let ft = get(keyargs, 'scratch_filetype', '')
" TLogVAR ft
" if !empty(ft)
Expand Down
19 changes: 17 additions & 2 deletions autoload/tlib/var.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: 2007-08-27.
" @Revision: 0.0.18
" @Last Change: 2007-09-09.
" @Revision: 0.0.20

if &cp || exists("loaded_tlib_var_autoload")
finish
Expand Down Expand Up @@ -68,3 +68,18 @@ function! tlib#var#Get(var, namespace, ...) "{{{3
endf


" :def: function! tlib#var#List(rx, ?prefix='')
" Get a list of variables matching rx.
" EXAMPLE:
" echo tlib#var#List('tlib_', 'g:')
function! tlib#var#List(rx, ...) "{{{3
TVarArg ['prefix', '']
redir => vars
silent! exec 'let '. prefix
redir END
let varlist = split(vars, '\n')
call map(varlist, 'matchstr(v:val, ''^\S\+'')')
call filter(varlist, 'v:val =~ a:rx')
return varlist
endf

Loading

0 comments on commit 61ee933

Please sign in to comment.