command-t.vim 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. " command-t.vim
  2. " Copyright 2010-2014 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. if exists("g:command_t_loaded") || &cp
  25. finish
  26. endif
  27. let g:command_t_loaded = 1
  28. command CommandTBuffer call <SID>CommandTShowBufferFinder()
  29. command CommandTJump call <SID>CommandTShowJumpFinder()
  30. command CommandTTag call <SID>CommandTShowTagFinder()
  31. command -nargs=? -complete=dir CommandT call <SID>CommandTShowFileFinder(<q-args>)
  32. command CommandTFlush call <SID>CommandTFlush()
  33. if !hasmapto(':CommandT<CR>')
  34. silent! nnoremap <unique> <silent> <Leader>t :CommandT<CR>
  35. endif
  36. if !hasmapto(':CommandTBuffer<CR>')
  37. silent! nnoremap <unique> <silent> <Leader>b :CommandTBuffer<CR>
  38. endif
  39. function s:CommandTRubyWarning()
  40. echohl WarningMsg
  41. echo "command-t.vim requires Vim to be compiled with Ruby support"
  42. echo "For more information type: :help command-t"
  43. echohl none
  44. endfunction
  45. function s:CommandTShowBufferFinder()
  46. if has('ruby')
  47. ruby $command_t.show_buffer_finder
  48. else
  49. call s:CommandTRubyWarning()
  50. endif
  51. endfunction
  52. function s:CommandTShowFileFinder(arg)
  53. if has('ruby')
  54. ruby $command_t.show_file_finder
  55. else
  56. call s:CommandTRubyWarning()
  57. endif
  58. endfunction
  59. function s:CommandTShowJumpFinder()
  60. if has('ruby')
  61. ruby $command_t.show_jump_finder
  62. else
  63. call s:CommandTRubyWarning()
  64. endif
  65. endfunction
  66. function s:CommandTShowTagFinder()
  67. if has('ruby')
  68. ruby $command_t.show_tag_finder
  69. else
  70. call s:CommandTRubyWarning()
  71. endif
  72. endfunction
  73. function s:CommandTFlush()
  74. if has('ruby')
  75. ruby $command_t.flush
  76. else
  77. call s:CommandTRubyWarning()
  78. endif
  79. endfunction
  80. if !has('ruby')
  81. finish
  82. endif
  83. function CommandTListMatches()
  84. ruby $command_t.list_matches
  85. endfunction
  86. function CommandTHandleKey(arg)
  87. ruby $command_t.handle_key
  88. endfunction
  89. function CommandTBackspace()
  90. ruby $command_t.backspace
  91. endfunction
  92. function CommandTDelete()
  93. ruby $command_t.delete
  94. endfunction
  95. function CommandTAcceptSelection()
  96. ruby $command_t.accept_selection
  97. endfunction
  98. function CommandTAcceptSelectionTab()
  99. ruby $command_t.accept_selection :command => 'tabe'
  100. endfunction
  101. function CommandTAcceptSelectionSplit()
  102. ruby $command_t.accept_selection :command => 'sp'
  103. endfunction
  104. function CommandTAcceptSelectionVSplit()
  105. ruby $command_t.accept_selection :command => 'vs'
  106. endfunction
  107. function CommandTQuickfix()
  108. ruby $command_t.quickfix
  109. endfunction
  110. function CommandTRefresh()
  111. ruby $command_t.refresh
  112. endfunction
  113. function CommandTToggleFocus()
  114. ruby $command_t.toggle_focus
  115. endfunction
  116. function CommandTCancel()
  117. ruby $command_t.cancel
  118. endfunction
  119. function CommandTSelectNext()
  120. ruby $command_t.select_next
  121. endfunction
  122. function CommandTSelectPrev()
  123. ruby $command_t.select_prev
  124. endfunction
  125. function CommandTClear()
  126. ruby $command_t.clear
  127. endfunction
  128. function CommandTCursorLeft()
  129. ruby $command_t.cursor_left
  130. endfunction
  131. function CommandTCursorRight()
  132. ruby $command_t.cursor_right
  133. endfunction
  134. function CommandTCursorEnd()
  135. ruby $command_t.cursor_end
  136. endfunction
  137. function CommandTCursorStart()
  138. ruby $command_t.cursor_start
  139. endfunction
  140. ruby << EOF
  141. # require Ruby files
  142. begin
  143. # prepare controller
  144. require 'command-t/vim'
  145. require 'command-t/controller'
  146. $command_t = CommandT::Controller.new
  147. rescue LoadError
  148. load_path_modified = false
  149. ::VIM::evaluate('&runtimepath').to_s.split(',').each do |path|
  150. lib = "#{path}/ruby"
  151. if !$LOAD_PATH.include?(lib) and File.exist?(lib)
  152. $LOAD_PATH << lib
  153. load_path_modified = true
  154. end
  155. end
  156. retry if load_path_modified
  157. # could get here if C extension was not compiled, or was compiled
  158. # for the wrong architecture or Ruby version
  159. require 'command-t/stub'
  160. $command_t = CommandT::Stub.new
  161. end
  162. EOF