mirror of
https://github.com/amix/vimrc
synced 2025-06-16 09:35:01 +08:00
Updated plugins
This commit is contained in:
@ -0,0 +1,12 @@
|
||||
" para_move.vim
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Created: 2012-08-28.
|
||||
" @Last Change: 2012-08-29.
|
||||
" @Revision: 3
|
||||
|
||||
" Move paragraphs
|
||||
call tinykeymap#EnterMap("para_move", "gp", {'name': 'move paragraph'})
|
||||
call tinykeymap#Map("para_move", "j", "silent call tlib#paragraph#Move('Down', '<count>')")
|
||||
call tinykeymap#Map("para_move", "k", "silent call tlib#paragraph#Move('Up', '<count>')")
|
||||
|
@ -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: 2014-11-18.
|
||||
" @Revision: 0.0.114
|
||||
" @Last Change: 2017-09-28.
|
||||
" @Revision: 11.0.114
|
||||
|
||||
let s:prototype = tlib#Object#New({'_class': ['Filter_cnf'], 'name': 'cnf'}) "{{{2
|
||||
let s:prototype.highlight = g:tlib#input#higroup
|
||||
@ -47,7 +47,8 @@ function! s:prototype.AssessName(world, name) dict "{{{3
|
||||
" if flt =~# '\u' && a:name =~# flt
|
||||
" let xa += 5
|
||||
" endif
|
||||
|
||||
let rel = 1.0 + 5.0 * len(flt) / len(a:name)
|
||||
let xa += float2nr(rel)
|
||||
if a:name =~ '\^'. flt
|
||||
let xa += 4
|
||||
elseif a:name =~ '\<'. flt
|
||||
@ -131,7 +132,7 @@ function! s:prototype.ReduceFrontFilter(world) dict "{{{3
|
||||
if empty(str)
|
||||
let filter = filter[0 : -2]
|
||||
else
|
||||
let filter = strpart(filter, 0, len(filter) - len(str))
|
||||
let filter = tlib#string#Strcharpart(filter, 0, len(filter) - len(str))
|
||||
endif
|
||||
" TLogVAR str, filter
|
||||
let a:world.filter[0][0] = filter
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,7 @@
|
||||
" @Author: Tom Link (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)
|
||||
" @Revision: 328
|
||||
|
||||
" @Revision: 362
|
||||
|
||||
" :filedoc:
|
||||
" Various agents for use as key handlers in tlib#input#List()
|
||||
@ -14,7 +13,8 @@ TLet g:tlib_scroll_lines = 10
|
||||
" General {{{1
|
||||
|
||||
function! tlib#agent#Exit(world, selected) "{{{3
|
||||
if a:world.key_mode == 'default'
|
||||
Tlibtrace 'tlib', a:selected
|
||||
if a:world.key_mode ==# 'default'
|
||||
call a:world.CloseScratch()
|
||||
let a:world.state = 'exit empty escape'
|
||||
let a:world.list = []
|
||||
@ -29,6 +29,7 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#CopyItems(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
let @* = join(a:selected, "\n")
|
||||
let a:world.state = 'redisplay'
|
||||
return a:world
|
||||
@ -39,6 +40,7 @@ endf
|
||||
" InputList related {{{1
|
||||
|
||||
function! tlib#agent#PageUp(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
let a:world.offset -= (winheight(0) / 2)
|
||||
let a:world.state = 'scroll'
|
||||
return a:world
|
||||
@ -46,6 +48,7 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#PageDown(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
let a:world.offset += (winheight(0) / 2)
|
||||
let a:world.state = 'scroll'
|
||||
return a:world
|
||||
@ -53,6 +56,7 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#Home(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
let a:world.prefidx = 1
|
||||
let a:world.state = 'redisplay'
|
||||
return a:world
|
||||
@ -60,6 +64,7 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#End(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
let a:world.prefidx = len(a:world.list)
|
||||
let a:world.state = 'redisplay'
|
||||
return a:world
|
||||
@ -68,6 +73,7 @@ endf
|
||||
|
||||
function! tlib#agent#Up(world, selected, ...) "{{{3
|
||||
TVarArg ['lines', 1]
|
||||
Tlibtrace 'tlib', a:selected, lines
|
||||
let a:world.idx = ''
|
||||
if a:world.prefidx > lines
|
||||
let a:world.prefidx -= lines
|
||||
@ -81,6 +87,7 @@ endf
|
||||
|
||||
function! tlib#agent#Down(world, selected, ...) "{{{3
|
||||
TVarArg ['lines', 1]
|
||||
Tlibtrace 'tlib', a:selected, lines
|
||||
let a:world.idx = ''
|
||||
if a:world.prefidx <= (len(a:world.list) - lines)
|
||||
let a:world.prefidx += lines
|
||||
@ -93,16 +100,19 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#UpN(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
return tlib#agent#Up(a:world, a:selected, g:tlib_scroll_lines)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#DownN(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
return tlib#agent#Down(a:world, a:selected, g:tlib_scroll_lines)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#ShiftLeft(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
let a:world.offset_horizontal -= (winwidth(0) / 2)
|
||||
if a:world.offset_horizontal < 0
|
||||
let a:world.offset_horizontal = 0
|
||||
@ -113,6 +123,7 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#ShiftRight(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
let a:world.offset_horizontal += (winwidth(0) / 2)
|
||||
let a:world.state = 'display shift'
|
||||
return a:world
|
||||
@ -120,12 +131,14 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#Reset(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
let a:world.state = 'reset'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#ToggleRestrictView(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
if empty(a:world.filtered_items)
|
||||
return tlib#agent#RestrictView(a:world, a:selected)
|
||||
else
|
||||
@ -135,11 +148,11 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#RestrictView(world, selected) "{{{3
|
||||
" TLogVAR a:selected
|
||||
Tlibtrace 'tlib', a:selected
|
||||
let filtered_items = map(copy(a:selected), 'index(a:world.base, v:val) + 1')
|
||||
" TLogVAR 1, filtered_items
|
||||
Tlibtrace 'tlib', 1, filtered_items
|
||||
let filtered_items = filter(filtered_items, 'v:val > 0')
|
||||
" TLogVAR 2, filtered_items
|
||||
Tlibtrace 'tlib', 2, filtered_items
|
||||
if !empty(filtered_items)
|
||||
let a:world.filtered_items = filtered_items
|
||||
endif
|
||||
@ -149,6 +162,7 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#UnrestrictView(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
let a:world.filtered_items = []
|
||||
let a:world.state = 'display'
|
||||
return a:world
|
||||
@ -156,6 +170,7 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#Input(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
let flt0 = a:world.CleanFilter(a:world.filter[0][0])
|
||||
let flt1 = input('Filter: ', flt0)
|
||||
echo
|
||||
@ -174,15 +189,16 @@ endf
|
||||
" Suspend (see |tlib#agent#Suspend|) the input loop and jump back to the
|
||||
" original position in the parent window.
|
||||
function! tlib#agent#SuspendToParentWindow(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
let world = a:world
|
||||
let winnr = world.win_wnr
|
||||
" TLogVAR winnr
|
||||
if winnr != -1
|
||||
let wid = world.win_id
|
||||
Tlibtrace 'tlib', wid
|
||||
if wid != -1
|
||||
let world = tlib#agent#Suspend(world, a:selected)
|
||||
if world.state =~ '\<suspend\>'
|
||||
if world.state =~# '\<suspend\>'
|
||||
call world.SwitchWindow('win')
|
||||
" let pos = world.cursor
|
||||
" " TLogVAR pos
|
||||
" Tlibtrace 'tlib', pos
|
||||
" if !empty(pos)
|
||||
" call setpos('.', pos)
|
||||
" endif
|
||||
@ -200,17 +216,18 @@ endf
|
||||
" <cr> and <LeftMouse> will immediatly select the item under the cursor.
|
||||
" < will select the item but the window will remain opened.
|
||||
function! tlib#agent#Suspend(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
if a:world.allow_suspend
|
||||
" TAssert IsNotEmpty(a:world.scratch)
|
||||
" TLogDBG bufnr('%')
|
||||
let br = tlib#buffer#Set(a:world.scratch)
|
||||
" TLogVAR br, a:world.bufnr, a:world.scratch
|
||||
Tlibtrace 'tlib', br, a:world.bufnr, a:world.scratch
|
||||
if bufnr('%') != a:world.scratch
|
||||
echohl WarningMsg
|
||||
echom "tlib#agent#Suspend: Internal error: Not a scratch buffer:" bufname('%')
|
||||
echohl NONE
|
||||
endif
|
||||
" TLogVAR bufnr('%'), bufname('%'), a:world.scratch
|
||||
Tlibtrace 'tlib', bufnr('%'), bufname('%'), a:world.scratch
|
||||
call tlib#autocmdgroup#Init()
|
||||
exec 'autocmd TLib BufEnter <buffer='. a:world.scratch .'> call tlib#input#Resume("world", 0, '. a:world.scratch .')'
|
||||
let b:tlib_world = a:world
|
||||
@ -225,12 +242,14 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#Help(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
let a:world.state = 'help'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#OR(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
if !empty(a:world.filter[0])
|
||||
call insert(a:world.filter[0], '')
|
||||
endif
|
||||
@ -240,6 +259,7 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#AND(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
if !empty(a:world.filter[0])
|
||||
call insert(a:world.filter, [''])
|
||||
endif
|
||||
@ -249,6 +269,7 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#ReduceFilter(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
call a:world.ReduceFilter()
|
||||
let a:world.offset = 1
|
||||
let a:world.state = 'display'
|
||||
@ -257,6 +278,7 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#PopFilter(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
call a:world.PopFilter()
|
||||
let a:world.offset = 1
|
||||
let a:world.state = 'display'
|
||||
@ -265,6 +287,7 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#Debug(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
" echo string(world.state)
|
||||
echo string(a:world.filter)
|
||||
echo string(a:world.idx)
|
||||
@ -277,6 +300,7 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#Select(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
call a:world.SelectItem('toggle', a:world.prefidx)
|
||||
" let a:world.state = 'display keepcursor'
|
||||
let a:world.state = 'redisplay'
|
||||
@ -285,6 +309,7 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#SelectUp(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
call a:world.SelectItem('toggle', a:world.prefidx)
|
||||
if a:world.prefidx > 1
|
||||
let a:world.prefidx -= 1
|
||||
@ -295,6 +320,7 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#SelectDown(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
call a:world.SelectItem('toggle', a:world.prefidx)
|
||||
if a:world.prefidx < len(a:world.list)
|
||||
let a:world.prefidx += 1
|
||||
@ -305,6 +331,7 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#SelectAll(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
let listrange = range(1, len(a:world.list))
|
||||
let mode = empty(filter(copy(listrange), 'index(a:world.sel_idx, a:world.GetBaseIdx(v:val)) == -1'))
|
||||
\ ? 'toggle' : 'set'
|
||||
@ -317,6 +344,7 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#ToggleStickyList(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
let a:world.sticky = !a:world.sticky
|
||||
let a:world.state = 'display keepcursor'
|
||||
return a:world
|
||||
@ -327,11 +355,11 @@ endf
|
||||
" EditList related {{{1
|
||||
|
||||
function! tlib#agent#EditItem(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
let lidx = a:world.prefidx
|
||||
" TLogVAR lidx
|
||||
" TLogVAR a:world.table
|
||||
Tlibtrace 'tlib', lidx
|
||||
let bidx = a:world.GetBaseIdx(lidx)
|
||||
" TLogVAR bidx
|
||||
Tlibtrace 'tlib', bidx
|
||||
let item = a:world.GetBaseItem(bidx)
|
||||
let item = input(lidx .'@'. bidx .': ', item)
|
||||
if item != ''
|
||||
@ -344,6 +372,7 @@ endf
|
||||
|
||||
" Insert a new item below the current one.
|
||||
function! tlib#agent#NewItem(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
let basepi = a:world.GetBaseIdx(a:world.prefidx)
|
||||
let item = input('New item: ')
|
||||
call insert(a:world.base, item, basepi)
|
||||
@ -353,6 +382,7 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#DeleteItems(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
let remove = copy(a:world.sel_idx)
|
||||
let basepi = a:world.GetBaseIdx(a:world.prefidx)
|
||||
if index(remove, basepi) == -1
|
||||
@ -370,12 +400,14 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#Cut(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
let world = tlib#agent#Copy(a:world, a:selected)
|
||||
return tlib#agent#DeleteItems(world, a:selected)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#Copy(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
let a:world.clipboard = []
|
||||
let bidxs = copy(a:world.sel_idx)
|
||||
call add(bidxs, a:world.GetBaseIdx(a:world.prefidx))
|
||||
@ -388,6 +420,7 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#Paste(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
if has_key(a:world, 'clipboard')
|
||||
for e in reverse(copy(a:world.clipboard))
|
||||
call insert(a:world.base, e, a:world.prefidx)
|
||||
@ -400,6 +433,7 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#EditReturnValue(world, rv) "{{{3
|
||||
Tlibtrace 'tlib', a:rv
|
||||
return [a:world.state !~ '\<exit\>', a:world.base]
|
||||
endf
|
||||
|
||||
@ -408,22 +442,15 @@ endf
|
||||
" Files related {{{1
|
||||
|
||||
function! tlib#agent#ViewFile(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
if !empty(a:selected)
|
||||
let back = a:world.SwitchWindow('win')
|
||||
" TLogVAR back
|
||||
Tlibtrace 'tlib', back
|
||||
for filename in a:selected
|
||||
call tlib#file#Edit(filename)
|
||||
endfor
|
||||
" if !&hidden && &l:modified
|
||||
" let cmd0 = 'split'
|
||||
" let cmd1 = 'sbuffer'
|
||||
" else
|
||||
" let cmd0 = 'edit'
|
||||
" let cmd1 = 'buffer'
|
||||
" endif
|
||||
" call tlib#file#With(cmd0, cmd1, a:selected, a:world)
|
||||
" TLogVAR &filetype
|
||||
exec back
|
||||
call a:world.SetOrigin(1)
|
||||
silent! exec back
|
||||
let a:world.state = 'display'
|
||||
endif
|
||||
return a:world
|
||||
@ -431,41 +458,53 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#EditFile(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
return tlib#agent#Exit(tlib#agent#ViewFile(a:world, a:selected), a:selected)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#EditFileInSplit(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
call a:world.CloseScratch()
|
||||
" call tlib#file#With('edit', 'buffer', a:selected[0:0], a:world)
|
||||
" call tlib#file#With('split', 'sbuffer', a:selected[1:-1], a:world)
|
||||
call tlib#file#With('split', 'sbuffer', a:selected, a:world)
|
||||
call tlib#file#With('split', 'sbuffer', a:selected, a:world, 1)
|
||||
call a:world.SetOrigin(1)
|
||||
return tlib#agent#Exit(a:world, a:selected)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#EditFileInVSplit(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
call a:world.CloseScratch()
|
||||
" call tlib#file#With('edit', 'buffer', a:selected[0:0], a:world)
|
||||
" call tlib#file#With('vertical split', 'vertical sbuffer', a:selected[1:-1], a:world)
|
||||
let winpos = tlib#fixes#Winpos()
|
||||
call tlib#file#With('vertical split', 'vertical sbuffer', a:selected, a:world)
|
||||
call tlib#file#With('vertical split', 'vertical sbuffer', a:selected, a:world, 1)
|
||||
if !empty(winpos)
|
||||
exec winpos
|
||||
endif
|
||||
call a:world.SetOrigin(1)
|
||||
return tlib#agent#Exit(a:world, a:selected)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#EditFileInTab(world, selected) "{{{3
|
||||
" TLogVAR a:selected
|
||||
Tlibtrace 'tlib', a:selected
|
||||
call a:world.CloseScratch()
|
||||
call tlib#file#With('tabedit', 'tab sbuffer', a:selected, a:world)
|
||||
call tlib#file#With('tabedit', 'tab sbuffer', a:selected, a:world, 1)
|
||||
call a:world.SetOrigin(1)
|
||||
return tlib#agent#Exit(a:world, a:selected)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#EditFileInWindow(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
call a:world.CloseScratch()
|
||||
call tlib#file#With('hide edit', 'hide buffer', a:selected, a:world, 1)
|
||||
call a:world.SetOrigin(1)
|
||||
return tlib#agent#Exit(a:world, a:selected)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#ToggleScrollbind(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
let a:world.scrollbind = get(a:world, 'scrollbind') ? 0 : 1
|
||||
let a:world.state = 'redisplay'
|
||||
return a:world
|
||||
@ -473,6 +512,7 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#ShowInfo(world, selected)
|
||||
Tlibtrace 'tlib', a:selected
|
||||
let lines = []
|
||||
for f in a:selected
|
||||
if filereadable(f)
|
||||
@ -490,12 +530,30 @@ endf
|
||||
|
||||
" Buffer related {{{1
|
||||
|
||||
function! tlib#agent#ViewBufferInWindow(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
if !empty(a:selected)
|
||||
let back = a:world.SwitchWindow('win')
|
||||
Tlibtrace 'tlib', back
|
||||
for bufname in a:selected
|
||||
let cmd = &modified && !&hidden ? 'sbuffer' : 'buffer'
|
||||
exec cmd fnameescape(bufname)
|
||||
endfor
|
||||
" exec back
|
||||
endif
|
||||
return tlib#agent#Exit(a:world, a:selected)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#PreviewLine(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
let l = a:selected[0]
|
||||
let ww = winnr()
|
||||
exec a:world.win_wnr .'wincmd w'
|
||||
" let ww = winnr()
|
||||
let wid = tlib#win#GetID()
|
||||
call tlib#agent#SuspendToParentWindow(a:world, a:selected)
|
||||
call tlib#buffer#ViewLine(l, 1)
|
||||
exec ww .'wincmd w'
|
||||
call tlib#win#GotoID(wid)
|
||||
" exec ww .'wincmd w'
|
||||
let a:world.state = 'redisplay'
|
||||
return a:world
|
||||
endf
|
||||
@ -504,24 +562,12 @@ endf
|
||||
" If not called from the scratch, we assume/guess that we don't have to
|
||||
" suspend the input-evaluation loop.
|
||||
function! tlib#agent#GotoLine(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
if !empty(a:selected)
|
||||
|
||||
" let l = a:selected[0]
|
||||
" " TLogVAR l
|
||||
" let back = a:world.SwitchWindow('win')
|
||||
" " TLogVAR back
|
||||
" " if a:world.win_wnr != winnr()
|
||||
" " let world = tlib#agent#Suspend(a:world, a:selected)
|
||||
" " exec a:world.win_wnr .'wincmd w'
|
||||
" " endif
|
||||
" call tlib#buffer#ViewLine(l)
|
||||
" exec back
|
||||
" let a:world.state = 'display'
|
||||
|
||||
let l = a:selected[0]
|
||||
if a:world.win_wnr != winnr()
|
||||
if a:world.win_id != tlib#win#GetID()
|
||||
let world = tlib#agent#Suspend(a:world, a:selected)
|
||||
exec a:world.win_wnr .'wincmd w'
|
||||
call tlib#win#GotoID(a:world.win_id)
|
||||
endif
|
||||
call tlib#buffer#ViewLine(l, 1)
|
||||
|
||||
@ -531,6 +577,7 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#DoAtLine(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
if !empty(a:selected)
|
||||
let cmd = input('Command: ', '', 'command')
|
||||
if !empty(cmd)
|
||||
@ -552,6 +599,7 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#Wildcard(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
if !empty(a:world.filter[0])
|
||||
let rx_type = a:world.matcher.FilterRxPrefix()
|
||||
let flt0 = a:world.CleanFilter(a:world.filter[0][0])
|
||||
@ -568,12 +616,14 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#Null(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
let a:world.state = 'redisplay'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#ExecAgentByName(world, selected) "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
let s:agent_names_world = a:world
|
||||
let agent_names = {'Help': 'tlib#agent#Help'}
|
||||
for def in values(a:world.key_map[a:world.key_mode])
|
||||
@ -583,11 +633,11 @@ function! tlib#agent#ExecAgentByName(world, selected) "{{{3
|
||||
endfor
|
||||
let s:agent_names = sort(keys(agent_names))
|
||||
let command = input('Command: ', '', 'customlist,tlib#agent#CompleteAgentNames')
|
||||
" TLogVAR command
|
||||
Tlibtrace 'tlib', command
|
||||
if !has_key(agent_names, command)
|
||||
" TLogVAR command
|
||||
Tlibtrace 'tlib', command
|
||||
silent! let matches = filter(keys(agent_names), 'v:val =~ command')
|
||||
" TLogVAR matches
|
||||
Tlibtrace 'tlib', matches
|
||||
if len(matches) == 1
|
||||
let command = matches[0]
|
||||
endif
|
||||
@ -609,43 +659,45 @@ endf
|
||||
|
||||
|
||||
function! tlib#agent#CompleteAgentNames(ArgLead, CmdLine, CursorPos)
|
||||
return filter(copy(s:agent_names), 'stridx(v:val, a:ArgLead) != -1')
|
||||
let arglead = tolower(a:Arglead)
|
||||
return filter(copy(s:agent_names), 'stridx(tolower(v:val), arglead) != -1')
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#Complete(world, selected) abort "{{{3
|
||||
Tlibtrace 'tlib', a:selected
|
||||
let rxprefix = a:world.matcher.FilterRxPrefix()
|
||||
let flt = a:world.filter[0][0]
|
||||
" TLogVAR flt
|
||||
Tlibtrace 'tlib', flt
|
||||
let fltrx = rxprefix . flt . '\m[^[:space:][:cntrl:][:punct:]<>*+?&~{}()\[\]\\/]\+'
|
||||
let fltrx0 = '\m^' . fltrx
|
||||
" TLogVAR fltrx, fltrx0
|
||||
Tlibtrace 'tlib', fltrx, fltrx0
|
||||
let words = {}
|
||||
for item in a:world.list
|
||||
let parts = split(item, '\ze'. fltrx)
|
||||
" TLogVAR item, parts
|
||||
Tlibtrace 'tlib', item, parts
|
||||
for part in parts
|
||||
let word = matchstr(part, fltrx0)
|
||||
" TLogVAR part, word
|
||||
Tlibtrace 'tlib', part, word
|
||||
if !empty(word)
|
||||
let words[word] = 1
|
||||
endif
|
||||
endfor
|
||||
endfor
|
||||
" TLogVAR keys(words)
|
||||
Tlibtrace 'tlib', keys(words)
|
||||
let completions = keys(words)
|
||||
" let completions = filter(keys(words), 'matchstr(v:val, fltrx0)')
|
||||
let completions = sort(completions, 's:SortCompletions')
|
||||
let completions = tlib#list#Uniq(completions)
|
||||
" TLogVAR 0, completions
|
||||
Tlibtrace 'tlib', 0, completions
|
||||
while len(completions) > 1
|
||||
let nchar = strwidth(completions[0]) - 1
|
||||
let completions = map(completions, 'strpart(v:val, 0, nchar)')
|
||||
" TLogVAR 'reduce', completions
|
||||
let completions = map(completions, 'tlib#string#Strcharpart(v:val, 0, nchar)')
|
||||
Tlibtrace 'tlib', 'reduce', completions
|
||||
let completions = tlib#list#Uniq(completions)
|
||||
" TLogVAR 'unique', len(completions), completions
|
||||
Tlibtrace 'tlib', 'unique', len(completions), completions
|
||||
endwh
|
||||
" TLogVAR 9, completions
|
||||
Tlibtrace 'tlib', 9, completions
|
||||
if empty(completions)
|
||||
let a:world.state = 'redisplay update'
|
||||
else
|
||||
|
@ -1,8 +1,8 @@
|
||||
" @Author: Tom Link (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)
|
||||
" @Last Change: 2015-11-19.
|
||||
" @Revision: 251
|
||||
" @Last Change: 2017-09-28.
|
||||
" @Revision: 273
|
||||
|
||||
|
||||
" :def: function! tlib#arg#Get(n, var, ?default="", ?test='')
|
||||
@ -92,30 +92,34 @@ endf
|
||||
" ['-ab', '--', '--foo', '--bar=BAR']
|
||||
" => {'a': 1, 'b': 1, '__rest__': ['--foo', '--bar=BAR']}
|
||||
function! tlib#arg#GetOpts(args, ...) abort "{{{3
|
||||
let throw = a:0 == 0
|
||||
TVarArg ['def', {}]
|
||||
" TLogVAR def
|
||||
let opts = {'__exit__': 0}
|
||||
for [key, vdef] in items(get(def, 'values', {}))
|
||||
if has_key(vdef, 'default')
|
||||
let opts[key] = vdef.default
|
||||
endif
|
||||
endfor
|
||||
let idx = 0
|
||||
for o in a:args
|
||||
let [break, idx] = s:SetOpt(def, opts, idx, o)
|
||||
if break == 1
|
||||
break
|
||||
elseif break == 2
|
||||
if throw
|
||||
throw 'tlib#arg#GetOpts: Show help'
|
||||
else
|
||||
let opts.__exit__ = 5
|
||||
if type(a:args) == 4
|
||||
reutrn a:args
|
||||
else
|
||||
let throw = a:0 == 0
|
||||
TVarArg ['def', {}]
|
||||
" TLogVAR def
|
||||
let opts = {'__exit__': 0}
|
||||
for [key, vdef] in items(get(def, 'values', {}))
|
||||
if has_key(vdef, 'default')
|
||||
let opts[key] = vdef.default
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
let opts.__rest__ = a:args[idx : -1]
|
||||
return opts
|
||||
endfor
|
||||
let idx = 0
|
||||
for o in a:args
|
||||
let [break, idx] = s:SetOpt(def, opts, idx, o)
|
||||
if break == 1
|
||||
break
|
||||
elseif break == 2
|
||||
if throw
|
||||
throw 'tlib#arg#GetOpts: Show help'
|
||||
else
|
||||
let opts.__exit__ = 5
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
let opts.__rest__ = a:args[idx : -1]
|
||||
return opts
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
@ -147,7 +151,7 @@ function! s:SetOpt(def, opts, idx, opt) abort "{{{3
|
||||
let default = get(vdef, 'default', '')
|
||||
let type = s:GetValueType(vdef)
|
||||
if default =~ '^-\?\d\+\%(\.\d\+\)$'
|
||||
if type == -1
|
||||
if type == -1 || type == 6
|
||||
let opt .= ' (flag)'
|
||||
elseif type == 1
|
||||
let opt .= '=INT'
|
||||
@ -171,6 +175,11 @@ function! s:SetOpt(def, opts, idx, opt) abort "{{{3
|
||||
endif
|
||||
endif
|
||||
let break = 2
|
||||
elseif long && a:opt =~# '^--\%(no-\)\?debug$'
|
||||
if has_key(a:def, 'trace')
|
||||
let mod = a:opt =~# '--no-' ? '-' : '+'
|
||||
exec 'Tlibtraceset' mod . a:def.trace
|
||||
endif
|
||||
elseif long && a:opt =~# '^--no-.\+'
|
||||
let key = matchstr(a:opt, '^--no-\zs.\+$')
|
||||
let a:opts[key] = s:Validate(a:def, key, 0)
|
||||
@ -267,12 +276,14 @@ function! tlib#arg#CComplete(def, ArgLead) abort "{{{3
|
||||
" endif
|
||||
endif
|
||||
if !empty(words)
|
||||
let lead = substitute(a:ArgLead, '^--\w\+=', '', '')
|
||||
let prefix = matchstr(a:ArgLead, '^--\w\+=\%([^,]\+,\s*\)*')
|
||||
let lead = substitute(a:ArgLead, '^--\w\+=\%([^,]\+,\s*\)*', '', '')
|
||||
" TLogVAR a:ArgLead, lead
|
||||
if !empty(lead)
|
||||
let nchar = len(lead)
|
||||
call filter(words, 'strpart(v:val, 0, nchar) ==# lead')
|
||||
call filter(words, 'tlib#string#Strcharpart(v:val, 0, nchar) ==# lead')
|
||||
endif
|
||||
let words = map(words, '"--". opt ."=". v:val')
|
||||
let words = map(words, 'prefix . v:val')
|
||||
return sort(words)
|
||||
endif
|
||||
endif
|
||||
@ -294,9 +305,12 @@ function! tlib#arg#CComplete(def, ArgLead) abort "{{{3
|
||||
endif
|
||||
let cs['-'. name] = 1
|
||||
endfor
|
||||
if has_key(a:def, 'trace')
|
||||
let cs['--debug'] = 1
|
||||
endif
|
||||
let nchar = len(a:ArgLead)
|
||||
if nchar > 0
|
||||
call filter(cs, 'strpart(v:key, 0, nchar) ==# a:ArgLead')
|
||||
call filter(cs, 'tlib#string#Strcharpart(v:key, 0, nchar) ==# a:ArgLead')
|
||||
endif
|
||||
return sort(keys(cs))
|
||||
endf
|
||||
|
@ -1,21 +1,21 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: https://github.com/tomtom
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Last Change: 2015-11-23
|
||||
" @Revision: 38
|
||||
" @Last Change: 2017-02-22
|
||||
" @Revision: 42
|
||||
|
||||
|
||||
" Enable tracing via |:Tlibassert|.
|
||||
function! tlib#assert#Enable() abort "{{{3
|
||||
" :nodoc:
|
||||
command! -nargs=+ -bar Tlibassert call tlib#assert#Assert(expand('<sfile>'), <q-args>, [<args>])
|
||||
command! -nargs=+ -bang Tlibassert call tlib#assert#Assert(expand('<sfile>'), <q-args>, [<args>])
|
||||
endf
|
||||
|
||||
|
||||
" Disable tracing via |:Tlibassert|.
|
||||
function! tlib#assert#Disable() abort "{{{3
|
||||
" :nodoc:
|
||||
command! -nargs=+ -bang -bar Tlibassert :
|
||||
command! -nargs=+ -bang Tlibassert :
|
||||
endf
|
||||
|
||||
|
||||
|
@ -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: 2015-11-06.
|
||||
" @Revision: 7.1.352
|
||||
" @Last Change: 2017-09-28.
|
||||
" @Revision: 12.1.352
|
||||
|
||||
|
||||
" Where to display the line when using |tlib#buffer#ViewLine|.
|
||||
@ -15,19 +15,19 @@ TLet g:tlib_viewline_position = 'zz'
|
||||
let s:bmru = []
|
||||
|
||||
|
||||
function! tlib#buffer#EnableMRU() "{{{3
|
||||
function! tlib#buffer#EnableMRU() abort "{{{3
|
||||
call tlib#autocmdgroup#Init()
|
||||
autocmd TLib BufEnter * call s:BMRU_Push(bufnr('%'))
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#buffer#DisableMRU() "{{{3
|
||||
function! tlib#buffer#DisableMRU() abort "{{{3
|
||||
call tlib#autocmdgroup#Init()
|
||||
autocmd! TLib BufEnter
|
||||
endf
|
||||
|
||||
|
||||
function! s:BMRU_Push(bnr) "{{{3
|
||||
function! s:BMRU_Push(bnr) abort "{{{3
|
||||
let i = index(s:bmru, a:bnr)
|
||||
if i >= 0
|
||||
call remove(s:bmru, i)
|
||||
@ -36,7 +36,7 @@ function! s:BMRU_Push(bnr) "{{{3
|
||||
endf
|
||||
|
||||
|
||||
function! s:CompareBuffernameByBasename(a, b) "{{{3
|
||||
function! s:CompareBuffernameByBasename(a, b) abort "{{{3
|
||||
let rx = '"\zs.\{-}\ze" \+\S\+ \+\d\+$'
|
||||
let an = matchstr(a:a, rx)
|
||||
let an = fnamemodify(an, ':t')
|
||||
@ -47,7 +47,7 @@ function! s:CompareBuffernameByBasename(a, b) "{{{3
|
||||
endf
|
||||
|
||||
|
||||
function! s:CompareBufferNrByMRU(a, b) "{{{3
|
||||
function! s:CompareBufferNrByMRU(a, b) abort "{{{3
|
||||
let an = matchstr(a:a, '\s*\zs\d\+\ze')
|
||||
let bn = matchstr(a:b, '\s*\zs\d\+\ze')
|
||||
let ai = index(s:bmru, 0 + an)
|
||||
@ -66,7 +66,7 @@ endf
|
||||
|
||||
" 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#Set(buffer) "{{{3
|
||||
function! tlib#buffer#Set(buffer) abort "{{{3
|
||||
let lazyredraw = &lazyredraw
|
||||
set lazyredraw
|
||||
try
|
||||
@ -91,12 +91,12 @@ function! tlib#buffer#Set(buffer) "{{{3
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#buffer#Eval(buffer, code)
|
||||
" :def: function! tlib#buffer#Eval(buffer, code) abort
|
||||
" Evaluate CODE in BUFFER.
|
||||
"
|
||||
" EXAMPLES: >
|
||||
" call tlib#buffer#Eval('foo.txt', 'echo b:bar')
|
||||
function! tlib#buffer#Eval(buffer, code) "{{{3
|
||||
function! tlib#buffer#Eval(buffer, code) abort "{{{3
|
||||
" let cb = bufnr('%')
|
||||
" let wb = bufwinnr('%')
|
||||
" " TLogVAR cb
|
||||
@ -134,7 +134,7 @@ function! tlib#buffer#Eval(buffer, code) "{{{3
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#buffer#GetList(?show_hidden=0, ?show_number=0, " ?order='bufnr')
|
||||
" :def: function! tlib#buffer#GetList(?show_hidden=0, ?show_number=0, " ?order='bufnr') abort
|
||||
" Possible values for the "order" argument:
|
||||
" bufnr :: Default behaviour
|
||||
" mru :: Sort buffers according to most recent use
|
||||
@ -142,7 +142,7 @@ endf
|
||||
"
|
||||
" NOTE: MRU order works on second invocation only. If you want to always
|
||||
" use MRU order, call tlib#buffer#EnableMRU() in your ~/.vimrc file.
|
||||
function! tlib#buffer#GetList(...)
|
||||
function! tlib#buffer#GetList(...) abort
|
||||
TVarArg ['show_hidden', 0], ['show_number', 0], ['order', '']
|
||||
" TLogVAR show_hidden, show_number, order
|
||||
let ls_bang = show_hidden ? '!' : ''
|
||||
@ -150,14 +150,14 @@ function! tlib#buffer#GetList(...)
|
||||
exec 'silent ls'. ls_bang
|
||||
redir END
|
||||
let buffer_list = split(bfs, '\n')
|
||||
if order == 'mru'
|
||||
if order ==# 'mru'
|
||||
if empty(s:bmru)
|
||||
call tlib#buffer#EnableMRU()
|
||||
echom 'tlib: Installed Buffer MRU logger; disable with: call tlib#buffer#DisableMRU()'
|
||||
else
|
||||
call sort(buffer_list, function('s:CompareBufferNrByMRU'))
|
||||
endif
|
||||
elseif order == 'basename'
|
||||
elseif order ==# 'basename'
|
||||
call sort(buffer_list, function('s:CompareBuffernameByBasename'))
|
||||
endif
|
||||
let buffer_nr = map(copy(buffer_list), 'str2nr(matchstr(v:val, ''\s*\zs\d\+\ze''))')
|
||||
@ -176,11 +176,11 @@ function! tlib#buffer#GetList(...)
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#buffer#ViewLine(line, ?position='z')
|
||||
" :def: function! tlib#buffer#ViewLine(line, ?position='z') abort
|
||||
" line is either a number or a string that begins with a number.
|
||||
" For possible values for position see |scroll-cursor|.
|
||||
" See also |g:tlib_viewline_position|.
|
||||
function! tlib#buffer#ViewLine(line, ...) "{{{3
|
||||
function! tlib#buffer#ViewLine(line, ...) abort "{{{3
|
||||
if a:line
|
||||
TVarArg 'pos'
|
||||
let ln = matchstr(a:line, '^\d\+')
|
||||
@ -200,7 +200,7 @@ function! tlib#buffer#ViewLine(line, ...) "{{{3
|
||||
endf
|
||||
|
||||
|
||||
function! s:UndoHighlightLine() "{{{3
|
||||
function! s:UndoHighlightLine() abort "{{{3
|
||||
2match none
|
||||
autocmd! TLib CursorMoved,CursorMovedI <buffer>
|
||||
autocmd! TLib CursorHold,CursorHoldI <buffer>
|
||||
@ -209,7 +209,7 @@ function! s:UndoHighlightLine() "{{{3
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#buffer#HighlightLine(...) "{{{3
|
||||
function! tlib#buffer#HighlightLine(...) abort "{{{3
|
||||
TVarArg ['line', line('.')]
|
||||
" exec '2match MatchParen /^\%'. a:line .'l.*/'
|
||||
exec '2match Search /^\%'. line .'l.*/'
|
||||
@ -222,7 +222,7 @@ endf
|
||||
|
||||
|
||||
" Delete the lines in the current buffer. Wrapper for |:delete|.
|
||||
function! tlib#buffer#DeleteRange(line1, line2) "{{{3
|
||||
function! tlib#buffer#DeleteRange(line1, line2) abort "{{{3
|
||||
let r = @t
|
||||
try
|
||||
exec a:line1.','.a:line2.'delete t'
|
||||
@ -233,14 +233,14 @@ endf
|
||||
|
||||
|
||||
" Replace a range of lines.
|
||||
function! tlib#buffer#ReplaceRange(line1, line2, lines)
|
||||
function! tlib#buffer#ReplaceRange(line1, line2, lines) abort
|
||||
call tlib#buffer#DeleteRange(a:line1, a:line2)
|
||||
call append(a:line1 - 1, a:lines)
|
||||
endf
|
||||
|
||||
|
||||
" Initialize some scratch area at the bottom of the current buffer.
|
||||
function! tlib#buffer#ScratchStart() "{{{3
|
||||
function! tlib#buffer#ScratchStart() abort "{{{3
|
||||
norm! Go
|
||||
let b:tlib_inbuffer_scratch = line('$')
|
||||
return b:tlib_inbuffer_scratch
|
||||
@ -248,7 +248,7 @@ endf
|
||||
|
||||
|
||||
" Remove the in-buffer scratch area.
|
||||
function! tlib#buffer#ScratchEnd() "{{{3
|
||||
function! tlib#buffer#ScratchEnd() abort "{{{3
|
||||
if !exists('b:tlib_inbuffer_scratch')
|
||||
echoerr 'tlib: In-buffer scratch not initalized'
|
||||
endif
|
||||
@ -258,14 +258,14 @@ endf
|
||||
|
||||
|
||||
" Run exec on all buffers via bufdo and return to the original buffer.
|
||||
function! tlib#buffer#BufDo(exec) "{{{3
|
||||
function! tlib#buffer#BufDo(exec) abort "{{{3
|
||||
let bn = bufnr('%')
|
||||
exec 'bufdo '. a:exec
|
||||
exec 'buffer! '. bn
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#buffer#InsertText(text, keyargs)
|
||||
" :def: function! tlib#buffer#InsertText(text, keyargs) abort
|
||||
" Keyargs:
|
||||
" 'shift': 0|N
|
||||
" 'col': col('.')|N
|
||||
@ -273,7 +273,7 @@ endf
|
||||
" 'indent': 0|1
|
||||
" 'pos': 'e'|'s' ... Where to locate the cursor (somewhat like s and e in {offset})
|
||||
" Insert text (a string) in the buffer.
|
||||
function! tlib#buffer#InsertText(text, ...) "{{{3
|
||||
function! tlib#buffer#InsertText(text, ...) abort "{{{3
|
||||
TVarArg ['keyargs', {}]
|
||||
" TLogVAR a:text, keyargs
|
||||
let keyargs = extend({
|
||||
@ -298,16 +298,16 @@ function! tlib#buffer#InsertText(text, ...) "{{{3
|
||||
" exec 'norm! '. keyargs.lineno .'G'
|
||||
call cursor(keyargs.lineno, keyargs.col)
|
||||
if keyargs.indent && keyargs.col > 1
|
||||
if &fo =~# '[or]'
|
||||
if &formatoptions =~# '[or]'
|
||||
" FIXME: Is the simple version sufficient?
|
||||
" VERSION 1
|
||||
" " This doesn't work because it's not guaranteed that the
|
||||
" " cursor is set.
|
||||
" let cline = getline('.')
|
||||
" norm! a
|
||||
" norm! a
|
||||
" "norm! o
|
||||
" " TAssertExec redraw | sleep 3
|
||||
" let idt = strpart(getline('.'), 0, keyargs.col('.') + keyargs.shift)
|
||||
" let idt = tlib#string#Strcharpart(getline('.'), 0, keyargs.col('.') + keyargs.shift)
|
||||
" " TLogVAR idt
|
||||
" let idtl = len(idt)
|
||||
" -1,.delete
|
||||
@ -346,10 +346,10 @@ function! tlib#buffer#InsertText(text, ...) "{{{3
|
||||
let tlen = len(text)
|
||||
let posshift = matchstr(keyargs.pos, '\d\+')
|
||||
" TLogVAR keyargs.pos
|
||||
if keyargs.pos =~ '^e'
|
||||
if keyargs.pos =~# '^e'
|
||||
exec keyargs.lineno + tlen - 1
|
||||
exec 'norm! 0'. (len(text[-1]) - len(post) + posshift - 1) .'l'
|
||||
elseif keyargs.pos =~ '^s'
|
||||
elseif keyargs.pos =~# '^s'
|
||||
" TLogVAR keyargs.lineno, pre, posshift
|
||||
exec keyargs.lineno
|
||||
exec 'norm! '. len(pre) .'|'
|
||||
@ -363,7 +363,7 @@ function! tlib#buffer#InsertText(text, ...) "{{{3
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#buffer#InsertText0(text, ...) "{{{3
|
||||
function! tlib#buffer#InsertText0(text, ...) abort "{{{3
|
||||
TVarArg ['keyargs', {}]
|
||||
let mode = get(keyargs, 'mode', 'i')
|
||||
" TLogVAR mode
|
||||
@ -382,13 +382,13 @@ function! tlib#buffer#InsertText0(text, ...) "{{{3
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#buffer#CurrentByte() "{{{3
|
||||
function! tlib#buffer#CurrentByte() abort "{{{3
|
||||
return line2byte(line('.')) + col('.')
|
||||
endf
|
||||
|
||||
|
||||
" Evaluate cmd while maintaining the cursor position and jump registers.
|
||||
function! tlib#buffer#KeepCursorPosition(cmd) "{{{3
|
||||
function! tlib#buffer#KeepCursorPosition(cmd) abort "{{{3
|
||||
" let pos = getpos('.')
|
||||
let view = winsaveview()
|
||||
try
|
||||
|
@ -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: 2015-10-24.
|
||||
" @Revision: 31.1.243
|
||||
" @Last Change: 2019-01-02.
|
||||
" @Revision: 125.1.243
|
||||
|
||||
|
||||
" The cache directory. If empty, use |tlib#dir#MyRuntime|.'/cache'.
|
||||
@ -45,21 +45,37 @@ TLet g:tlib#cache#dont_purge = ['[\/]\.last_purge$']
|
||||
" |pathshorten()|.
|
||||
TLet g:tlib#cache#max_filename = 200
|
||||
|
||||
TLet g:tlib#cache#use_json = 0
|
||||
|
||||
TLet g:tlib#cache#use_encoding = ''
|
||||
|
||||
|
||||
let s:cache = {}
|
||||
|
||||
|
||||
" :display: tlib#cache#Dir(?mode = 'bg')
|
||||
" :display: tlib#cache#Dir(?mode = 'bg', ?ensure_dir = true)
|
||||
" The default cache directory.
|
||||
function! tlib#cache#Dir(...) "{{{3
|
||||
TVarArg ['mode', 'bg']
|
||||
TVarArg ['mode', 'bg'], ['ensure_dir', 1]
|
||||
let dir = tlib#var#Get('tlib_cache', mode)
|
||||
if empty(dir)
|
||||
let dir = tlib#file#Join([tlib#dir#MyRuntime(), 'cache'])
|
||||
endif
|
||||
if ensure_dir
|
||||
call tlib#dir#Ensure(dir)
|
||||
endif
|
||||
return dir
|
||||
endf
|
||||
|
||||
|
||||
" :display: tlib#cache#EncodedFilename(type, file, ?mkdir=0, ?dir='')
|
||||
" Encode `file` and call |tlib#cache#Filename()|.
|
||||
function! tlib#cache#EncodedFilename(type, file, ...) "{{{3
|
||||
let file = tlib#url#Encode(a:file)
|
||||
return call(function('tlib#cache#Filename'), [a:type, file] + a:000)
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#cache#Filename(type, ?file=%, ?mkdir=0, ?dir='')
|
||||
function! tlib#cache#Filename(type, ...) "{{{3
|
||||
" TLogDBG 'bufname='. bufname('.')
|
||||
@ -90,12 +106,15 @@ function! tlib#cache#Filename(type, ...) "{{{3
|
||||
" TLogVAR file, dir, mkdir
|
||||
let cache_file = tlib#file#Join([dir, file])
|
||||
if len(cache_file) > g:tlib#cache#max_filename
|
||||
" echom "DBG long filename" cache_file
|
||||
" echom "DBG long filename" dir
|
||||
if v:version >= 704
|
||||
let shortfilename = pathshorten(file) .'_'. sha256(file)
|
||||
let shortfilename = sha256(file)
|
||||
else
|
||||
let shortfilename = pathshorten(file) .'_'. tlib#hash#Adler32(file)
|
||||
let shortfilename = tlib#hash#Adler32(file)
|
||||
endif
|
||||
let cache_file = tlib#cache#Filename(a:type, shortfilename, mkdir, dir0)
|
||||
" let cache_file = tlib#cache#Filename(a:type, shortfilename, mkdir, dir0)
|
||||
let cache_file = tlib#file#Join([dir, shortfilename])
|
||||
else
|
||||
if mkdir && !isdirectory(dir)
|
||||
try
|
||||
@ -126,15 +145,45 @@ function! s:SetTimestamp(cfile, type) "{{{3
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#cache#Save(cfile, dictionary, ...) "{{{3
|
||||
function! s:PutValue(cfile, value) abort "{{{3
|
||||
let s:cache[a:cfile] = {'mtime': localtime(), 'data': a:value}
|
||||
endf
|
||||
|
||||
|
||||
function! s:GetValue(cfile, default) abort "{{{3
|
||||
return get(get(s:cache, a:cfile, {}), 'data', a:default)
|
||||
endf
|
||||
|
||||
|
||||
function! s:GetCacheTime(cfile) abort "{{{3
|
||||
let not_found = !has_key(s:cache, a:cfile)
|
||||
let cftime = not_found ? -1 : s:cache[a:cfile].mtime
|
||||
return cftime
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#cache#Save(cfile, value, ...) "{{{3
|
||||
TVarArg ['options', {}]
|
||||
let in_memory = get(options, 'in_memory', 0)
|
||||
if in_memory
|
||||
" TLogVAR in_memory, a:cfile, localtime()
|
||||
let s:cache[a:cfile] = {'mtime': localtime(), 'data': a:dictionary}
|
||||
call s:PutValue(a:cfile, a:value)
|
||||
elseif !empty(a:cfile)
|
||||
" TLogVAR a:dictionary
|
||||
call writefile([string(a:dictionary)], a:cfile, 'b')
|
||||
" TLogVAR a:value
|
||||
let cfile = a:cfile
|
||||
if g:tlib#cache#use_json && exists('*json_encode')
|
||||
try
|
||||
let value = json_encode(a:value)
|
||||
let cfile .= '.json'
|
||||
catch
|
||||
echoerr v:exception
|
||||
let value = string(a:value)
|
||||
endtry
|
||||
else
|
||||
let value = string(a:value)
|
||||
endif
|
||||
Tlibtrace 'tlib', cfile, value
|
||||
call writefile([value], cfile, 'b')
|
||||
call s:SetTimestamp(a:cfile, 'write')
|
||||
endif
|
||||
endf
|
||||
@ -152,16 +201,57 @@ function! tlib#cache#Get(cfile, ...) "{{{3
|
||||
let in_memory = get(options, 'in_memory', 0)
|
||||
if in_memory
|
||||
" TLogVAR in_memory, a:cfile
|
||||
return get(get(s:cache, a:cfile, {}), 'data', default)
|
||||
return s:GetValue(a:cfile, default)
|
||||
else
|
||||
call tlib#cache#MaybePurge()
|
||||
if !empty(a:cfile) && filereadable(a:cfile)
|
||||
let val = readfile(a:cfile, 'b')
|
||||
call s:SetTimestamp(a:cfile, 'read')
|
||||
return eval(join(val, "\n"))
|
||||
else
|
||||
return default
|
||||
if !empty(a:cfile)
|
||||
let jsonfile = a:cfile .'.json'
|
||||
let use_json = g:tlib#cache#use_json && exists('*json_decode') && exists('v:none') && filereadable(jsonfile)
|
||||
if use_json
|
||||
let use_json = 1
|
||||
let cfile = jsonfile
|
||||
else
|
||||
let cfile = a:cfile
|
||||
endif
|
||||
let mt = s:GetCacheTime(cfile)
|
||||
let ft = getftime(cfile)
|
||||
if mt != -1 && mt >= ft
|
||||
return s:GetValue(cfile, default)
|
||||
elseif ft != -1
|
||||
call s:SetTimestamp(cfile, 'read')
|
||||
let val = join(readfile(cfile, 'b'), '\n')
|
||||
try
|
||||
if use_json
|
||||
" NOTE: Copy result of json_decode() in order to
|
||||
" avoid "E741: value is locked" error in vim8.
|
||||
let value = json_decode(val)
|
||||
if value is v:none
|
||||
let value = default
|
||||
else
|
||||
let value = copy(value)
|
||||
endif
|
||||
else
|
||||
let value = eval(val)
|
||||
endif
|
||||
call s:PutValue(cfile, value)
|
||||
return value
|
||||
catch
|
||||
echohl ErrorMsg
|
||||
echom v:exception
|
||||
echom 'tlib#cache#Get: Invalid value in:' cfile
|
||||
echom 'Value:' string(val)
|
||||
echom 'Please review the file and delete it if necessary'
|
||||
echom 'Will use default value:' string(default)
|
||||
echohl NONE
|
||||
if g:tlib#debug
|
||||
let @* = string(val)
|
||||
endif
|
||||
" call s:PutValue(cfile, default)
|
||||
return default
|
||||
endtry
|
||||
endif
|
||||
endif
|
||||
return default
|
||||
endif
|
||||
endf
|
||||
|
||||
@ -172,10 +262,14 @@ endf
|
||||
function! tlib#cache#Value(cfile, generator, ftime, ...) "{{{3
|
||||
TVarArg ['args', []], ['options', {}]
|
||||
let in_memory = get(options, 'in_memory', 0)
|
||||
let not_found = in_memory ? !has_key(s:cache, a:cfile) : !filereadable(a:cfile)
|
||||
" TLogVAR in_memory, not_found
|
||||
let cftime = in_memory ? (not_found ? 0 : s:cache[a:cfile].mtime) : getftime(a:cfile)
|
||||
if not_found || (a:ftime != 0 && cftime < a:ftime)
|
||||
if in_memory
|
||||
let cftime = s:GetCacheTime(a:cfile)
|
||||
else
|
||||
let cftime = getftime(a:cfile)
|
||||
endif
|
||||
let ftime = a:ftime
|
||||
" TLogVAR in_memory, cftime
|
||||
if cftime == -1 || ftime == -1 || (ftime != 0 && cftime < ftime)
|
||||
" TLogVAR a:generator, args
|
||||
let val = call(a:generator, args)
|
||||
" TLogVAR val
|
||||
@ -194,6 +288,12 @@ function! tlib#cache#Value(cfile, generator, ftime, ...) "{{{3
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#cache#ValueFromName(type, name, ...) abort "{{{3
|
||||
let cfile = tlib#cache#Filename(a:type, tlib#url#Encode(a:name), 1)
|
||||
return call(function('tlib#cache#Value'), [cfile] + a:000)
|
||||
endf
|
||||
|
||||
|
||||
" Call |tlib#cache#Purge()| if the last purge was done before
|
||||
" |g:tlib#cache#purge_every_days|.
|
||||
function! tlib#cache#MaybePurge() "{{{3
|
||||
@ -251,16 +351,12 @@ function! tlib#cache#Purge() "{{{3
|
||||
try
|
||||
for file in files
|
||||
if isdirectory(file)
|
||||
if empty(filter(copy(newer), 'strpart(v:val, 0, len(file)) ==# file'))
|
||||
if empty(filter(copy(newer), 'tlib#string#Strcharpart(v:val, 0, len(file)) ==# file'))
|
||||
call add(deldir, file)
|
||||
endif
|
||||
else
|
||||
if getftime(file) < threshold
|
||||
if delete(file)
|
||||
call add(msg, "TLib: Could not delete cache file: ". file)
|
||||
elseif g:tlib#cache#verbosity >= 2
|
||||
call add(msg, "TLib: Delete cache file: ". file)
|
||||
endif
|
||||
call s:Delete(msg, file, '')
|
||||
else
|
||||
call add(newer, file)
|
||||
endif
|
||||
@ -273,56 +369,68 @@ function! tlib#cache#Purge() "{{{3
|
||||
echo join(msg, "\n")
|
||||
endif
|
||||
if !empty(deldir)
|
||||
if &shell =~ 'sh\(\.exe\)\?$'
|
||||
let scriptfile = 'deldir.sh'
|
||||
let rmdir = 'rm -rf %s'
|
||||
else
|
||||
let scriptfile = 'deldir.bat'
|
||||
let rmdir = 'rmdir /S /Q %s'
|
||||
endif
|
||||
let enc = g:tlib#cache#script_encoding
|
||||
if has('multi_byte') && enc != &enc
|
||||
call map(deldir, 'iconv(v:val, &enc, enc)')
|
||||
endif
|
||||
let scriptfile = tlib#file#Join([dir, scriptfile])
|
||||
if filereadable(scriptfile)
|
||||
let script = readfile(scriptfile)
|
||||
else
|
||||
let script = []
|
||||
endif
|
||||
let script += map(copy(deldir), 'printf(rmdir, shellescape(v:val, 1))')
|
||||
let script = tlib#list#Uniq(script)
|
||||
call writefile(script, scriptfile)
|
||||
call inputsave()
|
||||
if g:tlib#cache#run_script == 0
|
||||
if g:tlib#cache#verbosity >= 1
|
||||
echohl WarningMsg
|
||||
if g:tlib#cache#verbosity >= 2
|
||||
echom "TLib: Purged cache. Need to run script to delete directories"
|
||||
endif
|
||||
echom "TLib: Please review and execute: ". scriptfile
|
||||
echohl NONE
|
||||
let deldir = filter(reverse(sort(deldir)), 's:Delete(msg, v:val, "d")')
|
||||
if !empty(deldir)
|
||||
if &shell =~ 'sh\(\.exe\)\?$'
|
||||
let scriptfile = 'deldir.sh'
|
||||
let rmdir = 'rm -rf %s'
|
||||
else
|
||||
let scriptfile = 'deldir.bat'
|
||||
let rmdir = 'rmdir /S /Q %s'
|
||||
endif
|
||||
else
|
||||
try
|
||||
let yn = g:tlib#cache#run_script == 2 ? 'y' : tlib#input#Dialog("TLib: About to delete directories by means of a shell script.\nDirectory removal script: ". scriptfile ."\nRun script to delete directories now?", ['yes', 'no', 'edit'], 'no')
|
||||
if yn =~ '^y\%[es]$'
|
||||
exec 'cd '. fnameescape(dir)
|
||||
exec '! ' &shell shellescape(scriptfile, 1)
|
||||
exec 'cd -'
|
||||
call delete(scriptfile)
|
||||
elseif yn =~ '^e\%[dit]$'
|
||||
exec 'edit '. fnameescape(scriptfile)
|
||||
let enc = g:tlib#cache#script_encoding
|
||||
if has('multi_byte') && enc != &enc
|
||||
call map(deldir, 'iconv(v:val, &enc, enc)')
|
||||
endif
|
||||
let scriptfile = tlib#file#Join([dir, scriptfile])
|
||||
if filereadable(scriptfile)
|
||||
let script = readfile(scriptfile)
|
||||
else
|
||||
let script = []
|
||||
endif
|
||||
let script += map(copy(deldir), 'printf(rmdir, shellescape(v:val, 1))')
|
||||
let script = tlib#list#Uniq(script)
|
||||
call writefile(script, scriptfile)
|
||||
call inputsave()
|
||||
if g:tlib#cache#run_script == 0
|
||||
if g:tlib#cache#verbosity >= 1
|
||||
echohl WarningMsg
|
||||
if g:tlib#cache#verbosity >= 2
|
||||
echom "TLib: Purged cache. Need to run script to delete directories"
|
||||
endif
|
||||
echom "TLib: Please review and execute: ". scriptfile
|
||||
echohl NONE
|
||||
endif
|
||||
finally
|
||||
call inputrestore()
|
||||
endtry
|
||||
else
|
||||
try
|
||||
let yn = g:tlib#cache#run_script == 2 ? 'y' : tlib#input#Dialog("TLib: About to delete directories by means of a shell script.\nDirectory removal script: ". scriptfile ."\nRun script to delete directories now?", ['yes', 'no', 'edit'], 'no')
|
||||
if yn =~ '^y\%[es]$'
|
||||
exec 'silent cd '. fnameescape(dir)
|
||||
exec '! ' &shell shellescape(scriptfile, 1)
|
||||
exec 'silent cd -'
|
||||
call delete(scriptfile)
|
||||
elseif yn =~ '^e\%[dit]$'
|
||||
exec 'edit '. fnameescape(scriptfile)
|
||||
endif
|
||||
finally
|
||||
call inputrestore()
|
||||
endtry
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
call s:PurgeTimestamp(dir)
|
||||
endf
|
||||
|
||||
|
||||
function! s:Delete(msg, file, flags) abort "{{{3
|
||||
let rv = delete(a:file, a:flags)
|
||||
if !rv && g:tlib#cache#verbosity >= 2
|
||||
call add(a:msg, "TLib#cache: Delete ". file)
|
||||
endif
|
||||
return rv
|
||||
endf
|
||||
|
||||
|
||||
function! s:PurgeTimestamp(dir) "{{{3
|
||||
let last_purge = tlib#file#Join([a:dir, '.last_purge'])
|
||||
" TLogVAR last_purge
|
||||
@ -338,7 +446,7 @@ function! tlib#cache#ListFilesInCache(...) "{{{3
|
||||
endif
|
||||
let files = reverse(split(filess, '\n'))
|
||||
let pos0 = len(tlib#dir#CanonicName(dir))
|
||||
call filter(files, 's:ShouldPurge(strpart(v:val, pos0))')
|
||||
call filter(files, 's:ShouldPurge(tlib#string#Strcharpart(v:val, pos0))')
|
||||
return files
|
||||
endf
|
||||
|
||||
|
@ -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: 2010-03-25.
|
||||
" @Last Change: 2015-11-23.
|
||||
" @Revision: 21.0.34
|
||||
" @Last Change: 2017-09-06.
|
||||
" @Revision: 44.0.34
|
||||
|
||||
|
||||
if !exists('g:tlib#date#ShortDatePrefix') | let g:tlib#date#ShortDatePrefix = '20' | endif "{{{2
|
||||
@ -17,12 +17,14 @@ let g:tlib#date#date_format = '%Y-%m-%d'
|
||||
|
||||
|
||||
function! tlib#date#IsDate(text) abort "{{{3
|
||||
return a:text =~# '^'. g:tlib#date#date_rx .'$'
|
||||
return a:text =~# '^'. g:tlib#date#date_rx .'$' &&
|
||||
\ !empty(tlib#date#Parse(a:text, 0, 1))
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#date#Format(secs1970) abort "{{{3
|
||||
return strftime(g:tlib#date#date_format, a:secs1970)
|
||||
function! tlib#date#Format(...) abort "{{{3
|
||||
let secs1970 = a:0 >= 1 ? a:1 : localtime()
|
||||
return strftime(g:tlib#date#date_format, secs1970)
|
||||
endf
|
||||
|
||||
|
||||
@ -37,11 +39,16 @@ function! tlib#date#DiffInDays(date, ...)
|
||||
endf
|
||||
|
||||
|
||||
" :display: tlib#date#Parse(date, ?allow_zero=0) "{{{3
|
||||
" :display: tlib#date#Parse(date, ?allow_zero=0, ?silent=0) "{{{3
|
||||
function! tlib#date#Parse(date, ...) "{{{3
|
||||
let min = a:0 >= 1 && a:1 ? 0 : 1
|
||||
" TLogVAR a:date, min
|
||||
let silent = a:0 >= 2 ? a:2 : 0
|
||||
Tlibtype 'tlib', a:date, min, silent
|
||||
let m = matchlist(a:date, '^\(\d\{2}\|\d\{4}\)-\(\d\{1,2}\)-\(\d\{1,2}\)$')
|
||||
Tlibtype 'tlib', m
|
||||
let year = ''
|
||||
let month = ''
|
||||
let days = ''
|
||||
if !empty(m)
|
||||
let year = m[1]
|
||||
let month = m[2]
|
||||
@ -61,13 +68,17 @@ function! tlib#date#Parse(date, ...) "{{{3
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
Tlibtype 'tlib', year, month, days
|
||||
if empty(m) || year == '' || month == '' || days == '' ||
|
||||
\ month < min || month > 12 || days < min || days > 31
|
||||
echoerr 'TLib: Invalid date: '. a:date
|
||||
if !silent
|
||||
echoerr 'TLib: Invalid date: '. a:date
|
||||
endif
|
||||
return []
|
||||
endif
|
||||
if strlen(year) == 2
|
||||
let year = g:tlib#date#ShortDatePrefix . year
|
||||
Tlibtype 'tlib', year
|
||||
endif
|
||||
return [0 + year, 0 + month, 0 + days]
|
||||
endf
|
||||
@ -137,22 +148,35 @@ function! tlib#date#Shift(date, shift) abort "{{{3
|
||||
let ml = matchlist(a:date, g:tlib#date#date_rx)
|
||||
" TLogVAR a:date, a:shift, n, ml
|
||||
if a:shift =~ 'd$'
|
||||
let secs = tlib#date#SecondsSince1970(a:date) + g:tlib#date#dayshift * n
|
||||
" TLogVAR secs
|
||||
let date = tlib#date#AddDays(a:date, n)
|
||||
elseif a:shift =~ 'b$'
|
||||
let n1 = n
|
||||
let secs = tlib#date#SecondsSince1970(a:date)
|
||||
while n1 > 0
|
||||
let n1 -= 1
|
||||
let secs += g:tlib#date#dayshift
|
||||
let uday = strftime('%u', secs)
|
||||
if uday == 6
|
||||
let secs += g:tlib#date#dayshift * 2
|
||||
elseif uday == 7
|
||||
let secs += g:tlib#date#dayshift
|
||||
endif
|
||||
endwh
|
||||
let date = tlib#date#Format(secs)
|
||||
elseif a:shift =~ 'w$'
|
||||
let secs = tlib#date#SecondsSince1970(a:date) + g:tlib#date#dayshift * n * 7
|
||||
let date = tlib#date#Format(secs)
|
||||
let date = tlib#date#AddDays(a:date, n * 7)
|
||||
elseif a:shift =~ 'm$'
|
||||
let d = str2nr(ml[3])
|
||||
let ms = str2nr(ml[2]) + n
|
||||
let m = (ms - 1) % 12 + 1
|
||||
let yr = str2nr(ml[1]) + ms / 12
|
||||
let yr = str2nr(ml[1]) + (ms - 1) / 12
|
||||
let date = printf('%04d-%02d-%02d', yr, m, d)
|
||||
" TLogVAR d, ms, m, yr, date
|
||||
elseif a:shift =~ 'y$'
|
||||
let yr = str2nr(ml[1]) + n
|
||||
let date = substitute(a:date, '^\d\{4}', yr, '')
|
||||
else
|
||||
throw 'tlib#date#Shift: Unsupported arguments: '. string(a:shift)
|
||||
endif
|
||||
" if !empty(ml[4]) && date !~ '\s'. ml[4] .'$'
|
||||
" let date .= ' '. ml[4]
|
||||
@ -161,3 +185,11 @@ function! tlib#date#Shift(date, shift) abort "{{{3
|
||||
return date
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#date#AddDays(date, n) abort "{{{3
|
||||
let secs = tlib#date#SecondsSince1970(a:date) + g:tlib#date#dayshift * a:n
|
||||
" TLogVAR secs
|
||||
let date = tlib#date#Format(secs)
|
||||
return date
|
||||
endf
|
||||
|
||||
|
@ -1,14 +1,44 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: https://github.com/tomtom
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Last Change: 2015-10-14
|
||||
" @Revision: 2
|
||||
" @Last Change: 2016-04-06
|
||||
" @Revision: 22
|
||||
|
||||
|
||||
function! tlib#dictionary#Rev(dict) abort "{{{3
|
||||
" :display: tlib#dictionary#Rev(dict, ?opts = {}) abort "{{{3
|
||||
function! tlib#dictionary#Rev(dict, ...) abort "{{{3
|
||||
let opts = a:0 >= 1 ? a:1 : {}
|
||||
Tlibtype a:dict, 'dict', opts, 'dict'
|
||||
let rev = {}
|
||||
let use_string = get(opts, 'use_string', 0)
|
||||
let use_eval = get(opts, 'use_eval', 0)
|
||||
let values_as_list = get(opts, 'values_as_list', 0)
|
||||
for [m, f] in items(a:dict)
|
||||
let rev[f] = m
|
||||
if use_string
|
||||
let k = string(f)
|
||||
else
|
||||
let k = type(f) == 1 ? f : string(f)
|
||||
if k ==# ''
|
||||
let k = get(opts, 'empty', '')
|
||||
if empty(k)
|
||||
continue
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
if use_eval
|
||||
let v = eval(m)
|
||||
else
|
||||
let v = m
|
||||
endif
|
||||
if values_as_list
|
||||
if has_key(rev, k)
|
||||
call add(rev[k], v)
|
||||
else
|
||||
let rev[k] = [v]
|
||||
endif
|
||||
else
|
||||
let rev[k] = v
|
||||
endif
|
||||
endfor
|
||||
return rev
|
||||
endf
|
||||
|
@ -1,7 +1,7 @@
|
||||
" @Author: Tom Link (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)
|
||||
" @Revision: 40
|
||||
" @Revision: 43
|
||||
|
||||
" TLet g:tlib#dir#sep = '/'
|
||||
TLet g:tlib#dir#sep = exists('+shellslash') && !&shellslash ? '\' : '/'
|
||||
@ -65,12 +65,12 @@ endf
|
||||
|
||||
" :def: function! tlib#dir#CD(dir, ?locally=0) => CWD
|
||||
function! tlib#dir#CD(dir, ...) "{{{3
|
||||
TVarArg ['locally', 0]
|
||||
TVarArg ['locally', haslocaldir()]
|
||||
let cmd = locally ? 'lcd! ' : 'cd! '
|
||||
" let cwd = getcwd()
|
||||
let cmd .= tlib#arg#Ex(a:dir)
|
||||
" TLogVAR a:dir, locally, cmd
|
||||
exec cmd
|
||||
exec 'silent' cmd
|
||||
" return cwd
|
||||
return getcwd()
|
||||
endf
|
||||
@ -78,7 +78,7 @@ endf
|
||||
|
||||
" :def: function! tlib#dir#Push(dir, ?locally=0) => CWD
|
||||
function! tlib#dir#Push(dir, ...) "{{{3
|
||||
TVarArg ['locally', 0]
|
||||
TVarArg ['locally', haslocaldir()]
|
||||
call add(s:dir_stack, [getcwd(), locally])
|
||||
return tlib#dir#CD(a:dir, locally)
|
||||
endf
|
||||
|
@ -1,7 +1,7 @@
|
||||
" @Author: Tom Link (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)
|
||||
" @Revision: 168
|
||||
" @Revision: 225
|
||||
|
||||
|
||||
if !exists('g:tlib#file#drop')
|
||||
@ -24,6 +24,12 @@ if !exists('g:tlib#file#absolute_filename_rx')
|
||||
let g:tlib#file#absolute_filename_rx = '^\~\?[\/]' "{{{2
|
||||
endif
|
||||
|
||||
|
||||
if !exists('g:tlib#file#reject_rx')
|
||||
let g:tlib#file#reject_rx = '\%(^\|[\/]\)\%(tags\|Thumbs\.db\)$' "{{{2
|
||||
endif
|
||||
|
||||
|
||||
""" File related {{{1
|
||||
" For the following functions please see ../../test/tlib.vim for examples.
|
||||
|
||||
@ -31,9 +37,9 @@ endif
|
||||
" EXAMPLES: >
|
||||
" tlib#file#Split('foo/bar/filename.txt')
|
||||
" => ['foo', 'bar', 'filename.txt']
|
||||
function! tlib#file#Split(filename) "{{{3
|
||||
function! tlib#file#Split(filename) abort "{{{3
|
||||
let prefix = matchstr(a:filename, '^\(\w\+:\)\?/\+')
|
||||
" TLogVAR prefix
|
||||
Tlibtrace 'tlib', prefix
|
||||
if !empty(prefix)
|
||||
let filename = a:filename[len(prefix) : -1]
|
||||
else
|
||||
@ -52,9 +58,9 @@ endf
|
||||
" EXAMPLES: >
|
||||
" tlib#file#Join(['foo', 'bar', 'filename.txt'])
|
||||
" => 'foo/bar/filename.txt'
|
||||
function! tlib#file#Join(filename_parts, ...) "{{{3
|
||||
function! tlib#file#Join(filename_parts, ...) abort "{{{3
|
||||
TVarArg ['strip_slashes', 1], 'maybe_absolute'
|
||||
" TLogVAR a:filename_parts, strip_slashes
|
||||
Tlibtrace 'tlib', a:filename_parts, strip_slashes
|
||||
if maybe_absolute
|
||||
let filename_parts = []
|
||||
for part in a:filename_parts
|
||||
@ -70,7 +76,7 @@ function! tlib#file#Join(filename_parts, ...) "{{{3
|
||||
" let rx = tlib#rx#Escape(g:tlib#dir#sep) .'$'
|
||||
let rx = '[/\\]\+$'
|
||||
let parts = map(copy(filename_parts), 'substitute(v:val, rx, "", "")')
|
||||
" TLogVAR parts
|
||||
Tlibtrace 'tlib', parts
|
||||
return join(parts, g:tlib#dir#sep)
|
||||
else
|
||||
return join(filename_parts, g:tlib#dir#sep)
|
||||
@ -81,18 +87,18 @@ endf
|
||||
" EXAMPLES: >
|
||||
" tlib#file#Relative('foo/bar/filename.txt', 'foo')
|
||||
" => 'bar/filename.txt'
|
||||
function! tlib#file#Relative(filename, basedir) "{{{3
|
||||
" TLogVAR a:filename, a:basedir
|
||||
function! tlib#file#Relative(filename, basedir) abort "{{{3
|
||||
Tlibtrace 'tlib', a:filename, a:basedir
|
||||
" TLogDBG getcwd()
|
||||
" TLogDBG expand('%:p')
|
||||
let b0 = tlib#file#Absolute(a:basedir)
|
||||
let b = tlib#file#Split(b0)
|
||||
" TLogVAR b
|
||||
Tlibtrace 'tlib', b
|
||||
let f0 = tlib#file#Absolute(a:filename)
|
||||
let fn = fnamemodify(f0, ':t')
|
||||
let fd = fnamemodify(f0, ':h')
|
||||
let f = tlib#file#Split(fd)
|
||||
" TLogVAR f0, fn, fd, f
|
||||
Tlibtrace 'tlib', f0, fn, fd, f
|
||||
if f[0] != b[0]
|
||||
let rv = f0
|
||||
else
|
||||
@ -103,18 +109,23 @@ function! tlib#file#Relative(filename, basedir) "{{{3
|
||||
call remove(f, 0)
|
||||
call remove(b, 0)
|
||||
endwh
|
||||
" TLogVAR f, b
|
||||
Tlibtrace 'tlib', f, b
|
||||
let rv = tlib#file#Join(repeat(['..'], len(b)) + f + [fn])
|
||||
endif
|
||||
" TLogVAR rv
|
||||
Tlibtrace 'tlib', rv
|
||||
return rv
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#file#Absolute(filename, ...) "{{{3
|
||||
function! tlib#file#IsAbsolute(filename) abort "{{{3
|
||||
return a:filename =~? '^\%(/\|\w\+:/\)'
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#file#Absolute(filename, ...) abort "{{{3
|
||||
if filereadable(a:filename)
|
||||
let filename = fnamemodify(a:filename, ':p')
|
||||
elseif a:filename =~ '^\(/\|[^\/]\+:\)'
|
||||
elseif a:filename =~# '^\(/\|[^\/]\+:\)'
|
||||
let filename = a:filename
|
||||
else
|
||||
let cwd = a:0 >= 1 ? a:1 : getcwd()
|
||||
@ -126,17 +137,19 @@ function! tlib#file#Absolute(filename, ...) "{{{3
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#file#Canonic(filename, ...) "{{{3
|
||||
function! tlib#file#Canonic(filename, ...) abort "{{{3
|
||||
TVarArg ['mode', '']
|
||||
if a:filename =~ '^\\\\'
|
||||
let mode = 'windows'
|
||||
elseif a:filename =~ '^\(file\|ftp\|http\)s\?:'
|
||||
let mode = 'url'
|
||||
elseif (empty(mode) && g:tlib#sys#windows)
|
||||
let mode = 'windows'
|
||||
if empty(mode)
|
||||
if a:filename =~# '^\\\\'
|
||||
let mode = 'windows'
|
||||
elseif a:filename =~# '^\(file\|ftp\|http\)s\?:'
|
||||
let mode = 'url'
|
||||
elseif (empty(mode) && g:tlib#sys#windows)
|
||||
let mode = 'windows'
|
||||
endif
|
||||
endif
|
||||
let filename = a:filename
|
||||
if mode == 'windows'
|
||||
if mode ==# 'windows'
|
||||
let filename = substitute(filename, '/', '\\', 'g')
|
||||
else
|
||||
let filename = substitute(filename, '\\', '/', 'g')
|
||||
@ -145,7 +158,7 @@ function! tlib#file#Canonic(filename, ...) "{{{3
|
||||
endf
|
||||
|
||||
|
||||
function! s:SetScrollBind(world) "{{{3
|
||||
function! s:SetScrollBind(world) abort "{{{3
|
||||
let sb = get(a:world, 'scrollbind', &scrollbind)
|
||||
if sb != &scrollbind
|
||||
let &scrollbind = sb
|
||||
@ -153,60 +166,81 @@ function! s:SetScrollBind(world) "{{{3
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#file#With(fcmd, bcmd, files, ?world={})
|
||||
function! tlib#file#With(fcmd, bcmd, files, ...) "{{{3
|
||||
" TLogVAR a:fcmd, a:bcmd, a:files
|
||||
" :def: function! tlib#file#With(fcmd, bcmd, files, ?world={}) abort
|
||||
function! tlib#file#With(fcmd, bcmd, files, ...) abort "{{{3
|
||||
Tlibtrace 'tlib', a:fcmd, a:bcmd, a:files
|
||||
let world = a:0 >= 1 ? a:1 : {}
|
||||
let unset_switchbuf = a:0 >= 2 ? a:2 : 0
|
||||
exec tlib#arg#Let([['world', {}]])
|
||||
call tlib#autocmdgroup#Init()
|
||||
augroup TLibFileRead
|
||||
autocmd!
|
||||
augroup END
|
||||
for f in a:files
|
||||
let bn = bufnr('^'.f.'$')
|
||||
" TLogVAR f, bn
|
||||
let bufloaded = bufloaded(bn)
|
||||
let ok = 0
|
||||
let s:bufread = ""
|
||||
if bn != -1 && buflisted(bn)
|
||||
if !empty(a:bcmd)
|
||||
" TLogDBG a:bcmd .' '. bn
|
||||
exec a:bcmd .' '. bn
|
||||
let ok = 1
|
||||
call s:SetScrollBind(world)
|
||||
endif
|
||||
else
|
||||
if filereadable(f)
|
||||
if !empty(a:fcmd)
|
||||
" TLogDBG a:fcmd .' '. tlib#arg#Ex(f)
|
||||
exec 'autocmd TLibFileRead BufRead' escape(f, '\ ') 'let s:bufread=expand("<afile>:p")'
|
||||
try
|
||||
exec a:fcmd .' '. tlib#arg#Ex(f)
|
||||
finally
|
||||
exec 'autocmd! TLibFileRead BufRead'
|
||||
endtry
|
||||
let ok = 1
|
||||
call s:SetScrollBind(world)
|
||||
if unset_switchbuf
|
||||
let switchbuf = &switchbuf
|
||||
set switchbuf&
|
||||
endif
|
||||
try
|
||||
for f in a:files
|
||||
try
|
||||
let bn = bufnr('^'.f.'$')
|
||||
Tlibtrace 'tlib', f, bn
|
||||
let bufloaded = bufloaded(bn)
|
||||
let ok = 0
|
||||
let s:bufread = ""
|
||||
if bn != -1 && buflisted(bn)
|
||||
if !empty(a:bcmd)
|
||||
let bcmd = a:bcmd .' '. bn
|
||||
Tlibtrace 'tlib', bcmd
|
||||
exec bcmd
|
||||
let ok = 1
|
||||
call s:SetScrollBind(world)
|
||||
endif
|
||||
else
|
||||
if filereadable(f)
|
||||
if !empty(a:fcmd)
|
||||
" TLogDBG a:fcmd .' '. tlib#arg#Ex(f)
|
||||
exec 'autocmd TLibFileRead BufRead' escape(f, '\ ') 'let s:bufread=expand("<afile>:p")'
|
||||
try
|
||||
let fcmd = a:fcmd .' '. tlib#arg#Ex(f)
|
||||
Tlibtrace 'tlib', fcmd
|
||||
exec fcmd
|
||||
finally
|
||||
exec 'autocmd! TLibFileRead BufRead'
|
||||
endtry
|
||||
let ok = 1
|
||||
call s:SetScrollBind(world)
|
||||
endif
|
||||
else
|
||||
echohl error
|
||||
echom 'File not readable: '. f
|
||||
echohl NONE
|
||||
endif
|
||||
endif
|
||||
else
|
||||
echohl error
|
||||
echom 'File not readable: '. f
|
||||
Tlibtrace 'tlib', ok, bufloaded, &filetype
|
||||
if empty(s:bufread) && ok && !bufloaded && empty(&filetype)
|
||||
doautocmd BufRead
|
||||
endif
|
||||
catch /^Vim\%((\a\+)\)\=:E325/
|
||||
echohl ErrorMsg
|
||||
echom v:exception
|
||||
echohl NONE
|
||||
endif
|
||||
endtry
|
||||
endfor
|
||||
finally
|
||||
augroup! TLibFileRead
|
||||
if unset_switchbuf
|
||||
let &switchbuf = switchbuf
|
||||
endif
|
||||
" TLogVAR ok, bufloaded, &filetype
|
||||
if empty(s:bufread) && ok && !bufloaded && empty(&filetype)
|
||||
doautocmd BufRead
|
||||
endif
|
||||
endfor
|
||||
augroup! TLibFileRead
|
||||
unlet! s:bufread
|
||||
unlet! s:bufread
|
||||
endtry
|
||||
" TLogDBG "done"
|
||||
endf
|
||||
|
||||
|
||||
" Return 0 if the file isn't readable/doesn't exist.
|
||||
" Otherwise return 1.
|
||||
function! tlib#file#Edit(fileid) "{{{3
|
||||
function! tlib#file#Edit(fileid) abort "{{{3
|
||||
if type(a:fileid) == 0
|
||||
let bn = a:fileid
|
||||
let filename = fnamemodify(bufname(bn), ':p')
|
||||
@ -217,20 +251,26 @@ function! tlib#file#Edit(fileid) "{{{3
|
||||
if filename == expand('%:p')
|
||||
return 1
|
||||
else
|
||||
" TLogVAR a:fileid, bn, filename, g:tlib#file#drop, filereadable(filename)
|
||||
Tlibtrace 'tlib', a:fileid, bn, filename, g:tlib#file#drop, filereadable(filename), bufnr('%')
|
||||
if bn != -1 && buflisted(bn)
|
||||
if g:tlib#file#drop
|
||||
" echom "DBG" get(g:tlib#file#edit_cmds, 'drop', 'drop') fnameescape(filename)
|
||||
exec get(g:tlib#file#edit_cmds, 'drop', 'drop') fnameescape(filename)
|
||||
" echom "DBG" bufnr('%')
|
||||
else
|
||||
" echom "DBG" get(g:tlib#file#edit_cmds, 'buffer', 'buffer') bn
|
||||
exec get(g:tlib#file#edit_cmds, 'buffer', 'buffer') bn
|
||||
" echom "DBG" bufnr('%')
|
||||
endif
|
||||
return 1
|
||||
elseif filereadable(filename)
|
||||
endif
|
||||
if !filereadable(filename) && exists('#TLibPrepareFile#User')
|
||||
exec 'doautocmd TLibPrepareFile User' filename
|
||||
endif
|
||||
if filereadable(filename)
|
||||
try
|
||||
" let file = tlib#arg#Ex(filename)
|
||||
" " TLogVAR file
|
||||
" Tlibtrace 'tlib', file
|
||||
" echom "DBG" get(g:tlib#file#edit_cmds, 'edit', 'edit') fnameescape(filename)
|
||||
exec get(g:tlib#file#edit_cmds, 'edit', 'edit') fnameescape(filename)
|
||||
catch /E325/
|
||||
@ -252,27 +292,65 @@ function! tlib#file#Edit(fileid) "{{{3
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#file#FilterFiles(files, options) abort "{{{3
|
||||
Tlibtrace 'tlib', a:files, a:options, g:tlib#file#reject_rx
|
||||
if !get(a:options, 'all', 0)
|
||||
call filter(a:files, 'v:val !~# g:tlib#file#reject_rx')
|
||||
endif
|
||||
Tlibtrace 'tlib', a:files
|
||||
let type = get(a:options, 'type', 'fd')
|
||||
Tlibtrace 'tlib', type
|
||||
if type !~# 'd' || type !~# 'f'
|
||||
call filter(a:files, 'isdirectory(v:val) ? type =~# "d" : type =~# "f"')
|
||||
endif
|
||||
Tlibtrace 'tlib', a:files
|
||||
return a:files
|
||||
endf
|
||||
|
||||
|
||||
if v:version > 704 || (v:version == 704 && has('patch279'))
|
||||
|
||||
function! tlib#file#Glob(pattern) abort "{{{3
|
||||
return glob(a:pattern, 0, 1)
|
||||
function! tlib#file#Glob(pattern, ...) abort "{{{3
|
||||
let all = a:0 >= 1 ? a:1 : 0
|
||||
let nosuf = a:0 >= 2 ? a:2 : 0
|
||||
return tlib#file#FilterFiles(glob(a:pattern, nosuf, 1), {'all': all})
|
||||
endf
|
||||
|
||||
function! tlib#file#Globpath(path, pattern) abort "{{{3
|
||||
return globpath(a:path, a:pattern, 0, 1)
|
||||
function! tlib#file#Globpath(path, pattern, ...) abort "{{{3
|
||||
let all = a:0 >= 1 ? a:1 : 0
|
||||
let nosuf = a:0 >= 2 ? a:2 : 0
|
||||
return tlib#file#FilterFiles(globpath(a:path, a:pattern, nosuf, 1), {'all': all})
|
||||
endf
|
||||
|
||||
else
|
||||
|
||||
" :nodoc:
|
||||
function! tlib#file#Glob(pattern) abort "{{{3
|
||||
return split(glob(a:pattern), '\n')
|
||||
function! tlib#file#Glob(pattern, ...) abort "{{{3
|
||||
let all = a:0 >= 1 ? a:1 : 0
|
||||
let nosuf = a:0 >= 2 ? a:2 : 0
|
||||
return tlib#file#FilterFiles(split(glob(a:pattern, nosuf), '\n'), {'all': all})
|
||||
endf
|
||||
|
||||
" :nodoc:
|
||||
function! tlib#file#Globpath(path, pattern) abort "{{{3
|
||||
return split(globpath(a:path, a:pattern), '\n')
|
||||
function! tlib#file#Globpath(path, pattern, ...) abort "{{{3
|
||||
let all = a:0 >= 1 ? a:1 : 0
|
||||
let nosuf = a:0 >= 2 ? a:2 : 0
|
||||
return tlib#file#FilterFiles(split(globpath(a:path, a:pattern), '\n'), {'all': all})
|
||||
endf
|
||||
|
||||
endif
|
||||
|
||||
|
||||
let s:filereadable = {}
|
||||
|
||||
augroup TLib
|
||||
autocmd BufWritePost,FileWritePost,FocusLost * let s:filereadable = {}
|
||||
augroup end
|
||||
|
||||
function! tlib#file#Filereadable(filename) abort "{{{3
|
||||
if !has_key(s:filereadable, a:filename)
|
||||
let s:filereadable[a:filename] = filereadable(a:filename)
|
||||
endif
|
||||
return s:filereadable[a:filename]
|
||||
endf
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
" @Author: Tom Link (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)
|
||||
" @Revision: 1366
|
||||
|
||||
" @Revision: 1430
|
||||
|
||||
" :filedoc:
|
||||
" Input-related, select from a list etc.
|
||||
@ -312,7 +311,7 @@ function! tlib#input#List(type, ...) "{{{3
|
||||
if !empty(filter)
|
||||
" let world.initial_filter = [[''], [filter]]
|
||||
" let world.initial_filter = [[filter]]
|
||||
" TLogVAR world.initial_filter
|
||||
Tlibtrace 'tlib', world.initial_filter, filter
|
||||
call world.SetInitialFilter(filter)
|
||||
endif
|
||||
endif
|
||||
@ -333,10 +332,11 @@ endf
|
||||
" (an instance of tlib#World as returned by |tlib#World#New|).
|
||||
function! tlib#input#ListW(world, ...) "{{{3
|
||||
TVarArg 'cmd'
|
||||
" let time0 = str2float(reltimestr(reltime())) " DBG
|
||||
" TLogVAR time0
|
||||
let time0 = str2float(reltimestr(reltime()))
|
||||
Tlibtrace 'tlib', time0
|
||||
let world = a:world
|
||||
if world.pick_last_item >= 1 && stridx(world.type, 'e') == -1 && len(world.base) <= 1
|
||||
call world.CloseScratch(1)
|
||||
let rv = get(world.base, 0, world.rv)
|
||||
if stridx(world.type, 'm') != -1
|
||||
return [rv]
|
||||
@ -345,7 +345,7 @@ function! tlib#input#ListW(world, ...) "{{{3
|
||||
endif
|
||||
endif
|
||||
call s:Init(world, cmd)
|
||||
" TLogVAR world.state, world.sticky, world.initial_index
|
||||
Tlibtrace 'tlib', world.state, world.sticky, world.initial_index
|
||||
" let statusline = &l:statusline
|
||||
" let laststatus = &laststatus
|
||||
let showmode = &showmode
|
||||
@ -361,38 +361,24 @@ function! tlib#input#ListW(world, ...) "{{{3
|
||||
try
|
||||
while !empty(world.state) && world.state !~ '^exit' && (world.show_empty || !empty(world.base))
|
||||
let post_keys = ''
|
||||
" TLogDBG 'while'
|
||||
" TLogVAR world.state
|
||||
" let time01 = str2float(reltimestr(reltime())) " DBG
|
||||
" TLogVAR time01, time01 - time0
|
||||
Tlibtrace 'tlib', 'while', world.state
|
||||
let time01 = str2float(reltimestr(reltime()))
|
||||
Tlibtrace 'tlib', time01, time01 - time0
|
||||
try
|
||||
let world = s:RunStateHandlers(world)
|
||||
|
||||
" if exists('b:tlib_world_event')
|
||||
" let event = b:tlib_world_event
|
||||
" unlet! b:tlib_world_event
|
||||
" if event == 'WinLeave'
|
||||
" " let world.resume_state = world.state
|
||||
" let world = tlib#agent#Suspend(world, world.rv)
|
||||
" break
|
||||
" endif
|
||||
" endif
|
||||
|
||||
" let time02 = str2float(reltimestr(reltime())) " DBG
|
||||
" TLogVAR time02, time02 - time0
|
||||
let time02 = str2float(reltimestr(reltime()))
|
||||
Tlibtrace 'tlib', time02, time02 - time0
|
||||
if world.state =~ '\<reset\>'
|
||||
" TLogDBG 'reset'
|
||||
" call world.Reset(world.state =~ '\<initial\>')
|
||||
call world.Reset()
|
||||
continue
|
||||
endif
|
||||
|
||||
call s:SetOffset(world)
|
||||
|
||||
" let time02 = str2float(reltimestr(reltime())) " DBG
|
||||
" TLogVAR time02, time02 - time0
|
||||
" TLogDBG 1
|
||||
" TLogVAR world.state
|
||||
let time02 = str2float(reltimestr(reltime()))
|
||||
Tlibtrace 'tlib', time02, time02 - time0
|
||||
Tlibtrace 'tlib', world.state
|
||||
if world.state == 'scroll'
|
||||
let world.prefidx = world.offset
|
||||
let world.state = 'redisplay'
|
||||
@ -402,33 +388,26 @@ function! tlib#input#ListW(world, ...) "{{{3
|
||||
let world.sticky = 1
|
||||
endif
|
||||
|
||||
" TLogVAR world.filter
|
||||
" TLogVAR world.sticky
|
||||
Tlibtrace 'tlib', world.filter
|
||||
Tlibtrace 'tlib', world.sticky
|
||||
if world.state =~ '\<picked\>'
|
||||
" TLogVAR world.rv
|
||||
Tlibtrace 'tlib', world.rv
|
||||
throw 'picked'
|
||||
elseif world.state =~ '\<pick\>'
|
||||
let world.rv = world.CurrentItem()
|
||||
" TLogVAR world.rv
|
||||
Tlibtrace 'tlib', world.rv
|
||||
throw 'picked'
|
||||
elseif world.state =~ 'display'
|
||||
if world.state =~ '^display'
|
||||
" let time03 = str2float(reltimestr(reltime())) " DBG
|
||||
" TLogVAR time03, time03 - time0
|
||||
let time03 = str2float(reltimestr(reltime()))
|
||||
Tlibtrace 'tlib', time03, time03 - time0
|
||||
if world.IsValidFilter()
|
||||
|
||||
" let time1 = str2float(reltimestr(reltime())) " DBG
|
||||
" TLogVAR time1, time1 - time0
|
||||
let time1 = str2float(reltimestr(reltime()))
|
||||
Tlibtrace 'tlib', time1, time1 - time0
|
||||
call world.BuildTableList()
|
||||
" let time2 = str2float(reltimestr(reltime())) " DBG
|
||||
" TLogVAR time2, time2 - time0
|
||||
" TLogDBG 2
|
||||
" TLogDBG len(world.table)
|
||||
" TLogVAR world.table
|
||||
" let world.list = map(copy(world.table), 'world.GetBaseItem(v:val)')
|
||||
" TLogDBG 3
|
||||
let time2 = str2float(reltimestr(reltime()))
|
||||
Tlibtrace 'tlib', time2, time2 - time0
|
||||
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)
|
||||
@ -436,12 +415,11 @@ function! tlib#input#ListW(world, ...) "{{{3
|
||||
let dindex = world.index_table
|
||||
let world.index_width = len(max(dindex))
|
||||
endif
|
||||
" let time3 = str2float(reltimestr(reltime())) " DBG
|
||||
" TLogVAR time3, time3 - time0
|
||||
let time3 = str2float(reltimestr(reltime()))
|
||||
Tlibtrace 'tlib', time3, time3 - time0
|
||||
if world.llen == 0 && !world.show_empty
|
||||
call world.ReduceFilter()
|
||||
let world.offset = 1
|
||||
" TLogDBG 'ReduceFilter'
|
||||
continue
|
||||
else
|
||||
if world.llen == 1
|
||||
@ -449,18 +427,15 @@ function! tlib#input#ListW(world, ...) "{{{3
|
||||
if world.pick_last_item >= 2
|
||||
" 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
|
||||
" let time4 = str2float(reltimestr(reltime())) " DBG
|
||||
" TLogVAR time4, time4 - time0
|
||||
" TLogDBG 4
|
||||
" TLogVAR world.idx, world.llen, world.state
|
||||
" TLogDBG world.FilterIsEmpty()
|
||||
let time4 = str2float(reltimestr(reltime()))
|
||||
Tlibtrace 'tlib', time4, time4 - time0
|
||||
Tlibtrace 'tlib', world.idx, world.llen, world.state
|
||||
if world.state == 'display'
|
||||
if world.idx == '' && world.llen < g:tlib#input#sortprefs_threshold && !world.FilterIsEmpty()
|
||||
call world.SetPrefIdx()
|
||||
@ -473,27 +448,22 @@ function! tlib#input#ListW(world, ...) "{{{3
|
||||
let world.prefidx = 1
|
||||
endif
|
||||
endif
|
||||
" let time5 = str2float(reltimestr(reltime())) " DBG
|
||||
" TLogVAR time5, time5 - time0
|
||||
" TLogVAR world.initial_index, world.prefidx
|
||||
" TLogDBG 5
|
||||
" TLogDBG len(world.list)
|
||||
" TLogVAR world.list
|
||||
let time5 = str2float(reltimestr(reltime()))
|
||||
Tlibtrace 'tlib', time5, time5 - time0
|
||||
Tlibtrace 'tlib', world.initial_index, world.prefidx
|
||||
Tlibtrace 'tlib', len(world.list)
|
||||
let dlist = world.DisplayFormat(world.list)
|
||||
" TLogVAR world.prefidx
|
||||
" TLogDBG 6
|
||||
" let time6 = str2float(reltimestr(reltime())) " DBG
|
||||
" TLogVAR time6, time6 - time0
|
||||
Tlibtrace 'tlib', world.prefidx
|
||||
let time6 = str2float(reltimestr(reltime()))
|
||||
Tlibtrace 'tlib', time6, time6 - time0
|
||||
if world.offset_horizontal > 0
|
||||
call map(dlist, 'v:val[world.offset_horizontal:-1]')
|
||||
call map(dlist, 'tlib#string#Strcharpart(v:val, world.offset_horizontal)')
|
||||
endif
|
||||
" let time7 = str2float(reltimestr(reltime())) " DBG
|
||||
" TLogVAR time7, time7 - time0
|
||||
" TLogVAR dindex
|
||||
let time7 = str2float(reltimestr(reltime()))
|
||||
Tlibtrace 'tlib', time7, time7 - time0
|
||||
let dlist = map(range(0, world.llen - 1), 'printf("%0'. world.index_width .'d", dindex[v:val]) .": ". dlist[v:val]')
|
||||
" TLogVAR dlist
|
||||
" let time8 = str2float(reltimestr(reltime())) " DBG
|
||||
" TLogVAR time8, time8 - time0
|
||||
let time8 = str2float(reltimestr(reltime()))
|
||||
Tlibtrace 'tlib', time8, time8 - time0
|
||||
|
||||
else
|
||||
|
||||
@ -505,30 +475,14 @@ function! tlib#input#ListW(world, ...) "{{{3
|
||||
let world.prefidx = 1
|
||||
endif
|
||||
endif
|
||||
" TLogVAR world.idx, world.prefidx
|
||||
Tlibtrace 'tlib', world.idx, world.prefidx
|
||||
|
||||
" TLogDBG 7
|
||||
" TLogVAR world.prefidx, world.offset
|
||||
" TLogDBG (world.prefidx > world.offset + winheight(0) - 1)
|
||||
" if world.prefidx > world.offset + winheight(0) - 1
|
||||
" let listtop = world.llen - winheight(0) + 1
|
||||
" let listoff = world.prefidx - winheight(0) + 1
|
||||
" let world.offset = min([listtop, listoff])
|
||||
" TLogVAR world.prefidx
|
||||
" TLogDBG len(list)
|
||||
" TLogDBG winheight(0)
|
||||
" TLogVAR listtop, listoff, world.offset
|
||||
" elseif world.prefidx < world.offset
|
||||
" let world.offset = world.prefidx
|
||||
" endif
|
||||
" TLogDBG 8
|
||||
" TLogVAR world.initial_display, !tlib#char#IsAvailable()
|
||||
Tlibtrace 'tlib', world.prefidx, world.offset
|
||||
Tlibtrace 'tlib', world.initial_display, !tlib#char#IsAvailable()
|
||||
if world.state =~ '\<update\>' || world.initial_display || !tlib#char#IsAvailable()
|
||||
" TLogDBG len(dlist)
|
||||
call world.DisplayList(world.Query(), dlist)
|
||||
call world.FollowCursor()
|
||||
let world.initial_display = 0
|
||||
" TLogDBG 9
|
||||
endif
|
||||
if world.state =~ '\<hibernate\>'
|
||||
let world.state = 'suspend'
|
||||
@ -548,9 +502,10 @@ function! tlib#input#ListW(world, ...) "{{{3
|
||||
endif
|
||||
endif
|
||||
" TAssert IsNotEmpty(world.scratch)
|
||||
let world.list_wid = tlib#win#GetID()
|
||||
let world.list_wnr = winnr()
|
||||
|
||||
" TLogVAR world.state, world.next_state
|
||||
Tlibtrace 'tlib', world.state, world.next_state
|
||||
if !empty(world.next_state)
|
||||
let world.state = world.next_state
|
||||
let world.next_state = ''
|
||||
@ -568,7 +523,7 @@ function! tlib#input#ListW(world, ...) "{{{3
|
||||
endif
|
||||
if has('gui_win32')
|
||||
let exec_cmd = input(query, '')
|
||||
" TLogVAR exec_cmd
|
||||
Tlibtrace 'tlib', exec_cmd
|
||||
if exec_cmd == ''
|
||||
let world.state = 'redisplay'
|
||||
else
|
||||
@ -576,17 +531,15 @@ function! tlib#input#ListW(world, ...) "{{{3
|
||||
endif
|
||||
elseif has('gui_gtk') || has('gui_gtk2')
|
||||
let c = s:GetModdedChar(world)
|
||||
" TLogVAR c
|
||||
Tlibtrace 'tlib', c
|
||||
endif
|
||||
else
|
||||
" TLogVAR world.timeout
|
||||
Tlibtrace 'tlib', world.timeout
|
||||
let c = s:GetModdedChar(world)
|
||||
" TLogVAR c, has_key(world.key_map[world.key_mode],c)
|
||||
Tlibtrace 'tlib', c, has_key(world.key_map[world.key_mode],c)
|
||||
endif
|
||||
" TLogVAR c
|
||||
" TLogDBG string(sort(keys(world.key_map[world.key_mode])))
|
||||
|
||||
" TLogVAR world.next_agent, world.next_eval
|
||||
Tlibtrace 'tlib', c
|
||||
Tlibtrace 'tlib', world.next_agent, world.next_eval
|
||||
if !empty(world.next_agent)
|
||||
let nagent = world.next_agent
|
||||
let world.next_agent = ''
|
||||
@ -604,19 +557,17 @@ function! tlib#input#ListW(world, ...) "{{{3
|
||||
elseif has_key(world.key_map[world.key_mode], c)
|
||||
let sr = @/
|
||||
silent! let @/ = lastsearch
|
||||
" TLogVAR c, world.key_map[world.key_mode][c]
|
||||
Tlibtrace 'tlib', c, world.key_map[world.key_mode][c]
|
||||
" TLog "Agent: ". string(world.key_map[world.key_mode][c])
|
||||
let handler = world.key_map[world.key_mode][c]
|
||||
" " TLogVAR handler
|
||||
" let world = call(handler.agent, [world, world.GetSelectedItems(world.CurrentItem())])
|
||||
" call s:CheckAgentReturnValue(c, world)
|
||||
Tlibtrace 'tlib', handler
|
||||
let world = s:CallAgent(handler, world, world.GetSelectedItems(world.CurrentItem()))
|
||||
silent! let @/ = sr
|
||||
" continue
|
||||
elseif c == 13
|
||||
throw 'pick'
|
||||
elseif c == 27
|
||||
" TLogVAR c, world.key_mode
|
||||
Tlibtrace 'tlib', c, world.key_mode
|
||||
if world.key_mode != 'default'
|
||||
let world.key_mode = 'default'
|
||||
let world.state = 'redisplay'
|
||||
@ -666,7 +617,7 @@ function! tlib#input#ListW(world, ...) "{{{3
|
||||
let world.state = 'exit empty'
|
||||
endif
|
||||
endif
|
||||
" TLogVAR world.prefidx, world.state
|
||||
Tlibtrace 'tlib', world.prefidx, world.state
|
||||
elseif has_key(world.key_map[world.key_mode], 'unknown_key')
|
||||
let agent = world.key_map[world.key_mode].unknown_key.agent
|
||||
" let world = call(agent, [world, c])
|
||||
@ -675,17 +626,17 @@ function! tlib#input#ListW(world, ...) "{{{3
|
||||
elseif c >= 32
|
||||
let world.state = 'display'
|
||||
let numbase = get(world.numeric_chars, c, -99999)
|
||||
" TLogVAR numbase, world.numeric_chars, c
|
||||
Tlibtrace 'tlib', numbase, world.numeric_chars, c
|
||||
if numbase != -99999
|
||||
let world.idx .= (c - numbase)
|
||||
if len(world.idx) == world.index_width
|
||||
let world.prefidx = world.idx
|
||||
" TLogVAR world.prefidx
|
||||
Tlibtrace 'tlib', world.prefidx
|
||||
throw 'pick'
|
||||
endif
|
||||
else
|
||||
let world.idx = ''
|
||||
" TLogVAR world.filter
|
||||
Tlibtrace 'tlib', world.filter
|
||||
if world.llen > g:tlib#input#livesearch_threshold
|
||||
let pattern = input('Filter: ', world.CleanFilter(world.filter[0][0]) . nr2char(c))
|
||||
if empty(pattern)
|
||||
@ -718,61 +669,50 @@ function! tlib#input#ListW(world, ...) "{{{3
|
||||
call world.ClearAllMarks()
|
||||
call world.MarkCurrent(world.prefidx)
|
||||
let world.state = ''
|
||||
" TLogDBG 'Pick item #'. world.prefidx
|
||||
|
||||
finally
|
||||
" TLogDBG 'finally 1', world.state
|
||||
if world.state =~ '\<suspend\>'
|
||||
" if !world.allow_suspend
|
||||
" echom "Cannot be suspended"
|
||||
" let world.state = 'redisplay'
|
||||
" endif
|
||||
elseif !empty(world.list) && !empty(world.base)
|
||||
" TLogVAR world.list
|
||||
if empty(world.state)
|
||||
let world.rv = world.CurrentItem()
|
||||
" TLogVAR world.state, world.rv
|
||||
Tlibtrace 'tlib', world.state, world.rv
|
||||
endif
|
||||
" TLogVAR "postprocess"
|
||||
for handler in world.post_handlers
|
||||
let state = get(handler, 'postprocess', '')
|
||||
" TLogVAR handler
|
||||
" TLogVAR state
|
||||
" TLogVAR world.state
|
||||
Tlibtrace 'tlib', handler
|
||||
Tlibtrace 'tlib', state
|
||||
Tlibtrace 'tlib', world.state
|
||||
if state == world.state
|
||||
let agent = handler.agent
|
||||
let [world, world.rv] = call(agent, [world, world.rv])
|
||||
" TLogVAR world.state, world.rv
|
||||
Tlibtrace 'tlib', world.state, world.rv
|
||||
call s:CheckAgentReturnValue(agent, world)
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
" TLogDBG 'state0='. world.state
|
||||
endtry
|
||||
" TLogDBG 'state1='. world.state
|
||||
endwh
|
||||
|
||||
" TLogVAR world.state
|
||||
" TLogDBG string(tlib#win#List())
|
||||
" TLogDBG 'exit while loop'
|
||||
" TLogVAR world.list
|
||||
" TLogVAR world.sel_idx
|
||||
" TLogVAR world.idx
|
||||
" TLogVAR world.prefidx
|
||||
" TLogVAR world.rv
|
||||
" TLogVAR world.type, world.state, world.return_agent, world.index_table, world.rv
|
||||
Tlibtrace 'tlib', world.state
|
||||
Tlibtrace 'tlib', len(world.list)
|
||||
Tlibtrace 'tlib', world.sel_idx
|
||||
Tlibtrace 'tlib', world.idx
|
||||
Tlibtrace 'tlib', world.prefidx
|
||||
Tlibtrace 'tlib', world.rv
|
||||
if world.state =~ '\<\(empty\|escape\)\>'
|
||||
let world.sticky = 0
|
||||
endif
|
||||
if world.state =~ '\<suspend\>'
|
||||
" TLogDBG 'return suspended'
|
||||
" TLogVAR world.prefidx
|
||||
Tlibtrace 'tlib', world.prefidx
|
||||
" exec world.prefidx
|
||||
return
|
||||
elseif world.state =~ '\<empty\>'
|
||||
" TLog "empty"
|
||||
" TLogDBG 'return empty'
|
||||
" TLogVAR world.type
|
||||
Tlibtrace 'tlib', world.type
|
||||
if stridx(world.type, 'm') != -1
|
||||
return []
|
||||
elseif stridx(world.type, 'i') != -1
|
||||
@ -781,23 +721,18 @@ function! tlib#input#ListW(world, ...) "{{{3
|
||||
return ''
|
||||
endif
|
||||
elseif !empty(world.return_agent)
|
||||
" TLogDBG 'return agent'
|
||||
" TLogVAR world.return_agent
|
||||
call world.CloseScratch()
|
||||
" TLogDBG "return_agent ". string(tlib#win#List())
|
||||
Tlibtrace 'tlib', world.return_agent
|
||||
call world.CloseScratch(1)
|
||||
" TAssert IsNotEmpty(world.scratch)
|
||||
return call(world.return_agent, [world, world.GetSelectedItems(world.rv)])
|
||||
elseif stridx(world.type, 'w') != -1
|
||||
" TLog "return_world"
|
||||
" TLogDBG 'return world'
|
||||
return world
|
||||
elseif stridx(world.type, 'm') != -1
|
||||
" TLog "return_multi"
|
||||
" TLogDBG 'return multi'
|
||||
return world.GetSelectedItems(world.rv)
|
||||
elseif stridx(world.type, 'i') != -1
|
||||
" TLog "return_index"
|
||||
" TLogDBG 'return index'
|
||||
if empty(world.index_table)
|
||||
return world.rv
|
||||
else
|
||||
@ -805,14 +740,13 @@ function! tlib#input#ListW(world, ...) "{{{3
|
||||
endif
|
||||
else
|
||||
" TLog "return_else"
|
||||
" TLogDBG 'return normal'
|
||||
return world.rv
|
||||
endif
|
||||
|
||||
finally
|
||||
call world.Leave()
|
||||
|
||||
" TLogVAR statusline
|
||||
" Tlibtrace 'tlib', statusline
|
||||
" let &l:statusline = statusline
|
||||
" let &laststatus = laststatus
|
||||
if &showmode != showmode
|
||||
@ -824,42 +758,39 @@ function! tlib#input#ListW(world, ...) "{{{3
|
||||
silent! aunmenu ]TLibInputListPopupMenu
|
||||
endif
|
||||
|
||||
" TLogDBG 'finally 2'
|
||||
" TLogDBG string(world.Methods())
|
||||
" TLogVAR world.state
|
||||
" TLogDBG string(tlib#win#List())
|
||||
Tlibtrace 'tlib', world.state
|
||||
if world.state !~ '\<suspend\>'
|
||||
" redraw
|
||||
" TLogVAR world.sticky, bufnr("%")
|
||||
Tlibtrace 'tlib', world.sticky, bufnr("%")
|
||||
if world.sticky
|
||||
" TLogDBG "sticky"
|
||||
" TLogVAR world.bufnr
|
||||
" TLogDBG bufwinnr(world.bufnr)
|
||||
Tlibtrace 'tlib', world.bufnr
|
||||
if world.scratch_split > 0
|
||||
if bufwinnr(world.bufnr) == -1
|
||||
" TLogDBG "UseScratch"
|
||||
call world.UseScratch()
|
||||
endif
|
||||
let world = tlib#agent#SuspendToParentWindow(world, world.GetSelectedItems(world.rv))
|
||||
endif
|
||||
else
|
||||
" TLogDBG "non sticky"
|
||||
" TLogVAR world.state, world.win_wnr, world.bufnr
|
||||
if world.CloseScratch()
|
||||
" TLogVAR world.winview
|
||||
Tlibtrace 'tlib', world.state, world.win_id, world.bufnr
|
||||
if world.CloseScratch(1)
|
||||
Tlibtrace 'tlib', get(world,'winview','')
|
||||
call tlib#win#SetLayout(world.winview)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
if world.state !~ '\<norestore\>'
|
||||
call world.RestoreWindow()
|
||||
endif
|
||||
" for i in range(0,5)
|
||||
" call getchar(0)
|
||||
" endfor
|
||||
echo
|
||||
redraw!
|
||||
if !empty(post_keys)
|
||||
" TLogVAR post_keys
|
||||
Tlibtrace 'tlib', post_keys
|
||||
call feedkeys(post_keys)
|
||||
endif
|
||||
let world.state = ''
|
||||
endtry
|
||||
endf
|
||||
|
||||
@ -871,7 +802,7 @@ function! s:CallAgent(handler, world, list) abort "{{{3
|
||||
let args += a:handler.args
|
||||
endif
|
||||
let world = call(agent, args)
|
||||
" TLogVAR world.state, world.rv
|
||||
Tlibtrace 'tlib', world.state, world.rv
|
||||
call s:CheckAgentReturnValue(agent, world)
|
||||
return world
|
||||
endf
|
||||
@ -887,7 +818,7 @@ endf
|
||||
|
||||
|
||||
function! s:Init(world, cmd) "{{{3
|
||||
" TLogVAR a:cmd
|
||||
Tlibtrace 'tlib', a:cmd
|
||||
let a:world.initial_display = 1
|
||||
if a:cmd =~ '\<sticky\>'
|
||||
let a:world.sticky = 1
|
||||
@ -905,7 +836,7 @@ function! s:Init(world, cmd) "{{{3
|
||||
" let a:world.state = a:world.resume_state
|
||||
" endif
|
||||
elseif !a:world.initialized
|
||||
" TLogVAR a:world.initialized, a:world.win_wnr, a:world.bufnr
|
||||
Tlibtrace 'tlib', a:world.initialized, a:world.win_id, a:world.bufnr
|
||||
let a:world.filetype = &filetype
|
||||
let a:world.fileencoding = &fileencoding
|
||||
call a:world.SetMatchMode(tlib#var#Get('tlib#input#filter_mode', 'wb'))
|
||||
@ -913,9 +844,9 @@ function! s:Init(world, cmd) "{{{3
|
||||
if !has_key(a:world, 'key_mode')
|
||||
let a:world.key_mode = 'default'
|
||||
endif
|
||||
" TLogVAR has_key(a:world,'key_map')
|
||||
Tlibtrace 'tlib', has_key(a:world,'key_map')
|
||||
if has_key(a:world, 'key_map')
|
||||
" TLogVAR has_key(a:world.key_map,a:world.key_mode)
|
||||
Tlibtrace 'tlib', has_key(a:world.key_map,a:world.key_mode)
|
||||
if has_key(a:world.key_map, a:world.key_mode)
|
||||
let a:world.key_map[a:world.key_mode] = extend(
|
||||
\ a:world.key_map[a:world.key_mode],
|
||||
@ -929,14 +860,14 @@ function! s:Init(world, cmd) "{{{3
|
||||
\ a:world.key_mode : copy(g:tlib#input#keyagents_InputList_s)
|
||||
\ }
|
||||
endif
|
||||
" TLogVAR a:world.type
|
||||
Tlibtrace 'tlib', a:world.type
|
||||
if stridx(a:world.type, 'm') != -1
|
||||
call extend(a:world.key_map[a:world.key_mode], g:tlib#input#keyagents_InputList_m, 'force')
|
||||
endif
|
||||
for key_mode in keys(a:world.key_map)
|
||||
let a:world.key_map[key_mode] = map(a:world.key_map[key_mode], 'type(v:val) == 4 ? v:val : {"agent": v:val}')
|
||||
endfor
|
||||
" TLogVAR a:world.key_mode
|
||||
Tlibtrace 'tlib', a:world.key_mode
|
||||
if type(a:world.key_handlers) == 3
|
||||
call s:ExtendKeyMap(a:world, a:world.key_mode, a:world.key_handlers)
|
||||
elseif type(a:world.key_handlers) == 4
|
||||
@ -946,12 +877,12 @@ function! s:Init(world, cmd) "{{{3
|
||||
else
|
||||
throw "tlib#input#ListW: key_handlers must be either a list or a dictionary"
|
||||
endif
|
||||
" TLogVAR a:world.type, a:world.key_map
|
||||
Tlibtrace 'tlib', a:world.type, a:world.key_map
|
||||
if !empty(a:cmd)
|
||||
let a:world.state .= ' '. a:cmd
|
||||
endif
|
||||
endif
|
||||
" TLogVAR a:world.state, a:world.sticky
|
||||
Tlibtrace 'tlib', a:world.state, a:world.sticky
|
||||
endf
|
||||
|
||||
|
||||
@ -979,7 +910,7 @@ function! s:PopupmenuExists()
|
||||
let rv = 0
|
||||
endtry
|
||||
endif
|
||||
" TLogVAR rv
|
||||
Tlibtrace 'tlib', rv
|
||||
return rv
|
||||
endf
|
||||
|
||||
@ -1144,9 +1075,9 @@ function! tlib#input#EditList(query, list, ...) "{{{3
|
||||
let handlers = a:0 >= 1 && !empty(a:1) ? a:1 : g:tlib#input#handlers_EditList
|
||||
let default = a:0 >= 2 ? a:2 : []
|
||||
let timeout = a:0 >= 3 ? a:3 : 0
|
||||
" TLogVAR handlers
|
||||
Tlibtrace 'tlib', handlers
|
||||
let rv = tlib#input#List('me', a:query, copy(a:list), handlers, default, timeout)
|
||||
" TLogVAR rv
|
||||
Tlibtrace 'tlib', rv
|
||||
if empty(rv)
|
||||
return a:list
|
||||
else
|
||||
@ -1157,7 +1088,7 @@ endf
|
||||
|
||||
|
||||
function! tlib#input#Resume(name, pick, bufnr) "{{{3
|
||||
" TLogVAR a:name, a:pick
|
||||
Tlibtrace 'tlib', a:name, a:pick
|
||||
echo
|
||||
if bufnr('%') != a:bufnr
|
||||
if g:tlib#debug
|
||||
@ -1182,10 +1113,8 @@ function! tlib#input#Resume(name, pick, bufnr) "{{{3
|
||||
else
|
||||
call tlib#autocmdgroup#Init()
|
||||
autocmd! TLib BufEnter <buffer>
|
||||
if b:tlib_{a:name}.state =~ '\<suspend\>'
|
||||
if b:tlib_{a:name}.state !~# 'display\>'
|
||||
let b:tlib_{a:name}.state = 'redisplay'
|
||||
else
|
||||
let b:tlib_{a:name}.state .= ' redisplay'
|
||||
endif
|
||||
" call tlib#input#List('resume '. a:name)
|
||||
let cmd = 'resume '. a:name
|
||||
@ -1245,24 +1174,25 @@ endf
|
||||
" endif
|
||||
" endf
|
||||
" call tlib#input#Edit('foo', b:var, 'FooContinue')
|
||||
function! tlib#input#Edit(name, value, callback, ...) "{{{3
|
||||
" TLogVAR a:value
|
||||
function! tlib#input#EditW(world, name, value, callback, ...) "{{{3
|
||||
Tlibtrace 'tlib', a:value
|
||||
TVarArg ['args', []]
|
||||
let sargs = {'scratch': '__EDIT__'. a:name .'__', 'win_wnr': winnr()}
|
||||
let sargs = {'scratch': '__EDIT__'. a:name .'__', 'win_id': tlib#win#GetID()}
|
||||
let scr = tlib#scratch#UseScratch(sargs)
|
||||
let b:tlib_world = a:world
|
||||
|
||||
" :nodoc:
|
||||
map <buffer> <c-w>c :call <SID>EditCallback(0)<cr>
|
||||
map <buffer> <c-w>c :call tlib#input#EditCallback(0)<cr>
|
||||
" :nodoc:
|
||||
imap <buffer> <c-w>c <c-o>call <SID>EditCallback(0)<cr>
|
||||
imap <buffer> <c-w>c <c-o>call tlib#input#EditCallback(0)<cr>
|
||||
" :nodoc:
|
||||
map <buffer> <c-s> :call <SID>EditCallback(1)<cr>
|
||||
map <buffer> <c-s> :call tlib#input#EditCallback(1)<cr>
|
||||
" :nodoc:
|
||||
imap <buffer> <c-s> <c-o>call <SID>EditCallback(1)<cr>
|
||||
imap <buffer> <c-s> <c-o>call tlib#input#EditCallback(1)<cr>
|
||||
" :nodoc:
|
||||
map <buffer> <c-w><cr> :call <SID>EditCallback(1)<cr>
|
||||
map <buffer> <c-w><cr> :call tlib#input#EditCallback(1)<cr>
|
||||
" :nodoc:
|
||||
imap <buffer> <c-w><cr> <c-o>call <SID>EditCallback(1)<cr>
|
||||
imap <buffer> <c-w><cr> <c-o>call tlib#input#EditCallback(1)<cr>
|
||||
|
||||
call tlib#normal#WithRegister('gg"tdG', 't')
|
||||
call append(1, split(a:value, "\<c-j>", 1))
|
||||
@ -1285,14 +1215,17 @@ function! tlib#input#Edit(name, value, callback, ...) "{{{3
|
||||
endif
|
||||
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) .')'
|
||||
" exec 'autocmd BufDelete,BufHidden,BufUnload <buffer> call tlib#input#EditCallback('. string(a:name) .')'
|
||||
" echohl MoreMsg
|
||||
" echom 'Press <c-s> to enter, <c-w>c to cancel editing.'
|
||||
" echohl NONE
|
||||
let world = getbufvar(scr, 'tlib_world', a:world)
|
||||
let world.state .= ' norestore'
|
||||
return world
|
||||
endf
|
||||
|
||||
|
||||
function! s:EditCallback(...) "{{{3
|
||||
function! tlib#input#EditCallback(...) "{{{3
|
||||
TVarArg ['ok', -1]
|
||||
" , ['bufnr', -1]
|
||||
" autocmd! BufDelete,BufHidden,BufUnload <buffer>
|
||||
@ -1304,10 +1237,11 @@ function! s:EditCallback(...) "{{{3
|
||||
let cb = b:tlib_scratch_edit_callback
|
||||
let args = b:tlib_scratch_edit_args
|
||||
let sargs = b:tlib_scratch_edit_scratch
|
||||
" TLogVAR cb, args, sargs
|
||||
let world = b:tlib_world
|
||||
Tlibtrace 'tlib', cb, args, sargs
|
||||
call call(cb, args + [ok, text, world])
|
||||
call tlib#scratch#CloseScratch(b:tlib_scratch_edit_scratch)
|
||||
call tlib#win#Set(sargs.win_wnr)
|
||||
call call(cb, args + [ok, text])
|
||||
call tlib#win#SetById(sargs.win_id)
|
||||
endf
|
||||
|
||||
|
||||
|
@ -3,18 +3,18 @@
|
||||
" @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: 2015-10-21.
|
||||
" @Revision: 61
|
||||
" @Last Change: 2017-03-26.
|
||||
" @Revision: 71
|
||||
|
||||
|
||||
""" List related functions {{{1
|
||||
" For the following functions please see ../../test/tlib.vim for examples.
|
||||
|
||||
" :def: function! tlib#list#Inject(list, initial_value, funcref)
|
||||
" :def: function! tlib#list#Inject(list, initial_value, funcref) abort
|
||||
" EXAMPLES: >
|
||||
" echo tlib#list#Inject([1,2,3], 0, function('Add')
|
||||
" => 6
|
||||
function! tlib#list#Inject(list, value, Function) "{{{3
|
||||
function! tlib#list#Inject(list, value, Function) abort "{{{3
|
||||
if empty(a:list)
|
||||
return a:value
|
||||
else
|
||||
@ -29,7 +29,7 @@ endf
|
||||
" EXAMPLES: >
|
||||
" tlib#list#Compact([0,1,2,3,[], {}, ""])
|
||||
" => [1,2,3]
|
||||
function! tlib#list#Compact(list) "{{{3
|
||||
function! tlib#list#Compact(list) abort "{{{3
|
||||
return filter(copy(a:list), '!empty(v:val)')
|
||||
endf
|
||||
|
||||
@ -37,7 +37,7 @@ endf
|
||||
" EXAMPLES: >
|
||||
" tlib#list#Flatten([0,[1,2,[3,""]]])
|
||||
" => [0,1,2,3,""]
|
||||
function! tlib#list#Flatten(list) "{{{3
|
||||
function! tlib#list#Flatten(list) abort "{{{3
|
||||
let acc = []
|
||||
for e in a:list
|
||||
if type(e) == 3
|
||||
@ -51,27 +51,27 @@ function! tlib#list#Flatten(list) "{{{3
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#list#FindAll(list, filter, ?process_expr="")
|
||||
" :def: function! tlib#list#FindAll(list, filter, ?process_expr="") abort
|
||||
" Basically the same as filter()
|
||||
"
|
||||
" EXAMPLES: >
|
||||
" tlib#list#FindAll([1,2,3], 'v:val >= 2')
|
||||
" => [2, 3]
|
||||
function! tlib#list#FindAll(list, filter, ...) "{{{3
|
||||
function! tlib#list#FindAll(list, filter, ...) abort "{{{3
|
||||
let rv = filter(copy(a:list), a:filter)
|
||||
if a:0 >= 1 && a:1 != ''
|
||||
if a:0 >= 1 && !empty(a:1)
|
||||
let rv = map(rv, a:1)
|
||||
endif
|
||||
return rv
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#list#Find(list, filter, ?default="", ?process_expr="")
|
||||
" :def: function! tlib#list#Find(list, filter, ?default="", ?process_expr="") abort
|
||||
"
|
||||
" EXAMPLES: >
|
||||
" tlib#list#Find([1,2,3], 'v:val >= 2')
|
||||
" => 2
|
||||
function! tlib#list#Find(list, filter, ...) "{{{3
|
||||
function! tlib#list#Find(list, filter, ...) abort "{{{3
|
||||
let default = a:0 >= 1 ? a:1 : ''
|
||||
let expr = a:0 >= 2 ? a:2 : ''
|
||||
return get(tlib#list#FindAll(a:list, a:filter, expr), 0, default)
|
||||
@ -81,7 +81,7 @@ endf
|
||||
" EXAMPLES: >
|
||||
" tlib#list#Any([1,2,3], 'v:val >= 2')
|
||||
" => 1
|
||||
function! tlib#list#Any(list, expr) "{{{3
|
||||
function! tlib#list#Any(list, expr) abort "{{{3
|
||||
return !empty(tlib#list#FindAll(a:list, a:expr))
|
||||
endf
|
||||
|
||||
@ -89,7 +89,7 @@ endf
|
||||
" EXAMPLES: >
|
||||
" tlib#list#All([1,2,3], 'v:val >= 2')
|
||||
" => 0
|
||||
function! tlib#list#All(list, expr) "{{{3
|
||||
function! tlib#list#All(list, expr) abort "{{{3
|
||||
return len(tlib#list#FindAll(a:list, a:expr)) == len(a:list)
|
||||
endf
|
||||
|
||||
@ -97,7 +97,7 @@ endf
|
||||
" EXAMPLES: >
|
||||
" tlib#list#Remove([1,2,1,2], 2)
|
||||
" => [1,1,2]
|
||||
function! tlib#list#Remove(list, element) "{{{3
|
||||
function! tlib#list#Remove(list, element) abort "{{{3
|
||||
let idx = index(a:list, a:element)
|
||||
if idx != -1
|
||||
call remove(a:list, idx)
|
||||
@ -109,17 +109,17 @@ endf
|
||||
" EXAMPLES: >
|
||||
" tlib#list#RemoveAll([1,2,1,2], 2)
|
||||
" => [1,1]
|
||||
function! tlib#list#RemoveAll(list, element) "{{{3
|
||||
function! tlib#list#RemoveAll(list, element) abort "{{{3
|
||||
call filter(a:list, 'v:val != a:element')
|
||||
return a:list
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#list#Zip(lists, ?default='')
|
||||
" :def: function! tlib#list#Zip(lists, ?default='') abort
|
||||
" EXAMPLES: >
|
||||
" tlib#list#Zip([[1,2,3], [4,5,6]])
|
||||
" => [[1,4], [2,5], [3,6]]
|
||||
function! tlib#list#Zip(lists, ...) "{{{3
|
||||
function! tlib#list#Zip(lists, ...) abort "{{{3
|
||||
TVarArg 'default'
|
||||
let lists = copy(a:lists)
|
||||
let max = 0
|
||||
@ -133,24 +133,30 @@ function! tlib#list#Zip(lists, ...) "{{{3
|
||||
return map(range(0, max - 1), 's:GetNthElement(v:val, lists, default)')
|
||||
endf
|
||||
|
||||
function! s:GetNthElement(n, lists, default) "{{{3
|
||||
function! s:GetNthElement(n, lists, default) abort "{{{3
|
||||
" TLogVAR a:n, a:lists, a:default
|
||||
return map(copy(a:lists), 'get(v:val, a:n, a:default)')
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#list#Uniq(list, ...) "{{{3
|
||||
function! tlib#list#Uniq(list, ...) abort "{{{3
|
||||
" TLogVAR a:list
|
||||
TVarArg ['get_value', ''], ['remove_empty', 0]
|
||||
if remove_empty
|
||||
call filter(a:list, 'type(v:val) == 0 || !empty(v:val)')
|
||||
endif
|
||||
" CREDITS: Based on syntastic#util#unique(list) by scrooloose
|
||||
let emptystring = 0
|
||||
let seen = {}
|
||||
let uniques = []
|
||||
if empty(get_value)
|
||||
for e in a:list
|
||||
if !has_key(seen, e)
|
||||
if empty(e)
|
||||
if !emptystring
|
||||
let emptystring = 1
|
||||
call add(uniques, e)
|
||||
endif
|
||||
elseif !has_key(seen, e)
|
||||
let seen[e] = 1
|
||||
call add(uniques, e)
|
||||
endif
|
||||
@ -159,18 +165,23 @@ function! tlib#list#Uniq(list, ...) "{{{3
|
||||
else
|
||||
for e in a:list
|
||||
let v = eval(printf(get_value, string(e)))
|
||||
if !has_key(seen, v)
|
||||
if empty(v)
|
||||
if !emptystring
|
||||
let emptystring = 1
|
||||
call add(uniques, v)
|
||||
endif
|
||||
elseif !has_key(seen, v)
|
||||
let seen[v] = 1
|
||||
call add(uniques, e)
|
||||
call add(uniques, v)
|
||||
endif
|
||||
unlet e
|
||||
unlet e v
|
||||
endfor
|
||||
endif
|
||||
return uniques
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#list#ToDictionary(list, default, ...) "{{{3
|
||||
function! tlib#list#ToDictionary(list, default, ...) abort "{{{3
|
||||
TVarArg ['generator', '']
|
||||
let dict = {}
|
||||
for item in a:list
|
||||
|
@ -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-09-19.
|
||||
" @Last Change: 2015-04-07.
|
||||
" @Revision: 0.3.19
|
||||
" @Last Change: 2017-09-28.
|
||||
" @Revision: 3.3.19
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
@ -24,7 +24,7 @@ function! tlib#notify#Echo(text, ...)
|
||||
if !empty(style)
|
||||
exec 'echohl' style
|
||||
endif
|
||||
echo strpart(text, 0, &columns - 1)
|
||||
echo tlib#string#Strcharpart(text, 0, &columns - 1)
|
||||
finally
|
||||
if !empty(style)
|
||||
echohl None
|
||||
@ -93,13 +93,21 @@ function! tlib#notify#TrimMessage(message) "{{{3
|
||||
let front = to_fill / 2 - 1
|
||||
let back = front
|
||||
if to_fill % 2 == 0 | let back -= 1 | endif
|
||||
return strpart(a:message, 0, front) . filler .
|
||||
\strpart(a:message, strlen(a:message) - back)
|
||||
return tlib#string#Strcharpart(a:message, 0, front) . filler .
|
||||
\ tlib#string#Strcharpart(a:message, strlen(a:message) - back)
|
||||
else
|
||||
return a:message
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
function! tlib#notify#PrintError() abort "{{{3
|
||||
echohl ErrorMsg
|
||||
echom v:exception
|
||||
echom v:throwpoint
|
||||
echohl NONE
|
||||
endf
|
||||
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
@ -1,22 +1,21 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Revision: 14
|
||||
" @Revision: 18
|
||||
|
||||
|
||||
function! tlib#number#ConvertBase(num, base, ...) "{{{3
|
||||
let rtype = a:0 >= 1 ? a:1 : 'string'
|
||||
if a:base > 36
|
||||
throw 'tlib#number#ConvertBase: base > 36 is not supported'
|
||||
endif
|
||||
" TLogVAR a:num, a:base, rtype
|
||||
let rv = []
|
||||
let num = 0.0 + a:num
|
||||
let chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
while floor(num) > 0.0
|
||||
let div = floor(num / a:base)
|
||||
let num1 = float2nr(num - a:base * div)
|
||||
if a:base <= 10
|
||||
call insert(rv, num1)
|
||||
elseif a:base == 16
|
||||
let char = "0123456789ABCDEF"[num1]
|
||||
call insert(rv, char)
|
||||
endif
|
||||
call insert(rv, chars[num1])
|
||||
let num = num / a:base
|
||||
endwh
|
||||
" TLogVAR rv
|
||||
|
@ -2,8 +2,8 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Created: 2012-05-11.
|
||||
" @Last Change: 2012-05-11.
|
||||
" @Revision: 12
|
||||
" @Last Change: 2017-03-29.
|
||||
" @Revision: 15
|
||||
|
||||
" The directory for persistent data files. If empty, use
|
||||
" |tlib#dir#MyRuntime|.'/share'.
|
||||
@ -21,6 +21,13 @@ function! tlib#persistent#Dir() "{{{3
|
||||
return dir
|
||||
endf
|
||||
|
||||
" :display: tlib#persistent#EncodedFilename(type, file, ?mkdir=0, ?dir='')
|
||||
" Encode `file` and call |tlib#persistent#Filename()|.
|
||||
function! tlib#persistent#EncodedFilename(type, file, ...) "{{{3
|
||||
let file = tlib#url#Encode(a:file)
|
||||
return call(function('tlib#persistent#Filename'), [a:type, file] + a:000)
|
||||
endf
|
||||
|
||||
" :def: function! tlib#persistent#Filename(type, ?file=%, ?mkdir=0)
|
||||
function! tlib#persistent#Filename(type, ...) "{{{3
|
||||
" TLogDBG 'bufname='. bufname('.')
|
||||
@ -41,7 +48,7 @@ function! tlib#persistent#Value(...) "{{{3
|
||||
return call('tlib#cache#Value', a:000)
|
||||
endf
|
||||
|
||||
function! tlib#persistent#Save(cfile, dictionary) "{{{3
|
||||
call tlib#cache#Save(a:cfile, a:dictionary)
|
||||
function! tlib#persistent#Save(...) "{{{3
|
||||
call call(function('tlib#cache#Save'), a:000)
|
||||
endf
|
||||
|
||||
|
@ -1,8 +1,10 @@
|
||||
" @Author: Tom 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)
|
||||
" @Revision: 72
|
||||
" @Revision: 86
|
||||
|
||||
let s:id = 0
|
||||
let s:ids = []
|
||||
let s:statusline = []
|
||||
let s:laststatus = []
|
||||
let s:max = []
|
||||
@ -23,14 +25,48 @@ let s:timestamp = -1
|
||||
" endtry
|
||||
function! tlib#progressbar#Init(max, ...) "{{{3
|
||||
TVarArg ['format', '%s'], ['width', 10]
|
||||
let s:id += 1
|
||||
call insert(s:ids, s:id)
|
||||
call insert(s:statusline, &statusline)
|
||||
call insert(s:laststatus, &laststatus)
|
||||
call insert(s:max, a:max)
|
||||
call insert(s:format, format)
|
||||
call insert(s:width, width)
|
||||
call insert(s:value, -1)
|
||||
let sl = {
|
||||
\ 'id': s:id,
|
||||
\ 'statusline': &statusline,
|
||||
\ 'laststatus': &laststatus,
|
||||
\ 'max': a:max,
|
||||
\ 'format': format,
|
||||
\ 'width': width,
|
||||
\ 'value': -1
|
||||
\ }
|
||||
let &laststatus = 2
|
||||
let s:timestamp = localtime()
|
||||
return sl
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#progressbar#Restore(...) "{{{3
|
||||
if a:0 >= 1
|
||||
let sl = a:1
|
||||
let idx = index(s:ids, sl.id)
|
||||
let &statusline = sl.statusline
|
||||
let &laststatus = sl.laststatus
|
||||
else
|
||||
let idx = 0
|
||||
let &statusline = remove(s:statusline, idx)
|
||||
let &laststatus = remove(s:laststatus, idx)
|
||||
endif
|
||||
call remove(s:ids, idx)
|
||||
call remove(s:max, idx)
|
||||
call remove(s:format, idx)
|
||||
call remove(s:width, idx)
|
||||
call remove(s:value, idx)
|
||||
redrawstatus
|
||||
" redraw
|
||||
" echo
|
||||
endf
|
||||
|
||||
|
||||
@ -48,7 +84,7 @@ function! tlib#progressbar#Display(value, ...) "{{{3
|
||||
let pbl = repeat('#', val)
|
||||
let pbr = repeat('.', s:width[0] - val)
|
||||
let txt = printf(s:format[0], '['.pbl.pbr.']') . extra
|
||||
let &l:statusline = txt
|
||||
let &statusline = txt
|
||||
" TLogDBG txt
|
||||
redrawstatus
|
||||
" redraw
|
||||
@ -57,16 +93,3 @@ function! tlib#progressbar#Display(value, ...) "{{{3
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#progressbar#Restore() "{{{3
|
||||
let &l:statusline = remove(s:statusline, 0)
|
||||
let &laststatus = remove(s:laststatus, 0)
|
||||
redrawstatus
|
||||
" redraw
|
||||
" echo
|
||||
call remove(s:max, 0)
|
||||
call remove(s:format, 0)
|
||||
call remove(s:width, 0)
|
||||
call remove(s:value, 0)
|
||||
endf
|
||||
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: https://github.com/tomtom
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Last Change: 2015-11-13
|
||||
" @Revision: 59
|
||||
" @Last Change: 2018-02-08
|
||||
" @Revision: 69
|
||||
|
||||
" :nodoc:
|
||||
TLet g:tlib#qfl#world = {
|
||||
@ -29,7 +29,10 @@ TLet g:tlib#qfl#world = {
|
||||
|
||||
function! tlib#qfl#FormatQFLE(qfe) dict abort "{{{3
|
||||
let filename = tlib#qfl#QfeFilename(a:qfe)
|
||||
if get(self, 'qfl_short_filename', '')
|
||||
let short_filename = get(self, 'qfl_short_filename', '')
|
||||
if short_filename ==# 'basename'
|
||||
let filename = matchstr(filename, '[^\\/]\+$')
|
||||
elseif !empty(short_filename)
|
||||
let filename = pathshorten(filename)
|
||||
endif
|
||||
return printf("%s|%d| %s", filename, a:qfe.lnum, get(a:qfe, "text"))
|
||||
@ -119,11 +122,11 @@ endf
|
||||
|
||||
|
||||
function! tlib#qfl#AgentEditQFE(world, selected, ...) "{{{3
|
||||
TVarArg ['cmd_edit', ''], ['cmd_buffer', '']
|
||||
TVarArg ['cmd_edit', ''], ['cmd_buffer', ''], ['set_origin', 1]
|
||||
" TVarArg ['cmd_edit', 'edit'], ['cmd_buffer', 'buffer']
|
||||
" TLogVAR a:selected
|
||||
if empty(a:selected)
|
||||
call a:world.RestoreOrigin()
|
||||
" call a:world.RestoreOrigin()
|
||||
" call a:world.ResetSelected()
|
||||
else
|
||||
call a:world.RestoreOrigin()
|
||||
@ -148,11 +151,13 @@ function! tlib#qfl#AgentEditQFE(world, selected, ...) "{{{3
|
||||
" TLogDBG bufname('%')
|
||||
" TLogVAR &filetype
|
||||
call tlib#buffer#ViewLine(qfe.lnum)
|
||||
" call a:world.SetOrigin()
|
||||
" exec back
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
if set_origin
|
||||
call a:world.SetOrigin()
|
||||
endif
|
||||
endif
|
||||
return a:world
|
||||
endf
|
||||
@ -161,7 +166,7 @@ endf
|
||||
function! tlib#qfl#AgentPreviewQFE(world, selected) "{{{3
|
||||
" TLogVAR a:selected
|
||||
let back = a:world.SwitchWindow('win')
|
||||
call tlib#qfl#AgentEditQFE(a:world, a:selected[0:0])
|
||||
call tlib#qfl#AgentEditQFE(a:world, a:selected[0:0], '', '', 0)
|
||||
exec back
|
||||
redraw
|
||||
let a:world.state = 'redisplay'
|
||||
@ -170,14 +175,12 @@ endf
|
||||
|
||||
|
||||
function! tlib#qfl#AgentGotoQFE(world, selected) "{{{3
|
||||
let world = a:world
|
||||
if !empty(a:selected)
|
||||
if a:world.win_wnr != winnr()
|
||||
let world = tlib#agent#Suspend(a:world, a:selected)
|
||||
exec a:world.win_wnr .'wincmd w'
|
||||
endif
|
||||
call tlib#qfl#AgentEditQFE(a:world, a:selected[0:0])
|
||||
let world = tlib#agent#Suspend(world, a:selected)
|
||||
call tlib#qfl#AgentEditQFE(world, a:selected[0:0])
|
||||
endif
|
||||
return a:world
|
||||
return world
|
||||
endf
|
||||
|
||||
|
||||
@ -201,7 +204,7 @@ function! tlib#qfl#RunCmdOnSelected(world, selected, cmd, ...) "{{{3
|
||||
" TLogVAR a:cmd
|
||||
for entry in a:selected
|
||||
" TLogVAR entry, a:world.GetBaseItem(entry)
|
||||
call tlib#qfl#AgentEditQFE(a:world, [entry])
|
||||
call tlib#qfl#AgentEditQFE(a:world, [entry], '', '', 0)
|
||||
" TLogDBG bufname('%')
|
||||
exec a:cmd
|
||||
" let item = a:world.data[a:world.GetBaseIdx(entry - 1)]
|
||||
|
@ -1,7 +1,7 @@
|
||||
" @Author: Tom Link (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)
|
||||
" @Revision: 113
|
||||
" @Revision: 114
|
||||
|
||||
|
||||
" :def: function! tlib#rx#Escape(text, ?magic='m')
|
||||
@ -30,13 +30,7 @@ endf
|
||||
" Escape return |sub-replace-special|.
|
||||
function! tlib#rx#EscapeReplace(text, ...) "{{{3
|
||||
TVarArg ['magic', 'm']
|
||||
if magic ==# 'm' || magic ==# 'v'
|
||||
return escape(a:text, '\&~')
|
||||
elseif magic ==# 'M' || magic ==# 'V'
|
||||
return escape(a:text, '\')
|
||||
else
|
||||
echoerr 'magic must be one of: m, v, M, V'
|
||||
endif
|
||||
return escape(a:text, '\&~')
|
||||
endf
|
||||
|
||||
|
||||
|
40
sources_non_forked/tlib/autoload/tlib/selection.vim
Normal file
40
sources_non_forked/tlib/autoload/tlib/selection.vim
Normal file
@ -0,0 +1,40 @@
|
||||
" @Author: Tom 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)
|
||||
" @Last Change: 2017-09-28
|
||||
" @Revision: 4
|
||||
|
||||
|
||||
" :display: tlib#selection#GetSelection(mode, ?mbeg="'<", ?mend="'>", ?opmode='selection')
|
||||
" mode can be one of: selection, lines, block
|
||||
function! tlib#selection#GetSelection(mode, ...) range "{{{3
|
||||
if a:0 >= 2
|
||||
let mbeg = a:1
|
||||
let mend = a:2
|
||||
else
|
||||
let mbeg = "'<"
|
||||
let mend = "'>"
|
||||
endif
|
||||
let opmode = a:0 >= 3 ? a:3 : 'selection'
|
||||
let l0 = line(mbeg)
|
||||
let l1 = line(mend)
|
||||
let text = getline(l0, l1)
|
||||
let c0 = col(mbeg)
|
||||
let c1 = col(mend)
|
||||
" TLogVAR mbeg, mend, opmode, l0, l1, c0, c1
|
||||
" TLogVAR text[-1]
|
||||
" TLogVAR len(text[-1])
|
||||
if opmode == 'block'
|
||||
let clen = c1 - c0
|
||||
call map(text, 'tlib#string#Strcharpart(v:val, c0, clen)')
|
||||
elseif opmode == 'selection'
|
||||
if c1 > 1
|
||||
let text[-1] = tlib#string#Strcharpart(text[-1], 0, c1 - (a:mode == 'o' || c1 > len(text[-1]) ? 0 : 1))
|
||||
endif
|
||||
if c0 > 1
|
||||
let text[0] = tlib#string#Strcharpart(text[0], c0 - 1)
|
||||
endif
|
||||
endif
|
||||
return text
|
||||
endf
|
||||
|
@ -1,7 +1,7 @@
|
||||
" @Author: Tom Link (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)
|
||||
" @Revision: 121
|
||||
" @Revision: 148
|
||||
|
||||
|
||||
" :def: function! tlib#string#RemoveBackslashes(text, ?chars=' ')
|
||||
@ -22,11 +22,21 @@ function! tlib#string#Chomp(string, ...) "{{{3
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#string#Format(template, dict) "{{{3
|
||||
let parts = split(a:template, '\ze%\({.\{-}}\|.\)')
|
||||
" Format a template string. Placeholders have the format "%{NAME}". A
|
||||
" "%" can be inserted as "%%".
|
||||
"
|
||||
" Examples:
|
||||
" echo tlib#string#Format("foo %{bar} foo", {'bar': 123}, ?prefix='%')
|
||||
" => foo 123 foo
|
||||
function! tlib#string#Format(template, dict, ...) "{{{3
|
||||
let prefix = a:0 >= 1 ? a:1 : '%'
|
||||
let pesc = prefix . prefix
|
||||
let prx = tlib#rx#Escape(prefix)
|
||||
let parts = split(a:template, '\ze'. prx .'\({.\{-}}\|.\)')
|
||||
let partrx = '^'. prx .'\({\(.\{-}\)}\|\(.\)\)\(.*\)$'
|
||||
let out = []
|
||||
for part in parts
|
||||
let ml = matchlist(part, '^%\({\(.\{-}\)}\|\(.\)\)\(.*\)$')
|
||||
let ml = matchlist(part, partrx)
|
||||
if empty(ml)
|
||||
let rest = part
|
||||
else
|
||||
@ -34,8 +44,8 @@ function! tlib#string#Format(template, dict) "{{{3
|
||||
let rest = ml[4]
|
||||
if has_key(a:dict, var)
|
||||
call add(out, a:dict[var])
|
||||
elseif var == '%%'
|
||||
call add(out, '%')
|
||||
elseif var ==# pesc
|
||||
call add(out, prefix)
|
||||
else
|
||||
call add(out, ml[1])
|
||||
endif
|
||||
@ -156,3 +166,43 @@ function! tlib#string#SplitCommaList(text, ...) abort "{{{3
|
||||
return parts
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#string#Input(...) abort "{{{3
|
||||
TVarArg ['text', ''], ['completion', '']
|
||||
call inputsave()
|
||||
let rv = call(function('input'), a:000)
|
||||
call inputrestore()
|
||||
return rv
|
||||
endf
|
||||
|
||||
|
||||
" :display: tlib#string#MatchAll(string, sep_regexp, ?item_regexp='') abort
|
||||
function! tlib#string#MatchAll(string, regexp, ...) abort "{{{3
|
||||
let eregexp = a:0 >= 1 ? a:1 : ''
|
||||
Tlibtrace 'tlib', a:string, a:regexp, eregexp
|
||||
let ms = []
|
||||
if a:regexp =~ '\\ze'
|
||||
let regexp1 = substitute(a:regexp, '\\ze.*$', '', '')
|
||||
else
|
||||
let regexp1 = a:regexp
|
||||
endif
|
||||
for m in split(a:string, '\ze'. regexp1)
|
||||
let m1 = matchstr(m, !empty(eregexp) ? eregexp : a:regexp)
|
||||
Tlibtrace 'tlib', m, m1
|
||||
if !empty(m1)
|
||||
call add(ms, m1)
|
||||
endif
|
||||
endfor
|
||||
return ms
|
||||
endf
|
||||
|
||||
if exists('*strcharpart')
|
||||
function! tlib#string#Strcharpart(...) abort "{{{3
|
||||
return call(function('strcharpart'), a:000)
|
||||
endf
|
||||
else
|
||||
function! tlib#string#Strcharpart(...) abort "{{{3
|
||||
return call(function('strpart'), a:000)
|
||||
endf
|
||||
endif
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Last Change: 2015-11-07.
|
||||
" @Revision: 51
|
||||
" @Last Change: 2017-04-12.
|
||||
" @Revision: 62
|
||||
|
||||
|
||||
if !exists('g:tlib#sys#special_protocols')
|
||||
@ -16,14 +16,14 @@ if !exists('g:tlib#sys#special_suffixes')
|
||||
" A list of |regexp|s matching suffixes that should be handled by
|
||||
" |g:tlib#sys#system_browser|.
|
||||
" CAVEAT: Must be a |\V| |regexp|.
|
||||
let g:tlib#sys#special_suffixes = ['xlsx\?', 'docx\?', 'pptx\?', 'accdb', 'mdb', 'sqlite', 'pdf', 'jpg', 'png', 'gif'] "{{{2
|
||||
let g:tlib#sys#special_suffixes = ['xlsx\?', 'docx\?', 'pptx\?', 'accdb', 'mdb', 'sqlite', 'pdf', 'jpg', 'png', 'gif', 'od\[tspg]'] "{{{2
|
||||
endif
|
||||
|
||||
|
||||
if !exists('g:tlib#sys#system_rx')
|
||||
" Open links matching this |regexp| with |g:tlib#sys#system_browser|.
|
||||
" CAVEAT: Must be a |\V| |regexp|.
|
||||
let g:tlib#sys#system_rx = printf('\V\%(\^\%(%s\):\|.\%(%s\)\)', join(g:tlib#sys#special_protocols, '\|'), join(g:tlib#sys#special_suffixes, '\|')) "{{{2
|
||||
let g:tlib#sys#system_rx = printf('\V\%(\^\%(%s\):\|.\%(%s\)\$\)', join(g:tlib#sys#special_protocols, '\|'), join(g:tlib#sys#special_suffixes, '\|')) "{{{2
|
||||
endif
|
||||
|
||||
|
||||
@ -39,7 +39,7 @@ if !exists("g:tlib#sys#system_browser")
|
||||
let g:tlib#sys#system_browser = "exec 'silent !open' shellescape('%s')"
|
||||
elseif exists('$XDG_CURRENT_DESKTOP') && !empty($XDG_CURRENT_DESKTOP)
|
||||
let g:tlib#sys#system_browser = "exec 'silent !xdg-open' shellescape('%s') '&'"
|
||||
elseif $GNOME_DESKTOP_SESSION_ID != "" || $DESKTOP_SESSION == 'gnome'
|
||||
elseif !empty($GNOME_DESKTOP_SESSION_ID) || $DESKTOP_SESSION ==# 'gnome'
|
||||
let g:tlib#sys#system_browser = "exec 'silent !gnome-open' shellescape('%s')"
|
||||
elseif exists("$KDEDIR") && !empty($KDEDIR)
|
||||
let g:tlib#sys#system_browser = "exec 'silent !kfmclient exec' shellescape('%s')"
|
||||
@ -185,9 +185,7 @@ function! tlib#sys#Open(filename) abort "{{{3
|
||||
Tlibtrace 'tlib', a:filename
|
||||
if !empty(g:tlib#sys#system_browser) && tlib#sys#IsSpecial(a:filename)
|
||||
try
|
||||
let cmd = printf(g:tlib#sys#system_browser, escape(a:filename, ' %#!'))
|
||||
Tlibtrace 'tlib', cmd
|
||||
exec cmd
|
||||
call tlib#sys#OpenWithSystemViewer(a:filename)
|
||||
return 1
|
||||
catch
|
||||
echohl ErrorMsg
|
||||
@ -199,13 +197,22 @@ function! tlib#sys#Open(filename) abort "{{{3
|
||||
endf
|
||||
|
||||
|
||||
" Open filename with the default system viewer.
|
||||
function! tlib#sys#OpenWithSystemViewer(filename) abort "{{{3
|
||||
let cmd = printf(g:tlib#sys#system_browser, a:filename)
|
||||
" let cmd = printf(g:tlib#sys#system_browser, escape(a:filename, ' %#!'))
|
||||
Tlibtrace 'tlib', cmd
|
||||
exec cmd
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#sys#SystemInDir(dir, expr, ?input='')
|
||||
function! tlib#sys#SystemInDir(dir, ...) abort "{{{3
|
||||
call tlib#dir#CD(a:dir)
|
||||
try
|
||||
return call(function('system'), a:000)
|
||||
finally
|
||||
cd! -
|
||||
silent cd! -
|
||||
endtry
|
||||
endf
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
" @Author: Tom 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)
|
||||
" @Revision: 59
|
||||
" @Revision: 64
|
||||
|
||||
|
||||
" Extra tags for |tlib#tag#Retrieve()| (see there). Can also be buffer-local.
|
||||
@ -47,7 +47,7 @@ TLet g:tlib_tag_substitute = {
|
||||
" < tags from the JDK will be included.
|
||||
function! tlib#tag#Retrieve(rx, ...) "{{{3
|
||||
TVarArg ['extra_tags', 0]
|
||||
" TLogVAR a:rx, extra_tags
|
||||
Tlibtrace 'tlib', a:rx, extra_tags
|
||||
if extra_tags
|
||||
let tags_orig = &l:tags
|
||||
if empty(tags_orig)
|
||||
@ -65,7 +65,8 @@ function! tlib#tag#Retrieve(rx, ...) "{{{3
|
||||
else
|
||||
let taglist = taglist(a:rx)
|
||||
endif
|
||||
return taglist
|
||||
Tlibtrace 'tlib', len(taglist)
|
||||
return copy(taglist)
|
||||
endf
|
||||
|
||||
|
||||
@ -76,7 +77,7 @@ endf
|
||||
" :def: function! tlib#tag#Collect(constraints, ?use_extra=1, ?match_front=1)
|
||||
function! tlib#tag#Collect(constraints, ...) "{{{3
|
||||
TVarArg ['use_extra', 0], ['match_end', 1], ['match_front', 1]
|
||||
" TLogVAR a:constraints, use_extra
|
||||
Tlibtrace 'tlib', a:constraints, use_extra, match_end, match_front
|
||||
let rx = get(a:constraints, 'name', '')
|
||||
if empty(rx) || rx == '*'
|
||||
let rx = '.'
|
||||
@ -92,9 +93,9 @@ function! tlib#tag#Collect(constraints, ...) "{{{3
|
||||
endif
|
||||
let rx = join(rxl, '')
|
||||
endif
|
||||
" TLogVAR rx, use_extra
|
||||
Tlibtrace 'tlib', rx, use_extra
|
||||
let tags = tlib#tag#Retrieve(rx, use_extra)
|
||||
" TLogDBG len(tags)
|
||||
Tlibtrace 'tlib', len(tags)
|
||||
for [field, rx] in items(a:constraints)
|
||||
if !empty(rx) && rx != '*'
|
||||
" TLogVAR field, rx
|
||||
@ -105,7 +106,7 @@ function! tlib#tag#Collect(constraints, ...) "{{{3
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
" TLogVAR tags
|
||||
Tlibtrace 'tlib', len(tags)
|
||||
return tags
|
||||
endf
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
" @Author: Tom 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)
|
||||
" @Revision: 36
|
||||
" @Revision: 42
|
||||
|
||||
|
||||
function! tlib#time#MSecs() "{{{3
|
||||
@ -65,3 +65,20 @@ function! tlib#time#DiffMSecs(a, b, ...) "{{{3
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#time#Command(cmd, ...) abort "{{{3
|
||||
let loops = a:0 >= 1 ? a:1 : 1
|
||||
let silent = a:0 >= 1 ? a:1 : 0
|
||||
let start = tlib#time#Now()
|
||||
for loop in range(loops)
|
||||
if silent
|
||||
silent! exec a:cmd
|
||||
else
|
||||
exec a:cmd
|
||||
endif
|
||||
endfor
|
||||
let end = tlib#time#Now()
|
||||
let diff = tlib#time#Diff(end, start)
|
||||
echom 'Time:' diff
|
||||
return diff
|
||||
endf
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @Website: https://github.com/tomtom
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Last Change: 2015-11-23
|
||||
" @Revision: 134
|
||||
" @Last Change: 2017-03-09
|
||||
" @Revision: 205
|
||||
|
||||
|
||||
if !exists('g:tlib#trace#backtrace')
|
||||
@ -12,19 +12,42 @@ if !exists('g:tlib#trace#backtrace')
|
||||
endif
|
||||
|
||||
|
||||
if !exists('g:tlib#trace#printf')
|
||||
" The command used for printing traces from |tlib#trace#Print()|.
|
||||
let g:tlib#trace#printf = 'echom %s' "{{{2
|
||||
if !exists('g:tlib#trace#printer')
|
||||
" Possible values:
|
||||
" - 'echom'
|
||||
" - ['file', FILENAME]
|
||||
let g:tlib#trace#printer = 'echom' "{{{2
|
||||
endif
|
||||
|
||||
|
||||
let s:trace_hl = {'error': 'ErrorMsg', 'fatal': 'ErrorMsg', 'warning': 'WarningMsg'}
|
||||
if !exists('g:tlib#trace#hl')
|
||||
let g:tlib#trace#hl = {'error': 'ErrorMsg', 'fatal': 'ErrorMsg', 'warn': 'WarningMsg'} "{{{2
|
||||
endif
|
||||
|
||||
|
||||
" Set |g:tlib#trace#printf| to make |tlib#trace#Print()| print to
|
||||
" `filename`.
|
||||
function! tlib#trace#PrintToFile(filename) abort "{{{3
|
||||
let g:tlib#trace#printf = 'call writefile([%s], '. string(a:filename) .', "a")'
|
||||
" Print traces from |tlib#trace#Print()|.
|
||||
function! tlib#trace#Printer_echom(type, text, args) abort "{{{3
|
||||
let hl = get(g:tlib#trace#hl, a:type, '')
|
||||
try
|
||||
if !empty(hl)
|
||||
exec 'echohl' hl
|
||||
endif
|
||||
echom a:text
|
||||
finally
|
||||
if !empty(hl)
|
||||
echohl NONE
|
||||
endif
|
||||
endtry
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#trace#Printer_file(type, text, args) abort "{{{3
|
||||
let filename = get(a:args, 0, '')
|
||||
if exists(filename) && !filewritable(filename)
|
||||
throw 'tlib#trace#Printer_file: Cannot write to file: '. filename
|
||||
else
|
||||
call writefile([a:text], filename, 'a')
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
@ -34,26 +57,58 @@ endf
|
||||
" Examples:
|
||||
" call tlib#trace#Set(["+foo", "-bar"])
|
||||
" call tlib#trace#Set("+foo,-bar")
|
||||
function! tlib#trace#Set(vars) abort "{{{3
|
||||
function! tlib#trace#Set(vars, ...) abort "{{{3
|
||||
let reset = a:0 >= 1 ? a:1 : 0
|
||||
if reset
|
||||
call tlib#trace#Reset()
|
||||
endif
|
||||
if empty(a:vars)
|
||||
return
|
||||
endif
|
||||
call tlib#trace#Enable()
|
||||
if type(a:vars) == 1
|
||||
if type(a:vars) == v:t_string
|
||||
let vars = tlib#string#SplitCommaList(a:vars, '[,[:space:]]\+')
|
||||
let opts = {}
|
||||
elseif type(a:vars) == v:t_dict
|
||||
let vars = a:vars.__rest__
|
||||
if has_key(a:vars, 'file')
|
||||
let g:tlib#trace#printer = ['file', a:vars.file]
|
||||
endif
|
||||
if has_key(a:vars, 'echo')
|
||||
let g:tlib#trace#printer = 'echom'
|
||||
endif
|
||||
else
|
||||
let vars = a:vars
|
||||
let opts = {}
|
||||
endif
|
||||
" TLogVAR vars
|
||||
for rx in vars
|
||||
let rx1 = substitute(rx, '^[+-]', '', 'g')
|
||||
if rx1 !~# '^\%(error\|fatal\)$' && s:trace_rx !~# '[(|]'. tlib#rx#Escape(rx1) .'\\'
|
||||
if rx1 !~# '^\%(error\|warn\|fatal\)$'
|
||||
let erx1 = tlib#rx#Escape(rx1)
|
||||
" TLogVAR rx, rx1
|
||||
if rx =~ '^+'
|
||||
let s:trace_rx = substitute(s:trace_rx, '\ze\\)\$', '\\|'. tlib#rx#EscapeReplace(rx1), '')
|
||||
elseif rx =~ '^-'
|
||||
let s:trace_rx = substitute(s:trace_rx, '\\|'. tlib#rx#Escape(rx1), '', '')
|
||||
" echom "DBG" s:trace_rx
|
||||
if rx =~ '^-'
|
||||
let erx1 .= '\[0-\d\]\\?'
|
||||
if s:trace_rx =~# '[(|]'. erx1 .'\\'
|
||||
let s:trace_rx = substitute(s:trace_rx, '\\|'. erx1, '', '')
|
||||
endif
|
||||
" elseif rx =~ '^+'
|
||||
else
|
||||
echohl WarningMsg
|
||||
echom 'tlib#trace#Print: Unsupported syntax:' rx
|
||||
echohl NONE
|
||||
if erx1 =~ '\d$'
|
||||
let erx1 = substitute(erx1, '\d$', '[0-\0]\\?', '')
|
||||
else
|
||||
let erx1 .= '[0-9]\?'
|
||||
endif
|
||||
if s:trace_rx !~# '[(|]'. erx1 .'\\'
|
||||
let s:trace_rx = substitute(s:trace_rx, '\ze\\)\$', '\\|'. escape(erx1, '\'), '')
|
||||
endif
|
||||
" else
|
||||
" echohl WarningMsg
|
||||
" echom 'tlib#trace#Print: Unsupported syntax:' rx
|
||||
" echohl NONE
|
||||
endif
|
||||
" echom "DBG" s:trace_rx
|
||||
endif
|
||||
endfor
|
||||
echom "SetTrace:" s:trace_rx
|
||||
@ -71,6 +126,7 @@ endf
|
||||
" Print the values of vars. The first value is a "guard" (see
|
||||
" |:Tlibtrace|).
|
||||
function! tlib#trace#Print(caller, vars, values) abort "{{{3
|
||||
" echom "DBG tlib#trace#Print" string(a:vars) string(a:values)
|
||||
let msg = ['TRACE']
|
||||
let guard = a:values[0]
|
||||
if type(guard) == 0
|
||||
@ -88,22 +144,47 @@ function! tlib#trace#Print(caller, vars, values) abort "{{{3
|
||||
call add(msg, bt .':')
|
||||
endif
|
||||
endif
|
||||
for i in range(1, len(a:vars) - 1)
|
||||
let v = substitute(a:vars[i], ',$', '', '')
|
||||
let r = string(a:values[i])
|
||||
call add(msg, v .'='. r .';')
|
||||
endfor
|
||||
exec printf(g:tlib#trace#printf, string(join(msg)))
|
||||
if len(a:vars) == len(a:values)
|
||||
for i in range(1, len(a:vars) - 1)
|
||||
let v = substitute(a:vars[i], ',$', '', '')
|
||||
if type(a:values[i]) == v:t_func
|
||||
let r = string(a:values[i])
|
||||
else
|
||||
let r = a:values[i]
|
||||
endif
|
||||
if v =~# '^\([''"]\).\{-}\1$'
|
||||
call add(msg, r .';')
|
||||
else
|
||||
call add(msg, v .'='. string(r) .';')
|
||||
endif
|
||||
unlet r
|
||||
endfor
|
||||
else
|
||||
call add(msg, join(a:values[1:-1]))
|
||||
endif
|
||||
if type(g:tlib#trace#printer) == v:t_string
|
||||
let printer = g:tlib#trace#printer
|
||||
let args = []
|
||||
else
|
||||
let [printer; args] = g:tlib#trace#printer
|
||||
endif
|
||||
call tlib#trace#Printer_{printer}(guard, join(msg), args)
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#trace#Reset() abort "{{{3
|
||||
let s:trace_rx = '^\%(error\|fatal\|warn\|info\)$'
|
||||
let g:tlib#trace#printer = 'echom'
|
||||
endf
|
||||
|
||||
|
||||
" Enable tracing via |:Tlibtrace|.
|
||||
function! tlib#trace#Enable() abort "{{{3
|
||||
if !exists('s:trace_rx')
|
||||
let s:trace_rx = '^\%(error\)$'
|
||||
call tlib#trace#Reset()
|
||||
" :nodoc:
|
||||
command! -nargs=+ -bar Tlibtrace call tlib#trace#Print(expand('<sfile>'), [<f-args>], [<args>])
|
||||
command! -nargs=+ -bang Tlibtrace call tlib#trace#Print(expand('<sfile>'), [<f-args>], [<args>])
|
||||
endif
|
||||
endf
|
||||
|
||||
@ -111,7 +192,7 @@ endf
|
||||
" Disable tracing via |:Tlibtrace|.
|
||||
function! tlib#trace#Disable() abort "{{{3
|
||||
" :nodoc:
|
||||
command! -nargs=+ -bang -bar Tlibtrace :
|
||||
command! -nargs=+ -bang Tlibtrace :
|
||||
unlet! s:trace_rx
|
||||
endf
|
||||
|
||||
|
@ -2,8 +2,30 @@
|
||||
" @Website: http://www.vim.org/account/profile.php?user_id=4037
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Created: 2007-09-30.
|
||||
" @Last Change: 2015-11-23.
|
||||
" @Revision: 6
|
||||
" @Last Change: 2017-02-22.
|
||||
" @Revision: 57
|
||||
|
||||
|
||||
let g:tlib#type#nil = []
|
||||
|
||||
|
||||
" Enable type assertiona via |:Tlibtype|.
|
||||
function! tlib#type#Enable() abort "{{{3
|
||||
" :nodoc:
|
||||
command! -nargs=+ Tlibtype call tlib#type#Check(expand('<sfile>'), [<f-args>], [<args>])
|
||||
endf
|
||||
|
||||
|
||||
" Disable type assertiona via |:Tlibtype|.
|
||||
function! tlib#type#Disable() abort "{{{3
|
||||
" :nodoc:
|
||||
command! -nargs=+ Tlibtype :
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#type#IsNil(expr) abort "{{{3
|
||||
return tlib#type#Is(a:expr, v:t_none) || a:expr is g:tlib#type#nil
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#type#IsNumber(expr)
|
||||
@ -32,25 +54,37 @@ endf
|
||||
|
||||
|
||||
function! tlib#type#Is(val, type) abort "{{{3
|
||||
if type(a:type) == 0
|
||||
let type = a:type
|
||||
elseif a:type =~? '^n\%[umber]'
|
||||
let type = 0
|
||||
elseif a:type =~? '^s\%[tring]'
|
||||
let type = 1
|
||||
elseif a:type =~? '^fu\%[ncref]'
|
||||
let type = 2
|
||||
elseif a:type =~? '^l\%[ist]'
|
||||
let type = 3
|
||||
elseif a:type =~? '^d\%[ictionary]'
|
||||
let type = 4
|
||||
elseif a:type =~? '^fl\%[oat]'
|
||||
let type = 5
|
||||
if has_key(s:schemas, a:type)
|
||||
return tlib#type#Has(a:val, a:type)
|
||||
else
|
||||
throw 'tlib#type#Is: Unknown type: ' a:type
|
||||
if type(a:type) == 0
|
||||
let type = a:type
|
||||
elseif a:type =~? '^b\%[oolean]$'
|
||||
let type = v:t_bool
|
||||
elseif a:type =~? '^c\%[hannel]$'
|
||||
let type = v:t_channel
|
||||
elseif a:type =~? '^d\%[ictionary]$'
|
||||
let type = v:t_dict
|
||||
elseif a:type =~? '^fl\%[oat]$'
|
||||
let type = v:t_float
|
||||
elseif a:type =~? '^fu\%[ncref]$'
|
||||
let type = v:t_func
|
||||
elseif a:type =~? '^j\%[ob]$'
|
||||
let type = v:t_job
|
||||
elseif a:type =~? '^l\%[ist]$'
|
||||
let type = v:t_list
|
||||
elseif a:type =~? '^\%(nil\|null\|none\)$'
|
||||
let type = v:t_none
|
||||
elseif a:type =~? '^n\%[umber]$'
|
||||
let type = v:t_number
|
||||
elseif a:type =~? '^s\%[tring]$'
|
||||
let type = v:t_string
|
||||
else
|
||||
throw 'tlib#type#Is: Unknown type: ' a:type
|
||||
endif
|
||||
Tlibtrace 'tlib', a:val, a:type, type, type(a:val), type(a:val) == a:type
|
||||
return type(a:val) == type
|
||||
endif
|
||||
" TLogVAR a:val, a:type, type, type(a:val), type(a:val) == a:type
|
||||
return type(a:val) == type
|
||||
endf
|
||||
|
||||
|
||||
@ -59,13 +93,50 @@ function! tlib#type#Are(vals, type) abort "{{{3
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#type#Has(val, lst) abort "{{{3
|
||||
return tlib#assert#All(map(a:lst, 'has_key(a:val, v:val)'))
|
||||
let s:schemas = {}
|
||||
|
||||
|
||||
function! tlib#type#Define(name, schema) abort "{{{3
|
||||
let s:schemas[a:name] = deepcopy(a:schema)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#type#Have(vals, lst) abort "{{{3
|
||||
return tlib#assert#Map(a:vals, 'tlib#type#Has(v:val,'. string(a:lst) .')')
|
||||
function! tlib#type#Has(val, schema) abort "{{{3
|
||||
Tlibtrace 'tlib', type(a:val), type(a:schema)
|
||||
if !tlib#type#IsDictionary(a:val)
|
||||
Tlibtrace 'tlib', 'not a dictionary', a:val
|
||||
return 0
|
||||
endif
|
||||
if tlib#type#IsString(a:schema)
|
||||
Tlibtrace 'tlib', a:schema
|
||||
let schema = copy(s:schemas[a:schema])
|
||||
else
|
||||
let schema = copy(a:schema)
|
||||
endif
|
||||
if tlib#type#IsDictionary(schema)
|
||||
return tlib#assert#All(map(schema, 'has_key(a:val, v:key) && tlib#type#Is(a:val[v:key], v:val)'))
|
||||
else
|
||||
Tlibtrace 'tlib', keys(a:val), schema
|
||||
return tlib#assert#All(map(schema, 'has_key(a:val, v:val)'))
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#type#Have(vals, schema) abort "{{{3
|
||||
return tlib#assert#Map(a:vals, 'tlib#type#Has(v:val,'. string(a:schema) .')')
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#type#Check(caller, names, vals) abort "{{{3
|
||||
Tlibtrace 'tlib', a:names, a:vals, len(a:names)
|
||||
for i in range(0, len(a:names) - 1, 2)
|
||||
let val = a:vals[i]
|
||||
let type = a:vals[i + 1]
|
||||
Tlibtrace 'tlib', i, val, type
|
||||
if !tlib#type#Is(val, type)
|
||||
let name = matchstr(a:names[i], '^''\zs.\{-}\ze'',\?$')
|
||||
throw 'tlib#type#Check: Type mismatch: '. name .':'. a:vals[i + 1]
|
||||
endif
|
||||
endfor
|
||||
endf
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
" @Author: Tom Link (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)
|
||||
" @Revision: 30
|
||||
" @Revision: 34
|
||||
|
||||
|
||||
" Define a variable called NAME if yet undefined.
|
||||
@ -52,10 +52,17 @@ endf
|
||||
function! tlib#var#Get(var, namespace, ...) "{{{3
|
||||
let var_ = substitute(a:var, '#', '_', 'g')
|
||||
for namespace in split(a:namespace, '\zs')
|
||||
let vname = namespace == 'g' ? a:var : var_
|
||||
let vname = namespace ==# 'g' ? a:var : var_
|
||||
let var = namespace .':'. vname
|
||||
if exists(var)
|
||||
return {var}
|
||||
elseif namespace ==# 'g'
|
||||
try
|
||||
let val = {var}
|
||||
catch /^Vim\%((\a\+)\)\=:E\(121\|15\)/
|
||||
continue
|
||||
endtry
|
||||
return val
|
||||
endif
|
||||
endfor
|
||||
return a:0 >= 1 ? a:1 : ''
|
||||
|
@ -1,8 +1,8 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Created: 2012-03-08.
|
||||
" @Last Change: 2015-11-07.
|
||||
" @Revision: 190
|
||||
" @Last Change: 2017-04-10.
|
||||
" @Revision: 224
|
||||
|
||||
scriptencoding utf-8
|
||||
|
||||
@ -14,21 +14,19 @@ TLet g:tlib#vcs#def = {
|
||||
\ 'dir': '.git',
|
||||
\ 'ls': 'git ls-files --full-name',
|
||||
\ 'ls.postprocess': '*tlib#vcs#GitLsPostprocess',
|
||||
\ 'diff': 'git diff --no-ext-diff -U0 %s'
|
||||
\ },
|
||||
\ 'diff': 'git diff --no-ext-diff -U0 %s',
|
||||
\ 'status': 'git status -s',
|
||||
\ 'status.filterrx': '^\C[ MADRCU!?]\{2}\s'},
|
||||
\ 'hg': {
|
||||
\ 'dir': '.hg',
|
||||
\ 'diff': 'hg diff -U0 %s',
|
||||
\ 'ls': 'hg manifest'
|
||||
\ },
|
||||
\ 'ls': 'hg manifest'},
|
||||
\ 'svn': {
|
||||
\ 'dir': '.svn',
|
||||
\ 'diff': 'svn diff --diff-cmd diff --extensions -U0 %s',
|
||||
\ },
|
||||
\ 'diff': 'svn diff --diff-cmd diff --extensions -U0 %s'},
|
||||
\ 'bzr': {
|
||||
\ 'dir': '.bzr',
|
||||
\ 'diff': 'bzr diff --diff-options=-U0 %s',
|
||||
\ }
|
||||
\ 'diff': 'bzr diff --diff-options=-U0 %s'}
|
||||
\ }
|
||||
|
||||
|
||||
@ -36,7 +34,7 @@ TLet g:tlib#vcs#def = {
|
||||
" empty, support for that VCS will be removed. If no key is present, it
|
||||
" is assumed that the VCS "type" is the name of the executable.
|
||||
" :display: g:tlib#vcs#executables {...}
|
||||
TLet g:tlib#vcs#executables = {}
|
||||
TLet g:tlib#vcs#executables = {}
|
||||
|
||||
|
||||
" If non-empty, use it as a format string to check whether a VCS is
|
||||
@ -60,36 +58,44 @@ function! tlib#vcs#Executable(type) "{{{3
|
||||
endf
|
||||
|
||||
|
||||
let s:vcs_cache = {}
|
||||
autocmd TLib FocusGained * let s:vcs_cache = {}
|
||||
|
||||
|
||||
function! tlib#vcs#FindVCS(filename) "{{{3
|
||||
let type = ''
|
||||
let dir = ''
|
||||
let dirname = fnamemodify(a:filename, isdirectory(a:filename) ? ':p' : ':p:h')
|
||||
let path = escape(dirname, ';') .';'
|
||||
" TLogVAR a:filename, dirname, path
|
||||
Tlibtrace 'tlib', a:filename, path
|
||||
let depth = -1
|
||||
for vcs in keys(g:tlib#vcs#def)
|
||||
let subdir = g:tlib#vcs#def[vcs].dir
|
||||
let vcsdir = finddir(subdir, path)
|
||||
" TLogVAR vcs, subdir, vcsdir
|
||||
Tlibtrace 'tlib', vcs, subdir, vcsdir
|
||||
if !empty(vcsdir)
|
||||
let vcsdir_depth = len(split(fnamemodify(vcsdir, ':p'), '\/'))
|
||||
if vcsdir_depth > depth
|
||||
let depth = vcsdir_depth
|
||||
let type = vcs
|
||||
let dir = vcsdir
|
||||
" TLogVAR type, depth
|
||||
let filename = fnamemodify(a:filename, ':p')
|
||||
let dirname = isdirectory(filename) ? filename : fnamemodify(filename, ':h')
|
||||
if !has_key(s:vcs_cache, dirname)
|
||||
let path = escape(dirname, ';') .';'
|
||||
" TLogVAR filename, dirname, path
|
||||
Tlibtrace 'tlib', filename, path
|
||||
let depth = -1
|
||||
for vcs in keys(g:tlib#vcs#def)
|
||||
let subdir = g:tlib#vcs#def[vcs].dir
|
||||
let vcsdir = finddir(subdir, path)
|
||||
" TLogVAR vcs, subdir, vcsdir
|
||||
Tlibtrace 'tlib', vcs, subdir, vcsdir
|
||||
if !empty(vcsdir)
|
||||
let vcsdir_depth = len(split(fnamemodify(vcsdir, ':p'), '\/'))
|
||||
if vcsdir_depth > depth
|
||||
let depth = vcsdir_depth
|
||||
let type = vcs
|
||||
let dir = vcsdir
|
||||
" TLogVAR type, depth
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
Tlibtrace 'tlib', type, dir
|
||||
" TLogVAR type, dir
|
||||
if empty(type)
|
||||
let s:vcs_cache[dirname] = ['', '']
|
||||
else
|
||||
let s:vcs_cache[dirname] = [type, dir]
|
||||
endif
|
||||
endfor
|
||||
Tlibtrace 'tlib', type, dir
|
||||
" TLogVAR type, dir
|
||||
if empty(type)
|
||||
return ['', '']
|
||||
else
|
||||
return [type, dir]
|
||||
endif
|
||||
return s:vcs_cache[dirname]
|
||||
endf
|
||||
|
||||
|
||||
@ -97,7 +103,7 @@ function! s:GetCmd(vcstype, cmd)
|
||||
let vcsdef = get(g:tlib#vcs#def, a:vcstype, {})
|
||||
if has_key(vcsdef, a:cmd)
|
||||
let cmd = vcsdef[a:cmd]
|
||||
if cmd =~ '^\*'
|
||||
if cmd =~# '^\*'
|
||||
let cmd = substitute(cmd, '^\*', '', '')
|
||||
else
|
||||
let bin = get(g:tlib#vcs#executables, a:vcstype, '')
|
||||
@ -134,7 +140,7 @@ function! tlib#vcs#Ls(...) "{{{3
|
||||
if !empty(ls)
|
||||
let rootdir = fnamemodify(vcsdir, ':p:h:h')
|
||||
" TLogVAR vcsdir, rootdir
|
||||
if ls =~ '%s'
|
||||
if ls =~# '%s'
|
||||
let cmd = printf(ls, shellescape(rootdir))
|
||||
else
|
||||
let cmd = ls
|
||||
@ -176,7 +182,7 @@ endf
|
||||
|
||||
|
||||
function! tlib#vcs#GitLsPostprocess(filename) abort "{{{3
|
||||
if a:filename =~ '^".\{-}"$'
|
||||
if a:filename =~# '^".\{-}"$'
|
||||
let filename = matchstr(a:filename, '^"\zs.\{-}\ze"$')
|
||||
let filename = substitute(filename, '\%(\\\@<!\\\(\d\d\d\)\)\+', '\=eval(''"''. submatch(0) .''"'')', 'g')
|
||||
" let filename = eval(a:filename)
|
||||
@ -187,3 +193,38 @@ function! tlib#vcs#GitLsPostprocess(filename) abort "{{{3
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#vcs#Status(...) abort "{{{3
|
||||
let filename = a:0 >= 1 ? a:1 : '%'
|
||||
let vcs = a:0 >= 2 ? a:2 : tlib#vcs#FindVCS(filename)
|
||||
if !empty(vcs)
|
||||
let [vcstype, vcsdir] = vcs
|
||||
let cstatus = s:GetCmd(vcstype, 'status')
|
||||
if !empty(cstatus)
|
||||
let status = exists('*systemlist') ? systemlist(cstatus) : split(system(cstatus), '\n')
|
||||
let sfilter = s:GetCmd(vcstype, 'status.filterrx')
|
||||
if !empty(sfilter)
|
||||
let status = filter(status, 'v:val =~# sfilter')
|
||||
endif
|
||||
return status
|
||||
endif
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#vcs#IsDirty(...) abort "{{{3
|
||||
let filename = a:0 >= 1 ? a:1 : '%'
|
||||
let vcs = a:0 >= 2 ? a:2 : tlib#vcs#FindVCS(filename)
|
||||
let status = tlib#vcs#Status(filename, vcs)
|
||||
return empty(status) ? '' : vcs[0] .'!'
|
||||
endf
|
||||
|
||||
|
||||
" function! tlib#vcs#EnableTStatus() abort "{{{3
|
||||
" if has('vim_starting')
|
||||
" autocmd VimEnter * TStatusregister1 --event=FocusGained,BufRead,BufWritePost %s tlib#vcs#IsDirty()
|
||||
" else
|
||||
" TStatusregister1 --event=FocusGained,BufRead,BufWritePost %s tlib#vcs#IsDirty()
|
||||
" endif
|
||||
" endf
|
||||
|
||||
|
@ -1,7 +1,12 @@
|
||||
" @Author: Tom Link (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)
|
||||
" @Revision: 55
|
||||
" @Revision: 84
|
||||
|
||||
|
||||
if !exists('g:tlib#win#use_winid')
|
||||
let g:tlib#win#use_winid = exists('*win_gotoid') && exists('*win_getid') "{{{2
|
||||
endif
|
||||
|
||||
|
||||
" Return vim code to jump back to the original window.
|
||||
@ -20,6 +25,70 @@ function! tlib#win#Set(winnr) "{{{3
|
||||
endif
|
||||
return ''
|
||||
endf
|
||||
|
||||
|
||||
if g:tlib#win#use_winid
|
||||
let g:tlib#win#null_id = -1
|
||||
function! tlib#win#GetID() abort "{{{3
|
||||
return win_getid()
|
||||
endf
|
||||
function! tlib#win#GotoID(win_id) abort "{{{3
|
||||
call win_gotoid(a:win_id)
|
||||
endf
|
||||
else
|
||||
let s:win_id = 0
|
||||
let g:tlib#win#null_id = {}
|
||||
function! tlib#win#GetID() abort "{{{3
|
||||
if !exists('w:tlib_win_id')
|
||||
let s:win_id += 1
|
||||
let w:tlib_win_id = s:win_id
|
||||
endif
|
||||
return {'tabpagenr': tabpagenr(), 'bufnr': bufnr('%'), 'winnr': winnr(), 'win_id': w:tlib_win_id}
|
||||
endf
|
||||
function! tlib#win#GotoID(win_id) abort "{{{3
|
||||
Tlibtrace 'tlib', a:win_id
|
||||
if tabpagenr() != a:win_id.tabpagenr
|
||||
exec 'tabnext' a:win_id.tabpagenr
|
||||
endif
|
||||
for wnr in range(1, winnr('$'))
|
||||
let win_id = getwinvar(wnr, 'tlib_win_id', -1)
|
||||
Tlibtrace 'tlib', wnr, win_id
|
||||
if win_id == a:win_id.win_id
|
||||
Tlibtrace 'tlib', wnr
|
||||
exec wnr 'wincmd w'
|
||||
return
|
||||
endif
|
||||
endfor
|
||||
" Was the window closed? What should we do now?
|
||||
if winnr() != a:win_id.winnr
|
||||
exec a:win_id.winnr 'wincmd w'
|
||||
endif
|
||||
if bufnr('%') != a:win_id.bufnr
|
||||
exec 'hide buffer' a:win_id.bufnr
|
||||
endif
|
||||
endf
|
||||
endif
|
||||
|
||||
|
||||
" Return vim code to jump back to the original window.
|
||||
function! tlib#win#SetById(win_id) "{{{3
|
||||
if a:win_id != g:tlib#win#null_id
|
||||
let win_id = tlib#win#GetID()
|
||||
call tlib#win#GotoID(a:win_id)
|
||||
return printf('call tlib#win#GotoID(%s)', win_id)
|
||||
" " TLogVAR a:winnr
|
||||
" " TLogDBG winnr()
|
||||
" " TLogDBG string(tlib#win#List())
|
||||
" if winnr() != a:winnr && winbufnr(a:winnr) != -1
|
||||
" let rv = winnr().'wincmd w'
|
||||
" exec a:winnr .'wincmd w'
|
||||
" " TLogVAR rv
|
||||
" " TLogDBG string(tlib#win#List())
|
||||
" return rv
|
||||
" endif
|
||||
endif
|
||||
return ''
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#win#GetLayout(?save_view=0)
|
||||
|
Reference in New Issue
Block a user