Permalink
Browse files

Version 0.28

- tlib#input#List():
-- Improved handling of sticky lists; <cr> and <Leftmouse> resume a suspended list and immediately selects the item under the cursor
-- Experimental "seq" matching style: the conjunctions are sequentially ordered, they are combined with "OR" (disjunctions), the regexp is 'magic', and "." is expanded to '.\{-}'
-- Experimental "cnfd" matching style: Same as cnf but with an "elastic" dot "." that matches '\.\{-}'
-- Filtering acts as if &ic=1 && $sc=1
-- Weighting is done by the filter
- tlib#agent#Input(): Consume <esc> when aborting input()
- INCOMPATIBLE CHANGE: Changed eligible values of g:tlib_inputlist_match to "cnf", "cnfd", "seq" and "fuzzy"
- NEW: tlib#buffer#KeepCursorPosition()
- tlib#buffer#InsertText(): Take care of the extra line when appending text to an empty buffer.
  • Loading branch information...
1 parent 3731cc3 commit 3c72e14bd233fa51541210f1741c2f0232d71254 @tomtom tomtom committed with Dec 2, 2008
@@ -0,0 +1,129 @@
+" Filter_cnf.vim
+" @Author: Thomas 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: 2008-11-25.
+" @Last Change: 2008-11-30.
+" @Revision: 0.0.53
+
+let s:save_cpo = &cpo
+set cpo&vim
+
+
+let s:prototype = tlib#Object#New({'_class': ['Filter_cnf'], 'name': 'cnf'}) "{{{2
+
+" The search pattern for |tlib#input#List()| is in conjunctive normal
+" form: (P1 OR P2 ...) AND (P3 OR P4 ...) ...
+" The pattern is a '/\V' very no-'/magic' regexp pattern.
+"
+" This is also the base class for other filters.
+function! tlib#Filter_cnf#New(...) "{{{3
+ let object = s:prototype.New(a:0 >= 1 ? a:1 : {})
+ return object
+endf
+
+
+" :nodoc:
+function! s:prototype.AssessName(world, name) dict "{{{3
+ let xa = 0
+ let prefix = self.FilterRxPrefix()
+ for flt in a:world.filter_pos
+ " let flt = prefix . a:world.GetRx(fltl)
+ " if flt =~# '\u' && a:name =~# flt
+ " let xa += 5
+ " 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
+ " if flt[0] =~# '\U' && matchstr(a:name, '\V\.\ze'. flt) =~# '\u'
+ " let xa += 1
+ " endif
+ " if flt[-1] =~# '\u' && matchstr(a:name, '\V'. flt .'\zs\.') =~# '\U'
+ " let xa += 1
+ " endif
+ " if flt[-1] =~# '\U' && matchstr(a:name, '\V'. flt .'\zs\.') =~# '\u'
+ " let xa += 1
+ " endif
+ endfor
+ " TLogVAR a:name, xa
+ return xa
+endf
+
+
+" :nodoc:
+function! s:prototype.Match(world, text) dict "{{{3
+ " let sc = &smartcase
+ " let ic = &ignorecase
+ " if &ignorecase
+ " set smartcase
+ " endif
+ " try
+ for rx in a:world.filter_neg
+ " TLogVAR rx
+ if a:text =~ rx
+ return 0
+ endif
+ endfor
+ for rx in a:world.filter_pos
+ " TLogVAR rx
+ if a:text !~ rx
+ return 0
+ endif
+ endfor
+ " finally
+ " let &smartcase = sc
+ " let &ignorecase = ic
+ " endtry
+ return 1
+endf
+
+
+" :nodoc:
+function! s:prototype.DisplayFilter(filter) dict "{{{3
+ let filter1 = deepcopy(a:filter)
+ call map(filter1, '"(". join(reverse(v:val), " OR ") .")"')
+ return join(reverse(filter1), ' AND ')
+endf
+
+
+" :nodoc:
+function! s:prototype.SetFrontFilter(world, pattern) dict "{{{3
+ let a:world.filter[0] = reverse(split(a:pattern, '\s*|\s*')) + a:world.filter[0][1 : -1]
+endf
+
+
+" :nodoc:
+function! s:prototype.PushFrontFilter(world, char) dict "{{{3
+ let a:world.filter[0][0] .= nr2char(a:char)
+endf
+
+
+" :nodoc:
+function! s:prototype.ReduceFrontFilter(world) dict "{{{3
+ let a:world.filter[0][0] = a:world.filter[0][0][0:-2]
+endf
+
+
+" :nodoc:
+function! s:prototype.FilterRxPrefix() dict "{{{3
+ return '\V'
+endf
+
+
+" :nodoc:
+function! s:prototype.CleanFilter(filter) dict "{{{3
+ return a:filter
+endf
+
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
@@ -0,0 +1,54 @@
+" Filter_cnfd.vim
+" @Author: Thomas 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: 2008-11-25.
+" @Last Change: 2008-11-30.
+" @Revision: 0.0.31
+
+let s:save_cpo = &cpo
+set cpo&vim
+
+
+let s:prototype = tlib#Filter_cnf#New({'_class': ['Filter_cnfd'], 'name': 'cnfd'}) "{{{2
+
+" The same as |tlib#FilterCNF#New()| but a dot is expanded to '\.\{-}'.
+" As a consequence, patterns cannot match dots.
+" The pattern is a '/\V' very no-'/magic' regexp pattern.
+function! tlib#Filter_cnfd#New(...) "{{{3
+ let object = s:prototype.New(a:0 >= 1 ? a:1 : {})
+ return object
+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]
+endf
+
+
+" :nodoc:
+function! s:prototype.PushFrontFilter(world, char) dict "{{{3
+ let a:world.filter[0][0] .= a:char == 46 ? '\.\{-}' : nr2char(a:char)
+endf
+
+
+" :nodoc:
+function! s:prototype.ReduceFrontFilter(world) dict "{{{3
+ let flt = a:world.filter[0][0]
+ if flt =~ '\\\.\\{-}$'
+ let a:world.filter[0][0] = flt[0:-7]
+ else
+ let a:world.filter[0][0] = flt[0:-2]
+ endif
+endf
+
+" :nodoc:
+function! s:prototype.CleanFilter(filter) dict "{{{3
+ return substitute(a:filter, '\\.\\{-}', '.', 'g')
+endf
+
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
@@ -0,0 +1,64 @@
+" Filter_fuzzy.vim
+" @Author: Thomas 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: 2008-11-25.
+" @Last Change: 2008-11-30.
+" @Revision: 0.0.30
+
+let s:save_cpo = &cpo
+set cpo&vim
+
+
+let s:prototype = tlib#Filter_cnf#New({'_class': ['Filter_fuzzy'], 'name': 'fuzzy'}) "{{{2
+
+" Support for "fuzzy" pattern matching in |tlib#input#List()|.
+" Characters are interpreted as if connected with '.\{-}'.
+function! tlib#Filter_fuzzy#New(...) "{{{3
+ let object = s:prototype.New(a:0 >= 1 ? a:1 : {})
+ return object
+endf
+
+
+" :nodoc:
+function! s:prototype.DisplayFilter(filter) dict "{{{3
+ " TLogVAR a:filter
+ let filter1 = deepcopy(a:filter)
+ call map(filter1, '"{". join(reverse(v:val), " OR ") ."}"')
+ return join(reverse(filter1), ' AND ')
+endf
+
+
+" :nodoc:
+function! s:prototype.SetFrontFilter(world, pattern) dict "{{{3
+ let a:world.filter[0] = map(reverse(split(a:pattern, '\s*|\s*')), 'join(map(split(v:val, ''\zs''), ''tlib#rx#Escape(v:val, "V")''), ''\.\{-}'')') + a:world.filter[0][1 : -1]
+ endif
+endf
+
+
+" :nodoc:
+function! s:prototype.PushFrontFilter(world, char) dict "{{{3
+ let ch = tlib#rx#Escape(nr2char(a:char), 'V')
+ if empty(a:world.filter[0][0])
+ let a:world.filter[0][0] .= ch
+ else
+ let a:world.filter[0][0] .= '\.\{-}'. ch
+ endif
+endf
+
+
+" :nodoc:
+function! s:prototype.ReduceFrontFilter(world) dict "{{{3
+ let a:world.filter[0][0] = substitute(a:world.filter[0][0], '\(\\\.\\{-}\)\?.$', '', '')
+endf
+
+
+" :nodoc:
+function! s:prototype.CleanFilter(filter) dict "{{{3
+ return substitute(a:filter, '\\\.\\{-}', '', 'g')
+endf
+
+
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
@@ -0,0 +1,94 @@
+" Filter_seq.vim
+" @Author: Thomas 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: 2008-11-25.
+" @Last Change: 2008-11-30.
+" @Revision: 0.0.21
+
+let s:save_cpo = &cpo
+set cpo&vim
+
+
+let s:prototype = tlib#Filter_cnf#New({'_class': ['Filter_seq'], 'name': 'seq'}) "{{{2
+
+" The search pattern for |tlib#input#List()| is interpreted as a
+" disjunction of 'magic' regular expressions with the exception of a dot
+" ".", which is interpreted as ".\{-}".
+" The pattern is a '/magic' regexp pattern.
+function! tlib#Filter_seq#New(...) "{{{3
+ let object = s:prototype.New(a:0 >= 1 ? a:1 : {})
+ return object
+endf
+
+
+" :nodoc:
+function! s:prototype.Match(world, text) dict "{{{3
+ " TLogVAR a:text
+ for rx in a:world.filter_neg
+ if a:text !~ rx
+ " TLogDBG "filter_neg ". rx
+ return 1
+ endif
+ endfor
+ for rx in a:world.filter_pos
+ if a:text =~ rx
+ " TLogDBG "filter_pos ". rx
+ return 1
+ endif
+ endfor
+ return 0
+endf
+
+
+" :nodoc:
+function! s:prototype.DisplayFilter(filter) dict "{{{3
+ let filter1 = deepcopy(a:filter)
+ call map(filter1, '"(". join(reverse(v:val), "_") .")"')
+ return join(reverse(filter1), ' OR ')
+endf
+
+
+" :nodoc:
+function! s:prototype.SetFrontFilter(world, pattern) dict "{{{3
+ let a:world.filter[0] = map(reverse(split(a:pattern, '\s*|\s*')), 'join(split(v:val, ''\.''), ''.\{-}'')') + a:world.filter[0][1 : -1]
+endf
+
+
+" :nodoc:
+function! s:prototype.PushFrontFilter(world, char) dict "{{{3
+ let cc = nr2char(a:char)
+ if cc == '.'
+ let a:world.filter[0][0] .= '.\{-}'
+ else
+ let a:world.filter[0][0] .= nr2char(a:char)
+ endif
+endf
+
+
+" :nodoc:
+function! s:prototype.ReduceFrontFilter(world) dict "{{{3
+ let flt = a:world.filter[0][0]
+ if flt =~ '\.\\{-}$'
+ let a:world.filter[0][0] = flt[0:-6]
+ else
+ let a:world.filter[0][0] = flt[0:-2]
+ endif
+endf
+
+
+" :nodoc:
+function! s:prototype.FilterRxPrefix() dict "{{{3
+ return ''
+endf
+
+
+" :nodoc:
+function! s:prototype.CleanFilter(filter) dict "{{{3
+ return substitute(a:filter, '.\\{-}', '.', 'g')
+endf
+
+
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
Oops, something went wrong.

0 comments on commit 3c72e14

Please sign in to comment.