Permalink
Browse files

Version 0.37

- g:tlib_inputlist_livesearch_threshold defaults to 1000
- tlib#World: optional scratch_pos field
- tlib#input#List: By default <m-NUMBER> selects by number but NUMBER is interpreted as string
- tlib#date
- TTimeCommand
  • Loading branch information...
tomtom authored and vim-scripts committed Mar 31, 2010
1 parent eb07ace commit 8956e715321fb494ed36a5a837c59352d7a29153
@@ -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: 2009-02-15.
-" @Revision: 0.0.57
+" @Last Change: 2010-03-22.
+" @Revision: 0.0.66
let s:save_cpo = &cpo
set cpo&vim
@@ -32,15 +32,26 @@ function! s:prototype.AssessName(world, name) dict "{{{3
" if flt =~# '\u' && a:name =~# flt
" let xa += 5
" endif
- if a:name =~ '\^'. flt .'\|'. flt .'\$'
+
+ if a:name =~ '\^'. flt
let xa += 4
- elseif a:name =~ '\<'. flt .'\|'. flt .'\>'
+ elseif a:name =~ '\<'. flt
let xa += 3
- " elseif a:name =~ flt .'\>'
+ " elseif a:name =~ '[[:punct:][:space:][:digit:]]'. flt
" let xa += 2
elseif a:name =~ '\A'. flt .'\|'. flt .'\A'
let xa += 1
endif
+
+ " if a:name =~ '\^'. flt .'\|'. flt .'\$'
+ " let xa += 4
+ " elseif a:name =~ '\<'. flt .'\|'. flt .'\>'
+ " let xa += 3
+ " " elseif a:name =~ flt .'\>'
+ " " let xa += 2
+ " elseif a:name =~ '\A'. flt .'\|'. flt .'\A'
+ " let xa += 1
+ " endif
" if flt[0] =~# '\u' && matchstr(a:name, '\V\.\ze'. flt) =~# '\U'
" let xa += 1
" endif
View
@@ -3,8 +3,8 @@
" @Website: http://members.a1.net/t.link/
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2007-05-01.
-" @Last Change: 2010-02-06.
-" @Revision: 0.1.812
+" @Last Change: 2010-03-28.
+" @Revision: 0.1.834
" :filedoc:
" A prototype used by |tlib#input#List|.
@@ -589,6 +589,7 @@ function! s:prototype.UseInputListScratch() dict "{{{3
" hi def link InputlListIndex Special
" let b:tlibDisplayListMarks = {}
let b:tlibDisplayListMarks = []
+ let b:tlibDisplayListWorld = self
call tlib#hook#Run('tlib_UseInputListScratch', self)
return scratch
endf
@@ -693,15 +694,21 @@ endf
" :nodoc:
function! s:prototype.Resize(hsize, vsize) dict "{{{3
" TLogVAR self.scratch_vertical, a:hsize, a:vsize
+ let world_resize = ''
if self.scratch_vertical
if a:vsize
- exec 'vert resize '. eval(a:vsize)
+ let world_resize = 'vert resize '. a:vsize
endif
else
if a:hsize
- exec 'resize '. eval(a:hsize)
+ let world_resize = 'resize '. a:hsize
endif
endif
+ if !empty(world_resize)
+ " TLogVAR world_resize
+ exec world_resize
+ redraw!
+ endif
endf
@@ -716,7 +723,7 @@ function! s:prototype.DisplayList(query, ...) dict "{{{3
" TLogVAR self.scratch
" TAssert IsNotEmpty(self.scratch)
if self.state == 'scroll'
- exec 'norm! '. self.offset .'zt'
+ call self.ScrollToOffset()
elseif self.state == 'help'
call self.DisplayHelp()
else
@@ -727,12 +734,13 @@ function! s:prototype.DisplayList(query, ...) dict "{{{3
let x = self.index_width + 1
" TLogVAR ll
if self.state =~ '\<display\>'
- let resize = get(self, 'resize', 0)
- " TLogVAR resize
+ let resize0 = get(self, 'resize', 0)
+ let resize = empty(resize0) ? 0 : eval(resize0)
+ " TLogVAR resize0, resize
let resize = resize == 0 ? ll : min([ll, resize])
let resize = min([resize, (&lines * g:tlib_inputlist_pct / 100)])
" TLogVAR resize, ll, &lines
- call self.Resize(resize, get(self, 'resize_vertical', 0))
+ call self.Resize(resize, eval(get(self, 'resize_vertical', 0)))
call tlib#normal#WithRegister('gg"tdG', 't')
let w = winwidth(0) - &fdc
" let w = winwidth(0) - &fdc - 1
@@ -759,17 +767,7 @@ function! s:prototype.DisplayList(query, ...) dict "{{{3
call self.SetOffset()
call self.SetStatusline(a:query)
" TLogVAR self.offset
- " TLogDBG winheight('.')
- " if self.prefidx > winheight(0)
- " let lt = len(list) - winheight('.') + 1
- " if self.offset > lt
- " exec 'norm! '. lt .'zt'
- " else
- exec 'norm! '. self.offset .'zt'
- " endif
- " else
- " norm! 1zt
- " endif
+ call self.ScrollToOffset()
let rx0 = self.GetRx0()
" TLogVAR rx0
if !empty(g:tlib_inputlist_higroup)
@@ -803,6 +801,13 @@ function! s:prototype.SetStatusline(query) dict "{{{3
endf
+" :nodoc:
+function! s:prototype.ScrollToOffset() dict "{{{3
+ " TLogVAR self.scratch_vertical, self.llen, winheight(0)
+ exec 'norm! '. self.offset .'zt'
+endf
+
+
" :nodoc:
function! s:prototype.SetOffset() dict "{{{3
" TLogVAR self.prefidx, self.offset
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: 2007-06-24.
-" @Last Change: 2010-01-05.
-" @Revision: 0.1.174
+" @Last Change: 2010-03-27.
+" @Revision: 0.1.178
" :filedoc:
@@ -157,6 +157,8 @@ function! tlib#agent#Suspend(world, selected) "{{{3
let br = tlib#buffer#Set(a:world.scratch)
" TLogVAR br, a:world.bufnr, a:world.scratch
" TLogDBG bufnr('%')
+ call tlib#autocmdgroup#Init()
+ autocmd TLib InsertEnter,InsertChange <buffer> call tlib#input#Resume("world", 0)
let b:tlib_suspend = {
\ '<m-z>': 0, '<c-z>': 0, '<space>': 0,
\ '<cr>': 1,
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: 2007-06-30.
-" @Last Change: 2010-01-05.
-" @Revision: 0.0.288
+" @Last Change: 2010-03-29.
+" @Revision: 0.0.315
let s:bmru = []
@@ -135,11 +135,11 @@ function! tlib#buffer#GetList(...)
endif
endif
let buffer_nr = map(copy(buffer_list), 'matchstr(v:val, ''\s*\zs\d\+\ze'')')
- " TLogVAR buffer_list
+ " TLogVAR buffer_list, buffer_nr
if show_number
- call map(buffer_list, 'matchstr(v:val, ''\s*\d\+.\{-}\ze\s\+line \d\+\s*$'')')
+ call map(buffer_list, 'matchstr(v:val, ''^\s*\d\+.\{-}\ze\s\+\S\+ \d\+\s*$'')')
else
- call map(buffer_list, 'matchstr(v:val, ''\s*\d\+\zs.\{-}\ze\s\+line \d\+\s*$'')')
+ call map(buffer_list, 'matchstr(v:val, ''^\s*\d\+\zs.\{-}\ze\s\+\S\+ \d\+\s*$'')')
endif
" TLogVAR buffer_list
" call map(buffer_list, 'matchstr(v:val, ''^.\{-}\ze\s\+line \d\+\s*$'')')
@@ -174,11 +174,22 @@ function! tlib#buffer#ViewLine(line, ...) "{{{3
endf
-function! tlib#buffer#HighlightLine(line) "{{{3
+function! s:UndoHighlightLine() "{{{3
+ 3match none
+ autocmd! TLib CursorMoved,CursorMovedI <buffer>
+ autocmd! TLib CursorHold,CursorHoldI <buffer>
+ autocmd! TLib BufLeave,BufWinLeave,WinLeave,BufHidden <buffer>
+endf
+
+
+function! tlib#buffer#HighlightLine(...) "{{{3
+ TVarArg ['line', line('.')]
" exec '3match MatchParen /^\%'. a:line .'l.*/'
- exec '3match Search /^\%'. a:line .'l.*/'
+ exec '3match Search /^\%'. line .'l.*/'
call tlib#autocmdgroup#Init()
- autocmd TLib CursorHold,CursorHoldI,CursorMoved,CursorMovedI * 3match none
+ exec 'autocmd TLib CursorMoved,CursorMovedI <buffer> if line(".") != '. line .' | call s:UndoHighlightLine() | endif'
+ autocmd TLib CursorHold,CursorHoldI <buffer> call s:UndoHighlightLine()
+ autocmd TLib BufLeave,BufWinLeave,WinLeave,BufHidden <buffer> call s:UndoHighlightLine()
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: 2007-08-23.
-" @Last Change: 2009-02-15.
-" @Revision: 0.0.21
+" @Last Change: 2010-03-29.
+" @Revision: 0.0.27
if &cp || exists("loaded_tlib_cmd_autoload")
finish
@@ -49,8 +49,16 @@ endf
" Print the time in seconds a command takes.
function! tlib#cmd#Time(cmd) "{{{3
- let start = localtime()
- exec a:cmd
- echom 'Time: '. (localtime() - start) .'s: '. a:cmd
+ if has('reltime')
+ let start = tlib#time#Now()
+ exec a:cmd
+ let end = tlib#time#Now()
+ let diff = string(tlib#time#Diff(end, start)) .'ms'
+ else
+ let start = localtime()
+ exec a:cmd
+ let diff = (localtime() - start) .'s'
+ endif
+ echom 'Time: '. diff .': '. a:cmd
endf
View
@@ -0,0 +1,97 @@
+" date.vim
+" @Author: Thomas Link (mailto:micathom AT gmail com?subject=[vim])
+" @Website: http://www.lithom.net
+" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
+" @Created: 2010-03-25.
+" @Last Change: 2010-03-31.
+" @Revision: 0.0.12
+
+let s:save_cpo = &cpo
+set cpo&vim
+
+
+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
+
+
+" :display: tlib#date#DiffInDays(date1, ?date2=localtime(), ?allow_zero=0)
+function! tlib#date#DiffInDays(date, ...)
+ let allow_zero = a:0 >= 2 ? a:2 : 0
+ let s0 = tlib#date#SecondsSince1970(a:date, 0, allow_zero)
+ let s1 = a:0 >= 1 ? tlib#date#SecondsSince1970(a:1, 0, allow_zero) : localtime()
+ let dd = (s0 - s1) / g:tlib#date#Dayshift
+ " TLogVAR dd
+ return dd
+endf
+
+
+" tlib#date#SecondsSince1970(date, ?daysshift=0, ?allow_zero=0)
+function! tlib#date#SecondsSince1970(date, ...) "{{{3
+ let allow_zero = a:0 >= 2 ? a:2 : 0
+ let min = allow_zero ? 0 : 1
+ " TLogVAR a:date
+ let year = matchstr(a:date, '^\(\d\+\)\ze-\(\d\+\)-\(\d\+\)$')
+ let month = matchstr(a:date, '^\(\d\+\)-\zs\(\d\+\)\ze-\(\d\+\)$')
+ let days = matchstr(a:date, '^\(\d\+\)-\(\d\+\)-\zs\(\d\+\)$')
+ if year == '' || month == '' || days == '' ||
+ \ month < min || month > 12 || days < min || days > 31
+ echoerr 'PIM: Invalid date: '. a:date
+ return 0
+ endif
+ if strlen(year) == 2
+ let year = g:tlib#date#ShortDatePrefix . year
+ endif
+ if a:0 >= 1 && a:1 > 0
+ let days = days + a:1
+ end
+ let days_passed = days
+ let i = 1970
+ while i < year
+ let days_passed = days_passed + 365
+ if i % 4 == 0 || i == 2000
+ let days_passed = days_passed + 1
+ endif
+ let i = i + 1
+ endwh
+ let i = 1
+ while i < month
+ if i == 1
+ let days_passed = days_passed + 31
+ elseif i == 2
+ let days_passed = days_passed + 28
+ if year % 4 == 0 || year == 2000
+ let days_passed = days_passed + 1
+ endif
+ elseif i == 3
+ let days_passed = days_passed + 31
+ elseif i == 4
+ let days_passed = days_passed + 30
+ elseif i == 5
+ let days_passed = days_passed + 31
+ elseif i == 6
+ let days_passed = days_passed + 30
+ elseif i == 7
+ let days_passed = days_passed + 31
+ elseif i == 8
+ let days_passed = days_passed + 31
+ elseif i == 9
+ let days_passed = days_passed + 30
+ elseif i == 10
+ let days_passed = days_passed + 31
+ elseif i == 11
+ let days_passed = days_passed + 30
+ endif
+ let i = i + 1
+ endwh
+ let seconds = (days_passed - 1) * 24 * 60 * 60
+ let seconds = seconds + (strftime('%H') + g:tlib#date#TimeZoneShift) * 60 * 60
+ let seconds = seconds + strftime('%M') * 60
+ let seconds = seconds + strftime('%S')
+ return seconds
+endf
+
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
Oops, something went wrong.

0 comments on commit 8956e71

Please sign in to comment.