mirror of
https://github.com/amix/vimrc
synced 2025-06-16 01:25:00 +08:00
Updated plugins
This commit is contained in:
@ -1,10 +1,7 @@
|
||||
" tlib.vim
|
||||
" @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)
|
||||
" @Created: 2007-07-17.
|
||||
" @Last Change: 2013-09-25.
|
||||
" @Revision: 0.0.12
|
||||
" @Revision: 13
|
||||
|
||||
" :nodefault:
|
||||
TLet g:tlib#debug = 0
|
||||
|
@ -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-06-02.
|
||||
" @Revision: 0.0.109
|
||||
" @Last Change: 2014-11-18.
|
||||
" @Revision: 0.0.114
|
||||
|
||||
let s:prototype = tlib#Object#New({'_class': ['Filter_cnf'], 'name': 'cnf'}) "{{{2
|
||||
let s:prototype.highlight = g:tlib#input#higroup
|
||||
|
@ -2,8 +2,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-01-23.
|
||||
" @Revision: 0.0.80
|
||||
" @Last Change: 2014-11-18.
|
||||
" @Revision: 0.0.82
|
||||
|
||||
let s:prototype = tlib#Filter_cnf#New({'_class': ['Filter_glob'], 'name': 'glob'}) "{{{2
|
||||
let s:prototype.highlight = g:tlib#input#higroup
|
||||
@ -61,8 +61,8 @@ endf
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.CleanFilter(filter) dict "{{{3
|
||||
let filter = substitute(a:filter, '\\.\\{-}', g:tlib#Filter_glob#seq, 'g')
|
||||
let filter = substitute(filter, '\\.', g:tlib#Filter_glob#char, 'g')
|
||||
let filter = substitute(a:filter, '\\\.\\{-}', g:tlib#Filter_glob#seq, 'g')
|
||||
let filter = substitute(filter, '\\\.', g:tlib#Filter_glob#char, 'g')
|
||||
return filter
|
||||
endf
|
||||
|
||||
|
@ -1,20 +1,11 @@
|
||||
" Object.vim -- Prototype objects?
|
||||
" @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)
|
||||
" @Created: 2007-05-01.
|
||||
" @Last Change: 2011-03-10.
|
||||
" @Revision: 0.1.126
|
||||
" @Revision: 127
|
||||
|
||||
" :filedoc:
|
||||
" Provides a prototype plus some OO-like methods.
|
||||
|
||||
|
||||
if &cp || exists("loaded_tlib_object_autoload")
|
||||
finish
|
||||
endif
|
||||
let loaded_tlib_object_autoload = 1
|
||||
|
||||
let s:id_counter = 0
|
||||
let s:prototype = {'_class': ['object'], '_super': [], '_id': 0} "{{{2
|
||||
|
||||
|
@ -1,18 +1,10 @@
|
||||
" Test.vim -- A test class
|
||||
" @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)
|
||||
" @Created: 2007-05-01.
|
||||
" @Last Change: 2010-09-05.
|
||||
" @Revision: 0.1.10
|
||||
" @Revision: 11
|
||||
|
||||
" :enddoc:
|
||||
|
||||
if &cp || exists("loaded_tlib_Test_autoload")
|
||||
finish
|
||||
endif
|
||||
let loaded_tlib_Test_autoload = 1
|
||||
|
||||
|
||||
let s:prototype = tlib#Object#New({'_class': ['Test']}) "{{{2
|
||||
function! tlib#Test#New(...) "{{{3
|
||||
|
@ -1,18 +1,10 @@
|
||||
" TestChild.vim
|
||||
" @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)
|
||||
" @Created: 2007-05-18.
|
||||
" @Last Change: 2010-09-05.
|
||||
" @Revision: 0.1.14
|
||||
" @Revision: 15
|
||||
|
||||
" :enddoc:
|
||||
|
||||
if &cp || exists("loaded_tlib_TestChild_autoload")
|
||||
finish
|
||||
endif
|
||||
let loaded_tlib_TestChild_autoload = 1
|
||||
|
||||
|
||||
let s:prototype = tlib#Test#New({'_class': ['TestChild']}) "{{{2
|
||||
function! tlib#TestChild#New(...) "{{{3
|
||||
|
@ -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: 1397
|
||||
" @Revision: 1432
|
||||
|
||||
" :filedoc:
|
||||
" A prototype used by |tlib#input#List|.
|
||||
@ -359,6 +359,7 @@ endf
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.SelectItem(mode, index) dict "{{{3
|
||||
" TLogVAR a:mode, a:index
|
||||
let bi = self.GetBaseIdx(a:index)
|
||||
" if self.RespondTo('MaySelectItem')
|
||||
" if !self.MaySelectItem(bi)
|
||||
@ -378,6 +379,14 @@ function! s:prototype.SelectItem(mode, index) dict "{{{3
|
||||
endf
|
||||
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.FormatBaseFromData() abort dict "{{{3
|
||||
if has_key(self, 'format_data') && has_key(self, 'data')
|
||||
let self.base = map(copy(self.data), 'call(self.format_data, [v:val], self)')
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.FormatArgs(format_string, arg) dict "{{{3
|
||||
let nargs = len(substitute(a:format_string, '%%\|[^%]', '', 'g'))
|
||||
@ -603,11 +612,13 @@ endf
|
||||
" :nodoc:
|
||||
function! s:prototype.IsValidFilter() dict "{{{3
|
||||
let last = self.FilterRxPrefix() .'\('. self.filter[0][0] .'\)'
|
||||
Tlibtrace 'tlib', last
|
||||
" TLogVAR last
|
||||
try
|
||||
let a = match("", last)
|
||||
return 1
|
||||
catch
|
||||
Tlibtrace 'tlib', v:exception
|
||||
return 0
|
||||
endtry
|
||||
endf
|
||||
@ -673,13 +684,19 @@ endf
|
||||
" :nodoc:
|
||||
function! s:prototype.ReduceFilter() dict "{{{3
|
||||
" TLogVAR self.filter
|
||||
if self.filter[0] == [''] && len(self.filter) > 1
|
||||
call remove(self.filter, 0)
|
||||
elseif empty(self.filter[0][0]) && len(self.filter[0]) > 1
|
||||
call remove(self.filter[0], 0)
|
||||
else
|
||||
call self.matcher.ReduceFrontFilter(self)
|
||||
endif
|
||||
let reduced = 0
|
||||
while !reduced
|
||||
if self.filter[0] == [''] && len(self.filter) > 1
|
||||
call remove(self.filter, 0)
|
||||
elseif empty(self.filter[0][0]) && len(self.filter[0]) > 1
|
||||
call remove(self.filter[0], 0)
|
||||
else
|
||||
call self.matcher.ReduceFrontFilter(self)
|
||||
endif
|
||||
if self.IsValidFilter()
|
||||
let reduced = 1
|
||||
endif
|
||||
endwh
|
||||
endf
|
||||
|
||||
|
||||
@ -687,6 +704,7 @@ endf
|
||||
" filter is either a string or a list of list of strings.
|
||||
function! s:prototype.SetInitialFilter(filter) dict "{{{3
|
||||
" let self.initial_filter = [[''], [a:filter]]
|
||||
Tlibtrace 'tlib', a:filter
|
||||
if type(a:filter) == 3
|
||||
let self.initial_filter = deepcopy(a:filter)
|
||||
else
|
||||
@ -816,10 +834,18 @@ function! s:prototype.UseInputListScratch() dict "{{{3
|
||||
if !exists('w:tlib_list_init')
|
||||
" TLogVAR scratch
|
||||
if has_key(self, 'index_next_syntax')
|
||||
exec 'syntax match InputlListIndex /^\d\+:\s/ nextgroup='. self.index_next_syntax
|
||||
if type(self.index_next_syntax) == 1
|
||||
exec 'syntax match InputlListIndex /^\d\+:\s/ nextgroup='. self.index_next_syntax
|
||||
elseif type(self.index_next_syntax) == 4
|
||||
for [n, nsyn] in items(self.index_next_syntax)
|
||||
let fn = printf('%0'. world.index_width .'d', n)
|
||||
exec 'syntax match InputlListIndex /^'. fn .':\s/ nextgroup='. nsyn
|
||||
endfor
|
||||
endif
|
||||
else
|
||||
syntax match InputlListIndex /^\d\+:\s/
|
||||
endif
|
||||
call tlib#hook#Run('tlib_UseInputListScratch', self)
|
||||
syntax match InputlListCursor /^\d\+\* .*$/ contains=InputlListIndex
|
||||
syntax match InputlListSelected /^\d\+# .*$/ contains=InputlListIndex
|
||||
hi def link InputlListIndex Constant
|
||||
@ -830,7 +856,6 @@ function! s:prototype.UseInputListScratch() dict "{{{3
|
||||
" let b:tlibDisplayListMarks = {}
|
||||
let b:tlibDisplayListMarks = []
|
||||
let b:tlibDisplayListWorld = self
|
||||
call tlib#hook#Run('tlib_UseInputListScratch', self)
|
||||
let w:tlib_list_init = 1
|
||||
endif
|
||||
return scratch
|
||||
@ -842,6 +867,7 @@ endf
|
||||
function! s:prototype.Reset(...) dict "{{{3
|
||||
TVarArg ['initial', 0]
|
||||
" TLogVAR initial
|
||||
Tlibtrace 'tlib', initial, self.initial_filter
|
||||
let self.state = 'display'
|
||||
let self.offset = 1
|
||||
let self.filter = deepcopy(self.initial_filter)
|
||||
@ -853,6 +879,7 @@ function! s:prototype.Reset(...) dict "{{{3
|
||||
call self.UseInputListScratch()
|
||||
call self.ResetSelected()
|
||||
call self.Retrieve(!initial)
|
||||
call self.FormatBaseFromData()
|
||||
return self
|
||||
endf
|
||||
|
||||
@ -977,6 +1004,7 @@ function! s:prototype.DisplayHelp() dict "{{{3
|
||||
call self.PushHelp('Mouse', 'L: Pick item, R: Show menu')
|
||||
call self.PushHelp('<M-Number>', 'Select an item')
|
||||
call self.PushHelp('<BS>, <C-BS>', 'Reduce filter')
|
||||
call self.PushHelp('<Tab>', 'Complete word')
|
||||
call self.PushHelp('<S-Esc>, <F10>', 'Enter command')
|
||||
|
||||
if self.key_mode == 'default'
|
||||
@ -1214,10 +1242,11 @@ endf
|
||||
|
||||
" :nodoc:
|
||||
function! s:prototype.Query() dict "{{{3
|
||||
let flt = self.DisplayFilter()
|
||||
if g:tlib_inputlist_shortmessage
|
||||
let query = 'Filter: '. self.DisplayFilter()
|
||||
let query = 'Filter: '. flt
|
||||
else
|
||||
let query = self.query .' (filter: '. self.DisplayFilter() .'; press <F1> for help)'
|
||||
let query = self.query .' (filter: '. flt .'; press <F1> for help)'
|
||||
endif
|
||||
return query
|
||||
endf
|
||||
|
@ -1,10 +1,7 @@
|
||||
" agent.vim
|
||||
" @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)
|
||||
" @Created: 2007-06-24.
|
||||
" @Last Change: 2014-02-06.
|
||||
" @Revision: 0.1.251
|
||||
" @Revision: 328
|
||||
|
||||
|
||||
" :filedoc:
|
||||
@ -414,14 +411,17 @@ function! tlib#agent#ViewFile(world, selected) "{{{3
|
||||
if !empty(a:selected)
|
||||
let back = a:world.SwitchWindow('win')
|
||||
" TLogVAR back
|
||||
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)
|
||||
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
|
||||
let a:world.state = 'display'
|
||||
@ -612,3 +612,53 @@ function! tlib#agent#CompleteAgentNames(ArgLead, CmdLine, CursorPos)
|
||||
return filter(copy(s:agent_names), 'stridx(v:val, a:ArgLead) != -1')
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#agent#Complete(world, selected) abort "{{{3
|
||||
let rxprefix = a:world.matcher.FilterRxPrefix()
|
||||
let flt = a:world.filter[0][0]
|
||||
" TLogVAR flt
|
||||
let fltrx = rxprefix . flt . '\m[^[:space:][:cntrl:][:punct:]<>*+?&~{}()\[\]\\/]\+'
|
||||
let fltrx0 = '\m^' . fltrx
|
||||
" TLogVAR fltrx, fltrx0
|
||||
let words = {}
|
||||
for item in a:world.list
|
||||
let parts = split(item, '\ze'. fltrx)
|
||||
" TLogVAR item, parts
|
||||
for part in parts
|
||||
let word = matchstr(part, fltrx0)
|
||||
" TLogVAR part, word
|
||||
if !empty(word)
|
||||
let words[word] = 1
|
||||
endif
|
||||
endfor
|
||||
endfor
|
||||
" TLogVAR 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
|
||||
while len(completions) > 1
|
||||
let nchar = strwidth(completions[0]) - 1
|
||||
let completions = map(completions, 'strpart(v:val, 0, nchar)')
|
||||
" TLogVAR 'reduce', completions
|
||||
let completions = tlib#list#Uniq(completions)
|
||||
" TLogVAR 'unique', len(completions), completions
|
||||
endwh
|
||||
" TLogVAR 9, completions
|
||||
if empty(completions)
|
||||
let a:world.state = 'redisplay update'
|
||||
else
|
||||
let a:world.filter[0][0] = completions[0]
|
||||
let a:world.state = 'display update'
|
||||
endif
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! s:SortCompletions(a, b) abort "{{{3
|
||||
let i1 = strwidth(a:a)
|
||||
let i2 = strwidth(a:b)
|
||||
return i2 - i1
|
||||
endf
|
||||
|
||||
|
@ -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: 2014-07-01.
|
||||
" @Revision: 63
|
||||
" @Last Change: 2015-11-19.
|
||||
" @Revision: 251
|
||||
|
||||
|
||||
" :def: function! tlib#arg#Get(n, var, ?default="", ?test='')
|
||||
@ -31,30 +31,25 @@ function! tlib#arg#Let(list, ...) "{{{3
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#arg#Key(dict, list, ?default='')
|
||||
" See |:TKeyArg|.
|
||||
function! tlib#arg#Key(list, ...) "{{{3
|
||||
let default = a:0 >= 1 ? a:1 : ''
|
||||
let dict = a:list[0]
|
||||
let list = map(copy(a:list[1:-1]), 'type(v:val) == 3 ? v:val : [v:val, default]')
|
||||
let args = map(list, '"let ". v:val[0] ." = ". string(get(dict, v:val[0], v:val[1]))')
|
||||
" TLogVAR dict, list, args
|
||||
return join(args, ' | ')
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#arg#StringAsKeyArgs(string, ?keys=[], ?evaluate=0, ?sep=':')
|
||||
" :def: function! tlib#arg#StringAsKeyArgs(string, ?keys=[], ?evaluate=0, ?sep=':', ?booleans=0)
|
||||
function! tlib#arg#StringAsKeyArgs(string, ...) "{{{1
|
||||
TVarArg ['keys', {}], ['evaluate', 0], ['sep', ':']
|
||||
TVarArg ['keys', {}], ['evaluate', 0], ['sep', ':'], ['booleans', 0]
|
||||
let keyargs = {}
|
||||
let args = split(a:string, '\\\@<! ')
|
||||
let arglist = map(args, 'matchlist(v:val, ''^\%(\(\w\+\)'. sep .'\(.*\)\|\(.*\)\)$'')')
|
||||
let key_rx = booleans ? '\([-+]\?\w\+\)' : '\(\w\+\)'
|
||||
let arglist = map(args, 'matchlist(v:val, ''^\%('. key_rx . sep .'\(.*\)\|\(.*\)\)$'')')
|
||||
" TLogVAR a:string, args, arglist
|
||||
let pos = 0
|
||||
let pos = -1
|
||||
for matchlist in arglist
|
||||
if !empty(matchlist[3])
|
||||
let keyargs[pos] = matchlist[3]
|
||||
let pos += 1
|
||||
if booleans && matchlist[3] =~ '^[-+]'
|
||||
let key = substitute(matchlist[3], '^[-+]', '', '')
|
||||
let val = matchstr(matchlist[3], '^[-+]')
|
||||
let keyargs[key] = val ==# '+'
|
||||
else
|
||||
let pos += 1
|
||||
let keyargs[pos] = matchlist[3]
|
||||
endif
|
||||
else
|
||||
let [match, key, val; rest] = matchlist
|
||||
if empty(keys) || has_key(keys, key)
|
||||
@ -68,12 +63,242 @@ function! tlib#arg#StringAsKeyArgs(string, ...) "{{{1
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
if pos >= 0
|
||||
let keyargs['__posargs__'] = range(0, pos)
|
||||
endif
|
||||
return keyargs
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#arg#StringAsKeyArgsEqual(string) "{{{1
|
||||
return tlib#arg#StringAsKeyArgs(a:string, [], 0, '=')
|
||||
return tlib#arg#StringAsKeyArgs(a:string, [], 0, '=', 1)
|
||||
endf
|
||||
|
||||
|
||||
" :display: tlib#arg#GetOpts(args, ?def={})
|
||||
" Convert a list of strings of command-line arguments into a dictonary.
|
||||
"
|
||||
" The main use case is to pass [<f-args>], i.e. the command-line
|
||||
" arguments of a command as list, from a command definition to this
|
||||
" function.
|
||||
"
|
||||
" Example:
|
||||
" ['-h']
|
||||
" => If def contains a 'help' key, invoke |:help| on its value.
|
||||
"
|
||||
" ['-ab', '--foo', '--bar=BAR', 'bla', bla']
|
||||
" => {'a': 1, 'b': 1, 'foo': 1, 'bar': 'BAR', '__rest__': ['bla', 'bla']}
|
||||
"
|
||||
" ['-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
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
let opts.__rest__ = a:args[idx : -1]
|
||||
return opts
|
||||
endf
|
||||
|
||||
|
||||
function! s:GetValueType(def) abort "{{{3
|
||||
return get(a:def, 'type', type(get(a:def, 'default', '')))
|
||||
endf
|
||||
|
||||
|
||||
function! s:SetOpt(def, opts, idx, opt) abort "{{{3
|
||||
" TLogVAR a:def
|
||||
let idx = a:idx + 1
|
||||
let break = 0
|
||||
let long = get(a:def, 'long', 1)
|
||||
let short = get(a:def, 'short', 1)
|
||||
if (short && a:opt =~# '^-[?h]$') || (long && a:opt ==# '--help')
|
||||
if has_key(a:def, 'help')
|
||||
exec 'help' a:def.help
|
||||
else
|
||||
" TLogVAR a:def
|
||||
let values = get(a:def, 'values', {})
|
||||
let flags = get(a:def, 'flags', {})
|
||||
if empty(values) && empty(flags)
|
||||
echom 'No help'
|
||||
else
|
||||
if !empty(values)
|
||||
echom 'Options:'
|
||||
for [key, vdef] in sort(items(values))
|
||||
let opt = key
|
||||
let default = get(vdef, 'default', '')
|
||||
let type = s:GetValueType(vdef)
|
||||
if default =~ '^-\?\d\+\%(\.\d\+\)$'
|
||||
if type == -1
|
||||
let opt .= ' (flag)'
|
||||
elseif type == 1
|
||||
let opt .= '=INT'
|
||||
else
|
||||
let opt .= '=INT or maybe BOOL'
|
||||
endif
|
||||
elseif type(default) == 1
|
||||
let opt .= '=STRING'
|
||||
elseif type(default) == 3
|
||||
let opt .= '=COMMA-LIST'
|
||||
endif
|
||||
echom printf(' --%20s (default: %s)', opt, string(default))
|
||||
endfor
|
||||
endif
|
||||
if !empty(flags)
|
||||
echom 'Short flags:'
|
||||
for [sflag, lflag] in sort(items(flags))
|
||||
echom printf(' -%s -> %s', sflag, lflag)
|
||||
endfor
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
let break = 2
|
||||
elseif long && a:opt =~# '^--no-.\+'
|
||||
let key = matchstr(a:opt, '^--no-\zs.\+$')
|
||||
let a:opts[key] = s:Validate(a:def, key, 0)
|
||||
elseif long && a:opt =~# '^--\w\+$'
|
||||
let key = matchstr(a:opt, '^--\zs.\+$')
|
||||
let a:opts[key] = s:Validate(a:def, key, 1)
|
||||
elseif long && a:opt =~# '^--\w\+='
|
||||
let ml = matchlist(a:opt, '^--\(\w\+\)=\(.*\)$')
|
||||
if empty(ml)
|
||||
throw 'tlib#arg#GetOpts: Cannot parse: '. a:opt
|
||||
else
|
||||
let values = get(a:def, 'values', {})
|
||||
if has_key(values, ml[1])
|
||||
let vdef = values[ml[1]]
|
||||
let type = s:GetValueType(vdef)
|
||||
if type == -1
|
||||
let opt_value = !!str2nr(ml[2])
|
||||
elseif type == 0
|
||||
let opt_value = str2nr(ml[2])
|
||||
elseif type == 1
|
||||
let opt_value = ml[2]
|
||||
elseif type == 2
|
||||
let opt_value = function(ml[2])
|
||||
elseif type == 3
|
||||
let opt_value = tlib#string#SplitCommaList(ml[2])
|
||||
elseif type == 4
|
||||
throw 'tlib#arg#GetOpts: Unsupported type conversion for '. ml[1]
|
||||
elseif type == 5
|
||||
let opt_value = str2float(ml[2])
|
||||
endif
|
||||
else
|
||||
let opt_value = ml[2]
|
||||
endif
|
||||
let a:opts[ml[1]] = s:Validate(a:def, ml[1], opt_value)
|
||||
unlet opt_value
|
||||
endif
|
||||
elseif short && a:opt =~# '^-\w='
|
||||
let flagdefs = get(a:def, 'flags', {})
|
||||
let flag = matchstr(a:opt, '^-\zs\w')
|
||||
let rest = matchstr(a:opt, '^-\w\zs.*$')
|
||||
call s:SetFlag(a:def, a:opts, idx, flag, rest, flagdefs)
|
||||
elseif short && a:opt =~# '^-\w\+$'
|
||||
let flagdefs = get(a:def, 'flags', {})
|
||||
for flag in split(substitute(a:opt, '^-', '', ''), '\zs')
|
||||
call s:SetFlag(a:def, a:opts, idx, flag, '', flagdefs)
|
||||
endfor
|
||||
else
|
||||
let break = 1
|
||||
if a:opt !=# '--'
|
||||
let idx -= 1
|
||||
endif
|
||||
endif
|
||||
return [break, idx]
|
||||
endf
|
||||
|
||||
|
||||
function! s:SetFlag(def, opts, idx, flag, rest, flagdefs) abort "{{{3
|
||||
" TLogVAR a:def
|
||||
if has_key(a:flagdefs, a:flag)
|
||||
call s:SetOpt(a:def, a:opts, a:idx, a:flagdefs[a:flag] . a:rest)
|
||||
else
|
||||
let a:opts[a:flag] = s:Validate(a:def, a:flag, 1)
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! s:Validate(def, name, value) abort "{{{3
|
||||
let values = get(a:def, 'values', {})
|
||||
if has_key(values, a:name)
|
||||
let vdef = values[a:name]
|
||||
if has_key(vdef, 'validate')
|
||||
if !call(vdef.validate, [a:value])
|
||||
throw printf('tlib#arg: %s has invalid value: %s', string(a:name), string(a:value))
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
return a:value
|
||||
endf
|
||||
|
||||
|
||||
":nodoc:
|
||||
function! tlib#arg#CComplete(def, ArgLead) abort "{{{3
|
||||
let values = get(a:def, 'values', {})
|
||||
let opt = matchstr(a:ArgLead, '^--\zs\w\+\ze=')
|
||||
if has_key(values, opt)
|
||||
let words = []
|
||||
let vals = values[opt]
|
||||
let complete_customlist = get(vals, 'complete_customlist', '')
|
||||
if !empty(complete_customlist)
|
||||
let words = eval(complete_customlist)
|
||||
" else
|
||||
" let complete = get(vals, 'complete', '')
|
||||
" if !empty(complete)
|
||||
" endif
|
||||
endif
|
||||
if !empty(words)
|
||||
let lead = substitute(a:ArgLead, '^--\w\+=', '', '')
|
||||
if !empty(lead)
|
||||
let nchar = len(lead)
|
||||
call filter(words, 'strpart(v:val, 0, nchar) ==# lead')
|
||||
endif
|
||||
let words = map(words, '"--". opt ."=". v:val')
|
||||
return sort(words)
|
||||
endif
|
||||
endif
|
||||
let cs = {'-h': 1, '--help': 1}
|
||||
for [name, vdef] in items(values)
|
||||
let type = s:GetValueType(vdef)
|
||||
if type >= 0
|
||||
let name .= '='
|
||||
else
|
||||
let cs['--no-'. name] = 1
|
||||
endif
|
||||
let cs['--'. name] = 1
|
||||
endfor
|
||||
for [name, subst] in items(get(a:def, 'flags', {}))
|
||||
let ldef = get(values, substitute(subst, '^--', '', ''), {})
|
||||
let type = s:GetValueType(ldef)
|
||||
if type >= 0
|
||||
let name .= '='
|
||||
endif
|
||||
let cs['-'. name] = 1
|
||||
endfor
|
||||
let nchar = len(a:ArgLead)
|
||||
if nchar > 0
|
||||
call filter(cs, 'strpart(v:key, 0, nchar) ==# a:ArgLead')
|
||||
endif
|
||||
return sort(keys(cs))
|
||||
endf
|
||||
|
||||
|
||||
|
44
sources_non_forked/tlib/autoload/tlib/assert.vim
Normal file
44
sources_non_forked/tlib/autoload/tlib/assert.vim
Normal file
@ -0,0 +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-11-23
|
||||
" @Revision: 38
|
||||
|
||||
|
||||
" Enable tracing via |:Tlibassert|.
|
||||
function! tlib#assert#Enable() abort "{{{3
|
||||
" :nodoc:
|
||||
command! -nargs=+ -bar 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 :
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#assert#Assert(caller, check, vals) abort "{{{3
|
||||
for val in a:vals
|
||||
" TLogVAR val
|
||||
if type(val) == 3
|
||||
call tlib#assert#Assert(a:caller, a:check, val)
|
||||
elseif !val
|
||||
throw 'Tlibassert: '. tlib#trace#Backtrace(a:caller) .': '. a:check
|
||||
endif
|
||||
endfor
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#assert#Map(vals, expr) abort "{{{3
|
||||
return tlib#assert#All(map(a:vals, a:expr))
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#assert#All(vals) abort "{{{3
|
||||
" TLogVAR a:vals, empty(filter(a:vals, '!v:val'))
|
||||
return empty(filter(a:vals, '!v:val'))
|
||||
endf
|
||||
|
||||
|
@ -3,8 +3,8 @@
|
||||
" @GIT: http://github.com/tomtom/tlib_vim/
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Created: 2010-08-30.
|
||||
" @Last Change: 2010-09-05.
|
||||
" @Revision: 27
|
||||
" @Last Change: 2015-11-23.
|
||||
" @Revision: 48
|
||||
|
||||
|
||||
function! tlib#balloon#Register(expr) "{{{3
|
||||
@ -30,8 +30,13 @@ endf
|
||||
|
||||
|
||||
function! tlib#balloon#Remove(expr) "{{{3
|
||||
if !exists('b:tlib_balloons')
|
||||
if exists('b:tlib_balloons')
|
||||
call filter(b:tlib_balloons, 'v:val != a:expr')
|
||||
if empty(b:tlib_balloons)
|
||||
setlocal ballooneval&
|
||||
setlocal balloonexpr&
|
||||
unlet b:tlib_balloons
|
||||
endif
|
||||
endif
|
||||
endf
|
||||
|
||||
@ -52,3 +57,17 @@ function! tlib#balloon#Expr() "{{{3
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#balloon#Expand(expr) abort "{{{3
|
||||
if v:beval_bufnr != bufnr('%')
|
||||
" TLogVAR v:beval_bufnr, bufnr('%')
|
||||
return ''
|
||||
endif
|
||||
let win = winsaveview()
|
||||
try
|
||||
call setpos('.', [v:beval_bufnr, v:beval_lnum, v:beval_col, 0])
|
||||
return expand(a:expr)
|
||||
finally
|
||||
call winrestview(win)
|
||||
endtry
|
||||
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: 2013-09-25.
|
||||
" @Revision: 0.0.352
|
||||
" @Last Change: 2015-11-06.
|
||||
" @Revision: 7.1.352
|
||||
|
||||
|
||||
" Where to display the line when using |tlib#buffer#ViewLine|.
|
||||
@ -160,7 +160,7 @@ function! tlib#buffer#GetList(...)
|
||||
elseif order == 'basename'
|
||||
call sort(buffer_list, function('s:CompareBuffernameByBasename'))
|
||||
endif
|
||||
let buffer_nr = map(copy(buffer_list), 'matchstr(v:val, ''\s*\zs\d\+\ze'')')
|
||||
let buffer_nr = map(copy(buffer_list), 'str2nr(matchstr(v:val, ''\s*\zs\d\+\ze''))')
|
||||
" TLogVAR buffer_list, buffer_nr
|
||||
if show_number
|
||||
call map(buffer_list, 'matchstr(v:val, ''^\s*\d\+.\{-}\ze\s\+\S\+ \d\+\s*$'')')
|
||||
@ -201,7 +201,7 @@ endf
|
||||
|
||||
|
||||
function! s:UndoHighlightLine() "{{{3
|
||||
3match none
|
||||
2match none
|
||||
autocmd! TLib CursorMoved,CursorMovedI <buffer>
|
||||
autocmd! TLib CursorHold,CursorHoldI <buffer>
|
||||
autocmd! TLib InsertEnter,InsertChange,InsertLeave <buffer>
|
||||
@ -211,8 +211,8 @@ endf
|
||||
|
||||
function! tlib#buffer#HighlightLine(...) "{{{3
|
||||
TVarArg ['line', line('.')]
|
||||
" exec '3match MatchParen /^\%'. a:line .'l.*/'
|
||||
exec '3match Search /^\%'. line .'l.*/'
|
||||
" exec '2match MatchParen /^\%'. a:line .'l.*/'
|
||||
exec '2match Search /^\%'. line .'l.*/'
|
||||
call tlib#autocmdgroup#Init()
|
||||
exec 'autocmd TLib CursorMoved,CursorMovedI <buffer> if line(".") != '. line .' | call s:UndoHighlightLine() | endif'
|
||||
autocmd TLib CursorHold,CursorHoldI <buffer> call s:UndoHighlightLine()
|
||||
@ -276,27 +276,28 @@ endf
|
||||
function! tlib#buffer#InsertText(text, ...) "{{{3
|
||||
TVarArg ['keyargs', {}]
|
||||
" TLogVAR a:text, keyargs
|
||||
TKeyArg keyargs, ['shift', 0], ['col', col('.')], ['lineno', line('.')], ['pos', 'e'],
|
||||
\ ['indent', 0]
|
||||
" TLogVAR shift, col, lineno, pos, indent
|
||||
let keyargs = extend({
|
||||
\ 'shift': 0, 'col': col('.'), 'lineno': line('.'), 'pos': 'e', 'indent': 0
|
||||
\ }, keyargs)
|
||||
" TLogVAR keyargs
|
||||
let grow = 0
|
||||
let post_del_last_line = line('$') == 1
|
||||
let line = getline(lineno)
|
||||
if col + shift > 0
|
||||
let pre = line[0 : (col - 1 + shift)]
|
||||
let post = line[(col + shift): -1]
|
||||
let line = getline(keyargs.lineno)
|
||||
if keyargs.col + keyargs.shift > 0
|
||||
let pre = line[0 : (keyargs.col - 1 + keyargs.shift)]
|
||||
let post = line[(keyargs.col + keyargs.shift): -1]
|
||||
else
|
||||
let pre = ''
|
||||
let post = line
|
||||
endif
|
||||
" TLogVAR lineno, line, pre, post
|
||||
" TLogVAR keyargs.lineno, line, pre, post
|
||||
let text0 = pre . a:text . post
|
||||
let text = split(text0, '\n', 1)
|
||||
" TLogVAR text
|
||||
let icol = len(pre)
|
||||
" exec 'norm! '. lineno .'G'
|
||||
call cursor(lineno, col)
|
||||
if indent && col > 1
|
||||
" exec 'norm! '. keyargs.lineno .'G'
|
||||
call cursor(keyargs.lineno, keyargs.col)
|
||||
if keyargs.indent && keyargs.col > 1
|
||||
if &fo =~# '[or]'
|
||||
" FIXME: Is the simple version sufficient?
|
||||
" VERSION 1
|
||||
@ -306,13 +307,13 @@ function! tlib#buffer#InsertText(text, ...) "{{{3
|
||||
" norm! a
|
||||
" "norm! o
|
||||
" " TAssertExec redraw | sleep 3
|
||||
" let idt = strpart(getline('.'), 0, col('.') + shift)
|
||||
" let idt = strpart(getline('.'), 0, keyargs.col('.') + keyargs.shift)
|
||||
" " TLogVAR idt
|
||||
" let idtl = len(idt)
|
||||
" -1,.delete
|
||||
" " TAssertExec redraw | sleep 3
|
||||
" call append(lineno - 1, cline)
|
||||
" call cursor(lineno, col)
|
||||
" call append(keyargs.lineno - 1, cline)
|
||||
" call cursor(keyargs.lineno, keyargs.col)
|
||||
" " TAssertExec redraw | sleep 3
|
||||
" if idtl == 0 && icol != 0
|
||||
" let idt = matchstr(pre, '^\s\+')
|
||||
@ -336,27 +337,27 @@ function! tlib#buffer#InsertText(text, ...) "{{{3
|
||||
endfor
|
||||
endif
|
||||
" TLogVAR text
|
||||
" exec 'norm! '. lineno .'Gdd'
|
||||
" exec 'norm! '. keyargs.lineno .'Gdd'
|
||||
call tlib#normal#WithRegister('"tdd', 't')
|
||||
call append(lineno - 1, text)
|
||||
call append(keyargs.lineno - 1, text)
|
||||
if post_del_last_line
|
||||
call tlib#buffer#KeepCursorPosition('$delete')
|
||||
endif
|
||||
let tlen = len(text)
|
||||
let posshift = matchstr(pos, '\d\+')
|
||||
" TLogVAR pos
|
||||
if pos =~ '^e'
|
||||
exec lineno + tlen - 1
|
||||
let posshift = matchstr(keyargs.pos, '\d\+')
|
||||
" TLogVAR keyargs.pos
|
||||
if keyargs.pos =~ '^e'
|
||||
exec keyargs.lineno + tlen - 1
|
||||
exec 'norm! 0'. (len(text[-1]) - len(post) + posshift - 1) .'l'
|
||||
elseif pos =~ '^s'
|
||||
" TLogVAR lineno, pre, posshift
|
||||
exec lineno
|
||||
elseif keyargs.pos =~ '^s'
|
||||
" TLogVAR keyargs.lineno, pre, posshift
|
||||
exec keyargs.lineno
|
||||
exec 'norm! '. len(pre) .'|'
|
||||
if !empty(posshift)
|
||||
exec 'norm! '. posshift .'h'
|
||||
endif
|
||||
endif
|
||||
" TLogDBG getline(lineno)
|
||||
" TLogDBG getline(keyargs.lineno)
|
||||
" TLogDBG string(getline(1, '$'))
|
||||
return grow
|
||||
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: 2013-09-25.
|
||||
" @Revision: 0.1.243
|
||||
" @Last Change: 2015-10-24.
|
||||
" @Revision: 31.1.243
|
||||
|
||||
|
||||
" The cache directory. If empty, use |tlib#dir#MyRuntime|.'/cache'.
|
||||
@ -45,6 +45,8 @@ TLet g:tlib#cache#dont_purge = ['[\/]\.last_purge$']
|
||||
" |pathshorten()|.
|
||||
TLet g:tlib#cache#max_filename = 200
|
||||
|
||||
let s:cache = {}
|
||||
|
||||
|
||||
" :display: tlib#cache#Dir(?mode = 'bg')
|
||||
" The default cache directory.
|
||||
@ -124,9 +126,13 @@ function! s:SetTimestamp(cfile, type) "{{{3
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#cache#Save(cfile, dictionary) "{{{3
|
||||
" TLogVAR a:cfile, a:dictionary
|
||||
if !empty(a:cfile)
|
||||
function! tlib#cache#Save(cfile, dictionary, ...) "{{{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}
|
||||
elseif !empty(a:cfile)
|
||||
" TLogVAR a:dictionary
|
||||
call writefile([string(a:dictionary)], a:cfile, 'b')
|
||||
call s:SetTimestamp(a:cfile, 'write')
|
||||
@ -142,33 +148,48 @@ endf
|
||||
|
||||
|
||||
function! tlib#cache#Get(cfile, ...) "{{{3
|
||||
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"))
|
||||
TVarArg ['default', {}], ['options', {}]
|
||||
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)
|
||||
else
|
||||
let default = a:0 >= 1 ? a:1 : {}
|
||||
return default
|
||||
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
|
||||
endif
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
" :display: tlib#cache#Value(cfile, generator, ftime, ?generator_args=[], ?options={})
|
||||
" Get a cached value from cfile. If it is outdated (compared to ftime)
|
||||
" or does not exist, create it calling a generator function.
|
||||
function! tlib#cache#Value(cfile, generator, ftime, ...) "{{{3
|
||||
if !filereadable(a:cfile) || (a:ftime != 0 && getftime(a:cfile) < a:ftime)
|
||||
let args = a:0 >= 1 ? a:1 : []
|
||||
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)
|
||||
" TLogVAR a:generator, args
|
||||
let val = call(a:generator, args)
|
||||
" TLogVAR val
|
||||
let cval = {'val': val}
|
||||
" TLogVAR cval
|
||||
call tlib#cache#Save(a:cfile, cval)
|
||||
call tlib#cache#Save(a:cfile, cval, options)
|
||||
return val
|
||||
else
|
||||
let val = tlib#cache#Get(a:cfile)
|
||||
return val.val
|
||||
let val = tlib#cache#Get(a:cfile, {}, options)
|
||||
if !has_key(val, 'val')
|
||||
throw 'tlib#cache#Value: Internal error: '. a:cfile
|
||||
else
|
||||
return val.val
|
||||
endif
|
||||
endif
|
||||
endf
|
||||
|
||||
|
@ -1,15 +1,7 @@
|
||||
" char.vim
|
||||
" @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)
|
||||
" @Created: 2007-06-30.
|
||||
" @Last Change: 2014-01-20.
|
||||
" @Revision: 0.0.37
|
||||
|
||||
if &cp || exists("loaded_tlib_char_autoload")
|
||||
finish
|
||||
endif
|
||||
let loaded_tlib_char_autoload = 1
|
||||
" @Revision: 38
|
||||
|
||||
|
||||
" :def: function! tlib#char#Get(?timeout=0)
|
||||
|
@ -1,15 +1,7 @@
|
||||
" cmd.vim
|
||||
" @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)
|
||||
" @Created: 2007-08-23.
|
||||
" @Last Change: 2014-10-21.
|
||||
" @Revision: 0.0.54
|
||||
|
||||
if &cp || exists("loaded_tlib_cmd_autoload")
|
||||
finish
|
||||
endif
|
||||
let loaded_tlib_cmd_autoload = 1
|
||||
" @Revision: 58
|
||||
|
||||
|
||||
let g:tlib#cmd#last_output = []
|
||||
@ -77,6 +69,12 @@ function! tlib#cmd#ParseScriptname(line) "{{{3
|
||||
exe 'drop '. fnameescape(parsedValue)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#cmd#TBrowseScriptnames() abort "{{{3
|
||||
call tlib#cmd#BrowseOutputWithCallback("tlib#cmd#ParseScriptname", "scriptnames")
|
||||
endf
|
||||
|
||||
|
||||
" :def: function! tlib#cmd#UseVertical(?rx='')
|
||||
" Look at the history whether the command was called with vertical. If
|
||||
" an rx is provided check first if the last entry in the history matches
|
||||
|
@ -1,17 +1,7 @@
|
||||
" comments.vim
|
||||
" @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)
|
||||
" @Created: 2007-11-15.
|
||||
" @Last Change: 2009-02-15.
|
||||
" @Revision: 0.0.24
|
||||
|
||||
if &cp || exists("loaded_tlib_comments_autoload")
|
||||
finish
|
||||
endif
|
||||
let loaded_tlib_comments_autoload = 1
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
" @Revision: 25
|
||||
|
||||
|
||||
" function! tlib#comments#Comments(?rx='')
|
||||
@ -34,24 +24,3 @@ function! tlib#comments#Comments(...)
|
||||
endf
|
||||
|
||||
|
||||
" function! tlib#comments#PartitionLine(line) "{{{3
|
||||
" if !empty(&commentstring)
|
||||
" let cs = '^\(\s*\)\('. printf(tlib#rx#Escape(&commentstring), '\)\(.\{-}\)\(') .'\)\(.*\)$'
|
||||
" let ml = matchlist(a:line, cs)
|
||||
" else
|
||||
" let ml = []
|
||||
" endif
|
||||
" if !empty(ml)
|
||||
" let [m_0, pre, open, line, close, post; rest] = ml
|
||||
" else
|
||||
" let [m_0, pre, line; rest] = matchstr(a:line, '^\(\s*\)\(.*\)$')
|
||||
" for [key, val] in tlib#comments#Comments()
|
||||
" if +++
|
||||
" endfor
|
||||
" endif
|
||||
" return {'pre': pre, 'open': open, 'line': line, 'close': close, 'post': post}
|
||||
" endf
|
||||
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
@ -3,14 +3,27 @@
|
||||
" @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: 2010-09-17.
|
||||
" @Revision: 0.0.34
|
||||
" @Last Change: 2015-11-23.
|
||||
" @Revision: 21.0.34
|
||||
|
||||
|
||||
if !exists('g:tlib#date#ShortDatePrefix') | let g:tlib#date#ShortDatePrefix = '20' | endif "{{{2
|
||||
if !exists('g:tlib#date#TimeZoneShift') | let g:tlib#date#TimeZoneShift = 0 | endif "{{{2
|
||||
|
||||
let g:tlib#date#dayshift = 60 * 60 * 24
|
||||
" let g:tlib#date#date_rx = '\<\(\d\{4}\)-\(\d\d\)-\(\d\d\)\%(\s\+\(\(\d\d\):\(\d\d\)\)\)\?\>'
|
||||
let g:tlib#date#date_rx = '\<\(\d\{4}\)-\(\d\d\)-\(\d\d\)\>'
|
||||
let g:tlib#date#date_format = '%Y-%m-%d'
|
||||
|
||||
|
||||
function! tlib#date#IsDate(text) abort "{{{3
|
||||
return a:text =~# '^'. g:tlib#date#date_rx .'$'
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#date#Format(secs1970) abort "{{{3
|
||||
return strftime(g:tlib#date#date_format, a:secs1970)
|
||||
endf
|
||||
|
||||
|
||||
" :display: tlib#date#DiffInDays(date1, ?date2=localtime(), ?allow_zero=0)
|
||||
@ -118,3 +131,33 @@ function! tlib#date#SecondsSince1970(date, ...) "{{{3
|
||||
return seconds
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#date#Shift(date, shift) abort "{{{3
|
||||
let n = str2nr(matchstr(a:shift, '\d\+'))
|
||||
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#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)
|
||||
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 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, '')
|
||||
endif
|
||||
" if !empty(ml[4]) && date !~ '\s'. ml[4] .'$'
|
||||
" let date .= ' '. ml[4]
|
||||
" endif
|
||||
" TLogVAR date
|
||||
return date
|
||||
endf
|
||||
|
||||
|
15
sources_non_forked/tlib/autoload/tlib/dictionary.vim
Normal file
15
sources_non_forked/tlib/autoload/tlib/dictionary.vim
Normal file
@ -0,0 +1,15 @@
|
||||
" @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
|
||||
|
||||
|
||||
function! tlib#dictionary#Rev(dict) abort "{{{3
|
||||
let rev = {}
|
||||
for [m, f] in items(a:dict)
|
||||
let rev[f] = m
|
||||
endfor
|
||||
return rev
|
||||
endf
|
||||
|
@ -1,15 +1,7 @@
|
||||
" dir.vim
|
||||
" @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)
|
||||
" @Created: 2007-06-30.
|
||||
" @Last Change: 2014-07-07.
|
||||
" @Revision: 0.0.38
|
||||
|
||||
if &cp || exists("loaded_tlib_dir_autoload")
|
||||
finish
|
||||
endif
|
||||
let loaded_tlib_dir_autoload = 1
|
||||
" @Revision: 40
|
||||
|
||||
" TLet g:tlib#dir#sep = '/'
|
||||
TLet g:tlib#dir#sep = exists('+shellslash') && !&shellslash ? '\' : '/'
|
||||
@ -74,7 +66,7 @@ endf
|
||||
" :def: function! tlib#dir#CD(dir, ?locally=0) => CWD
|
||||
function! tlib#dir#CD(dir, ...) "{{{3
|
||||
TVarArg ['locally', 0]
|
||||
let cmd = locally ? 'lcd ' : 'cd '
|
||||
let cmd = locally ? 'lcd! ' : 'cd! '
|
||||
" let cwd = getcwd()
|
||||
let cmd .= tlib#arg#Ex(a:dir)
|
||||
" TLogVAR a:dir, locally, cmd
|
||||
|
@ -1,15 +1,7 @@
|
||||
" eval.vim
|
||||
" @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)
|
||||
" @Created: 2007-09-16.
|
||||
" @Last Change: 2009-02-15.
|
||||
" @Revision: 0.0.34
|
||||
|
||||
if &cp || exists("loaded_tlib_eval_autoload")
|
||||
finish
|
||||
endif
|
||||
let loaded_tlib_eval_autoload = 1
|
||||
" @Revision: 56
|
||||
|
||||
|
||||
function! tlib#eval#FormatValue(value, ...) "{{{3
|
||||
@ -53,3 +45,28 @@ function! tlib#eval#FormatValue(value, ...) "{{{3
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#eval#Extend(a, b, ...) abort "{{{3
|
||||
let mode = a:0 >= 1 ? a:1 : 'force'
|
||||
if type(a:a) != type(a:b)
|
||||
throw 'tlib#eval#Extend: Incompatible types: a='. string(a:a) .' b='. string(a:b)
|
||||
elseif type(a:a) == 3 " list
|
||||
return extend(a:a, a:b, mode)
|
||||
elseif type(a:a) == 4 " dict
|
||||
for k in keys(a:b)
|
||||
if has_key(a:a, k)
|
||||
if mode == 'force'
|
||||
let a:a[k] = tlib#eval#Extend(copy(a:a[k]), a:b[k], mode)
|
||||
elseif mode == 'error'
|
||||
throw 'tlib#eval#Extend: Key already exists: '. k
|
||||
endif
|
||||
else
|
||||
let a:a[k] = a:b[k]
|
||||
endif
|
||||
unlet! k
|
||||
endfor
|
||||
return a:a
|
||||
else
|
||||
return a:b
|
||||
endif
|
||||
endf
|
||||
|
||||
|
@ -1,17 +1,29 @@
|
||||
" file.vim
|
||||
" @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)
|
||||
" @Created: 2007-06-30.
|
||||
" @Last Change: 2014-07-07.
|
||||
" @Revision: 0.0.150
|
||||
" @Revision: 168
|
||||
|
||||
if &cp || exists("loaded_tlib_file_autoload")
|
||||
finish
|
||||
|
||||
if !exists('g:tlib#file#drop')
|
||||
" If true, use |:drop| to edit loaded buffers (only available with GUI).
|
||||
let g:tlib#file#drop = has('gui') "{{{2
|
||||
endif
|
||||
let loaded_tlib_file_autoload = 1
|
||||
|
||||
|
||||
if !exists('g:tlib#file#use_tabs')
|
||||
let g:tlib#file#use_tabs = 0 "{{{2
|
||||
endif
|
||||
|
||||
|
||||
if !exists('g:tlib#file#edit_cmds')
|
||||
let g:tlib#file#edit_cmds = g:tlib#file#use_tabs ? {'buffer': 'tab split | buffer', 'edit': 'tabedit'} : {} "{{{2
|
||||
endif
|
||||
|
||||
|
||||
if !exists('g:tlib#file#absolute_filename_rx')
|
||||
let g:tlib#file#absolute_filename_rx = '^\~\?[\/]' "{{{2
|
||||
endif
|
||||
|
||||
""" File related {{{1
|
||||
" For the following functions please see ../../test/tlib.vim for examples.
|
||||
|
||||
@ -36,21 +48,32 @@ function! tlib#file#Split(filename) "{{{3
|
||||
endf
|
||||
|
||||
|
||||
" :display: tlib#file#Join(filename_parts, ?strip_slashes=1)
|
||||
" :display: tlib#file#Join(filename_parts, ?strip_slashes=1, ?maybe_absolute=0)
|
||||
" EXAMPLES: >
|
||||
" tlib#file#Join(['foo', 'bar', 'filename.txt'])
|
||||
" => 'foo/bar/filename.txt'
|
||||
function! tlib#file#Join(filename_parts, ...) "{{{3
|
||||
TVarArg ['strip_slashes', 1]
|
||||
TVarArg ['strip_slashes', 1], 'maybe_absolute'
|
||||
" TLogVAR a:filename_parts, strip_slashes
|
||||
if maybe_absolute
|
||||
let filename_parts = []
|
||||
for part in a:filename_parts
|
||||
if part =~ g:tlib#file#absolute_filename_rx
|
||||
let filename_parts = []
|
||||
endif
|
||||
call add(filename_parts, part)
|
||||
endfor
|
||||
else
|
||||
let filename_parts = a:filename_parts
|
||||
endif
|
||||
if strip_slashes
|
||||
" let rx = tlib#rx#Escape(g:tlib#dir#sep) .'$'
|
||||
let rx = '[/\\]\+$'
|
||||
let parts = map(copy(a:filename_parts), 'substitute(v:val, rx, "", "")')
|
||||
let parts = map(copy(filename_parts), 'substitute(v:val, rx, "", "")')
|
||||
" TLogVAR parts
|
||||
return join(parts, g:tlib#dir#sep)
|
||||
else
|
||||
return join(a:filename_parts, g:tlib#dir#sep)
|
||||
return join(filename_parts, g:tlib#dir#sep)
|
||||
endif
|
||||
endf
|
||||
|
||||
@ -181,3 +204,75 @@ function! tlib#file#With(fcmd, bcmd, files, ...) "{{{3
|
||||
endf
|
||||
|
||||
|
||||
" Return 0 if the file isn't readable/doesn't exist.
|
||||
" Otherwise return 1.
|
||||
function! tlib#file#Edit(fileid) "{{{3
|
||||
if type(a:fileid) == 0
|
||||
let bn = a:fileid
|
||||
let filename = fnamemodify(bufname(bn), ':p')
|
||||
else
|
||||
let filename = fnamemodify(a:fileid, ':p')
|
||||
let bn = bufnr(filename)
|
||||
endif
|
||||
if filename == expand('%:p')
|
||||
return 1
|
||||
else
|
||||
" TLogVAR a:fileid, bn, filename, g:tlib#file#drop, filereadable(filename)
|
||||
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)
|
||||
else
|
||||
" echom "DBG" get(g:tlib#file#edit_cmds, 'buffer', 'buffer') bn
|
||||
exec get(g:tlib#file#edit_cmds, 'buffer', 'buffer') bn
|
||||
endif
|
||||
return 1
|
||||
elseif filereadable(filename)
|
||||
try
|
||||
" let file = tlib#arg#Ex(filename)
|
||||
" " TLogVAR 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/
|
||||
" swap file exists, let the user handle it
|
||||
catch
|
||||
echohl error
|
||||
echom v:exception
|
||||
echohl NONE
|
||||
endtry
|
||||
return 1
|
||||
else
|
||||
echom "TLIB: File not readable: " . filename
|
||||
if filename != a:fileid
|
||||
echom "TLIB: original filename: " . a:fileid
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
return 0
|
||||
endf
|
||||
|
||||
|
||||
if v:version > 704 || (v:version == 704 && has('patch279'))
|
||||
|
||||
function! tlib#file#Glob(pattern) abort "{{{3
|
||||
return glob(a:pattern, 0, 1)
|
||||
endf
|
||||
|
||||
function! tlib#file#Globpath(path, pattern) abort "{{{3
|
||||
return globpath(a:path, a:pattern, 0, 1)
|
||||
endf
|
||||
|
||||
else
|
||||
|
||||
" :nodoc:
|
||||
function! tlib#file#Glob(pattern) abort "{{{3
|
||||
return split(glob(a:pattern), '\n')
|
||||
endf
|
||||
|
||||
" :nodoc:
|
||||
function! tlib#file#Globpath(path, pattern) abort "{{{3
|
||||
return split(globpath(a:path, a:pattern), '\n')
|
||||
endf
|
||||
|
||||
endif
|
||||
|
||||
|
@ -1,15 +1,7 @@
|
||||
" hook.vim
|
||||
" @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)
|
||||
" @Created: 2007-08-21.
|
||||
" @Last Change: 2009-02-15.
|
||||
" @Revision: 0.0.10
|
||||
|
||||
if &cp || exists("loaded_tlib_hook_autoload")
|
||||
finish
|
||||
endif
|
||||
let loaded_tlib_hook_autoload = 1
|
||||
" @Revision: 11
|
||||
|
||||
|
||||
" :def: function! tlib#hook#Run(hook, ?dict={})
|
||||
|
@ -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: 1338
|
||||
" @Revision: 1366
|
||||
|
||||
|
||||
" :filedoc:
|
||||
@ -131,6 +131,7 @@ TLet g:tlib#input#keyagents_InputList_s = {
|
||||
\ "\<End>": 'tlib#agent#End',
|
||||
\ "\<Up>": 'tlib#agent#Up',
|
||||
\ "\<Down>": 'tlib#agent#Down',
|
||||
\ 9: 'tlib#agent#Complete',
|
||||
\ "\<c-Up>": 'tlib#agent#UpN',
|
||||
\ "\<c-Down>": 'tlib#agent#DownN',
|
||||
\ "\<Left>": 'tlib#agent#ShiftLeft',
|
||||
@ -252,6 +253,9 @@ TLet g:tlib#input#filename_max_width = '&co / 2'
|
||||
" Several pattern matching styles are supported. See
|
||||
" |g:tlib#input#filter_mode|.
|
||||
"
|
||||
" Users can type <Tab> to complete the current filter with the longest
|
||||
" match.
|
||||
"
|
||||
" EXAMPLES: >
|
||||
" echo tlib#input#List('s', 'Select one item', [100,200,300])
|
||||
" echo tlib#input#List('si', 'Select one item', [100,200,300])
|
||||
@ -362,7 +366,7 @@ function! tlib#input#ListW(world, ...) "{{{3
|
||||
" let time01 = str2float(reltimestr(reltime())) " DBG
|
||||
" TLogVAR time01, time01 - time0
|
||||
try
|
||||
call s:RunStateHandlers(world)
|
||||
let world = s:RunStateHandlers(world)
|
||||
|
||||
" if exists('b:tlib_world_event')
|
||||
" let event = b:tlib_world_event
|
||||
@ -518,7 +522,8 @@ function! tlib#input#ListW(world, ...) "{{{3
|
||||
" let world.offset = world.prefidx
|
||||
" endif
|
||||
" TLogDBG 8
|
||||
if world.initial_display || !tlib#char#IsAvailable()
|
||||
" TLogVAR 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()
|
||||
@ -585,8 +590,9 @@ function! tlib#input#ListW(world, ...) "{{{3
|
||||
if !empty(world.next_agent)
|
||||
let nagent = world.next_agent
|
||||
let world.next_agent = ''
|
||||
let world = call(nagent, [world, world.GetSelectedItems(world.CurrentItem())])
|
||||
call s:CheckAgentReturnValue(nagent, world)
|
||||
" let world = call(nagent, [world, world.GetSelectedItems(world.CurrentItem())])
|
||||
" call s:CheckAgentReturnValue(nagent, world)
|
||||
let world = s:CallAgent({'agent': nagent}, world, world.GetSelectedItems(world.CurrentItem()))
|
||||
elseif !empty(world.next_eval)
|
||||
let selected = world.GetSelectedItems(world.CurrentItem())
|
||||
let neval = world.next_eval
|
||||
@ -601,9 +607,10 @@ function! tlib#input#ListW(world, ...) "{{{3
|
||||
" TLogVAR 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)
|
||||
" " TLogVAR handler
|
||||
" let world = call(handler.agent, [world, world.GetSelectedItems(world.CurrentItem())])
|
||||
" call s:CheckAgentReturnValue(c, world)
|
||||
let world = s:CallAgent(handler, world, world.GetSelectedItems(world.CurrentItem()))
|
||||
silent! let @/ = sr
|
||||
" continue
|
||||
elseif c == 13
|
||||
@ -662,8 +669,9 @@ function! tlib#input#ListW(world, ...) "{{{3
|
||||
" TLogVAR 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])
|
||||
call s:CheckAgentReturnValue(agent, world)
|
||||
" let world = call(agent, [world, c])
|
||||
" call s:CheckAgentReturnValue(agent, world)
|
||||
let world = s:CallAgent({'agent': agent}, world, c)
|
||||
elseif c >= 32
|
||||
let world.state = 'display'
|
||||
let numbase = get(world.numeric_chars, c, -99999)
|
||||
@ -856,6 +864,18 @@ function! tlib#input#ListW(world, ...) "{{{3
|
||||
endf
|
||||
|
||||
|
||||
function! s:CallAgent(handler, world, list) abort "{{{3
|
||||
let agent = a:handler.agent
|
||||
let args = [a:world, a:list]
|
||||
if has_key(a:handler, 'args')
|
||||
let args += a:handler.args
|
||||
endif
|
||||
let world = call(agent, args)
|
||||
" TLogVAR world.state, world.rv
|
||||
call s:CheckAgentReturnValue(agent, world)
|
||||
return world
|
||||
endf
|
||||
|
||||
function! s:GetModdedChar(world) "{{{3
|
||||
let [char, mode] = tlib#char#Get(a:world.timeout, a:world.timeout_resolution, 1)
|
||||
if char !~ '\D' && char > 0 && mode != 0
|
||||
@ -916,6 +936,7 @@ function! s:Init(world, cmd) "{{{3
|
||||
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
|
||||
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
|
||||
@ -925,6 +946,7 @@ 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
|
||||
if !empty(a:cmd)
|
||||
let a:world.state .= ' '. a:cmd
|
||||
endif
|
||||
@ -943,7 +965,7 @@ function! s:ExtendKeyMap(world, key_mode, key_handlers) "{{{3
|
||||
endf
|
||||
|
||||
|
||||
function s:PopupmenuExists()
|
||||
function! s:PopupmenuExists()
|
||||
if !g:tlib#input#use_popup
|
||||
\ || exists(':popup') != 2
|
||||
\ || !(has('gui_win32') || has('gui_gtk') || has('gui_gtk2'))
|
||||
@ -1082,11 +1104,13 @@ function! s:RunStateHandlers(world) "{{{3
|
||||
exec ea
|
||||
else
|
||||
let agent = get(handler, 'agent', '')
|
||||
let a:world = call(agent, [a:world, a:world.GetSelectedItems(a:world.CurrentItem())])
|
||||
call s:CheckAgentReturnValue(agent, a:world)
|
||||
" let world = call(agent, [a:world, a:world.GetSelectedItems(a:world.CurrentItem())])
|
||||
" call s:CheckAgentReturnValue(agent, a:world)
|
||||
let world = s:CallAgent({'agent': agent}, world, world.GetSelectedItems(world.CurrentItem()))
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
return world
|
||||
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: 2011-03-18.
|
||||
" @Revision: 57
|
||||
" @Last Change: 2015-10-21.
|
||||
" @Revision: 61
|
||||
|
||||
|
||||
""" List related functions {{{1
|
||||
@ -140,6 +140,7 @@ endf
|
||||
|
||||
|
||||
function! tlib#list#Uniq(list, ...) "{{{3
|
||||
" TLogVAR a:list
|
||||
TVarArg ['get_value', ''], ['remove_empty', 0]
|
||||
if remove_empty
|
||||
call filter(a:list, 'type(v:val) == 0 || !empty(v:val)')
|
||||
@ -153,6 +154,7 @@ function! tlib#list#Uniq(list, ...) "{{{3
|
||||
let seen[e] = 1
|
||||
call add(uniques, e)
|
||||
endif
|
||||
unlet e
|
||||
endfor
|
||||
else
|
||||
for e in a:list
|
||||
@ -161,6 +163,7 @@ function! tlib#list#Uniq(list, ...) "{{{3
|
||||
let seen[v] = 1
|
||||
call add(uniques, e)
|
||||
endif
|
||||
unlet e
|
||||
endfor
|
||||
endif
|
||||
return uniques
|
||||
|
13
sources_non_forked/tlib/autoload/tlib/loclist.vim
Normal file
13
sources_non_forked/tlib/autoload/tlib/loclist.vim
Normal file
@ -0,0 +1,13 @@
|
||||
" @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: 2015-10-24
|
||||
" @Revision: 2
|
||||
|
||||
|
||||
function! tlib#loclist#Browse(...) abort "{{{3
|
||||
let list = getloclist(0)
|
||||
return call(function('tlib#qfl#QflList'), [list] + a:000)
|
||||
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: 2008-09-19.
|
||||
" @Last Change: 2012-01-02.
|
||||
" @Revision: 0.0.19
|
||||
" @Last Change: 2015-04-07.
|
||||
" @Revision: 0.3.19
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
@ -17,13 +17,14 @@ function! tlib#notify#Echo(text, ...)
|
||||
TVarArg 'style'
|
||||
let ruler = &ruler
|
||||
let showcmd = &showcmd
|
||||
let text = substitute(a:text, '\n', '|', 'g')
|
||||
try
|
||||
set noruler
|
||||
set noshowcmd
|
||||
if !empty(style)
|
||||
exec 'echohl '. style
|
||||
exec 'echohl' style
|
||||
endif
|
||||
echo strpart(a:text, 0, &columns - 1)
|
||||
echo strpart(text, 0, &columns - 1)
|
||||
finally
|
||||
if !empty(style)
|
||||
echohl None
|
||||
|
@ -1,15 +1,7 @@
|
||||
" progressbar.vim
|
||||
" @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)
|
||||
" @Created: 2007-09-30.
|
||||
" @Last Change: 2010-01-07.
|
||||
" @Revision: 0.0.69
|
||||
|
||||
if &cp || exists("loaded_tlib_progressbar_autoload")
|
||||
finish
|
||||
endif
|
||||
let loaded_tlib_progressbar_autoload = 1
|
||||
" @Revision: 72
|
||||
|
||||
let s:statusline = []
|
||||
let s:laststatus = []
|
||||
@ -43,15 +35,15 @@ endf
|
||||
|
||||
|
||||
function! tlib#progressbar#Display(value, ...) "{{{3
|
||||
TVarArg 'extra'
|
||||
TVarArg 'extra', ['always', 0]
|
||||
let ts = localtime()
|
||||
if ts == s:timestamp
|
||||
if !always && ts == s:timestamp
|
||||
return
|
||||
else
|
||||
let s:timestamp = ts
|
||||
endif
|
||||
let val = a:value * s:width[0] / s:max[0]
|
||||
if val != s:value[0]
|
||||
if always || val != s:value[0]
|
||||
let s:value[0] = val
|
||||
let pbl = repeat('#', val)
|
||||
let pbr = repeat('.', s:width[0] - val)
|
||||
|
314
sources_non_forked/tlib/autoload/tlib/qfl.vim
Normal file
314
sources_non_forked/tlib/autoload/tlib/qfl.vim
Normal file
@ -0,0 +1,314 @@
|
||||
" @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
|
||||
|
||||
" :nodoc:
|
||||
TLet g:tlib#qfl#world = {
|
||||
\ 'type': 'mi',
|
||||
\ 'query': 'Select entry',
|
||||
\ 'pick_last_item': 0,
|
||||
\ 'resize_vertical': 0,
|
||||
\ 'resize': 20,
|
||||
\ 'scratch': '__TLibQFL__',
|
||||
\ 'tlib_UseInputListScratch': 'call tlib#qfl#InitListBuffer(world)',
|
||||
\ 'key_handlers': [
|
||||
\ {'key': 5, 'agent': 'tlib#qfl#AgentWithSelected', 'key_name': '<c-e>', 'help': 'Run a command on selected lines'},
|
||||
\ {'key': 16, 'agent': 'tlib#qfl#AgentPreviewQFE', 'key_name': '<c-p>', 'help': 'Preview'},
|
||||
\ {'key': 60, 'agent': 'tlib#qfl#AgentGotoQFE', 'key_name': '<', 'help': 'Jump (don''t close the list)'},
|
||||
\ {'key': 19, 'agent': 'tlib#qfl#AgentSplitBuffer', 'key_name': '<c-s>', 'help': 'Show in split buffer'},
|
||||
\ {'key': 20, 'agent': 'tlib#qfl#AgentTabBuffer', 'key_name': '<c-t>', 'help': 'Show in tab'},
|
||||
\ {'key': 22, 'agent': 'tlib#qfl#AgentVSplitBuffer', 'key_name': '<c-v>', 'help': 'Show in vsplit buffer'},
|
||||
\ {'key': 12, 'agent': 'tlib#qfl#AgentEditLine', 'key_name': '<c-l>', 'help': 'Edit selected line(s)'},
|
||||
\ {'key': "\<c-insert>", 'agent': 'tlib#qfl#SetFollowCursor', 'key_name': '<c-ins>', 'help': 'Toggle trace cursor'},
|
||||
\ ],
|
||||
\ 'return_agent': 'tlib#qfl#AgentEditQFE',
|
||||
\ }
|
||||
|
||||
|
||||
function! tlib#qfl#FormatQFLE(qfe) dict abort "{{{3
|
||||
let filename = tlib#qfl#QfeFilename(a:qfe)
|
||||
if get(self, 'qfl_short_filename', '')
|
||||
let filename = pathshorten(filename)
|
||||
endif
|
||||
return printf("%s|%d| %s", filename, a:qfe.lnum, get(a:qfe, "text"))
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#QfeFilename(qfe) abort "{{{3
|
||||
let filename = get(a:qfe, 'filename')
|
||||
if empty(filename)
|
||||
let filename = bufname(get(a:qfe, 'bufnr'))
|
||||
endif
|
||||
return filename
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#InitListBuffer(world) "{{{3
|
||||
let set_syntax = get(a:world, 'set_syntax', 'tlib#qfl#SetSyntax')
|
||||
call call(set_syntax, [], a:world)
|
||||
if has('balloon_eval')
|
||||
setlocal ballooneval balloonexpr=tlib#qfl#Balloon()
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#SetSyntax() dict abort "{{{3
|
||||
let syntax = get(self, 'qfl_list_syntax', '')
|
||||
let nextgroup = get(self, 'qfl_list_syntax_nextgroup', '')
|
||||
" TLogVAR syntax, nextgroup
|
||||
if !empty(syntax)
|
||||
exec printf('runtime syntax/%s.vim', syntax)
|
||||
endif
|
||||
syn match TTagedFilesFilename /\%(\f\+\| \)\+\ze|\d\+| / nextgroup=TTagedFilesLNum
|
||||
if !empty(nextgroup)
|
||||
exec 'syn match TTagedFilesLNum /|\d\+|\s\+/ nextgroup='. nextgroup
|
||||
else
|
||||
syn match TTagedFilesLNum /|\d\+|/
|
||||
endif
|
||||
hi def link TTagedFilesFilename Directory
|
||||
hi def link TTagedFilesLNum LineNr
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#Balloon() "{{{3
|
||||
let world = getbufvar(v:beval_bufnr, 'tlibDisplayListWorld')
|
||||
let current = max([1, world.offset]) + v:beval_lnum - 1
|
||||
if current > len(world.table)
|
||||
let current = len(world.table)
|
||||
endif
|
||||
let baseidx = world.GetBaseIdx0(current)
|
||||
" TLogVAR world.offset, v:beval_lnum, current, baseidx
|
||||
let item = world.data[baseidx]
|
||||
let bufnr = get(item, 'bufnr', 0)
|
||||
let bufname = get(item, 'filename', '')
|
||||
if bufnr == 0 && !empty(bufname)
|
||||
let bufnr = bufnr(bufname)
|
||||
endif
|
||||
if empty(bufname) && bufnr > 0
|
||||
let bufname = bufname(bufnr)
|
||||
endif
|
||||
" TLogVAR item
|
||||
if bufnr == 0
|
||||
return ''
|
||||
else
|
||||
let lines = [printf("%d#%d: %s", bufnr, item.lnum, bufname)]
|
||||
if has('balloon_multiline')
|
||||
let desc = {'nr': 'Error number', 'type': 'Error type', 'text': ''}
|
||||
for key in ['nr', 'type', 'text']
|
||||
if has_key(item, key) && !empty(item[key])
|
||||
let keydesc = get(desc, key, key)
|
||||
if empty(keydesc)
|
||||
let text = item[key]
|
||||
else
|
||||
let text = printf("%s: %s", key, item[key])
|
||||
endif
|
||||
call add(lines, text)
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
return join(lines, "\n")
|
||||
endif
|
||||
" v:beval_bufnr number of the buffer in which balloon is going to show
|
||||
" v:beval_winnr number of the window
|
||||
" v:beval_lnum line number
|
||||
" v:beval_col column number (byte index)
|
||||
" v:beval_text word under or after the mouse pointer
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#AgentEditQFE(world, selected, ...) "{{{3
|
||||
TVarArg ['cmd_edit', ''], ['cmd_buffer', '']
|
||||
" TVarArg ['cmd_edit', 'edit'], ['cmd_buffer', 'buffer']
|
||||
" TLogVAR a:selected
|
||||
if empty(a:selected)
|
||||
call a:world.RestoreOrigin()
|
||||
" call a:world.ResetSelected()
|
||||
else
|
||||
call a:world.RestoreOrigin()
|
||||
for idx in a:selected
|
||||
let idx -= 1
|
||||
" TLogVAR idx
|
||||
if idx >= 0
|
||||
" TLogVAR a:world.data
|
||||
" call tlog#Debug(string(map(copy(a:world.data), 'v:val.bufnr')))
|
||||
" TLogVAR idx, a:world.data[idx]
|
||||
let qfe = a:world.data[idx]
|
||||
" let back = a:world.SwitchWindow('win')
|
||||
" TLogVAR cmd_edit, cmd_buffer, qfe
|
||||
let fn = tlib#qfl#QfeFilename(qfe)
|
||||
" TLogVAR cmd_edit, cmd_buffer, fn
|
||||
if empty(cmd_edit) && empty(cmd_buffer)
|
||||
if tlib#file#Edit(fn)
|
||||
call tlib#buffer#ViewLine(qfe.lnum)
|
||||
endif
|
||||
else
|
||||
call tlib#file#With(cmd_edit, cmd_buffer, [fn], a:world)
|
||||
" TLogDBG bufname('%')
|
||||
" TLogVAR &filetype
|
||||
call tlib#buffer#ViewLine(qfe.lnum)
|
||||
" call a:world.SetOrigin()
|
||||
" exec back
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
return a:world
|
||||
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])
|
||||
exec back
|
||||
redraw
|
||||
let a:world.state = 'redisplay'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#AgentGotoQFE(world, selected) "{{{3
|
||||
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])
|
||||
endif
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#AgentWithSelected(world, selected, ...) "{{{3
|
||||
let cmd = a:0 >= 1 ? a:1 : input('Ex command: ', '', 'command')
|
||||
let world = a:world
|
||||
if !empty(cmd)
|
||||
let world = tlib#qfl#RunCmdOnSelected(world, a:selected, cmd)
|
||||
else
|
||||
let world.state = 'redisplay'
|
||||
endif
|
||||
return world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#RunCmdOnSelected(world, selected, cmd, ...) "{{{3
|
||||
let close_scratch = a:0 >= 1 ? a:1 : 1
|
||||
if close_scratch
|
||||
call a:world.CloseScratch()
|
||||
endif
|
||||
" TLogVAR a:cmd
|
||||
for entry in a:selected
|
||||
" TLogVAR entry, a:world.GetBaseItem(entry)
|
||||
call tlib#qfl#AgentEditQFE(a:world, [entry])
|
||||
" TLogDBG bufname('%')
|
||||
exec a:cmd
|
||||
" let item = a:world.data[a:world.GetBaseIdx(entry - 1)]
|
||||
" <+TODO+>
|
||||
let item = a:world.data[entry - 1]
|
||||
" TLogVAR entry, item, getline('.')
|
||||
if has_key(a:world, 'GetBufferLines')
|
||||
let lines = a:world.GetBufferLines('.', '.')
|
||||
else
|
||||
let lines = getline('.', '.')
|
||||
endif
|
||||
let item['text'] = tlib#string#Strip(lines[0])
|
||||
endfor
|
||||
if has_key(a:world, 'AfterRunCmd')
|
||||
if bufnr('%') == a:world.bufnr
|
||||
call a:world.AfterRunCmd()
|
||||
else
|
||||
" <+TODO+> Run in other buffer
|
||||
endif
|
||||
endif
|
||||
" call s:FormatBase(a:world)
|
||||
call a:world.RestoreOrigin()
|
||||
let a:world.state = 'reset'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#AgentSplitBuffer(world, selected) "{{{3
|
||||
call a:world.CloseScratch()
|
||||
return tlib#qfl#AgentEditQFE(a:world, a:selected, 'split', 'sbuffer')
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#AgentTabBuffer(world, selected) "{{{3
|
||||
call a:world.CloseScratch()
|
||||
return tlib#qfl#AgentEditQFE(a:world, a:selected, 'tabedit', 'tab sbuffer')
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#AgentVSplitBuffer(world, selected) "{{{3
|
||||
call a:world.CloseScratch()
|
||||
return tlib#qfl#AgentEditQFE(a:world, a:selected, 'vertical split', 'vertical sbuffer')
|
||||
endf
|
||||
|
||||
|
||||
" function! tlib#qfl#AgentOpenBuffer(world, selected) "{{{3
|
||||
" endf
|
||||
|
||||
|
||||
function! tlib#qfl#AgentEditLine(world, selected) "{{{3
|
||||
call a:world.CloseScratch()
|
||||
let cmd = 'call tlib#qfl#EditLine(".")'
|
||||
return tlib#qfl#RunCmdOnSelected(a:world, a:selected, cmd)
|
||||
let a:world.state = 'reset'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#EditLine(lnum) "{{{3
|
||||
call inputsave()
|
||||
let line = input('', getline(a:lnum))
|
||||
call inputrestore()
|
||||
if !empty(line)
|
||||
call setline(line(a:lnum), line)
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#SetFollowCursor(world, selected) "{{{3
|
||||
if empty(a:world.follow_cursor)
|
||||
let a:world.follow_cursor = 'tlib#qfl#AgentPreviewQFE'
|
||||
else
|
||||
let a:world.follow_cursor = ''
|
||||
endif
|
||||
let a:world.state = 'redisplay'
|
||||
return a:world
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#QflList(list, ...) abort "{{{3
|
||||
TVarArg ['world_dict', {}], ['anyway', 0], ['suspended', 0]
|
||||
Tlibtrace 'tlib', world_dict, anyway, suspended
|
||||
" TLogVAR a:list, world_dict, anyway, suspended
|
||||
if !anyway && empty(a:list)
|
||||
return
|
||||
endif
|
||||
let world = copy(g:tlib#qfl#world)
|
||||
if !empty(world_dict)
|
||||
let world = tlib#eval#Extend(world, world_dict)
|
||||
endif
|
||||
" TLogVAR world
|
||||
let world = tlib#World#New(world)
|
||||
" echom "DBG world" string(sort(keys(world)))
|
||||
let world.data = copy(a:list)
|
||||
if !has_key(world, 'format_data')
|
||||
let world.format_data = 'tlib#qfl#FormatQFLE'
|
||||
endif
|
||||
" TLogVAR world
|
||||
" TLogVAR world.data
|
||||
" call s:FormatBase(world)
|
||||
" TLogVAR world.base
|
||||
return tlib#input#ListW(world, suspended ? 'hibernate' : '')
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#qfl#Browse(...) abort "{{{3
|
||||
let list = getqflist()
|
||||
return call(function('tlib#qfl#QflList'), [list] + a:000)
|
||||
endf
|
||||
|
@ -1,15 +1,7 @@
|
||||
" rx.vim
|
||||
" @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)
|
||||
" @Created: 2007-07-20.
|
||||
" @Last Change: 2010-02-26.
|
||||
" @Revision: 0.0.28
|
||||
|
||||
if &cp || exists("loaded_tlib_rx_autoload")
|
||||
finish
|
||||
endif
|
||||
let loaded_tlib_rx_autoload = 1
|
||||
" @Revision: 113
|
||||
|
||||
|
||||
" :def: function! tlib#rx#Escape(text, ?magic='m')
|
||||
@ -61,3 +53,8 @@ function! tlib#rx#Suffixes(...) "{{{3
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#rx#LooksLikeRegexp(text) abort "{{{3
|
||||
return a:text =~ '[.?*+{}\[\]]'
|
||||
endf
|
||||
|
||||
|
@ -1,15 +1,7 @@
|
||||
" scratch.vim
|
||||
" @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)
|
||||
" @Created: 2007-07-18.
|
||||
" @Last Change: 2014-02-06.
|
||||
" @Revision: 0.0.252
|
||||
|
||||
if &cp || exists("loaded_tlib_scratch_autoload")
|
||||
finish
|
||||
endif
|
||||
let loaded_tlib_scratch_autoload = 1
|
||||
" @Revision: 255
|
||||
|
||||
|
||||
" Scratch window position. By default the list window is opened on the
|
||||
@ -92,8 +84,9 @@ function! tlib#scratch#UseScratch(...) "{{{3
|
||||
setlocal nobuflisted
|
||||
setlocal foldmethod=manual
|
||||
setlocal foldcolumn=0
|
||||
setlocal modifiable
|
||||
setlocal nospell
|
||||
setlocal modifiable
|
||||
setlocal noreadonly
|
||||
" TLogVAR &ft, ft
|
||||
if !empty(ft)
|
||||
let &l:ft = ft
|
||||
|
@ -1,15 +1,7 @@
|
||||
" string.vim
|
||||
" @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)
|
||||
" @Created: 2007-06-30.
|
||||
" @Last Change: 2009-02-15.
|
||||
" @Revision: 0.0.115
|
||||
|
||||
if &cp || exists("loaded_tlib_string_autoload")
|
||||
finish
|
||||
endif
|
||||
let loaded_tlib_string_autoload = 1
|
||||
" @Revision: 121
|
||||
|
||||
|
||||
" :def: function! tlib#string#RemoveBackslashes(text, ?chars=' ')
|
||||
@ -156,3 +148,11 @@ function! s:CountHelper() "{{{3
|
||||
let s:count += 1
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#string#SplitCommaList(text, ...) abort "{{{3
|
||||
let sep = a:0 >= 1 ? a:1 : ',\s*'
|
||||
let parts = split(a:text, '\\\@<!\zs'. sep)
|
||||
let parts = map(parts, 'substitute(v:val, ''\\\(.\)'', ''\1'', ''g'')')
|
||||
return parts
|
||||
endf
|
||||
|
||||
|
@ -1,17 +1,7 @@
|
||||
" syntax.vim
|
||||
" @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)
|
||||
" @Created: 2007-11-19.
|
||||
" @Last Change: 2009-02-15.
|
||||
" @Revision: 0.0.11
|
||||
|
||||
if &cp || exists("loaded_tlib_syntax_autoload")
|
||||
finish
|
||||
endif
|
||||
let loaded_tlib_syntax_autoload = 1
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
" @Revision: 13
|
||||
|
||||
|
||||
function! tlib#syntax#Collect() "{{{3
|
||||
@ -23,7 +13,7 @@ function! tlib#syntax#Collect() "{{{3
|
||||
elseif line =~ '^\w'
|
||||
let ml = matchlist(line, '^\(\w\+\)\s\+\(xxx\s\+\(.*\)\|\(cluster.*\)\)$')
|
||||
if empty(ml)
|
||||
echoerr 'Internal error: '. string(line)
|
||||
" echoerr 'Internal error: '. string(line)
|
||||
else
|
||||
let [m_0, syn, m_1, m_def1, m_def2; m_rest] = ml
|
||||
let acc[syn] = [empty(m_def1) ? m_def2 : m_def1]
|
||||
@ -46,6 +36,3 @@ function! tlib#syntax#Names(...) "{{{3
|
||||
return names
|
||||
endf
|
||||
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
@ -1,7 +1,52 @@
|
||||
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
|
||||
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
||||
" @Last Change: 2014-06-30.
|
||||
" @Revision: 25
|
||||
" @Last Change: 2015-11-07.
|
||||
" @Revision: 51
|
||||
|
||||
|
||||
if !exists('g:tlib#sys#special_protocols')
|
||||
" A list of |regexp|s matching protocol names that should be handled
|
||||
" by |g:tlib#sys#system_browser|.
|
||||
" CAVEAT: Must be a |\V| |regexp|.
|
||||
let g:tlib#sys#special_protocols = ['https\?', 'nntp', 'mailto'] "{{{2
|
||||
endif
|
||||
|
||||
|
||||
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
|
||||
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
|
||||
endif
|
||||
|
||||
|
||||
if !exists("g:tlib#sys#system_browser")
|
||||
if exists('g:netrw_browsex_viewer')
|
||||
" Open files in the system browser.
|
||||
" :read: let g:tlib#sys#system_browser = ... "{{{2
|
||||
let g:tlib#sys#system_browser = "exec 'silent !'. g:netrw_browsex_viewer shellescape('%s')"
|
||||
elseif has("win32") || has("win16") || has("win64")
|
||||
" let g:tlib#sys#system_browser = "exec 'silent ! start \"\"' shellescape('%s')"
|
||||
let g:tlib#sys#system_browser = "exec 'silent ! RunDll32.EXE URL.DLL,FileProtocolHandler' shellescape('%s')"
|
||||
elseif has("mac")
|
||||
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'
|
||||
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')"
|
||||
else
|
||||
let g:tlib#sys#system_browser = ''
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
if !exists('g:tlib#sys#windows')
|
||||
@ -14,47 +59,6 @@ if !exists('g:tlib#sys#null')
|
||||
endif
|
||||
|
||||
|
||||
let s:executables = {}
|
||||
|
||||
function! tlib#sys#IsExecutable(cmd, ...) "{{{3
|
||||
" TLogVAR a:cmd
|
||||
" echom "DBG has_key(s:executables, a:cmd)" has_key(s:executables, a:cmd)
|
||||
if !has_key(s:executables, a:cmd)
|
||||
let executable = executable(a:cmd)
|
||||
" TLogVAR 1, executable
|
||||
let ignore_cyg = a:0 >= 1 ? a:1 : !g:tlib#sys#windows
|
||||
if !executable && !ignore_cyg
|
||||
let executable = tlib#sys#IsCygwinBin(a:cmd)
|
||||
" TLogVAR 2, executable
|
||||
endif
|
||||
let s:executables[a:cmd] = executable
|
||||
endif
|
||||
" echom "DBG s:executables[a:cmd]" s:executables[a:cmd]
|
||||
return s:executables[a:cmd]
|
||||
endf
|
||||
|
||||
|
||||
if !exists('g:tlib#sys#check_cygpath')
|
||||
" If true, check whether we have to convert a path via cyppath --
|
||||
" see |tlib#sys#MaybeUseCygpath|
|
||||
let g:tlib#sys#check_cygpath = g:tlib#sys#windows && tlib#sys#IsExecutable('cygpath') "{{{2
|
||||
endif
|
||||
|
||||
|
||||
if !exists('g:tlib#sys#cygwin_path_rx')
|
||||
" If a full windows filename (with slashes instead of backslashes)
|
||||
" matches this |regexp|, it is assumed to be a cygwin executable.
|
||||
let g:tlib#sys#cygwin_path_rx = '/cygwin/' "{{{2
|
||||
endif
|
||||
|
||||
|
||||
if !exists('g:tlib#sys#cygwin_expr')
|
||||
" For cygwin binaries, convert command calls using this vim
|
||||
" expression.
|
||||
let g:tlib#sys#cygwin_expr = '"bash -c ''". escape(%s, "''\\") ."''"' "{{{2
|
||||
endif
|
||||
|
||||
|
||||
let s:cygwin = {}
|
||||
|
||||
function! tlib#sys#IsCygwinBin(cmd) "{{{3
|
||||
@ -84,6 +88,47 @@ function! tlib#sys#IsCygwinBin(cmd) "{{{3
|
||||
endf
|
||||
|
||||
|
||||
let s:executables = {}
|
||||
|
||||
function! tlib#sys#IsExecutable(cmd, ...) "{{{3
|
||||
" TLogVAR a:cmd
|
||||
" echom "DBG has_key(s:executables, a:cmd)" has_key(s:executables, a:cmd)
|
||||
if !has_key(s:executables, a:cmd)
|
||||
let executable = executable(a:cmd)
|
||||
" TLogVAR 1, executable
|
||||
let ignore_cyg = a:0 >= 1 ? a:1 : !g:tlib#sys#windows
|
||||
if !executable && !ignore_cyg
|
||||
let executable = tlib#sys#IsCygwinBin(a:cmd)
|
||||
" TLogVAR 2, executable
|
||||
endif
|
||||
let s:executables[a:cmd] = executable
|
||||
endif
|
||||
" echom "DBG s:executables[a:cmd]" s:executables[a:cmd]
|
||||
return s:executables[a:cmd]
|
||||
endf
|
||||
|
||||
|
||||
if !exists('g:tlib#sys#check_cygpath')
|
||||
" If true, check whether we have to convert a path via cyppath --
|
||||
" see |tlib#sys#MaybeUseCygpath|
|
||||
let g:tlib#sys#check_cygpath = g:tlib#sys#windows && tlib#sys#IsExecutable('cygpath', 1) "{{{2
|
||||
endif
|
||||
|
||||
|
||||
if !exists('g:tlib#sys#cygwin_path_rx')
|
||||
" If a full windows filename (with slashes instead of backslashes)
|
||||
" matches this |regexp|, it is assumed to be a cygwin executable.
|
||||
let g:tlib#sys#cygwin_path_rx = '/cygwin/' "{{{2
|
||||
endif
|
||||
|
||||
|
||||
if !exists('g:tlib#sys#cygwin_expr')
|
||||
" For cygwin binaries, convert command calls using this vim
|
||||
" expression.
|
||||
let g:tlib#sys#cygwin_expr = '"bash -c ''". escape(%s, "''\\") ."''"' "{{{2
|
||||
endif
|
||||
|
||||
|
||||
function! tlib#sys#GetCmd(cmd) "{{{3
|
||||
if !empty(g:tlib#sys#cygwin_expr) && tlib#sys#IsCygwinBin(matchstr(a:cmd, '^\S\+'))
|
||||
let cmd = eval(printf(g:tlib#sys#cygwin_expr, string(a:cmd)))
|
||||
@ -125,3 +170,42 @@ function! tlib#sys#FileArgs(cmd, files) "{{{3
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
" Check whether filename matches |g:tlib#sys#system_rx|, i.e. whether it
|
||||
" is a special file that should not be opened in vim.
|
||||
function! tlib#sys#IsSpecial(filename) abort "{{{3
|
||||
return a:filename =~ g:tlib#sys#system_rx
|
||||
endf
|
||||
|
||||
|
||||
" Open filename with the default OS application (see
|
||||
" |g:tlib#sys#system_browser|), if |tlib#sys#IsSpecial()| return 1.
|
||||
" Returns 1 if successful or 0 otherwise.
|
||||
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
|
||||
return 1
|
||||
catch
|
||||
echohl ErrorMsg
|
||||
echom v:exception
|
||||
echohl NONE
|
||||
endtry
|
||||
endif
|
||||
return 0
|
||||
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! -
|
||||
endtry
|
||||
endf
|
||||
|
||||
|
@ -1,15 +1,7 @@
|
||||
" tab.vim
|
||||
" @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)
|
||||
" @Created: 2007-08-27.
|
||||
" @Last Change: 2014-02-06.
|
||||
" @Revision: 0.0.30
|
||||
|
||||
if &cp || exists("loaded_tlib_tab_autoload")
|
||||
finish
|
||||
endif
|
||||
let loaded_tlib_tab_autoload = 1
|
||||
" @Revision: 31
|
||||
|
||||
|
||||
" Return a dictionary of bufnumbers => [[tabpage, winnr] ...]
|
||||
|
@ -1,15 +1,7 @@
|
||||
" tag.vim
|
||||
" @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)
|
||||
" @Created: 2007-11-01.
|
||||
" @Last Change: 2013-09-25.
|
||||
" @Revision: 0.0.58
|
||||
|
||||
if &cp || exists("loaded_tlib_tag_autoload")
|
||||
finish
|
||||
endif
|
||||
let loaded_tlib_tag_autoload = 1
|
||||
" @Revision: 59
|
||||
|
||||
|
||||
" Extra tags for |tlib#tag#Retrieve()| (see there). Can also be buffer-local.
|
||||
|
@ -1,15 +1,7 @@
|
||||
" time.vim
|
||||
" @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)
|
||||
" @Created: 2007-10-17.
|
||||
" @Last Change: 2009-02-22.
|
||||
" @Revision: 0.0.29
|
||||
|
||||
if &cp || exists("loaded_tlib_time_autoload")
|
||||
finish
|
||||
endif
|
||||
let loaded_tlib_time_autoload = 1
|
||||
" @Revision: 36
|
||||
|
||||
|
||||
function! tlib#time#MSecs() "{{{3
|
||||
@ -19,12 +11,27 @@ endf
|
||||
|
||||
|
||||
function! tlib#time#Now() "{{{3
|
||||
let rts = reltimestr(reltime())
|
||||
let rtl = split(rts, '\.')
|
||||
if has('reltime')
|
||||
let rts = reltimestr(reltime())
|
||||
let rtl = map(split(rts, '\.'), 'str2nr(v:val)')
|
||||
else
|
||||
let rtl = [localtime()]
|
||||
endif
|
||||
return rtl
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#time#FormatNow() "{{{3
|
||||
let rtl = tlib#time#Now()
|
||||
if len(rtl) == 2
|
||||
let rts = strftime(g:tlib#date#date_format .' %H:%M:%S', rtl[0]) .'.'. rtl[1]
|
||||
else
|
||||
let rts = strftime(g:tlib#date#date_format .' %H:%M:%S', rtl[0])
|
||||
endif
|
||||
return rts
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#time#Diff(a, b, ...) "{{{3
|
||||
TVarArg ['resolution', 2]
|
||||
let [as, am] = a:a
|
||||
|
117
sources_non_forked/tlib/autoload/tlib/trace.vim
Normal file
117
sources_non_forked/tlib/autoload/tlib/trace.vim
Normal file
@ -0,0 +1,117 @@
|
||||
" @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
|
||||
|
||||
|
||||
if !exists('g:tlib#trace#backtrace')
|
||||
" The length of the backtrace that should be included in
|
||||
" |tlib#trace#Print()|.
|
||||
let g:tlib#trace#backtrace = 2 "{{{2
|
||||
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
|
||||
endif
|
||||
|
||||
|
||||
let s:trace_hl = {'error': 'ErrorMsg', 'fatal': 'ErrorMsg', 'warning': 'WarningMsg'}
|
||||
|
||||
|
||||
" 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")'
|
||||
endf
|
||||
|
||||
|
||||
" Set the tracing |regexp|. See |:Tlibtrace|.
|
||||
" This will also call |tlib#trace#Enable()|.
|
||||
"
|
||||
" Examples:
|
||||
" call tlib#trace#Set(["+foo", "-bar"])
|
||||
" call tlib#trace#Set("+foo,-bar")
|
||||
function! tlib#trace#Set(vars) abort "{{{3
|
||||
call tlib#trace#Enable()
|
||||
if type(a:vars) == 1
|
||||
let vars = tlib#string#SplitCommaList(a:vars, '[,[:space:]]\+')
|
||||
else
|
||||
let vars = a:vars
|
||||
endif
|
||||
for rx in vars
|
||||
let rx1 = substitute(rx, '^[+-]', '', 'g')
|
||||
if rx1 !~# '^\%(error\|fatal\)$' && s:trace_rx !~# '[(|]'. 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), '', '')
|
||||
else
|
||||
echohl WarningMsg
|
||||
echom 'tlib#trace#Print: Unsupported syntax:' rx
|
||||
echohl NONE
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
echom "SetTrace:" s:trace_rx
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#trace#Backtrace(caller) abort "{{{3
|
||||
let caller = split(a:caller, '\.\.')
|
||||
let start = max([0, len(caller) - g:tlib#trace#backtrace - 1])
|
||||
let caller = caller[start : -1]
|
||||
return join(caller, '..')
|
||||
endf
|
||||
|
||||
|
||||
" Print the values of vars. The first value is a "guard" (see
|
||||
" |:Tlibtrace|).
|
||||
function! tlib#trace#Print(caller, vars, values) abort "{{{3
|
||||
let msg = ['TRACE']
|
||||
let guard = a:values[0]
|
||||
if type(guard) == 0
|
||||
let cond = guard
|
||||
else
|
||||
let cond = guard =~# s:trace_rx
|
||||
endif
|
||||
" TLogVAR guard, cond, a:vars, a:values
|
||||
if cond
|
||||
call add(msg, guard)
|
||||
call add(msg, tlib#time#FormatNow() .':')
|
||||
if g:tlib#trace#backtrace > 0
|
||||
let bt = tlib#trace#Backtrace(a:caller)
|
||||
if !empty(bt)
|
||||
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)))
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
" Enable tracing via |:Tlibtrace|.
|
||||
function! tlib#trace#Enable() abort "{{{3
|
||||
if !exists('s:trace_rx')
|
||||
let s:trace_rx = '^\%(error\)$'
|
||||
" :nodoc:
|
||||
command! -nargs=+ -bar Tlibtrace call tlib#trace#Print(expand('<sfile>'), [<f-args>], [<args>])
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
" Disable tracing via |:Tlibtrace|.
|
||||
function! tlib#trace#Disable() abort "{{{3
|
||||
" :nodoc:
|
||||
command! -nargs=+ -bang -bar Tlibtrace :
|
||||
unlet! s:trace_rx
|
||||
endf
|
||||
|
@ -1,29 +1,71 @@
|
||||
" type.vim
|
||||
" @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)
|
||||
" @Created: 2007-09-30.
|
||||
" @Last Change: 2010-09-27.
|
||||
" @Revision: 0.0.4
|
||||
" @Last Change: 2015-11-23.
|
||||
" @Revision: 6
|
||||
|
||||
|
||||
function! tlib#type#IsNumber(expr)
|
||||
return type(a:expr) == 0
|
||||
return tlib#type#Is(a:expr, 0)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#type#IsString(expr)
|
||||
return type(a:expr) == 1
|
||||
return tlib#type#Is(a:expr, 1)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#type#IsFuncref(expr)
|
||||
return type(a:expr) == 2
|
||||
return tlib#type#Is(a:expr, 2)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#type#IsList(expr)
|
||||
return type(a:expr) == 3
|
||||
return tlib#type#Is(a:expr, 3)
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#type#IsDictionary(expr)
|
||||
return type(a:expr) == 4
|
||||
return tlib#type#Is(a:expr, 4)
|
||||
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
|
||||
else
|
||||
throw 'tlib#type#Is: Unknown type: ' a:type
|
||||
endif
|
||||
" TLogVAR a:val, a:type, type, type(a:val), type(a:val) == a:type
|
||||
return type(a:val) == type
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#type#Are(vals, type) abort "{{{3
|
||||
return tlib#assert#Map(a:vals, 'tlib#type#Is(v:val,'. string(a:type) .')')
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#type#Has(val, lst) abort "{{{3
|
||||
return tlib#assert#All(map(a:lst, 'has_key(a:val, v:val)'))
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#type#Have(vals, lst) abort "{{{3
|
||||
return tlib#assert#Map(a:vals, 'tlib#type#Has(v:val,'. string(a:lst) .')')
|
||||
endf
|
||||
|
||||
|
||||
|
@ -1,15 +1,7 @@
|
||||
" var.vim
|
||||
" @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)
|
||||
" @Created: 2007-06-30.
|
||||
" @Last Change: 2014-07-08.
|
||||
" @Revision: 0.0.29
|
||||
|
||||
if &cp || exists("loaded_tlib_var_autoload")
|
||||
finish
|
||||
endif
|
||||
let loaded_tlib_var_autoload = 1
|
||||
" @Revision: 30
|
||||
|
||||
|
||||
" Define a variable called NAME if yet undefined.
|
||||
|
@ -1,9 +1,10 @@
|
||||
" vcs.vim
|
||||
" @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: 2014-09-30.
|
||||
" @Revision: 133
|
||||
" @Last Change: 2015-11-07.
|
||||
" @Revision: 190
|
||||
|
||||
scriptencoding utf-8
|
||||
|
||||
|
||||
" A dictionarie of supported VCS (currently: git, hg, svn, bzr).
|
||||
@ -11,7 +12,8 @@
|
||||
TLet g:tlib#vcs#def = {
|
||||
\ 'git': {
|
||||
\ 'dir': '.git',
|
||||
\ 'ls': 'git ls-files --full-name %s',
|
||||
\ 'ls': 'git ls-files --full-name',
|
||||
\ 'ls.postprocess': '*tlib#vcs#GitLsPostprocess',
|
||||
\ 'diff': 'git diff --no-ext-diff -U0 %s'
|
||||
\ },
|
||||
\ 'hg': {
|
||||
@ -64,11 +66,13 @@ function! tlib#vcs#FindVCS(filename) "{{{3
|
||||
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
|
||||
@ -79,6 +83,7 @@ function! tlib#vcs#FindVCS(filename) "{{{3
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
Tlibtrace 'tlib', type, dir
|
||||
" TLogVAR type, dir
|
||||
if empty(type)
|
||||
return ['', '']
|
||||
@ -92,13 +97,17 @@ 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]
|
||||
let bin = get(g:tlib#vcs#executables, a:vcstype, '')
|
||||
if empty(bin)
|
||||
let cmd = ''
|
||||
elseif bin != a:vcstype
|
||||
" let bin = escape(shellescape(bin), '\')
|
||||
let bin = escape(bin, '\')
|
||||
let cmd = substitute(cmd, '^.\{-}\zs'. escape(a:vcstype, '\'), bin, '')
|
||||
if cmd =~ '^\*'
|
||||
let cmd = substitute(cmd, '^\*', '', '')
|
||||
else
|
||||
let bin = get(g:tlib#vcs#executables, a:vcstype, '')
|
||||
if empty(bin)
|
||||
let cmd = ''
|
||||
elseif bin != a:vcstype
|
||||
" let bin = escape(shellescape(bin), '\')
|
||||
let bin = escape(bin, '\')
|
||||
let cmd = substitute(cmd, '^.\{-}\zs'. escape(a:vcstype, '\'), bin, '')
|
||||
endif
|
||||
endif
|
||||
return cmd
|
||||
else
|
||||
@ -115,6 +124,7 @@ function! tlib#vcs#Ls(...) "{{{3
|
||||
else
|
||||
let vcs = tlib#vcs#FindVCS(a:0 >= 1 ? a:1 : bufname('%'))
|
||||
endif
|
||||
Tlibtrace 'tlib', vcs, a:000
|
||||
" TLogVAR vcs
|
||||
if !empty(vcs)
|
||||
let [vcstype, vcsdir] = vcs
|
||||
@ -129,11 +139,17 @@ function! tlib#vcs#Ls(...) "{{{3
|
||||
else
|
||||
let cmd = ls
|
||||
endif
|
||||
" TLogVAR cmd
|
||||
let filess = system(cmd)
|
||||
" TLogVAR cmd, getcwd()
|
||||
Tlibtrace 'tlib', getcwd(), vcstype, vcsdir, rootdir, cmd
|
||||
let filess = tlib#sys#SystemInDir(rootdir, cmd)
|
||||
" TLogVAR filess
|
||||
let files = split(filess, '\n')
|
||||
let postprocess = s:GetCmd(vcstype, 'ls.postprocess')
|
||||
if !empty(postprocess)
|
||||
call map(files, 'call(postprocess, [v:val])')
|
||||
endif
|
||||
call map(files, 'join([rootdir, v:val], "/")')
|
||||
" TLogVAR files
|
||||
return files
|
||||
endif
|
||||
endif
|
||||
@ -158,3 +174,16 @@ function! tlib#vcs#Diff(filename, ...) "{{{3
|
||||
return []
|
||||
endf
|
||||
|
||||
|
||||
function! tlib#vcs#GitLsPostprocess(filename) abort "{{{3
|
||||
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)
|
||||
" TLogVAR a:filename, filename, &enc
|
||||
return filename
|
||||
else
|
||||
return a:filename
|
||||
endif
|
||||
endf
|
||||
|
||||
|
@ -1,15 +1,7 @@
|
||||
" win.vim
|
||||
" @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)
|
||||
" @Created: 2007-08-24.
|
||||
" @Last Change: 2010-12-04.
|
||||
" @Revision: 0.0.54
|
||||
|
||||
if &cp || exists("loaded_tlib_win_autoload")
|
||||
finish
|
||||
endif
|
||||
let loaded_tlib_win_autoload = 1
|
||||
" @Revision: 55
|
||||
|
||||
|
||||
" Return vim code to jump back to the original window.
|
||||
|
Reference in New Issue
Block a user