Permalink
Browse files

Version 1.17

- tlib#input#List: #ReduceFilter: make sure the regexp is valid- TTimeCommand -> Ttimecommand- tlib#eval#Extend: mode argument for expand() compatibility- tlib#input#List: Key handlers can have additional arguments- tlib#qfl#AgentWithSelected: Set world- prototype.UseInputListScratch: Run tlib_UseInputListScratch hook earlier- tlib#qfl#AgentWithSelected: typo- tlib#arg#GetOpts: type conversion (comma-separated lists etc.)- tlib#arg: validators- NEW tlib#date#IsDate()- tlib#balloon#Remove: Unset &ballooneval, &balloonexpr- NEW tlib#balloon#Expand()- NEW tlib#date#Format()- FIX tlib#date#Shift(..., "+Xm") for months- NEW tlib#trace#Backtrace()- NEW tlib#type#Is(), tlib#type#Are(), tlib#type#Has(), tlib#type#Have()- NEW :TlibassertMD5 checksum: 3c4125a28ff1860accd254846651c251
  • Loading branch information...
1 parent c09f468 commit 56c58fd2f90793a8eaffa9a7182259ae7a8dc93a @tomtom tomtom committed with Nov 24, 2015
View
@@ -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: 1424
+" @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)
@@ -683,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
@@ -838,6 +845,7 @@ function! s:prototype.UseInputListScratch() dict "{{{3
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
@@ -848,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
View
@@ -1,8 +1,8 @@
" @Author: Tom Link (micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
-" @Last Change: 2015-11-03.
-" @Revision: 236
+" @Last Change: 2015-11-19.
+" @Revision: 251
" :def: function! tlib#arg#Get(n, var, ?default="", ?test='')
@@ -156,6 +156,8 @@ function! s:SetOpt(def, opts, idx, opt) abort "{{{3
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
@@ -171,16 +173,39 @@ function! s:SetOpt(def, opts, idx, opt) abort "{{{3
let break = 2
elseif long && a:opt =~# '^--no-.\+'
let key = matchstr(a:opt, '^--no-\zs.\+$')
- let a:opts[key] = 0
+ 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] = 1
+ 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 a:opts[ml[1]] = ml[2]
+ 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', {})
@@ -207,8 +232,22 @@ function! s:SetFlag(def, opts, idx, flag, rest, flagdefs) abort "{{{3
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] = 1
+ 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
View
@@ -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
+
+
View
@@ -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
+
View
@@ -3,8 +3,8 @@
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2010-03-25.
-" @Last Change: 2015-11-02.
-" @Revision: 11.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
@@ -16,6 +16,16 @@ 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)
function! tlib#date#DiffInDays(date, ...)
let allow_zero = a:0 >= 2 ? a:2 : 0
@@ -129,14 +139,14 @@ function! tlib#date#Shift(date, shift) abort "{{{3
if a:shift =~ 'd$'
let secs = tlib#date#SecondsSince1970(a:date) + g:tlib#date#dayshift * n
" TLogVAR secs
- let date = strftime(g:tlib#date#date_format, 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 = strftime(g:tlib#date#date_format, secs)
+ let date = tlib#date#Format(secs)
elseif a:shift =~ 'm$'
let d = str2nr(ml[3])
let ms = str2nr(ml[2]) + n
- let m = ms % 12 + 1
+ 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
View
@@ -1,7 +1,7 @@
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
-" @Revision: 50
+" @Revision: 56
function! tlib#eval#FormatValue(value, ...) "{{{3
@@ -45,15 +45,20 @@ function! tlib#eval#FormatValue(value, ...) "{{{3
endf
-function! tlib#eval#Extend(a, b) abort "{{{3
+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)
+ 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)
- let a:a[k] = tlib#eval#Extend(copy(a:a[k]), a:b[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
Oops, something went wrong.

0 comments on commit 56c58fd

Please sign in to comment.