hotchpotch (owner)

Revisions

gist: 94299 Download_button fork
public
Public Clone URL: git://gist.github.com/94299.git
Embed All Files: show embed
fuzzyfinder.vim.diff #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
*** fuzzyfinder.vim.org 2009-04-13 14:42:27.000000000 +0900
--- fuzzyfinder.vim 2009-03-12 11:30:02.000000000 +0900
***************
*** 569,574 ****
--- 569,581 ----
    return a:str[:(a:len - len(s:ABBR_TRIM_MARK) - 1)] . s:ABBR_TRIM_MARK
  endfunction
  
+ function! s:TrimFirst(str, len)
+ if a:len <= 0 || len(a:str) <= a:len
+ return a:str
+ endif
+ return s:ABBR_TRIM_MARK . a:str[(len(a:str)-a:len):(len(a:str)-1)]
+ endfunction
+
  " takes suffix numer. if no digits, returns -1
  function! s:SuffixNumber(str)
    let s = matchstr(a:str, '\d\+$')
***************
*** 821,827 ****
  endfunction
  
  function! s:SetFormattedAbbr(item, key, trim_len)
! let a:item.abbr = s:TrimLast(printf('%3d: %s', a:item.index, a:item[a:key]), a:trim_len)
    return a:item
  endfunction
  
--- 828,835 ----
  endfunction
  
  function! s:SetFormattedAbbr(item, key, trim_len)
! " let a:item.abbr = s:TrimLast(printf('%3d: %s', a:item.index, a:item[a:key]), a:trim_len)
! let a:item.abbr = s:TrimFirst(printf('%3d: %s', a:item.index, a:item[a:key]), a:trim_len)
    return a:item
  endfunction
  
***************
*** 1090,1098 ****
  " partial: 'str' -> {'base':'str', 'wi':'*str*', 're':'\V\.\*str\.\*'}
  function! g:FuzzyFinderMode.Base.make_pattern(base)
    if self.partial_matching
! let wi = (a:base !~ '^[*?]' ? '*' : '') . a:base .
! \ (a:base =~ '[^*?]$' ? '*' : '')
! let re = s:ConvertWildcardToRegexp(wi)
      return { 'base': a:base, 'wi':wi, 're': re }
    else
      let wi = ''
--- 1098,1121 ----
  " partial: 'str' -> {'base':'str', 'wi':'*str*', 're':'\V\.\*str\.\*'}
  function! g:FuzzyFinderMode.Base.make_pattern(base)
    if self.partial_matching
! let words = split(a:base, '\v\s+')
! if len(words) >= 2
! let wi1 = (words[0] !~ '^[*?]' ? '*' : '') . words[0] .
! \ (words[0] =~ '[^*?]$' ? '*' : '')
! let wi2 = (words[1] !~ '^[*?]' ? '*' : '') . words[1] .
! \ (words[1] =~ '[^*?]$' ? '*' : '')
! let wi1 = substitute(s:ConvertWildcardToRegexp(wi1), '^\\V', '', '')
! let wi2 = substitute(s:ConvertWildcardToRegexp(wi2), '^\\V', '', '')
! let wi = 'FIXME'
! let re = '\V'.'\('.wi1.wi2.'\)\|\('.wi2.wi1.'\)'
! elseif len(words) == 1
! let wi = (words[0] !~ '^[*?]' ? '*' : '') . words[0] .
! \ (words[0] =~ '[^*?]$' ? '*' : '')
! let re = s:ConvertWildcardToRegexp(wi)
! else
! let wi = ''
! let re = s:ConvertWildcardToRegexp(wi)
! endif
      return { 'base': a:base, 'wi':wi, 're': re }
    else
      let wi = ''
***************
*** 1270,1280 ****
  " OBJECT: g:FuzzyFinderMode.MruFile ------------------------------------- {{{1
  let g:FuzzyFinderMode.MruFile = copy(g:FuzzyFinderMode.Base)
  
  function! g:FuzzyFinderMode.MruFile.on_complete(base)
    let patterns = self.make_pattern(a:base)
    let base_tail = s:SplitPath(a:base).tail
    let stats = self.get_filtered_stats(a:base)
! let result = s:FilterMatching(self.items, 'word', patterns.re, s:SuffixNumber(patterns.base), self.enumerating_limit)
    return map(result, 's:SetRanks(v:val, s:SplitPath(matchstr(v:val.word, ''^.*[^/\\]'')).tail, base_tail, stats)')
  endfunction
  
--- 1293,1320 ----
  " OBJECT: g:FuzzyFinderMode.MruFile ------------------------------------- {{{1
  let g:FuzzyFinderMode.MruFile = copy(g:FuzzyFinderMode.Base)
  
+ function! s:IndexOfMatching(str, words)
+ let s = tolower(a:str)
+ for word in a:words
+ if stridx(s, word) == -1
+ return 0
+ endif
+ endfor
+ return 1
+ endfunction
+
  function! g:FuzzyFinderMode.MruFile.on_complete(base)
    let patterns = self.make_pattern(a:base)
    let base_tail = s:SplitPath(a:base).tail
    let stats = self.get_filtered_stats(a:base)
!
! if 0
! let result = s:FilterMatching(self.items, 'word', patterns.re, s:SuffixNumber(patterns.base), self.enumerating_limit)
! else
! let words = split(tolower(a:base), ' ')
! let result = s:FilterEx(self.items, 's:IndexOfMatching(v:val.word, ' . string(words) . ')', self.enumerating_limit)
! endif
!
    return map(result, 's:SetRanks(v:val, s:SplitPath(matchstr(v:val.word, ''^.*[^/\\]'')).tail, base_tail, stats)')
  endfunction
  
***************
*** 1543,1549 ****
  
  function! s:SetLocalOptionsForFuzzyfinder(cwd, complete_func)
    " countermeasure for auto-cd script
! execute ':lcd ' . a:cwd
    setlocal filetype=fuzzyfinder
    setlocal bufhidden=delete
    setlocal buftype=nofile
--- 1583,1589 ----
  
  function! s:SetLocalOptionsForFuzzyfinder(cwd, complete_func)
    " countermeasure for auto-cd script
! execute ':lcd ' . escape(a:cwd, ' ')
    setlocal filetype=fuzzyfinder
    setlocal bufhidden=delete
    setlocal buftype=nofile