2 " Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
4 " Redistribution and use in source and binary forms, with or without
5 " modification, are permitted provided that the following conditions are met:
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.
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.
25 if exists("g:command_t_loaded")
28 let g:command_t_loaded = 1
30 command CommandTBuffer call <SID>CommandTShowBufferFinder()
31 command -nargs=? -complete=dir CommandT call <SID>CommandTShowFileFinder(<q-args>)
32 command CommandTFlush call <SID>CommandTFlush()
34 if !hasmapto(':CommandT<CR>')
35 silent! nmap <unique> <silent> <Leader>t :CommandT<CR>
38 if !hasmapto(':CommandTBuffer<CR>')
39 silent! nmap <unique> <silent> <Leader>b :CommandTBuffer<CR>
42 function s:CommandTRubyWarning()
44 echo "command-t.vim requires Vim to be compiled with Ruby support"
45 echo "For more information type: :help command-t"
49 function s:CommandTShowBufferFinder()
51 ruby $command_t.show_buffer_finder
53 call s:CommandTRubyWarning()
57 function s:CommandTShowFileFinder(arg)
59 ruby $command_t.show_file_finder
61 call s:CommandTRubyWarning()
65 function s:CommandTFlush()
69 call s:CommandTRubyWarning()
77 function CommandTHandleKey(arg)
78 ruby $command_t.handle_key
81 function CommandTBackspace()
82 ruby $command_t.backspace
85 function CommandTDelete()
86 ruby $command_t.delete
89 function CommandTAcceptSelection()
90 ruby $command_t.accept_selection
93 function CommandTAcceptSelectionTab()
94 ruby $command_t.accept_selection :command => 'tabe'
97 function CommandTAcceptSelectionSplit()
98 ruby $command_t.accept_selection :command => 'sp'
101 function CommandTAcceptSelectionVSplit()
102 ruby $command_t.accept_selection :command => 'vs'
105 function CommandTToggleFocus()
106 ruby $command_t.toggle_focus
109 function CommandTCancel()
110 ruby $command_t.cancel
113 function CommandTSelectNext()
114 ruby $command_t.select_next
117 function CommandTSelectPrev()
118 ruby $command_t.select_prev
121 function CommandTClear()
122 ruby $command_t.clear
125 function CommandTCursorLeft()
126 ruby $command_t.cursor_left
129 function CommandTCursorRight()
130 ruby $command_t.cursor_right
133 function CommandTCursorEnd()
134 ruby $command_t.cursor_end
137 function CommandTCursorStart()
138 ruby $command_t.cursor_start
145 require 'command-t/vim'
146 require 'command-t/controller'
147 $command_t = CommandT::Controller.new
149 load_path_modified = false
150 ::VIM::evaluate('&runtimepath').to_s.split(',').each do |path|
152 if !$LOAD_PATH.include?(lib) and File.exist?(lib)
154 load_path_modified = true
157 retry if load_path_modified
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