Skip to content
Browse files

Version 0.40

- tlib#agent#ViewFile: Use split/sbuffer if nohidden && modified
- tlib#buffer#GetList(): order by "basename"
  • Loading branch information...
1 parent fc9b9d2 commit 45d8ea16e2b940c4ab8a33f74704f0458951ff97 @tomtom tomtom committed with Oct 2, 2010
View
17 autoload/tlib/Filter_cnf.vim
@@ -3,14 +3,11 @@
" @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: 2010-03-22.
-" @Revision: 0.0.66
-
-let s:save_cpo = &cpo
-set cpo&vim
-
+" @Last Change: 2010-09-15.
+" @Revision: 0.0.69
let s:prototype = tlib#Object#New({'_class': ['Filter_cnf'], 'name': 'cnf'}) "{{{2
+let s:prototype.highlight = g:tlib_inputlist_higroup
" The search pattern for |tlib#input#List()| is in conjunctive normal
" form: (P1 OR P2 ...) AND (P3 OR P4 ...) ...
@@ -24,6 +21,11 @@ endf
" :nodoc:
+function! s:prototype.Init(world) dict "{{{3
+endf
+
+
+" :nodoc:
function! s:prototype.AssessName(world, name) dict "{{{3
let xa = 0
let prefix = self.FilterRxPrefix()
@@ -136,6 +138,3 @@ function! s:prototype.CleanFilter(filter) dict "{{{3
return a:filter
endf
-
-let &cpo = s:save_cpo
-unlet s:save_cpo
View
18 autoload/tlib/Filter_cnfd.vim
@@ -3,14 +3,12 @@
" @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.32
-
-let s:save_cpo = &cpo
-set cpo&vim
-
+" @Last Change: 2010-09-15.
+" @Revision: 0.0.35
let s:prototype = tlib#Filter_cnf#New({'_class': ['Filter_cnfd'], 'name': 'cnfd'}) "{{{2
+let s:prototype.highlight = g:tlib_inputlist_higroup
+
" The same as |tlib#FilterCNF#New()| but a dot is expanded to '\.\{-}'.
" As a consequence, patterns cannot match dots.
@@ -22,6 +20,11 @@ endf
" :nodoc:
+function! s:prototype.Init(world) dict "{{{3
+endf
+
+
+" :nodoc:
function! s:prototype.SetFrontFilter(world, pattern) dict "{{{3
let pattern = substitute(a:pattern, '\.', '\\.\\{-}', 'g')
let a:world.filter[0] = reverse(split(pattern, '\s*|\s*')) + a:world.filter[0][1 : -1]
@@ -49,6 +52,3 @@ function! s:prototype.CleanFilter(filter) dict "{{{3
return substitute(a:filter, '\\.\\{-}', '.', 'g')
endf
-
-let &cpo = s:save_cpo
-unlet s:save_cpo
View
29 autoload/tlib/Filter_fuzzy.vim
@@ -3,24 +3,37 @@
" @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.31
-
-let s:save_cpo = &cpo
-set cpo&vim
-
+" @Last Change: 2010-09-15.
+" @Revision: 0.0.38
let s:prototype = tlib#Filter_cnf#New({'_class': ['Filter_fuzzy'], 'name': 'fuzzy'}) "{{{2
+let s:prototype.highlight = ''
+
" Support for "fuzzy" pattern matching in |tlib#input#List()|.
" Characters are interpreted as if connected with '.\{-}'.
+"
+" In "fuzzy" mode, the pretty printing of filenames is disabled.
function! tlib#Filter_fuzzy#New(...) "{{{3
let object = s:prototype.New(a:0 >= 1 ? a:1 : {})
return object
endf
" :nodoc:
+function! s:prototype.Init(world) dict "{{{3
+ " TLogVAR a:world.display_format
+ function! a:world.Set_display_format(value) dict "{{{3
+ if a:value == 'filename'
+ let self.display_format = ''
+ else
+ let self.display_format = a:value
+ endif
+ endf
+endf
+
+
+" :nodoc:
function! s:prototype.DisplayFilter(filter) dict "{{{3
" TLogVAR a:filter
let filter1 = deepcopy(a:filter)
@@ -58,7 +71,3 @@ function! s:prototype.CleanFilter(filter) dict "{{{3
return substitute(a:filter, '\\\.\\{-}', '', 'g')
endf
-
-
-let &cpo = s:save_cpo
-unlet s:save_cpo
View
18 autoload/tlib/Filter_seq.vim
@@ -3,14 +3,11 @@
" @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.22
-
-let s:save_cpo = &cpo
-set cpo&vim
-
+" @Last Change: 2010-09-15.
+" @Revision: 0.0.24
let s:prototype = tlib#Filter_cnf#New({'_class': ['Filter_seq'], 'name': 'seq'}) "{{{2
+let s:prototype.highlight = g:tlib_inputlist_higroup
" The search pattern for |tlib#input#List()| is interpreted as a
" disjunction of 'magic' regular expressions with the exception of a dot
@@ -23,6 +20,11 @@ endf
" :nodoc:
+function! s:prototype.Init(world) dict "{{{3
+endf
+
+
+" :nodoc:
function! s:prototype.Match(world, text) dict "{{{3
" TLogVAR a:text
for rx in a:world.filter_neg
@@ -88,7 +90,3 @@ function! s:prototype.CleanFilter(filter) dict "{{{3
return substitute(a:filter, '.\\{-}', '.', 'g')
endf
-
-
-let &cpo = s:save_cpo
-unlet s:save_cpo
View
9 autoload/tlib/World.vim
@@ -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-05-01.
-" @Last Change: 2010-09-05.
-" @Revision: 0.1.871
+" @Last Change: 2010-09-22.
+" @Revision: 0.1.886
" :filedoc:
" A prototype used by |tlib#input#List|.
@@ -451,6 +451,7 @@ function! s:prototype.SetMatchMode(match_mode) dict "{{{3
unlet self.matcher
try
let self.matcher = tlib#Filter_{a:match_mode}#New()
+ call self.matcher.Init(self)
catch /^Vim\%((\a\+)\)\=:E117/
throw 'tlib: Unknown mode for tlib_inputlist_match: '. a:match_mode
endtry
@@ -797,11 +798,11 @@ function! s:prototype.DisplayList(query, ...) dict "{{{3
call self.ScrollToOffset()
let rx0 = self.GetRx0()
" TLogVAR rx0
- if !empty(g:tlib_inputlist_higroup)
+ if !empty(self.matcher.highlight)
if empty(rx0)
match none
elseif self.IsValidFilter()
- exec 'match '. g:tlib_inputlist_higroup .' /\c'. escape(rx0, '/') .'/'
+ exec 'match '. self.matcher.highlight .' /\c'. escape(rx0, '/') .'/'
endif
endif
endif
View
13 autoload/tlib/agent.vim
@@ -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-09-05.
-" @Revision: 0.1.180
+" @Last Change: 2010-09-16.
+" @Revision: 0.1.181
" :filedoc:
@@ -365,7 +365,14 @@ function! tlib#agent#ViewFile(world, selected) "{{{3
if !empty(a:selected)
let back = a:world.SwitchWindow('win')
" TLogVAR back
- call tlib#file#With('edit', 'buffer', a:selected, a:world)
+ 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)
exec back
let a:world.state = 'display'
endif
View
25 autoload/tlib/buffer.vim
@@ -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-04-28.
-" @Revision: 0.0.318
+" @Last Change: 2010-09-23.
+" @Revision: 0.0.334
let s:bmru = []
@@ -31,6 +31,17 @@ function! s:BMRU_Push(bnr) "{{{3
endf
+function! s:CompareBuffernameByBasename(a, b) "{{{3
+ let rx = '"\zs.\{-}\ze" \+\S\+ \+\d\+$'
+ let an = matchstr(a:a, rx)
+ let an = fnamemodify(an, ':t')
+ let bn = matchstr(a:b, rx)
+ let bn = fnamemodify(bn, ':t')
+ let rv = an == bn ? 0 : an > bn ? 1 : -1
+ return rv
+endf
+
+
function! s:CompareBufferNrByMRU(a, b) "{{{3
let an = matchstr(a:a, '\s*\zs\d\+\ze')
let bn = matchstr(a:b, '\s*\zs\d\+\ze')
@@ -119,8 +130,16 @@ endf
" :def: function! tlib#buffer#GetList(?show_hidden=0, ?show_number=0, " ?order='bufnr')
+" Possible values for the "order" argument:
+" bufnr :: Default behaviour
+" mru :: Sort buffers according to most recent use
+" basename :: Sort by the file's basename (last component)
+"
+" NOTE: MRU order works on second invocation only. If you want to always
+" use MRU order, call tlib#buffer#EnableMRU() in your ~/.vimrc file.
function! tlib#buffer#GetList(...)
TVarArg ['show_hidden', 0], ['show_number', 0], ['order', '']
+ " TLogVAR show_hidden, show_number, order
let ls_bang = show_hidden ? '!' : ''
redir => bfs
exec 'silent ls'. ls_bang
@@ -133,6 +152,8 @@ function! tlib#buffer#GetList(...)
else
call sort(buffer_list, function('s:CompareBufferNrByMRU'))
endif
+ 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'')')
" TLogVAR buffer_list, buffer_nr
View
65 autoload/tlib/date.vim
@@ -1,13 +1,10 @@
" date.vim
-" @Author: Thomas Link (mailto:micathom AT gmail com?subject=[vim])
-" @Website: http://www.lithom.net
+" @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: 2010-03-25.
-" @Last Change: 2010-09-13.
-" @Revision: 0.0.16
-
-let s:save_cpo = &cpo
-set cpo&vim
+" @Last Change: 2010-09-17.
+" @Revision: 0.0.34
if !exists('g:tlib#date#ShortDatePrefix') | let g:tlib#date#ShortDatePrefix = '20' | endif "{{{2
@@ -27,22 +24,51 @@ function! tlib#date#DiffInDays(date, ...)
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 == '' ||
+" :display: tlib#date#Parse(date, ?allow_zero=0) "{{{3
+function! tlib#date#Parse(date, ...) "{{{3
+ let min = a:0 >= 1 && a:1 ? 0 : 1
+ " TLogVAR a:date, min
+ let m = matchlist(a:date, '^\(\d\{2}\|\d\{4}\)-\(\d\{1,2}\)-\(\d\{1,2}\)$')
+ if !empty(m)
+ let year = m[1]
+ let month = m[2]
+ let days = m[3]
+ else
+ let m = matchlist(a:date, '^\(\d\+\)/\(\d\{1,2}\)/\(\d\{1,2}\)$')
+ if !empty(m)
+ let year = m[1]
+ let month = m[3]
+ let days = m[2]
+ else
+ let m = matchlist(a:date, '^\(\d\{1,2}\)\.\s*\(\d\{1,2}\)\.\s*\(\d\d\{2}\|\d\{4}\)$')
+ if !empty(m)
+ let year = m[3]
+ let month = m[2]
+ let days = m[1]
+ endif
+ endif
+ endif
+ if empty(m) || year == '' || month == '' || days == '' ||
\ month < min || month > 12 || days < min || days > 31
- echoerr 'PIM: Invalid date: '. a:date
- return 0
+ echoerr 'TLib: Invalid date: '. a:date
+ return []
endif
if strlen(year) == 2
let year = g:tlib#date#ShortDatePrefix . year
endif
+ return [0 + year, 0 + month, 0 + days]
+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
+ " TLogVAR a:date, allow_zero
+ let date = tlib#date#Parse(a:date, allow_zero)
+ if empty(date)
+ return 0
+ endif
+ let [year, month, days] = date
if a:0 >= 1 && a:1 > 0
let days = days + a:1
end
@@ -92,6 +118,3 @@ function! tlib#date#SecondsSince1970(date, ...) "{{{3
return seconds
endf
-
-let &cpo = s:save_cpo
-unlet s:save_cpo
View
11 autoload/tlib/input.vim
@@ -4,8 +4,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-09-05.
-" @Revision: 0.0.788
+" @Last Change: 2010-09-26.
+" @Revision: 0.0.807
" :filedoc:
@@ -258,6 +258,7 @@ function! tlib#input#ListW(world, ...) "{{{3
" TLogDBG len(world.list)
" TLogVAR world.list
let dlist = copy(world.list)
+ " TLogVAR world.display_format
if !empty(world.display_format)
let display_format = world.display_format
let cache = world.fmt_display
@@ -687,7 +688,7 @@ endf
function! tlib#input#Edit(name, value, callback, ...) "{{{3
" TLogVAR a:value
TVarArg ['args', []]
- let sargs = {'scratch': '__EDIT__'. a:name .'__'}
+ let sargs = {'scratch': '__EDIT__'. a:name .'__', 'win_wnr': winnr()}
let scr = tlib#scratch#UseScratch(sargs)
" :nodoc:
@@ -704,7 +705,6 @@ function! tlib#input#Edit(name, value, callback, ...) "{{{3
imap <buffer> <c-w><cr> <c-o>call <SID>EditCallback(1)<cr>
call tlib#normal#WithRegister('gg"tdG', 't')
- norm
call append(1, split(a:value, "\<c-j>", 1))
" let hrm = 'DON''T DELETE THIS HEADER'
" let hr3 = repeat('"', (tlib#win#Width(0) - len(hrm)) / 2)
@@ -743,7 +743,10 @@ function! s:EditCallback(...) "{{{3
let text = ok ? join(getline(start, '$'), "\n") : ''
let cb = b:tlib_scratch_edit_callback
let args = b:tlib_scratch_edit_args
+ let sargs = b:tlib_scratch_edit_scratch
+ " TLogVAR cb, args, sargs
call tlib#scratch#CloseScratch(b:tlib_scratch_edit_scratch)
+ call tlib#win#Set(sargs.win_wnr)
call call(cb, args + [ok, text])
endf
View
14 autoload/tlib/normal.vim
@@ -3,21 +3,29 @@
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2008-10-06.
-" @Last Change: 2009-02-15.
-" @Revision: 10
+" @Last Change: 2010-09-22.
+" @Revision: 28
let s:save_cpo = &cpo
set cpo&vim
+" :display: tlib#normal#WithRegister(cmd, ?register='t', ?norm_cmd='norm!')
+" Execute a normal command while maintaining all registers.
function! tlib#normal#WithRegister(cmd, ...) "{{{3
TVarArg ['register', 't'], ['norm_cmd', 'norm!']
+ let registers = {}
+ for reg in split('123456789'. register, '\zs')
+ exec 'let registers[reg] = @'. reg
+ endfor
exec 'let reg = @'. register
try
exec norm_cmd .' '. a:cmd
exec 'return @'. register
finally
- exec 'let @'. register .' = reg'
+ for [reg, value] in items(registers)
+ exec 'let @'. reg .' = value'
+ endfor
endtry
endf
View
9 autoload/tlib/type.vim
@@ -3,13 +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-09-30.
-" @Last Change: 2009-02-15.
-" @Revision: 0.0.3
-
-if &cp || exists("loaded_tlib_type_autoload")
- finish
-endif
-let loaded_tlib_type_autoload = 1
+" @Last Change: 2010-09-27.
+" @Revision: 0.0.4
function! tlib#type#IsNumber(expr)
return type(a:expr) == 0
View
29 doc/tlib.txt
@@ -108,6 +108,7 @@ Contents~
tlib#file#With .......................... |tlib#file#With()|
tlib#Filter_seq#New ..................... |tlib#Filter_seq#New()|
tlib#date#DiffInDays .................... |tlib#date#DiffInDays()|
+ tlib#date#Parse ......................... |tlib#date#Parse()|
tlib#date#SecondsSince1970 .............. |tlib#date#SecondsSince1970()|
tlib#balloon#Register ................... |tlib#balloon#Register()|
tlib#balloon#Remove ..................... |tlib#balloon#Remove()|
@@ -346,7 +347,8 @@ g:tlib_sortprefs_threshold (default: 200)
*g:tlib_scratch_pos*
g:tlib_scratch_pos (default: 'botright')
- Scratch window position
+ Scratch window position. By default the list window is opened on the
+ bottom. Set this variable to 'topleft' or '' to change this behaviour.
*g:tlib_inputlist_pct*
g:tlib_inputlist_pct (default: 50)
@@ -433,6 +435,13 @@ g:tlib_numeric_chars
*g:tlib_keyagents_InputList_s*
g:tlib_keyagents_InputList_s
+ The default key bindings for single-item-select list views. If you
+ want to use <c-j>, <c-k> to move the cursor up and down, add these two
+ lines to after/plugin/02tlib.vim: >
+
+ let g:tlib_keyagents_InputList_s[10] = 'tlib#agent#Down' " <c-j>
+ let g:tlib_keyagents_InputList_s[11] = 'tlib#agent#Up' " <c-k>
+<
*g:tlib_scroll_lines*
g:tlib_scroll_lines (default: 10)
@@ -714,6 +723,11 @@ autoload/tlib/Filter_fuzzy.vim~
tlib#Filter_fuzzy#New(...)
Support for "fuzzy" pattern matching in |tlib#input#List()|.
Characters are interpreted as if connected with '.\{-}'.
+
+ In "fuzzy" mode, the pretty printing of filenames is disabled.
+
+
+ TLogVAR a:world.display_format
========================================================================
@@ -761,6 +775,9 @@ autoload/tlib/date.vim~
*tlib#date#DiffInDays()*
tlib#date#DiffInDays(date1, ?date2=localtime(), ?allow_zero=0)
+ *tlib#date#Parse()*
+tlib#date#Parse(date, ?allow_zero=0) "{{{3
+
*tlib#date#SecondsSince1970()*
tlib#date#SecondsSince1970(date, ...)
tlib#date#SecondsSince1970(date, ?daysshift=0, ?allow_zero=0)
@@ -803,6 +820,13 @@ tlib#buffer#Eval(buffer, code)
*tlib#buffer#GetList()*
tlib#buffer#GetList(?show_hidden=0, ?show_number=0, " ?order='bufnr')
+ Possible values for the "order" argument:
+ bufnr :: Default behaviour
+ mru :: Sort buffers according to most recent use
+ basename :: Sort by the file's basename (last component)
+
+ NOTE: MRU order works on second invocation only. If you want to always
+ use MRU order, call tlib#buffer#EnableMRU() in your ~/.vimrc file.
*tlib#buffer#ViewLine()*
tlib#buffer#ViewLine(line, ?position='z')
@@ -1425,7 +1449,8 @@ tlib#map#PumAccept(key)
autoload/tlib/normal.vim~
*tlib#normal#WithRegister()*
-tlib#normal#WithRegister(cmd, ...)
+tlib#normal#WithRegister(cmd, ?register='t', ?norm_cmd='norm!')
+ Execute a normal command while maintaining all registers.
========================================================================
View
19 plugin/02tlib.vim
@@ -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-04-10.
-" @Last Change: 2010-09-05.
-" @Revision: 634
+" @Last Change: 2010-10-02.
+" @Revision: 646
" GetLatestVimScripts: 1863 1 tlib.vim
if &cp || exists("loaded_tlib")
@@ -14,7 +14,7 @@ if v:version < 700 "{{{2
echoerr "tlib requires Vim >= 7"
finish
endif
-let loaded_tlib = 39
+let loaded_tlib = 40
let s:save_cpo = &cpo
set cpo&vim
@@ -115,7 +115,8 @@ TLet g:tlib_pick_last_item = 1
" selecting an item. Be slightly faster instead.
TLet g:tlib_sortprefs_threshold = 200
-" Scratch window position
+" Scratch window position. By default the list window is opened on the
+" bottom. Set this variable to 'topleft' or '' to change this behaviour.
TLet g:tlib_scratch_pos = 'botright'
" Size of the input list window (in percent) from the main size (of &lines).
@@ -222,6 +223,12 @@ TLet g:tlib_numeric_chars = {
" \ 57: 48,
" :nodefault:
+" The default key bindings for single-item-select list views. If you
+" want to use <c-j>, <c-k> to move the cursor up and down, add these two
+" lines to after/plugin/02tlib.vim: >
+"
+" let g:tlib_keyagents_InputList_s[10] = 'tlib#agent#Down' " <c-j>
+" let g:tlib_keyagents_InputList_s[11] = 'tlib#agent#Up' " <c-k>
TLet g:tlib_keyagents_InputList_s = {
\ "\<PageUp>": 'tlib#agent#PageUp',
\ "\<PageDown>": 'tlib#agent#PageDown',
@@ -577,3 +584,7 @@ interpreted as string
- tlib#vim#RestoreWindow()
- tlib#ballon#...()
+0.40
+- tlib#agent#ViewFile: Use split/sbuffer if nohidden && modified
+- tlib#buffer#GetList(): order by "basename"
+

0 comments on commit 45d8ea1

Please sign in to comment.
Something went wrong with that request. Please try again.