Mercurial > dotfiles
comparison .vim/plugin/fuzzyfinder_textmate.vim @ 0:c30d68fbd368
Initial import from svn.
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Wed, 26 Nov 2008 10:56:09 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c30d68fbd368 |
---|---|
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 | |
29 require "#{ENV['HOME']}/.vim/ruby/fuzzy_file_finder" | |
30 rescue LoadError | |
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' | |
42 end | |
43 RUBY | |
44 | |
45 " Configuration option: g:fuzzy_roots | |
46 " Specifies roots in which the FuzzyFinder will search. | |
47 if !exists('g:fuzzy_roots') | |
48 let g:fuzzy_roots = ['.'] | |
49 endif | |
50 | |
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 | |
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 | |
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 = [] | |
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 | |
106 ruby << RUBY | |
107 text = VIM.evaluate('self.remove_prompt(a:base)') | |
108 limit = VIM.evaluate('l:limit').to_i | |
109 | |
110 matches = finder.find(text, limit) | |
111 matches.sort_by { |a| [-a[:score], a[:path]] }.each_with_index do |match, index| | |
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 | |
118 | |
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 |