]> git.r.bdr.sh - rbdr/dotfiles/blob - vim/tmp/command_t/plugin/command-t.vim
Update the stuff
[rbdr/dotfiles] / vim / tmp / command_t / plugin / command-t.vim
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
25 if exists("g:command_t_loaded")
26 finish
27 endif
28 let g:command_t_loaded = 1
29
30 command CommandTBuffer call <SID>CommandTShowBufferFinder()
31 command -nargs=? -complete=dir CommandT call <SID>CommandTShowFileFinder(<q-args>)
32 command CommandTFlush call <SID>CommandTFlush()
33
34 if !hasmapto(':CommandT<CR>')
35 silent! nmap <unique> <silent> <Leader>t :CommandT<CR>
36 endif
37
38 if !hasmapto(':CommandTBuffer<CR>')
39 silent! nmap <unique> <silent> <Leader>b :CommandTBuffer<CR>
40 endif
41
42 function 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
47 endfunction
48
49 function s:CommandTShowBufferFinder()
50 if has('ruby')
51 ruby $command_t.show_buffer_finder
52 else
53 call s:CommandTRubyWarning()
54 endif
55 endfunction
56
57 function s:CommandTShowFileFinder(arg)
58 if has('ruby')
59 ruby $command_t.show_file_finder
60 else
61 call s:CommandTRubyWarning()
62 endif
63 endfunction
64
65 function s:CommandTFlush()
66 if has('ruby')
67 ruby $command_t.flush
68 else
69 call s:CommandTRubyWarning()
70 endif
71 endfunction
72
73 if !has('ruby')
74 finish
75 endif
76
77 function CommandTHandleKey(arg)
78 ruby $command_t.handle_key
79 endfunction
80
81 function CommandTBackspace()
82 ruby $command_t.backspace
83 endfunction
84
85 function CommandTDelete()
86 ruby $command_t.delete
87 endfunction
88
89 function CommandTAcceptSelection()
90 ruby $command_t.accept_selection
91 endfunction
92
93 function CommandTAcceptSelectionTab()
94 ruby $command_t.accept_selection :command => 'tabe'
95 endfunction
96
97 function CommandTAcceptSelectionSplit()
98 ruby $command_t.accept_selection :command => 'sp'
99 endfunction
100
101 function CommandTAcceptSelectionVSplit()
102 ruby $command_t.accept_selection :command => 'vs'
103 endfunction
104
105 function CommandTToggleFocus()
106 ruby $command_t.toggle_focus
107 endfunction
108
109 function CommandTCancel()
110 ruby $command_t.cancel
111 endfunction
112
113 function CommandTSelectNext()
114 ruby $command_t.select_next
115 endfunction
116
117 function CommandTSelectPrev()
118 ruby $command_t.select_prev
119 endfunction
120
121 function CommandTClear()
122 ruby $command_t.clear
123 endfunction
124
125 function CommandTCursorLeft()
126 ruby $command_t.cursor_left
127 endfunction
128
129 function CommandTCursorRight()
130 ruby $command_t.cursor_right
131 endfunction
132
133 function CommandTCursorEnd()
134 ruby $command_t.cursor_end
135 endfunction
136
137 function CommandTCursorStart()
138 ruby $command_t.cursor_start
139 endfunction
140
141 ruby << 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
164 EOF