]> git.r.bdr.sh - rbdr/dotfiles/blame_incremental - vim/tmp/command_t/plugin/command-t.vim
Update the stuff
[rbdr/dotfiles] / vim / tmp / command_t / plugin / command-t.vim
... / ...
CommitLineData
1" command-t.vim
2" Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
3"
4" Redistribution and use in source and binary forms, with or without
5" modification, are permitted provided that the following conditions are met:
6"
7" 1. Redistributions of source code must retain the above copyright notice,
8" this list of conditions and the following disclaimer.
9" 2. Redistributions in binary form must reproduce the above copyright notice,
10" this list of conditions and the following disclaimer in the documentation
11" and/or other materials provided with the distribution.
12"
13" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16" ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
17" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23" POSSIBILITY OF SUCH DAMAGE.
24
25if exists("g:command_t_loaded")
26 finish
27endif
28let g:command_t_loaded = 1
29
30command CommandTBuffer call <SID>CommandTShowBufferFinder()
31command -nargs=? -complete=dir CommandT call <SID>CommandTShowFileFinder(<q-args>)
32command CommandTFlush call <SID>CommandTFlush()
33
34if !hasmapto(':CommandT<CR>')
35 silent! nmap <unique> <silent> <Leader>t :CommandT<CR>
36endif
37
38if !hasmapto(':CommandTBuffer<CR>')
39 silent! nmap <unique> <silent> <Leader>b :CommandTBuffer<CR>
40endif
41
42function s:CommandTRubyWarning()
43 echohl WarningMsg
44 echo "command-t.vim requires Vim to be compiled with Ruby support"
45 echo "For more information type: :help command-t"
46 echohl none
47endfunction
48
49function s:CommandTShowBufferFinder()
50 if has('ruby')
51 ruby $command_t.show_buffer_finder
52 else
53 call s:CommandTRubyWarning()
54 endif
55endfunction
56
57function s:CommandTShowFileFinder(arg)
58 if has('ruby')
59 ruby $command_t.show_file_finder
60 else
61 call s:CommandTRubyWarning()
62 endif
63endfunction
64
65function s:CommandTFlush()
66 if has('ruby')
67 ruby $command_t.flush
68 else
69 call s:CommandTRubyWarning()
70 endif
71endfunction
72
73if !has('ruby')
74 finish
75endif
76
77function CommandTHandleKey(arg)
78 ruby $command_t.handle_key
79endfunction
80
81function CommandTBackspace()
82 ruby $command_t.backspace
83endfunction
84
85function CommandTDelete()
86 ruby $command_t.delete
87endfunction
88
89function CommandTAcceptSelection()
90 ruby $command_t.accept_selection
91endfunction
92
93function CommandTAcceptSelectionTab()
94 ruby $command_t.accept_selection :command => 'tabe'
95endfunction
96
97function CommandTAcceptSelectionSplit()
98 ruby $command_t.accept_selection :command => 'sp'
99endfunction
100
101function CommandTAcceptSelectionVSplit()
102 ruby $command_t.accept_selection :command => 'vs'
103endfunction
104
105function CommandTToggleFocus()
106 ruby $command_t.toggle_focus
107endfunction
108
109function CommandTCancel()
110 ruby $command_t.cancel
111endfunction
112
113function CommandTSelectNext()
114 ruby $command_t.select_next
115endfunction
116
117function CommandTSelectPrev()
118 ruby $command_t.select_prev
119endfunction
120
121function CommandTClear()
122 ruby $command_t.clear
123endfunction
124
125function CommandTCursorLeft()
126 ruby $command_t.cursor_left
127endfunction
128
129function CommandTCursorRight()
130 ruby $command_t.cursor_right
131endfunction
132
133function CommandTCursorEnd()
134 ruby $command_t.cursor_end
135endfunction
136
137function CommandTCursorStart()
138 ruby $command_t.cursor_start
139endfunction
140
141ruby << EOF
142 # require Ruby files
143 begin
144 # prepare controller
145 require 'command-t/vim'
146 require 'command-t/controller'
147 $command_t = CommandT::Controller.new
148 rescue LoadError
149 load_path_modified = false
150 ::VIM::evaluate('&runtimepath').to_s.split(',').each do |path|
151 lib = "#{path}/ruby"
152 if !$LOAD_PATH.include?(lib) and File.exist?(lib)
153 $LOAD_PATH << lib
154 load_path_modified = true
155 end
156 end
157 retry if load_path_modified
158
159 # could get here if C extension was not compiled, or was compiled
160 # for the wrong architecture or Ruby version
161 require 'command-t/stub'
162 $command_t = CommandT::Stub.new
163 end
164EOF