Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 151 lines (125 sloc) 5.121 kB
0f5c8cb @jamis Initial commit
jamis authored
1 if has("ruby")
2
3 " ====================================================================================
4 " COPIED FROM FUZZYFINDER.VIM {{{
5 " since they can't be called from outside fuzzyfinder.vim
6 " ====================================================================================
7 function! s:GetCurrentTagFiles()
8 return sort(filter(map(tagfiles(), 'fnamemodify(v:val, '':p'')'), 'filereadable(v:val)'))
9 endfunction
10
11 function! s:HighlightPrompt(prompt, highlight)
12 syntax clear
13 execute printf('syntax match %s /^\V%s/', a:highlight, escape(a:prompt, '\'))
14 endfunction
15
16 function! s:HighlightError()
17 syntax clear
18 syntax match Error /^.*$/
19 endfunction
20 " ------------------------------------------------------------------------------------
21 " }}}
22 " ====================================================================================
23
24 command! -bang -narg=? -complete=file FuzzyFinderTextMate call FuzzyFinderTextMateLauncher(<q-args>, len(<q-bang>), bufnr('%'), s:GetCurrentTagFiles())
25
26 function! InstantiateTextMateMode() "{{{
27 ruby << RUBY
28 begin
c524007 @jamis Smarter loading of the fuzzy_file_finder module
jamis authored
29 require "#{ENV['HOME']}/.vim/ruby/fuzzy_file_finder"
0f5c8cb @jamis Initial commit
jamis authored
30 rescue LoadError
c524007 @jamis Smarter loading of the fuzzy_file_finder module
jamis authored
31 begin
32 require 'rubygems'
33 begin
34 gem 'fuzzy_file_finder'
35 rescue Gem::LoadError
36 gem 'jamis-fuzzy_file_finder'
37 end
38 rescue LoadError
39 end
40
41 require 'fuzzy_file_finder'
0f5c8cb @jamis Initial commit
jamis authored
42 end
43 RUBY
44
e2e1d44 Pass multiple roots to FuzzyFileFinder constructor via the g:fuzzy_ro…
Kevin authored
45 " Configuration option: g:fuzzy_roots
46 " Specifies roots in which the FuzzyFinder will search.
47 if !exists('g:fuzzy_roots')
8641b06 @jamis Add g:fuzzy_ceiling variable for handling very large trees
jamis authored
48 let g:fuzzy_roots = ['.']
e2e1d44 Pass multiple roots to FuzzyFileFinder constructor via the g:fuzzy_ro…
Kevin authored
49 endif
50
8641b06 @jamis Add g:fuzzy_ceiling variable for handling very large trees
jamis authored
51 " Configuration option: g:fuzzy_ceiling
52 " Specifies the maximum number of files that FuzzyFinder allows to be searched
53 if !exists('g:fuzzy_ceiling')
54 let g:fuzzy_ceiling = 10000
55 endif
56
5b47120 @jamis Add variables for the different options. See README.
jamis authored
57 " Configuration option: g:fuzzy_ignore
58 " A semi-colon delimited list of file glob patterns to ignore
59 if !exists('g:fuzzy_ignore')
60 let g:fuzzy_ignore = ""
61 endif
62
63 " Configuration option: g:fuzzy_matching_limit
64 " The maximum number of matches to return at a time. Defaults to 200, via the
65 " g:FuzzyFinderMode.TextMate.matching_limit variable, but using a global variable
66 " makes it easier to set this value.
67
68 ruby << RUBY
69 def finder
70 @finder ||= begin
71 roots = VIM.evaluate("g:fuzzy_roots").split("\n")
72 ceiling = VIM.evaluate("g:fuzzy_ceiling").to_i
73 ignore = VIM.evaluate("g:fuzzy_ignore").split(/;/)
74 FuzzyFileFinder.new(roots, ceiling, ignore)
75 end
76 end
77 RUBY
0f5c8cb @jamis Initial commit
jamis authored
78
79 let g:FuzzyFinderMode.TextMate = copy(g:FuzzyFinderMode.Base)
80
81 " ================================================================================
82 " This function is copied almost whole-sale from fuzzyfinder.vim. Ideally, I could
83 " used the on_complete callback to more cleanly add the new behavior, but the
84 " TextMate-style completion broke a few of fuzzyfinder.vim's assumptions, and the
85 " only way to patch that up was to override Base.complete...which required me to
86 " copy-and-paste much of the original implementation.
87 "
88 " Ugly. But effective.
89 " ================================================================================
90 function! g:FuzzyFinderMode.TextMate.complete(findstart, base)
91 if a:findstart
92 return 0
93 elseif !self.exists_prompt(a:base) || len(self.remove_prompt(a:base)) < self.min_length
94 return []
95 endif
96 call s:HighlightPrompt(self.prompt, self.prompt_highlight)
97
98 let result = []
5b47120 @jamis Add variables for the different options. See README.
jamis authored
99
100 if exists('g:fuzzy_matching_limit')
101 let l:limit = g:fuzzy_matching_limit
102 else
103 let l:limit = self.matching_limit
104 endif
105
0f5c8cb @jamis Initial commit
jamis authored
106 ruby << RUBY
5b47120 @jamis Add variables for the different options. See README.
jamis authored
107 text = VIM.evaluate('self.remove_prompt(a:base)')
108 limit = VIM.evaluate('l:limit').to_i
109
110 matches = finder.find(text, limit)
99bdad5 @jamis revert the constraint of [0,50] since that's the point of self.matchi…
jamis authored
111 matches.sort_by { |a| [-a[:score], a[:path]] }.each_with_index do |match, index|
0f5c8cb @jamis Initial commit
jamis authored
112 word = match[:path]
113 abbr = "%2d: %s" % [index+1, match[:abbr]]
114 menu = "[%5d]" % [match[:score] * 10000]
115 VIM.evaluate("add(result, { 'word' : #{word.inspect}, 'abbr' : #{abbr.inspect}, 'menu' : #{menu.inspect} })")
116 end
117 RUBY
5b47120 @jamis Add variables for the different options. See README.
jamis authored
118
0f5c8cb @jamis Initial commit
jamis authored
119 if empty(result) || len(result) >= self.matching_limit
120 call s:HighlightError()
121 endif
122
123 if !empty(result)
124 call feedkeys("\<C-p>\<Down>", 'n')
125 endif
126
127 return result
128 endfunction
129
130 function! FuzzyFinderTextMateLauncher(initial_text, partial_matching, prev_bufnr, tag_files)
131 call g:FuzzyFinderMode.TextMate.launch(a:initial_text, a:partial_matching, a:prev_bufnr, a:tag_files)
132 endfunction
133
134 let g:FuzzyFinderOptions.TextMate = copy(g:FuzzyFinderOptions.File)
135 endfunction "}}}
136
137 if !exists('loaded_fuzzyfinder') "{{{
138 function! FuzzyFinderTextMateLauncher(initial_text, partial_matching, prev_bufnr, tag_files)
139 call InstantiateTextMateMode()
140 function! FuzzyFinderTextMateLauncher(initial_text, partial_matching, prev_bufnr, tag_files)
141 call g:FuzzyFinderMode.TextMate.launch(a:initial_text, a:partial_matching, a:prev_bufnr, a:tag_files)
142 endfunction
143 call g:FuzzyFinderMode.TextMate.launch(a:initial_text, a:partial_matching, a:prev_bufnr, a:tag_files)
144 endfunction
145 finish
146 end "}}}
147
148 call InstantiateTextMateMode()
149
150 endif
Something went wrong with that request. Please try again.