1 " Vimball Archiver by Charles E. Campbell, Jr., Ph.D.
4 ruby/command-t/controller.rb [[[1
6 # Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions are met:
11 # 1. Redistributions of source code must retain the above copyright notice,
12 # this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright notice,
14 # this list of conditions and the following disclaimer in the documentation
15 # and/or other materials provided with the distribution.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
21 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
29 require 'command-t/finder/buffer_finder'
30 require 'command-t/finder/file_finder'
31 require 'command-t/match_window'
32 require 'command-t/prompt'
33 require 'command-t/vim/path_utilities'
37 include VIM::PathUtilities
41 @buffer_finder = CommandT::BufferFinder.new
46 def show_buffer_finder
48 @active_finder = @buffer_finder
53 # optional parameter will be desired starting directory, or ""
54 @path = File.expand_path(::VIM::evaluate('a:arg'), VIM::pwd)
55 @file_finder.path = @path
56 @active_finder = @file_finder
59 # probably a problem with the optional parameter
60 @match_window.print_no_such_file_or_directory
65 if VIM::Window.select @initial_window
66 if @initial_buffer.number == 0
67 # upstream bug: buffer number misreported as 0
68 # see: https://wincent.com/issues/1617
69 ::VIM::command "silent b #{@initial_buffer.name}"
71 ::VIM::command "silent b #{@initial_buffer.number}"
82 key = ::VIM::evaluate('a:arg').to_i.chr
87 @match_window.find key
105 def accept_selection options = {}
106 selection = @match_window.selection
108 open_selection(selection, options) unless selection.nil?
112 @focus.unfocus # old focus
113 @focus = @focus == @prompt ? @match_window : @prompt
114 @focus.focus # new focus
122 @match_window.select_next
126 @match_window.select_prev
135 @prompt.cursor_left if @focus == @prompt
139 @prompt.cursor_right if @focus == @prompt
143 @prompt.cursor_end if @focus == @prompt
147 @prompt.cursor_start if @focus == @prompt
161 @initial_window = $curwin
162 @initial_buffer = $curbuf
163 @match_window = MatchWindow.new \
165 :match_window_at_top => get_bool('g:CommandTMatchWindowAtTop'),
166 :match_window_reverse => get_bool('g:CommandTMatchWindowReverse')
169 register_for_key_presses
170 clear # clears prompt and lists matches
173 def set_up_max_height
174 @max_height = get_number('g:CommandTMaxHeight') || 0
177 def set_up_file_finder
178 @file_finder = CommandT::FileFinder.new nil,
179 :max_files => get_number('g:CommandTMaxFiles'),
180 :max_depth => get_number('g:CommandTMaxDepth'),
181 :always_show_dot_files => get_bool('g:CommandTAlwaysShowDotFiles'),
182 :never_show_dot_files => get_bool('g:CommandTNeverShowDotFiles'),
183 :scan_dot_directories => get_bool('g:CommandTScanDotDirectories')
187 ::VIM::evaluate("exists(\"#{name}\")").to_i != 0
191 exists?(name) ? ::VIM::evaluate("#{name}").to_i : nil
195 exists?(name) ? ::VIM::evaluate("#{name}").to_i != 0 : nil
199 exists?(name) ? ::VIM::evaluate("#{name}").to_s : nil
202 # expect a string or a list of strings
203 def get_list_or_string name
204 return nil unless exists?(name)
205 list_or_string = ::VIM::evaluate("#{name}")
206 if list_or_string.kind_of?(Array)
207 list_or_string.map { |item| item.to_s }
213 # Backslash-escape space, \, |, %, #, "
214 def sanitize_path_string str
215 # for details on escaping command-line mode arguments see: :h :
216 # (that is, help on ":") in the Vim documentation.
217 str.gsub(/[ \\|%#"]/, '\\\\\0')
220 def default_open_command
221 if !get_bool('&hidden') && get_bool('&modified')
228 def ensure_appropriate_window_selection
229 # normally we try to open the selection in the current window, but there
232 # - we don't touch any "unlisted" buffer with buftype "nofile" (such as
233 # NERDTree or MiniBufExplorer); this is to avoid things like the "Not
234 # enough room" error which occurs when trying to open in a split in a
235 # shallow (potentially 1-line) buffer like MiniBufExplorer is current
237 # Other "unlisted" buffers, such as those with buftype "help" are treated
241 break unless ::VIM::evaluate('&buflisted').to_i == 0 &&
242 ::VIM::evaluate('&buftype').to_s == 'nofile'
243 ::VIM::command 'wincmd w' # try next window
244 break if $curwin == initial # have already tried all
248 def open_selection selection, options = {}
249 command = options[:command] || default_open_command
250 selection = File.expand_path selection, @path
251 selection = relative_path_under_working_directory selection
252 selection = sanitize_path_string selection
253 ensure_appropriate_window_selection
254 ::VIM::command "silent #{command} #{selection}"
257 def map key, function, param = nil
258 ::VIM::command "noremap <silent> <buffer> #{key} " \
259 ":call CommandT#{function}(#{param})<CR>"
263 !!(::VIM::evaluate('&term') =~ /\Axterm/)
267 !!(::VIM::evaluate('&term') =~ /\Avt100/)
270 def register_for_key_presses
271 # "normal" keys (interpreted literally)
272 numbers = ('0'..'9').to_a.join
273 lowercase = ('a'..'z').to_a.join
274 uppercase = lowercase.upcase
275 punctuation = '<>`@#~!"$%&/()=+*-_.,;:?\\\'{}[] ' # and space
276 (numbers + lowercase + uppercase + punctuation).each_byte do |b|
277 map "<Char-#{b}>", 'HandleKey', b
280 # "special" keys (overridable by settings)
281 { 'Backspace' => '<BS>',
283 'AcceptSelection' => '<CR>',
284 'AcceptSelectionSplit' => ['<C-CR>', '<C-s>'],
285 'AcceptSelectionTab' => '<C-t>',
286 'AcceptSelectionVSplit' => '<C-v>',
287 'ToggleFocus' => '<Tab>',
288 'Cancel' => ['<C-c>', '<Esc>'],
289 'SelectNext' => ['<C-n>', '<C-j>', '<Down>'],
290 'SelectPrev' => ['<C-p>', '<C-k>', '<Up>'],
292 'CursorLeft' => ['<Left>', '<C-h>'],
293 'CursorRight' => ['<Right>', '<C-l>'],
294 'CursorEnd' => '<C-e>',
295 'CursorStart' => '<C-a>' }.each do |key, value|
296 if override = get_list_or_string("g:CommandT#{key}Map")
297 [override].flatten.each do |mapping|
301 [value].flatten.each do |mapping|
302 map mapping, key unless mapping == '<Esc>' && (xterm? || vt100?)
308 # Returns the desired maximum number of matches, based on available
309 # vertical space and the g:CommandTMaxHeight option.
311 limit = VIM::Screen.lines - 5
312 limit = 1 if limit < 0
313 limit = [limit, @max_height].min if @max_height > 0
318 matches = @active_finder.sorted_matches_for @prompt.abbrev, :limit => match_limit
319 @match_window.matches = matches
321 end # class Controller
322 end # module commandT
323 ruby/command-t/extconf.rb [[[1
325 # Copyright 2010 Wincent Colaiuta. All rights reserved.
327 # Redistribution and use in source and binary forms, with or without
328 # modification, are permitted provided that the following conditions are met:
330 # 1. Redistributions of source code must retain the above copyright notice,
331 # this list of conditions and the following disclaimer.
332 # 2. Redistributions in binary form must reproduce the above copyright notice,
333 # this list of conditions and the following disclaimer in the documentation
334 # and/or other materials provided with the distribution.
336 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
337 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
338 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
339 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
340 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
341 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
342 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
343 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
344 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
345 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
346 # POSSIBILITY OF SUCH DAMAGE.
351 puts "couldn't find #{item} (required)"
355 have_header('ruby.h') or missing('ruby.h')
356 create_makefile('ext')
357 ruby/command-t/finder/buffer_finder.rb [[[1
359 # Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
361 # Redistribution and use in source and binary forms, with or without
362 # modification, are permitted provided that the following conditions are met:
364 # 1. Redistributions of source code must retain the above copyright notice,
365 # this list of conditions and the following disclaimer.
366 # 2. Redistributions in binary form must reproduce the above copyright notice,
367 # this list of conditions and the following disclaimer in the documentation
368 # and/or other materials provided with the distribution.
370 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
371 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
372 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
373 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
374 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
375 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
376 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
377 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
378 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
379 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
380 # POSSIBILITY OF SUCH DAMAGE.
382 require 'command-t/ext' # CommandT::Matcher
383 require 'command-t/scanner/buffer_scanner'
384 require 'command-t/finder'
387 class BufferFinder < Finder
389 @scanner = BufferScanner.new
390 @matcher = Matcher.new @scanner, :always_show_dot_files => true
392 end # class BufferFinder
394 ruby/command-t/finder/file_finder.rb [[[1
396 # Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
398 # Redistribution and use in source and binary forms, with or without
399 # modification, are permitted provided that the following conditions are met:
401 # 1. Redistributions of source code must retain the above copyright notice,
402 # this list of conditions and the following disclaimer.
403 # 2. Redistributions in binary form must reproduce the above copyright notice,
404 # this list of conditions and the following disclaimer in the documentation
405 # and/or other materials provided with the distribution.
407 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
408 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
409 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
410 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
411 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
412 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
413 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
414 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
415 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
416 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
417 # POSSIBILITY OF SUCH DAMAGE.
419 require 'command-t/ext' # CommandT::Matcher
420 require 'command-t/finder'
421 require 'command-t/scanner/file_scanner'
424 class FileFinder < Finder
425 def initialize path = Dir.pwd, options = {}
426 @scanner = FileScanner.new path, options
427 @matcher = Matcher.new @scanner, options
429 end # class FileFinder
431 ruby/command-t/finder.rb [[[1
433 # Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
435 # Redistribution and use in source and binary forms, with or without
436 # modification, are permitted provided that the following conditions are met:
438 # 1. Redistributions of source code must retain the above copyright notice,
439 # this list of conditions and the following disclaimer.
440 # 2. Redistributions in binary form must reproduce the above copyright notice,
441 # this list of conditions and the following disclaimer in the documentation
442 # and/or other materials provided with the distribution.
444 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
445 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
446 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
447 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
448 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
449 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
450 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
451 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
452 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
453 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
454 # POSSIBILITY OF SUCH DAMAGE.
456 require 'command-t/ext' # CommandT::Matcher
459 # Encapsulates a Scanner instance (which builds up a list of available files
460 # in a directory) and a Matcher instance (which selects from that list based
461 # on a search string).
463 # Specialized subclasses use different kinds of scanners adapted for
464 # different kinds of search (files, buffers).
466 def initialize path = Dir.pwd, options = {}
467 raise RuntimeError, 'Subclass responsibility'
471 # :limit (integer): limit the number of returned matches
472 def sorted_matches_for str, options = {}
473 @matcher.sorted_matches_for str, options
485 ruby/command-t/match_window.rb [[[1
487 # Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
489 # Redistribution and use in source and binary forms, with or without
490 # modification, are permitted provided that the following conditions are met:
492 # 1. Redistributions of source code must retain the above copyright notice,
493 # this list of conditions and the following disclaimer.
494 # 2. Redistributions in binary form must reproduce the above copyright notice,
495 # this list of conditions and the following disclaimer in the documentation
496 # and/or other materials provided with the distribution.
498 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
499 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
500 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
501 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
502 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
503 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
504 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
505 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
506 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
507 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
508 # POSSIBILITY OF SUCH DAMAGE.
511 require 'command-t/settings'
515 @@selection_marker = '> '
516 @@marker_length = @@selection_marker.length
517 @@unselected_marker = ' ' * @@marker_length
520 def initialize options = {}
521 @prompt = options[:prompt]
522 @reverse_list = options[:match_window_reverse]
524 # save existing window dimensions so we can restore them later
526 (0..(::VIM::Window.count - 1)).each do |i|
527 window = OpenStruct.new :index => i, :height => ::VIM::Window[i].height
531 # global settings (must manually save and restore)
532 @settings = Settings.new
533 ::VIM::set_option 'timeout' # ensure mappings timeout
534 ::VIM::set_option 'timeoutlen=0' # respond immediately to mappings
535 ::VIM::set_option 'nohlsearch' # don't highlight search strings
536 ::VIM::set_option 'noinsertmode' # don't make Insert mode the default
537 ::VIM::set_option 'noshowcmd' # don't show command info on last line
538 ::VIM::set_option 'report=9999' # don't show "X lines changed" reports
539 ::VIM::set_option 'sidescroll=0' # don't sidescroll in jumps
540 ::VIM::set_option 'sidescrolloff=0' # don't sidescroll automatically
541 ::VIM::set_option 'noequalalways' # don't auto-balance window sizes
544 split_location = options[:match_window_at_top] ? 'topleft' : 'botright'
545 if @@buffer # still have buffer from last time
546 ::VIM::command "silent! #{split_location} #{@@buffer.number}sbuffer"
547 raise "Can't re-open GoToFile buffer" unless $curbuf.number == @@buffer.number
549 else # creating match window for first time and set it up
550 split_command = "silent! #{split_location} 1split GoToFile"
553 'setlocal bufhidden=unload', # unload buf when no longer displayed
554 'setlocal buftype=nofile', # buffer is not related to any file
555 'setlocal nomodifiable', # prevent manual edits
556 'setlocal noswapfile', # don't create a swapfile
557 'setlocal nowrap', # don't soft-wrap
558 'setlocal nonumber', # don't show line numbers
559 'setlocal nolist', # don't use List mode (visible tabs etc)
560 'setlocal foldcolumn=0', # don't show a fold column at side
561 'setlocal foldlevel=99', # don't fold anything
562 'setlocal nocursorline', # don't highlight line cursor is on
563 'setlocal nospell', # spell-checking off
564 'setlocal nobuflisted', # don't show up in the buffer list
565 'setlocal textwidth=0' # don't hard-wrap (break long lines)
566 ].each { |command| ::VIM::command command }
568 # sanity check: make sure the buffer really was created
569 raise "Can't find GoToFile buffer" unless $curbuf.name.match /GoToFile\z/
575 ::VIM::command "syntax match CommandTSelection \"^#{@@selection_marker}.\\+$\""
576 ::VIM::command 'syntax match CommandTNoEntries "^-- NO MATCHES --$"'
577 ::VIM::command 'syntax match CommandTNoEntries "^-- NO SUCH FILE OR DIRECTORY --$"'
578 ::VIM::command 'highlight link CommandTSelection Visual'
579 ::VIM::command 'highlight link CommandTNoEntries Error'
580 ::VIM::evaluate 'clearmatches()'
583 @cursor_highlight = get_cursor_highlight
587 # perform cleanup using an autocmd to ensure we don't get caught out
588 # by some unexpected means of dismissing or leaving the Command-T window
589 # (eg. <C-W q>, <C-W k> etc)
590 ::VIM::command 'autocmd! * <buffer>'
591 ::VIM::command 'autocmd BufLeave <buffer> ruby $command_t.leave'
592 ::VIM::command 'autocmd BufUnload <buffer> ruby $command_t.unload'
601 # Workaround for upstream bug in Vim 7.3 on some platforms
603 # On some platforms, $curbuf.number always returns 0. One workaround is
604 # to build Vim with --disable-largefile, but as this is producing lots of
605 # support requests, implement the following fallback to the buffer name
606 # instead, at least until upstream gets fixed.
608 # For more details, see: https://wincent.com/issues/1617
609 if $curbuf.number == 0
610 # use bwipeout as bunload fails if passed the name of a hidden buffer
611 ::VIM::command 'bwipeout! GoToFile'
614 ::VIM::command "bunload! #{@@buffer.number}"
624 restore_window_dimensions
639 if @selection < @matches.length - 1
641 print_match(@selection - 1) # redraw old selection (removes marker)
642 print_match(@selection) # redraw new selection (adds marker)
643 move_cursor_to_selected_line
645 # (possibly) loop or scroll
652 print_match(@selection + 1) # redraw old selection (removes marker)
653 print_match(@selection) # redraw new selection (adds marker)
654 move_cursor_to_selected_line
656 # (possibly) loop or scroll
661 matches = matches.reverse if @reverse_list
662 if matches != @matches
664 @selection = @reverse_list ? @matches.length - 1 : 0
666 move_cursor_to_selected_line
674 ::VIM::command 'highlight link CommandTSelection Search'
683 ::VIM::command 'highlight link CommandTSelection Visual'
689 # is this a new search or the continuation of a previous one?
691 if @last_key_time.nil? or @last_key_time < (now - 0.5)
698 # see if there's anything up ahead that matches
699 @matches.each_with_index do |match, idx|
700 if match[0, @find_string.length].casecmp(@find_string) == 0
701 old_selection = @selection
703 print_match(old_selection) # redraw old selection (removes marker)
704 print_match(@selection) # redraw new selection (adds marker)
710 # Returns the currently selected item as a String.
715 def print_no_such_file_or_directory
716 print_error 'NO SUCH FILE OR DIRECTORY'
721 def move_cursor_to_selected_line
722 # on some non-GUI terminals, the cursor doesn't hide properly
723 # so we move the cursor to prevent it from blinking away in the
724 # upper-left corner in a distracting fashion
725 @window.cursor = [@selection + 1, 0]
729 return unless VIM::Window.select(@window)
733 @@buffer[1] = "-- #{msg} --"
737 def restore_window_dimensions
738 # sort from tallest to shortest
739 @windows.sort! { |a, b| b.height <=> a.height }
741 # starting with the tallest ensures that there are no constraints
742 # preventing windows on the side of vertical splits from regaining
743 # their original full size
745 # beware: window may be nil
746 window = ::VIM::Window[w.index]
747 window.height = w.height if window
751 def match_text_for_idx idx
752 match = truncated_match @matches[idx]
754 prefix = @@selection_marker
755 suffix = padding_for_selected_match match
757 prefix = @@unselected_marker
760 prefix + match + suffix
763 # Print just the specified match.
765 return unless VIM::Window.select(@window)
767 @@buffer[idx + 1] = match_text_for_idx idx
773 match_count = @matches.length
775 print_error 'NO MATCHES'
777 return unless VIM::Window.select(@window)
781 @window_width = @window.width # update cached value
782 max_lines = VIM::Screen.lines - 5
783 max_lines = 1 if max_lines < 0
784 actual_lines = match_count > max_lines ? max_lines : match_count
785 @window.height = actual_lines
786 (1..actual_lines).each do |line|
788 if @@buffer.count >= line
789 @@buffer[line] = match_text_for_idx idx
791 @@buffer.append line - 1, match_text_for_idx(idx)
798 # Prepare padding for match text (trailing spaces) so that selection
799 # highlighting extends all the way to the right edge of the window.
800 def padding_for_selected_match str
802 if len >= @window_width - @@marker_length
805 ' ' * (@window_width - @@marker_length - len)
809 # Convert "really/long/path" into "really...path" based on available
811 def truncated_match str
813 available_width = @window_width - @@marker_length
814 return str if len <= available_width
815 left = (available_width / 2) - 1
816 right = (available_width / 2) - 2 + (available_width % 2)
817 str[0, left] + '...' + str[-right, right]
821 # range = % (whole buffer)
822 # action = d (delete)
823 # register = _ (black hole register, don't record deleted text)
824 ::VIM::command 'silent %d _'
827 def get_cursor_highlight
828 # as :highlight returns nothing and only prints,
829 # must redirect its output to a variable
830 ::VIM::command 'silent redir => g:command_t_cursor_highlight'
832 # force 0 verbosity to ensure origin information isn't printed as well
833 ::VIM::command 'silent! 0verbose highlight Cursor'
834 ::VIM::command 'silent redir END'
836 # there are 3 possible formats to check for, each needing to be
837 # transformed in a certain way in order to reapply the highlight:
838 # Cursor xxx guifg=bg guibg=fg -> :hi! Cursor guifg=bg guibg=fg
839 # Cursor xxx links to SomethingElse -> :hi! link Cursor SomethingElse
840 # Cursor xxx cleared -> :hi! clear Cursor
841 highlight = ::VIM::evaluate 'g:command_t_cursor_highlight'
842 if highlight =~ /^Cursor\s+xxx\s+links to (\w+)/
843 "link Cursor #{$~[1]}"
844 elsif highlight =~ /^Cursor\s+xxx\s+cleared/
846 elsif highlight =~ /Cursor\s+xxx\s+(.+)/
848 else # likely cause E411 Cursor highlight group not found
855 ::VIM::command 'highlight Cursor NONE'
861 ::VIM::command "highlight #{@cursor_highlight}"
866 ::VIM::command 'setlocal nomodifiable'
870 ::VIM::command 'setlocal modifiable'
874 ruby/command-t/prompt.rb [[[1
876 # Copyright 2010 Wincent Colaiuta. All rights reserved.
878 # Redistribution and use in source and binary forms, with or without
879 # modification, are permitted provided that the following conditions are met:
881 # 1. Redistributions of source code must retain the above copyright notice,
882 # this list of conditions and the following disclaimer.
883 # 2. Redistributions in binary form must reproduce the above copyright notice,
884 # this list of conditions and the following disclaimer in the documentation
885 # and/or other materials provided with the distribution.
887 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
888 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
889 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
890 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
891 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
892 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
893 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
894 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
895 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
896 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
897 # POSSIBILITY OF SUCH DAMAGE.
900 # Abuse the status line as a prompt.
902 attr_accessor :abbrev
905 @abbrev = '' # abbreviation entered so far
906 @col = 0 # cursor position
910 # Erase whatever is displayed in the prompt line,
911 # effectively disposing of the prompt
913 ::VIM::command 'echo'
914 ::VIM::command 'redraw'
917 # Clear any entered text.
924 # Insert a character at (before) the current cursor position.
926 left, cursor, right = abbrev_segments
927 @abbrev = left + char + cursor + right
932 # Delete a character to the left of the current cursor position.
935 left, cursor, right = abbrev_segments
936 @abbrev = left.chop! + cursor + right
942 # Delete a character at the current cursor position.
944 if @col < @abbrev.length
945 left, cursor, right = abbrev_segments
946 @abbrev = left + right
959 if @col < @abbrev.length
966 if @col < @abbrev.length
967 @col = @abbrev.length
981 prompt_highlight = 'Comment'
982 normal_highlight = 'None'
983 cursor_highlight = 'Underlined'
985 prompt_highlight = 'NonText'
986 normal_highlight = 'NonText'
987 cursor_highlight = 'NonText'
989 left, cursor, right = abbrev_segments
990 components = [prompt_highlight, '>>', 'None', ' ']
991 components += [normal_highlight, left] unless left.empty?
992 components += [cursor_highlight, cursor] unless cursor.empty?
993 components += [normal_highlight, right] unless right.empty?
994 components += [cursor_highlight, ' '] if cursor.empty?
995 set_status *components
1014 # Returns the @abbrev string divided up into three sections, any of
1015 # which may actually be zero width, depending on the location of the
1017 # - left segment (to left of cursor)
1018 # - cursor segment (character at cursor)
1019 # - right segment (to right of cursor)
1021 left = @abbrev[0, @col]
1022 cursor = @abbrev[@col, 1]
1023 right = @abbrev[(@col + 1)..-1] || ''
1024 [left, cursor, right]
1027 def set_status *args
1028 # see ':help :echo' for why forcing a redraw here helps
1029 # prevent the status line from getting inadvertantly cleared
1030 # after our echo commands
1031 ::VIM::command 'redraw'
1032 while (highlight = args.shift) and (text = args.shift) do
1033 text = VIM::escape_for_single_quotes text
1034 ::VIM::command "echohl #{highlight}"
1035 ::VIM::command "echon '#{text}'"
1037 ::VIM::command 'echohl None'
1040 end # module CommandT
1041 ruby/command-t/scanner/buffer_scanner.rb [[[1
1043 # Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
1045 # Redistribution and use in source and binary forms, with or without
1046 # modification, are permitted provided that the following conditions are met:
1048 # 1. Redistributions of source code must retain the above copyright notice,
1049 # this list of conditions and the following disclaimer.
1050 # 2. Redistributions in binary form must reproduce the above copyright notice,
1051 # this list of conditions and the following disclaimer in the documentation
1052 # and/or other materials provided with the distribution.
1054 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1055 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1056 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1057 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
1058 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1059 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1060 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1061 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1062 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1063 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1064 # POSSIBILITY OF SUCH DAMAGE.
1066 require 'command-t/vim'
1067 require 'command-t/vim/path_utilities'
1068 require 'command-t/scanner'
1071 # Returns a list of all open buffers.
1072 class BufferScanner < Scanner
1073 include VIM::PathUtilities
1076 (0..(::VIM::Buffer.count - 1)).map do |n|
1077 buffer = ::VIM::Buffer[n]
1078 if buffer.name # beware, may be nil
1079 relative_path_under_working_directory buffer.name
1083 end # class BufferScanner
1084 end # module CommandT
1085 ruby/command-t/scanner/file_scanner.rb [[[1
1087 # Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
1089 # Redistribution and use in source and binary forms, with or without
1090 # modification, are permitted provided that the following conditions are met:
1092 # 1. Redistributions of source code must retain the above copyright notice,
1093 # this list of conditions and the following disclaimer.
1094 # 2. Redistributions in binary form must reproduce the above copyright notice,
1095 # this list of conditions and the following disclaimer in the documentation
1096 # and/or other materials provided with the distribution.
1098 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1099 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1100 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1101 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
1102 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1103 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1104 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1105 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1106 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1107 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1108 # POSSIBILITY OF SUCH DAMAGE.
1110 require 'command-t/vim'
1111 require 'command-t/scanner'
1114 # Reads the current directory recursively for the paths to all regular files.
1115 class FileScanner < Scanner
1116 class FileLimitExceeded < ::RuntimeError; end
1118 def initialize path = Dir.pwd, options = {}
1120 @max_depth = options[:max_depth] || 15
1121 @max_files = options[:max_files] || 10_000
1122 @scan_dot_directories = options[:scan_dot_directories] || false
1126 return @paths unless @paths.nil?
1131 @prefix_len = @path.chomp('/').length
1132 add_paths_for_directory @path, @paths
1133 rescue FileLimitExceeded
1151 def path_excluded? path
1152 # first strip common prefix (@path) from path to match VIM's behavior
1153 path = path[(@prefix_len + 1)..-1]
1154 path = VIM::escape_for_single_quotes path
1155 ::VIM::evaluate("empty(expand(fnameescape('#{path}')))").to_i == 1
1158 def add_paths_for_directory dir, accumulator
1159 Dir.foreach(dir) do |entry|
1160 next if ['.', '..'].include?(entry)
1161 path = File.join(dir, entry)
1162 unless path_excluded?(path)
1165 raise FileLimitExceeded if @files > @max_files
1166 accumulator << path[@prefix_len + 1..-1]
1167 elsif File.directory?(path)
1168 next if @depth >= @max_depth
1169 next if (entry.match(/\A\./) && !@scan_dot_directories)
1171 add_paths_for_directory path, accumulator
1176 rescue Errno::EACCES
1177 # skip over directories for which we don't have access
1179 end # class FileScanner
1180 end # module CommandT
1181 ruby/command-t/scanner.rb [[[1
1183 # Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
1185 # Redistribution and use in source and binary forms, with or without
1186 # modification, are permitted provided that the following conditions are met:
1188 # 1. Redistributions of source code must retain the above copyright notice,
1189 # this list of conditions and the following disclaimer.
1190 # 2. Redistributions in binary form must reproduce the above copyright notice,
1191 # this list of conditions and the following disclaimer in the documentation
1192 # and/or other materials provided with the distribution.
1194 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1195 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1196 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1197 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
1198 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1199 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1200 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1201 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1202 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1203 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1204 # POSSIBILITY OF SUCH DAMAGE.
1206 require 'command-t/vim'
1210 end # module CommandT
1211 ruby/command-t/settings.rb [[[1
1213 # Copyright 2010 Wincent Colaiuta. All rights reserved.
1215 # Redistribution and use in source and binary forms, with or without
1216 # modification, are permitted provided that the following conditions are met:
1218 # 1. Redistributions of source code must retain the above copyright notice,
1219 # this list of conditions and the following disclaimer.
1220 # 2. Redistributions in binary form must reproduce the above copyright notice,
1221 # this list of conditions and the following disclaimer in the documentation
1222 # and/or other materials provided with the distribution.
1224 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1225 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1226 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1227 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
1228 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1229 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1230 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1231 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1232 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1233 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1234 # POSSIBILITY OF SUCH DAMAGE.
1237 # Convenience class for saving and restoring global settings.
1244 @timeoutlen = get_number 'timeoutlen'
1245 @report = get_number 'report'
1246 @sidescroll = get_number 'sidescroll'
1247 @sidescrolloff = get_number 'sidescrolloff'
1248 @timeout = get_bool 'timeout'
1249 @equalalways = get_bool 'equalalways'
1250 @hlsearch = get_bool 'hlsearch'
1251 @insertmode = get_bool 'insertmode'
1252 @showcmd = get_bool 'showcmd'
1256 set_number 'timeoutlen', @timeoutlen
1257 set_number 'report', @report
1258 set_number 'sidescroll', @sidescroll
1259 set_number 'sidescrolloff', @sidescrolloff
1260 set_bool 'timeout', @timeout
1261 set_bool 'equalalways', @equalalways
1262 set_bool 'hlsearch', @hlsearch
1263 set_bool 'insertmode', @insertmode
1264 set_bool 'showcmd', @showcmd
1269 def get_number setting
1270 ::VIM::evaluate("&#{setting}").to_i
1273 def get_bool setting
1274 ::VIM::evaluate("&#{setting}").to_i == 1
1277 def set_number setting, value
1278 ::VIM::set_option "#{setting}=#{value}"
1281 def set_bool setting, value
1283 ::VIM::set_option setting
1285 ::VIM::set_option "no#{setting}"
1288 end # class Settings
1289 end # module CommandT
1290 ruby/command-t/stub.rb [[[1
1292 # Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
1294 # Redistribution and use in source and binary forms, with or without
1295 # modification, are permitted provided that the following conditions are met:
1297 # 1. Redistributions of source code must retain the above copyright notice,
1298 # this list of conditions and the following disclaimer.
1299 # 2. Redistributions in binary form must reproduce the above copyright notice,
1300 # this list of conditions and the following disclaimer in the documentation
1301 # and/or other materials provided with the distribution.
1303 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1304 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1305 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1306 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
1307 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1308 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1309 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1310 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1311 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1312 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1313 # POSSIBILITY OF SUCH DAMAGE.
1317 @@load_error = ['command-t.vim could not load the C extension',
1318 'Please see INSTALLATION and TROUBLE-SHOOTING in the help',
1319 'For more information type: :help command-t']
1321 def show_file_finder
1332 ::VIM::command 'echohl WarningMsg'
1333 msg.each { |m| ::VIM::command "echo '#{m}'" }
1334 ::VIM::command 'echohl none'
1337 end # module CommandT
1338 ruby/command-t/vim/path_utilities.rb [[[1
1340 # Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
1342 # Redistribution and use in source and binary forms, with or without
1343 # modification, are permitted provided that the following conditions are met:
1345 # 1. Redistributions of source code must retain the above copyright notice,
1346 # this list of conditions and the following disclaimer.
1347 # 2. Redistributions in binary form must reproduce the above copyright notice,
1348 # this list of conditions and the following disclaimer in the documentation
1349 # and/or other materials provided with the distribution.
1351 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1352 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1353 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1354 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
1355 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1356 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1357 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1358 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1359 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1360 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1361 # POSSIBILITY OF SUCH DAMAGE.
1363 require 'command-t/vim'
1367 module PathUtilities
1371 def relative_path_under_working_directory path
1372 # any path under the working directory will be specified as a relative
1373 # path to improve the readability of the buffer list etc
1374 pwd = File.expand_path(VIM::pwd) + '/'
1375 path.index(pwd) == 0 ? path[pwd.length..-1] : path
1377 end # module PathUtilities
1379 end # module CommandT
1380 ruby/command-t/vim/screen.rb [[[1
1382 # Copyright 2010 Wincent Colaiuta. All rights reserved.
1384 # Redistribution and use in source and binary forms, with or without
1385 # modification, are permitted provided that the following conditions are met:
1387 # 1. Redistributions of source code must retain the above copyright notice,
1388 # this list of conditions and the following disclaimer.
1389 # 2. Redistributions in binary form must reproduce the above copyright notice,
1390 # this list of conditions and the following disclaimer in the documentation
1391 # and/or other materials provided with the distribution.
1393 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1394 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1395 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1396 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
1397 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1398 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1399 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1400 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1401 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1402 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1403 # POSSIBILITY OF SUCH DAMAGE.
1409 ::VIM::evaluate('&lines').to_i
1413 end # module CommandT
1414 ruby/command-t/vim/window.rb [[[1
1416 # Copyright 2010 Wincent Colaiuta. All rights reserved.
1418 # Redistribution and use in source and binary forms, with or without
1419 # modification, are permitted provided that the following conditions are met:
1421 # 1. Redistributions of source code must retain the above copyright notice,
1422 # this list of conditions and the following disclaimer.
1423 # 2. Redistributions in binary form must reproduce the above copyright notice,
1424 # this list of conditions and the following disclaimer in the documentation
1425 # and/or other materials provided with the distribution.
1427 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1428 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1429 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1430 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
1431 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1432 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1433 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1434 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1435 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1436 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1437 # POSSIBILITY OF SUCH DAMAGE.
1442 def self.select window
1443 return true if $curwin == window
1446 ::VIM::command 'wincmd w' # cycle through windows
1447 return true if $curwin == window # have selected desired window
1448 return false if $curwin == initial # have already looped through all
1453 end # module CommandT
1454 ruby/command-t/vim.rb [[[1
1456 # Copyright 2010 Wincent Colaiuta. All rights reserved.
1458 # Redistribution and use in source and binary forms, with or without
1459 # modification, are permitted provided that the following conditions are met:
1461 # 1. Redistributions of source code must retain the above copyright notice,
1462 # this list of conditions and the following disclaimer.
1463 # 2. Redistributions in binary form must reproduce the above copyright notice,
1464 # this list of conditions and the following disclaimer in the documentation
1465 # and/or other materials provided with the distribution.
1467 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1468 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1469 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1470 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
1471 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1472 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1473 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1474 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1475 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1476 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1477 # POSSIBILITY OF SUCH DAMAGE.
1479 require 'command-t/vim/screen'
1480 require 'command-t/vim/window'
1484 def self.has_syntax?
1485 ::VIM::evaluate('has("syntax")').to_i != 0
1489 ::VIM::evaluate 'getcwd()'
1492 # Escape a string for safe inclusion in a Vim single-quoted string
1493 # (single quotes escaped by doubling, everything else is literal)
1494 def self.escape_for_single_quotes str
1498 end # module CommandT
1499 ruby/command-t/ext.c [[[1
1501 // Copyright 2010 Wincent Colaiuta. All rights reserved.
1503 // Redistribution and use in source and binary forms, with or without
1504 // modification, are permitted provided that the following conditions are met:
1506 // 1. Redistributions of source code must retain the above copyright notice,
1507 // this list of conditions and the following disclaimer.
1508 // 2. Redistributions in binary form must reproduce the above copyright notice,
1509 // this list of conditions and the following disclaimer in the documentation
1510 // and/or other materials provided with the distribution.
1512 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1513 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1514 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1515 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
1516 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1517 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1518 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1519 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1520 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1521 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1522 // POSSIBILITY OF SUCH DAMAGE.
1525 #include "matcher.h"
1527 VALUE mCommandT = 0; // module CommandT
1528 VALUE cCommandTMatch = 0; // class CommandT::Match
1529 VALUE cCommandTMatcher = 0; // class CommandT::Matcher
1531 VALUE CommandT_option_from_hash(const char *option, VALUE hash)
1535 VALUE key = ID2SYM(rb_intern(option));
1536 if (rb_funcall(hash, rb_intern("has_key?"), 1, key) == Qtrue)
1537 return rb_hash_aref(hash, key);
1545 mCommandT = rb_define_module("CommandT");
1547 // class CommandT::Match
1548 cCommandTMatch = rb_define_class_under(mCommandT, "Match", rb_cObject);
1551 rb_define_method(cCommandTMatch, "initialize", CommandTMatch_initialize, -1);
1552 rb_define_method(cCommandTMatch, "matches?", CommandTMatch_matches, 0);
1553 rb_define_method(cCommandTMatch, "to_s", CommandTMatch_to_s, 0);
1556 rb_define_attr(cCommandTMatch, "score", Qtrue, Qfalse); // reader: true, writer: false
1558 // class CommandT::Matcher
1559 cCommandTMatcher = rb_define_class_under(mCommandT, "Matcher", rb_cObject);
1562 rb_define_method(cCommandTMatcher, "initialize", CommandTMatcher_initialize, -1);
1563 rb_define_method(cCommandTMatcher, "sorted_matches_for", CommandTMatcher_sorted_matches_for, 2);
1564 rb_define_method(cCommandTMatcher, "matches_for", CommandTMatcher_matches_for, 1);
1566 ruby/command-t/match.c [[[1
1568 // Copyright 2010 Wincent Colaiuta. All rights reserved.
1570 // Redistribution and use in source and binary forms, with or without
1571 // modification, are permitted provided that the following conditions are met:
1573 // 1. Redistributions of source code must retain the above copyright notice,
1574 // this list of conditions and the following disclaimer.
1575 // 2. Redistributions in binary form must reproduce the above copyright notice,
1576 // this list of conditions and the following disclaimer in the documentation
1577 // and/or other materials provided with the distribution.
1579 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1580 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1581 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1582 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
1583 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1584 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1585 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1586 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1587 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1588 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1589 // POSSIBILITY OF SUCH DAMAGE.
1593 #include "ruby_compat.h"
1595 // use a struct to make passing params during recursion easier
1598 char *str_p; // pointer to string to be searched
1599 long str_len; // length of same
1600 char *abbrev_p; // pointer to search string (abbreviation)
1601 long abbrev_len; // length of same
1602 double max_score_per_char;
1603 int dot_file; // boolean: true if str is a dot-file
1604 int always_show_dot_files; // boolean
1605 int never_show_dot_files; // boolean
1608 double recursive_match(matchinfo_t *m, // sharable meta-data
1609 long str_idx, // where in the path string to start
1610 long abbrev_idx, // where in the search string to start
1611 long last_idx, // location of last matched character
1612 double score) // cumulative score so far
1614 double seen_score = 0; // remember best score seen via recursion
1615 int dot_file_match = 0; // true if abbrev matches a dot-file
1616 int dot_search = 0; // true if searching for a dot
1618 for (long i = abbrev_idx; i < m->abbrev_len; i++)
1620 char c = m->abbrev_p[i];
1624 for (long j = str_idx; j < m->str_len; j++, str_idx++)
1626 char d = m->str_p[j];
1629 if (j == 0 || m->str_p[j - 1] == '/')
1631 m->dot_file = 1; // this is a dot-file
1632 if (dot_search) // and we are searching for a dot
1633 dot_file_match = 1; // so this must be a match
1636 else if (d >= 'A' && d <= 'Z')
1637 d += 'a' - 'A'; // add 32 to downcase
1644 double score_for_char = m->max_score_per_char;
1645 long distance = j - last_idx;
1648 double factor = 1.0;
1649 char last = m->str_p[j - 1];
1650 char curr = m->str_p[j]; // case matters, so get again
1653 else if (last == '-' ||
1656 (last >= '0' && last <= '9'))
1658 else if (last >= 'a' && last <= 'z' &&
1659 curr >= 'A' && curr <= 'Z')
1661 else if (last == '.')
1664 // if no "special" chars behind char, factor diminishes
1665 // as distance from last matched char increases
1666 factor = (1.0 / distance) * 0.75;
1667 score_for_char *= factor;
1670 if (++j < m->str_len)
1672 // bump cursor one char to the right and
1673 // use recursion to try and find a better match
1674 double sub_score = recursive_match(m, j, i, last_idx, score);
1675 if (sub_score > seen_score)
1676 seen_score = sub_score;
1679 score += score_for_char;
1680 last_idx = str_idx++;
1689 if (m->never_show_dot_files ||
1690 (!dot_file_match && !m->always_show_dot_files))
1693 return (score > seen_score) ? score : seen_score;
1696 // Match.new abbrev, string, options = {}
1697 VALUE CommandTMatch_initialize(int argc, VALUE *argv, VALUE self)
1699 // process arguments: 2 mandatory, 1 optional
1700 VALUE str, abbrev, options;
1701 if (rb_scan_args(argc, argv, "21", &str, &abbrev, &options) == 2)
1703 str = StringValue(str);
1704 abbrev = StringValue(abbrev); // already downcased by caller
1706 // check optional options hash for overrides
1707 VALUE always_show_dot_files = CommandT_option_from_hash("always_show_dot_files", options);
1708 VALUE never_show_dot_files = CommandT_option_from_hash("never_show_dot_files", options);
1711 m.str_p = RSTRING_PTR(str);
1712 m.str_len = RSTRING_LEN(str);
1713 m.abbrev_p = RSTRING_PTR(abbrev);
1714 m.abbrev_len = RSTRING_LEN(abbrev);
1715 m.max_score_per_char = (1.0 / m.str_len + 1.0 / m.abbrev_len) / 2;
1717 m.always_show_dot_files = always_show_dot_files == Qtrue;
1718 m.never_show_dot_files = never_show_dot_files == Qtrue;
1722 if (m.abbrev_len == 0) // special case for zero-length search string
1724 // filter out dot files
1725 if (!m.always_show_dot_files)
1727 for (long i = 0; i < m.str_len; i++)
1729 char c = m.str_p[i];
1730 if (c == '.' && (i == 0 || m.str_p[i - 1] == '/'))
1739 score = recursive_match(&m, 0, 0, 0, 0.0);
1741 // clean-up and final book-keeping
1742 rb_iv_set(self, "@score", rb_float_new(score));
1743 rb_iv_set(self, "@str", str);
1747 VALUE CommandTMatch_matches(VALUE self)
1749 double score = NUM2DBL(rb_iv_get(self, "@score"));
1750 return score > 0 ? Qtrue : Qfalse;
1753 VALUE CommandTMatch_to_s(VALUE self)
1755 return rb_iv_get(self, "@str");
1757 ruby/command-t/matcher.c [[[1
1759 // Copyright 2010 Wincent Colaiuta. All rights reserved.
1761 // Redistribution and use in source and binary forms, with or without
1762 // modification, are permitted provided that the following conditions are met:
1764 // 1. Redistributions of source code must retain the above copyright notice,
1765 // this list of conditions and the following disclaimer.
1766 // 2. Redistributions in binary form must reproduce the above copyright notice,
1767 // this list of conditions and the following disclaimer in the documentation
1768 // and/or other materials provided with the distribution.
1770 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1771 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1772 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1773 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
1774 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1775 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1776 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1777 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1778 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1779 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1780 // POSSIBILITY OF SUCH DAMAGE.
1782 #include <stdlib.h> /* for qsort() */
1783 #include <string.h> /* for strcmp() */
1784 #include "matcher.h"
1786 #include "ruby_compat.h"
1788 // comparison function for use with qsort
1789 int comp_alpha(const void *a, const void *b)
1791 VALUE a_val = *(VALUE *)a;
1792 VALUE b_val = *(VALUE *)b;
1793 ID to_s = rb_intern("to_s");
1795 VALUE a_str = rb_funcall(a_val, to_s, 0);
1796 VALUE b_str = rb_funcall(b_val, to_s, 0);
1797 char *a_p = RSTRING_PTR(a_str);
1798 long a_len = RSTRING_LEN(a_str);
1799 char *b_p = RSTRING_PTR(b_str);
1800 long b_len = RSTRING_LEN(b_str);
1804 order = strncmp(a_p, b_p, b_len);
1806 order = 1; // shorter string (b) wins
1808 else if (a_len < b_len)
1810 order = strncmp(a_p, b_p, a_len);
1812 order = -1; // shorter string (a) wins
1815 order = strncmp(a_p, b_p, a_len);
1819 // comparison function for use with qsort
1820 int comp_score(const void *a, const void *b)
1822 VALUE a_val = *(VALUE *)a;
1823 VALUE b_val = *(VALUE *)b;
1824 ID score = rb_intern("score");
1825 double a_score = RFLOAT_VALUE(rb_funcall(a_val, score, 0));
1826 double b_score = RFLOAT_VALUE(rb_funcall(b_val, score, 0));
1827 if (a_score > b_score)
1828 return -1; // a scores higher, a should appear sooner
1829 else if (a_score < b_score)
1830 return 1; // b scores higher, a should appear later
1832 return comp_alpha(a, b);
1835 VALUE CommandTMatcher_initialize(int argc, VALUE *argv, VALUE self)
1837 // process arguments: 1 mandatory, 1 optional
1838 VALUE scanner, options;
1839 if (rb_scan_args(argc, argv, "11", &scanner, &options) == 1)
1842 rb_raise(rb_eArgError, "nil scanner");
1843 rb_iv_set(self, "@scanner", scanner);
1845 // check optional options hash for overrides
1846 VALUE always_show_dot_files = CommandT_option_from_hash("always_show_dot_files", options);
1847 if (always_show_dot_files != Qtrue)
1848 always_show_dot_files = Qfalse;
1849 VALUE never_show_dot_files = CommandT_option_from_hash("never_show_dot_files", options);
1850 if (never_show_dot_files != Qtrue)
1851 never_show_dot_files = Qfalse;
1852 rb_iv_set(self, "@always_show_dot_files", always_show_dot_files);
1853 rb_iv_set(self, "@never_show_dot_files", never_show_dot_files);
1857 VALUE CommandTMatcher_sorted_matches_for(VALUE self, VALUE abbrev, VALUE options)
1859 // process optional options hash
1860 VALUE limit_option = CommandT_option_from_hash("limit", options);
1862 // get unsorted matches
1863 VALUE matches = CommandTMatcher_matches_for(self, abbrev);
1865 abbrev = StringValue(abbrev);
1866 if (RSTRING_LEN(abbrev) == 0 ||
1867 (RSTRING_LEN(abbrev) == 1 && RSTRING_PTR(abbrev)[0] == '.'))
1868 // alphabetic order if search string is only "" or "."
1869 qsort(RARRAY_PTR(matches), RARRAY_LEN(matches), sizeof(VALUE), comp_alpha);
1871 // for all other non-empty search strings, sort by score
1872 qsort(RARRAY_PTR(matches), RARRAY_LEN(matches), sizeof(VALUE), comp_score);
1874 // apply optional limit option
1875 long limit = NIL_P(limit_option) ? 0 : NUM2LONG(limit_option);
1876 if (limit == 0 || RARRAY_LEN(matches) < limit)
1877 limit = RARRAY_LEN(matches);
1879 // will return an array of strings, not an array of Match objects
1880 for (long i = 0; i < limit; i++)
1882 VALUE str = rb_funcall(RARRAY_PTR(matches)[i], rb_intern("to_s"), 0);
1883 RARRAY_PTR(matches)[i] = str;
1886 // trim off any items beyond the limit
1887 if (limit < RARRAY_LEN(matches))
1888 (void)rb_funcall(matches, rb_intern("slice!"), 2, LONG2NUM(limit),
1889 LONG2NUM(RARRAY_LEN(matches) - limit));
1893 VALUE CommandTMatcher_matches_for(VALUE self, VALUE abbrev)
1896 rb_raise(rb_eArgError, "nil abbrev");
1897 VALUE matches = rb_ary_new();
1898 VALUE scanner = rb_iv_get(self, "@scanner");
1899 VALUE always_show_dot_files = rb_iv_get(self, "@always_show_dot_files");
1900 VALUE never_show_dot_files = rb_iv_get(self, "@never_show_dot_files");
1901 VALUE options = Qnil;
1902 if (always_show_dot_files == Qtrue)
1904 options = rb_hash_new();
1905 rb_hash_aset(options, ID2SYM(rb_intern("always_show_dot_files")), always_show_dot_files);
1907 else if (never_show_dot_files == Qtrue)
1909 options = rb_hash_new();
1910 rb_hash_aset(options, ID2SYM(rb_intern("never_show_dot_files")), never_show_dot_files);
1912 abbrev = rb_funcall(abbrev, rb_intern("downcase"), 0);
1913 VALUE paths = rb_funcall(scanner, rb_intern("paths"), 0);
1914 for (long i = 0, max = RARRAY_LEN(paths); i < max; i++)
1916 VALUE path = RARRAY_PTR(paths)[i];
1917 VALUE match = rb_funcall(cCommandTMatch, rb_intern("new"), 3, path, abbrev, options);
1918 if (rb_funcall(match, rb_intern("matches?"), 0) == Qtrue)
1919 rb_funcall(matches, rb_intern("push"), 1, match);
1923 ruby/command-t/ext.h [[[1
1925 // Copyright 2010 Wincent Colaiuta. All rights reserved.
1927 // Redistribution and use in source and binary forms, with or without
1928 // modification, are permitted provided that the following conditions are met:
1930 // 1. Redistributions of source code must retain the above copyright notice,
1931 // this list of conditions and the following disclaimer.
1932 // 2. Redistributions in binary form must reproduce the above copyright notice,
1933 // this list of conditions and the following disclaimer in the documentation
1934 // and/or other materials provided with the distribution.
1936 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1937 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1938 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1939 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
1940 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1941 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1942 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1943 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1944 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1945 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1946 // POSSIBILITY OF SUCH DAMAGE.
1950 extern VALUE mCommandT; // module CommandT
1951 extern VALUE cCommandTMatch; // class CommandT::Match
1952 extern VALUE cCommandTMatcher; // class CommandT::Matcher
1954 // Encapsulates common pattern of checking for an option in an optional
1955 // options hash. The hash itself may be nil, but an exception will be
1956 // raised if it is not nil and not a hash.
1957 VALUE CommandT_option_from_hash(const char *option, VALUE hash);
1960 #define ruby_inspect(obj) rb_funcall(rb_mKernel, rb_intern("p"), 1, obj)
1961 ruby/command-t/match.h [[[1
1963 // Copyright 2010 Wincent Colaiuta. All rights reserved.
1965 // Redistribution and use in source and binary forms, with or without
1966 // modification, are permitted provided that the following conditions are met:
1968 // 1. Redistributions of source code must retain the above copyright notice,
1969 // this list of conditions and the following disclaimer.
1970 // 2. Redistributions in binary form must reproduce the above copyright notice,
1971 // this list of conditions and the following disclaimer in the documentation
1972 // and/or other materials provided with the distribution.
1974 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1975 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1976 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1977 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
1978 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1979 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1980 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1981 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1982 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1983 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1984 // POSSIBILITY OF SUCH DAMAGE.
1988 extern VALUE CommandTMatch_initialize(int argc, VALUE *argv, VALUE self);
1989 extern VALUE CommandTMatch_matches(VALUE self);
1990 extern VALUE CommandTMatch_score(VALUE self);
1991 extern VALUE CommandTMatch_to_s(VALUE self);
1992 ruby/command-t/matcher.h [[[1
1994 // Copyright 2010 Wincent Colaiuta. All rights reserved.
1996 // Redistribution and use in source and binary forms, with or without
1997 // modification, are permitted provided that the following conditions are met:
1999 // 1. Redistributions of source code must retain the above copyright notice,
2000 // this list of conditions and the following disclaimer.
2001 // 2. Redistributions in binary form must reproduce the above copyright notice,
2002 // this list of conditions and the following disclaimer in the documentation
2003 // and/or other materials provided with the distribution.
2005 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2006 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2007 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2008 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
2009 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2010 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2011 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2012 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2013 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2014 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2015 // POSSIBILITY OF SUCH DAMAGE.
2019 extern VALUE CommandTMatcher_initialize(int argc, VALUE *argv, VALUE self);
2020 extern VALUE CommandTMatcher_sorted_matches_for(VALUE self, VALUE abbrev, VALUE options);
2022 // most likely the function will be subsumed by the sorted_matcher_for function
2023 extern VALUE CommandTMatcher_matches_for(VALUE self, VALUE abbrev);
2024 ruby/command-t/ruby_compat.h [[[1
2026 // Copyright 2010 Wincent Colaiuta. All rights reserved.
2028 // Redistribution and use in source and binary forms, with or without
2029 // modification, are permitted provided that the following conditions are met:
2031 // 1. Redistributions of source code must retain the above copyright notice,
2032 // this list of conditions and the following disclaimer.
2033 // 2. Redistributions in binary form must reproduce the above copyright notice,
2034 // this list of conditions and the following disclaimer in the documentation
2035 // and/or other materials provided with the distribution.
2037 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2038 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2039 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2040 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
2041 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2042 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2043 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2044 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2045 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2046 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2047 // POSSIBILITY OF SUCH DAMAGE.
2051 // for compatibility with older versions of Ruby which don't declare RSTRING_PTR
2053 #define RSTRING_PTR(s) (RSTRING(s)->ptr)
2056 // for compatibility with older versions of Ruby which don't declare RSTRING_LEN
2058 #define RSTRING_LEN(s) (RSTRING(s)->len)
2061 // for compatibility with older versions of Ruby which don't declare RARRAY_PTR
2063 #define RARRAY_PTR(a) (RARRAY(a)->ptr)
2066 // for compatibility with older versions of Ruby which don't declare RARRAY_LEN
2068 #define RARRAY_LEN(a) (RARRAY(a)->len)
2071 // for compatibility with older versions of Ruby which don't declare RFLOAT_VALUE
2072 #ifndef RFLOAT_VALUE
2073 #define RFLOAT_VALUE(f) (RFLOAT(f)->value)
2075 ruby/command-t/depend [[[1
2077 # Copyright 2010 Wincent Colaiuta. All rights reserved.
2079 # Redistribution and use in source and binary forms, with or without
2080 # modification, are permitted provided that the following conditions are met:
2082 # 1. Redistributions of source code must retain the above copyright notice,
2083 # this list of conditions and the following disclaimer.
2084 # 2. Redistributions in binary form must reproduce the above copyright notice,
2085 # this list of conditions and the following disclaimer in the documentation
2086 # and/or other materials provided with the distribution.
2088 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2089 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2090 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2091 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
2092 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2093 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2094 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2095 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2096 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2097 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2098 # POSSIBILITY OF SUCH DAMAGE.
2100 CFLAGS += -std=c99 -Wall -Wextra -Wno-unused-parameter
2101 doc/command-t.txt [[[1
2103 *command-t.txt* Command-T plug-in for Vim *command-t*
2105 CONTENTS *command-t-contents*
2107 1. Introduction |command-t-intro|
2108 2. Requirements |command-t-requirements|
2109 3. Installation |command-t-installation|
2110 3. Managing using Pathogen |command-t-pathogen|
2111 4. Trouble-shooting |command-t-trouble-shooting|
2112 5. Usage |command-t-usage|
2113 6. Commands |command-t-commands|
2114 7. Mappings |command-t-mappings|
2115 8. Options |command-t-options|
2116 9. Authors |command-t-authors|
2117 10. Website |command-t-website|
2118 11. Donations |command-t-donations|
2119 12. License |command-t-license|
2120 13. History |command-t-history|
2123 INTRODUCTION *command-t-intro*
2125 The Command-T plug-in provides an extremely fast, intuitive mechanism for
2126 opening files and buffers with a minimal number of keystrokes. It's named
2127 "Command-T" because it is inspired by the "Go to File" window bound to
2128 Command-T in TextMate.
2130 Files are selected by typing characters that appear in their paths, and are
2131 ordered by an algorithm which knows that characters that appear in certain
2132 locations (for example, immediately after a path separator) should be given
2135 To search efficiently, especially in large projects, you should adopt a
2136 "path-centric" rather than a "filename-centric" mentality. That is you should
2137 think more about where the desired file is found rather than what it is
2138 called. This means narrowing your search down by including some characters
2139 from the upper path components rather than just entering characters from the
2142 Screencasts demonstrating the plug-in can be viewed at:
2144 https://wincent.com/products/command-t
2147 REQUIREMENTS *command-t-requirements*
2149 The plug-in requires Vim compiled with Ruby support, a compatible Ruby
2150 installation at the operating system level, and a C compiler to build
2154 1. Vim compiled with Ruby support
2156 You can check for Ruby support by launching Vim with the --version switch:
2160 If "+ruby" appears in the version information then your version of Vim has
2163 Another way to check is to simply try using the :ruby command from within Vim
2168 If your Vim lacks support you'll see an error message like this:
2170 E319: Sorry, the command is not available in this version
2172 The version of Vim distributed with Mac OS X does not include Ruby support,
2173 while MacVim does; it is available from:
2175 http://github.com/b4winckler/macvim/downloads
2177 For Windows users, the Vim 7.2 executable available from www.vim.org does
2178 include Ruby support, and is recommended over version 7.3 (which links against
2179 Ruby 1.9, but apparently has some bugs that need to be resolved).
2184 In addition to having Ruby support in Vim, your system itself must have a
2185 compatible Ruby install. "Compatible" means the same version as Vim itself
2186 links against. If you use a different version then Command-T is unlikely
2187 to work (see TROUBLE-SHOOTING below).
2189 On Mac OS X Snow Leopard, the system comes with Ruby 1.8.7 and all recent
2190 versions of MacVim (the 7.2 snapshots and 7.3) are linked against it.
2192 On Linux and similar platforms, the linked version of Ruby will depend on
2193 your distribution. You can usually find this out by examining the
2194 compilation and linking flags displayed by the |:version| command in Vim, and
2195 by looking at the output of:
2197 :ruby puts RUBY_VERSION
2199 A suitable Ruby environment for Windows can be installed using the Ruby
2200 1.8.7-p299 RubyInstaller available at:
2202 http://rubyinstaller.org/downloads/archives
2204 If using RubyInstaller be sure to download the installer executable, not the
2205 7-zip archive. When installing mark the checkbox "Add Ruby executables to your
2206 PATH" so that Vim can find them.
2211 Part of Command-T is implemented in C as a Ruby extension for speed, allowing
2212 it to work responsively even on directory hierarchies containing enormous
2213 numbers of files. As such, a C compiler is required in order to build the
2214 extension and complete the installation.
2216 On Mac OS X, this can be obtained by installing the Xcode Tools that come on
2217 the Mac OS X install disc.
2219 On Windows, the RubyInstaller Development Kit can be used to conveniently
2220 install the necessary tool chain:
2222 http://rubyinstaller.org/downloads/archives
2224 At the time of writing, the appropriate development kit for use with Ruby
2225 1.8.7 is DevKit-3.4.5r3-20091110.
2227 To use the Development Kit extract the archive contents to your C:\Ruby
2231 INSTALLATION *command-t-installation*
2233 Command-T is distributed as a "vimball" which means that it can be installed
2234 by opening it in Vim and then sourcing it:
2239 The files will be installed in your |'runtimepath'|. To check where this is
2244 The C extension must then be built, which can be done from the shell. If you
2245 use a typical |'runtimepath'| then the files were installed inside ~/.vim and
2246 you can build the extension with:
2248 cd ~/.vim/ruby/command-t
2252 Note: If you are an RVM user, you must perform the build using the same
2253 version of Ruby that Vim itself is linked against. This will often be the
2254 system Ruby, which can be selected before issuing the "make" command with:
2259 MANAGING USING PATHOGEN *command-t-pathogen*
2261 Pathogen is a plugin that allows you to maintain plugin installations in
2262 separate, isolated subdirectories under the "bundle" directory in your
2263 |'runtimepath'|. The following examples assume that you already have
2264 Pathogen installed and configured, and that you are installing into
2265 ~/.vim/bundle. For more information about Pathogen, see:
2267 http://www.vim.org/scripts/script.php?script_id=2332
2269 If you manage your entire ~/.vim folder using Git then you can add the
2270 Command-T repository as a submodule:
2273 git submodule add git://git.wincent.com/command-t.git bundle/command-t
2276 Or if you just wish to do a simple clone instead of using submodules:
2279 git clone git://git.wincent.com/command-t.git bundle/command-t
2281 Once you have a local copy of the repository you can update it at any time
2284 cd ~/.vim/bundle/command-t
2287 Or you can switch to a specific release with:
2289 cd ~/.vim/bundle/command-t
2292 After installing or updating you must build the extension:
2294 cd ~/.vim/bundle/command-t
2297 While the Vimball installation automatically generates the help tags, under
2298 Pathogen it is necessary to do so explicitly from inside Vim:
2300 :call pathogen#helptags()
2303 TROUBLE-SHOOTING *command-t-trouble-shooting*
2305 Most installation problems are caused by a mismatch between the version of
2306 Ruby on the host operating system, and the version of Ruby that Vim itself
2307 linked against at compile time. For example, if one is 32-bit and the other is
2308 64-bit, or one is from the Ruby 1.9 series and the other is from the 1.8
2309 series, then the plug-in is not likely to work.
2311 As such, on Mac OS X, I recommend using the standard Ruby that comes with the
2312 system (currently 1.8.7) along with the latest version of MacVim (currently
2313 version 7.3). If you wish to use custom builds of Ruby or of MacVim (not
2314 recommmended) then you will have to take extra care to ensure that the exact
2315 same Ruby environment is in effect when building Ruby, Vim and the Command-T
2318 For Windows, the following combination is known to work:
2320 - Vim 7.2 from http://www.vim.org/download.php:
2321 ftp://ftp.vim.org/pub/vim/pc/gvim72.exe
2322 - Ruby 1.8.7-p299 from http://rubyinstaller.org/downloads/archives:
2323 http://rubyforge.org/frs/download.php/71492/rubyinstaller-1.8.7-p299.exe
2324 - DevKit 3.4.5r3-20091110 from http://rubyinstaller.org/downloads/archives:
2325 http://rubyforge.org/frs/download.php/66888/devkit-3.4.5r3-20091110.7z
2327 If a problem occurs the first thing you should do is inspect the output of:
2332 During the installation, and:
2336 And compare the compilation and linker flags that were passed to the
2337 extension and to Vim itself when they were built. If the Ruby-related
2338 flags or architecture flags are different then it is likely that something
2339 has changed in your Ruby environment and the extension may not work until
2340 you eliminate the discrepancy.
2343 USAGE *command-t-usage*
2345 Bring up the Command-T file window by typing:
2349 This mapping is set up automatically for you, provided you do not already have
2350 a mapping for <Leader>t or |:CommandT|. You can also bring up the file window
2351 by issuing the command:
2355 A prompt will appear at the bottom of the screen along with a file window
2356 showing all of the files in the current directory (as returned by the
2359 For the most efficient file navigation within a project it's recommended that
2360 you |:cd| into the root directory of your project when starting to work on it.
2361 If you wish to open a file from outside of the project folder you can pass in
2362 an optional path argument (relative or absolute) to |:CommandT|:
2364 :CommandT ../path/to/other/files
2366 Type letters in the prompt to narrow down the selection, showing only the
2367 files whose paths contain those letters in the specified order. Letters do not
2368 need to appear consecutively in a path in order for it to be classified as a
2371 Once the desired file has been selected it can be opened by pressing <CR>.
2372 (By default files are opened in the current window, but there are other
2373 mappings that you can use to open in a vertical or horizontal split, or in
2374 a new tab.) Note that if you have |'nohidden'| set and there are unsaved
2375 changes in the current window when you press <CR> then opening in the current
2376 window would fail; in this case Command-T will open the file in a new split.
2378 The following mappings are active when the prompt has focus:
2380 <BS> delete the character to the left of the cursor
2381 <Del> delete the character at the cursor
2382 <Left> move the cursor one character to the left
2383 <C-h> move the cursor one character to the left
2384 <Right> move the cursor one character to the right
2385 <C-l> move the cursor one character to the right
2386 <C-a> move the cursor to the start (left)
2387 <C-e> move the cursor to the end (right)
2388 <C-u> clear the contents of the prompt
2389 <Tab> change focus to the file listing
2391 The following mappings are active when the file listing has focus:
2393 <Tab> change focus to the prompt
2395 The following mappings are active when either the prompt or the file listing
2398 <CR> open the selected file
2399 <C-CR> open the selected file in a new split window
2400 <C-s> open the selected file in a new split window
2401 <C-v> open the selected file in a new vertical split window
2402 <C-t> open the selected file in a new tab
2403 <C-j> select next file in the file listing
2404 <C-n> select next file in the file listing
2405 <Down> select next file in the file listing
2406 <C-k> select previous file in the file listing
2407 <C-p> select previous file in the file listing
2408 <Up> select previous file in the file listing
2409 <C-c> cancel (dismisses file listing)
2411 The following is also available on terminals which support it:
2413 <Esc> cancel (dismisses file listing)
2415 Note that the default mappings can be overriden by setting options in your
2416 ~/.vimrc file (see the OPTIONS section for a full list of available options).
2418 In addition, when the file listing has focus, typing a character will cause
2419 the selection to jump to the first path which begins with that character.
2420 Typing multiple characters consecutively can be used to distinguish between
2421 paths which begin with the same prefix.
2424 COMMANDS *command-t-commands*
2427 |:CommandT| Brings up the Command-T file window, starting in the
2428 current working directory as returned by the|:pwd|
2432 |:CommandTBuffer|Brings up the Command-T buffer window.
2433 This works exactly like the standard file window,
2434 except that the selection is limited to files that
2435 you already have open in buffers.
2438 |:CommandTFlush|Instructs the plug-in to flush its path cache, causing
2439 the directory to be rescanned for new or deleted paths
2440 the next time the file window is shown. In addition, all
2441 configuration settings are re-evaluated, causing any
2442 changes made to settings via the |:let| command to be picked
2446 MAPPINGS *command-t-mappings*
2448 By default Command-T comes with only two mappings:
2450 <Leader>t bring up the Command-T file window
2451 <Leader>b bring up the Command-T buffer window
2453 However, Command-T won't overwrite a pre-existing mapping so if you prefer
2454 to define different mappings use lines like these in your ~/.vimrc:
2456 nmap <silent> <Leader>t :CommandT<CR>
2457 nmap <silent> <Leader>b :CommandTBuffer<CR>
2459 Replacing "<Leader>t" or "<Leader>b" with your mapping of choice.
2461 Note that in the case of MacVim you actually can map to Command-T (written
2462 as <D-t> in Vim) in your ~/.gvimrc file if you first unmap the existing menu
2463 binding of Command-T to "New Tab":
2465 if has("gui_macvim")
2466 macmenu &File.New\ Tab key=<nop>
2467 map <D-t> :CommandT<CR>
2470 When the Command-T window is active a number of other additional mappings
2471 become available for doing things like moving between and selecting matches.
2472 These are fully described above in the USAGE section, and settings for
2473 overriding the mappings are listed below under OPTIONS.
2476 OPTIONS *command-t-options*
2478 A number of options may be set in your ~/.vimrc to influence the behaviour of
2479 the plug-in. To set an option, you include a line like this in your ~/.vimrc:
2481 let g:CommandTMaxFiles=20000
2483 To have Command-T pick up new settings immediately (that is, without having
2484 to restart Vim) you can issue the |:CommandTFlush| command after making
2487 Following is a list of all available options:
2489 *g:CommandTMaxFiles*
2490 |g:CommandTMaxFiles| number (default 10000)
2492 The maximum number of files that will be considered when scanning the
2493 current directory. Upon reaching this number scanning stops. This
2494 limit applies only to file listings and is ignored for buffer
2497 *g:CommandTMaxDepth*
2498 |g:CommandTMaxDepth| number (default 15)
2500 The maximum depth (levels of recursion) to be explored when scanning the
2501 current directory. Any directories at levels beyond this depth will be
2504 *g:CommandTMaxHeight*
2505 |g:CommandTMaxHeight| number (default: 0)
2507 The maximum height in lines the match window is allowed to expand to.
2508 If set to 0, the window will occupy as much of the available space as
2509 needed to show matching entries.
2511 *g:CommandTAlwaysShowDotFiles*
2512 |g:CommandTAlwaysShowDotFiles| boolean (default: 0)
2514 When showing the file listing Command-T will by default show dot-files
2515 only if the entered search string contains a dot that could cause a
2516 dot-file to match. When set to a non-zero value, this setting instructs
2517 Command-T to always include matching dot-files in the match list
2518 regardless of whether the search string contains a dot. See also
2519 |g:CommandTNeverShowDotFiles|. Note that this setting only influences
2520 the file listing; the buffer listing treats dot-files like any other
2523 *g:CommandTNeverShowDotFiles*
2524 |g:CommandTNeverShowDotFiles| boolean (default: 0)
2526 In the file listing, Command-T will by default show dot-files if the
2527 entered search string contains a dot that could cause a dot-file to
2528 match. When set to a non-zero value, this setting instructs Command-T to
2529 never show dot-files under any circumstances. Note that it is
2530 contradictory to set both this setting and
2531 |g:CommandTAlwaysShowDotFiles| to true, and if you do so Vim will suffer
2532 from headaches, nervous twitches, and sudden mood swings. This setting
2533 has no effect in buffer listings, where dot files are treated like any
2536 *g:CommandTScanDotDirectories*
2537 |g:CommandTScanDotDirectories| boolean (default: 0)
2539 Normally Command-T will not recurse into "dot-directories" (directories
2540 whose names begin with a dot) while performing its initial scan. Set
2541 this setting to a non-zero value to override this behavior and recurse.
2542 Note that this setting is completely independent of the
2543 |g:CommandTAlwaysShowDotFiles| and |g:CommandTNeverShowDotFiles|
2544 settings; those apply only to the selection and display of matches
2545 (after scanning has been performed), whereas
2546 |g:CommandTScanDotDirectories| affects the behaviour at scan-time.
2548 Note also that even with this setting off you can still use Command-T to
2549 open files inside a "dot-directory" such as ~/.vim, but you have to use
2550 the |:cd| command to change into that directory first. For example:
2555 *g:CommandTMatchWindowAtTop*
2556 |g:CommandTMatchWindowAtTop| boolean (default: 0)
2558 When this setting is off (the default) the match window will appear at
2559 the bottom so as to keep it near to the prompt. Turning it on causes the
2560 match window to appear at the top instead. This may be preferable if you
2561 want the best match (usually the first one) to appear in a fixed location
2562 on the screen rather than moving as the number of matches changes during
2565 *g:CommandTMatchWindowReverse*
2566 |g:CommandTMatchWindowReverse| boolean (default: 0)
2568 When this setting is off (the default) the matches will appear from
2569 top to bottom with the topmost being selected. Turning it on causes the
2570 matches to be reversed so the best match is at the bottom and the
2571 initially selected match is the bottom most. This may be preferable if
2572 you want the best match to appear in a fixed location on the screen
2573 but still be near the prompt at the bottom.
2575 As well as the basic options listed above, there are a number of settings that
2576 can be used to override the default key mappings used by Command-T. For
2577 example, to set <C-x> as the mapping for cancelling (dismissing) the Command-T
2578 window, you would add the following to your ~/.vimrc:
2580 let g:CommandTCancelMap='<C-x>'
2582 Multiple, alternative mappings may be specified using list syntax:
2584 let g:CommandTCancelMap=['<C-x>', '<C-c>']
2586 Following is a list of all map settings and their defaults:
2588 Setting Default mapping(s)
2590 *g:CommandTBackspaceMap*
2591 |g:CommandTBackspaceMap| <BS>
2593 *g:CommandTDeleteMap*
2594 |g:CommandTDeleteMap| <Del>
2596 *g:CommandTAcceptSelectionMap*
2597 |g:CommandTAcceptSelectionMap| <CR>
2599 *g:CommandTAcceptSelectionSplitMap*
2600 |g:CommandTAcceptSelectionSplitMap| <C-CR>
2603 *g:CommandTAcceptSelectionTabMap*
2604 |g:CommandTAcceptSelectionTabMap| <C-t>
2606 *g:CommandTAcceptSelectionVSplitMap*
2607 |g:CommandTAcceptSelectionVSplitMap| <C-v>
2609 *g:CommandTToggleFocusMap*
2610 |g:CommandTToggleFocusMap| <Tab>
2612 *g:CommandTCancelMap*
2613 |g:CommandTCancelMap| <C-c>
2614 <Esc> (not on all terminals)
2616 *g:CommandTSelectNextMap*
2617 |g:CommandTSelectNextMap| <C-n>
2621 *g:CommandTSelectPrevMap*
2622 |g:CommandTSelectPrevMap| <C-p>
2626 *g:CommandTClearMap*
2627 |g:CommandTClearMap| <C-u>
2629 *g:CommandTCursorLeftMap*
2630 |g:CommandTCursorLeftMap| <Left>
2633 *g:CommandTCursorRightMap*
2634 |g:CommandTCursorRightMap| <Right>
2637 *g:CommandTCursorEndMap*
2638 |g:CommandTCursorEndMap| <C-e>
2640 *g:CommandTCursorStartMap*
2641 |g:CommandTCursorStartMap| <C-a>
2643 In addition to the options provided by Command-T itself, some of Vim's own
2644 settings can be used to control behavior:
2646 *command-t-wildignore*
2647 |'wildignore'| string (default: '')
2649 Vim's |'wildignore'| setting is used to determine which files should be
2650 excluded from listings. This is a comma-separated list of glob patterns.
2651 It defaults to the empty string, but common settings include "*.o,*.obj"
2652 (to exclude object files) or ".git,.svn" (to exclude SCM metadata
2653 directories). For example:
2655 :set wildignore+=*.o,*.obj,.git
2657 A pattern such as "vendor/rails/**" would exclude all files and
2658 subdirectories inside the "vendor/rails" directory (relative to
2659 directory Command-T starts in).
2661 See the |'wildignore'| documentation for more information.
2664 AUTHORS *command-t-authors*
2666 Command-T is written and maintained by Wincent Colaiuta <win@wincent.com>.
2667 Other contributors that have submitted patches include (in alphabetical
2680 As this was the first Vim plug-in I had ever written I was heavily influenced
2681 by the design of the LustyExplorer plug-in by Stephen Bach, which I understand
2682 is one of the largest Ruby-based Vim plug-ins to date.
2684 While the Command-T codebase doesn't contain any code directly copied from
2685 LustyExplorer, I did use it as a reference for answers to basic questions (like
2686 "How do you do 'X' in a Ruby-based Vim plug-in?"), and also copied some basic
2687 architectural decisions (like the division of the code into Prompt, Settings
2688 and MatchWindow classes).
2690 LustyExplorer is available from:
2692 http://www.vim.org/scripts/script.php?script_id=1890
2695 WEBSITE *command-t-website*
2697 The official website for Command-T is:
2699 https://wincent.com/products/command-t
2701 The latest release will always be available from there.
2703 Development in progress can be inspected via the project's Git repository
2706 https://wincent.com/repos/command-t
2708 A copy of each release is also available from the official Vim scripts site
2711 http://www.vim.org/scripts/script.php?script_id=3025
2713 Bug reports should be submitted to the issue tracker at:
2715 https://wincent.com/issues
2718 DONATIONS *command-t-donations*
2720 Command-T itself is free software released under the terms of the BSD license.
2721 If you would like to support further development you can make a donation via
2722 PayPal to win@wincent.com:
2724 https://wincent.com/products/command-t/donations
2727 LICENSE *command-t-license*
2729 Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
2731 Redistribution and use in source and binary forms, with or without
2732 modification, are permitted provided that the following conditions are met:
2734 1. Redistributions of source code must retain the above copyright notice,
2735 this list of conditions and the following disclaimer.
2736 2. Redistributions in binary form must reproduce the above copyright notice,
2737 this list of conditions and the following disclaimer in the documentation
2738 and/or other materials provided with the distribution.
2740 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2741 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2742 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2743 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
2744 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2745 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2746 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2747 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2748 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2749 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2750 POSSIBILITY OF SUCH DAMAGE.
2753 HISTORY *command-t-history*
2755 1.2.1 (30 April 2011)
2757 - Remove duplicate copy of the documentation that was causing "Duplicate tag"
2759 - Mitigate issue with distracting blinking cursor in non-GUI versions of Vim
2760 (patch from Steven Moazami)
2764 - added |g:CommandTMatchWindowReverse| option, to reverse the order of items
2765 in the match listing (patch from Steven Moazami)
2767 1.1b2 (26 March 2011)
2769 - fix a glitch in the release process; the plugin itself is unchanged since
2772 1.1b (26 March 2011)
2774 - add |:CommandTBuffer| command for quickly selecting among open buffers
2776 1.0.1 (5 January 2011)
2778 - work around bug when mapping |:CommandTFlush|, wherein the default mapping
2779 for |:CommandT| would not be set up
2780 - clean up when leaving the Command-T buffer via unexpected means (such as
2781 with <C-W k> or similar)
2783 1.0 (26 November 2010)
2785 - make relative path simplification work on Windows
2787 1.0b (5 November 2010)
2789 - work around platform-specific Vim 7.3 bug seen by some users (wherein
2790 Vim always falsely reports to Ruby that the buffer numbers is 0)
2791 - re-use the buffer that is used to show the match listing, rather than
2792 throwing it away and recreating it each time Command-T is shown; this
2793 stops the buffer numbers from creeping up needlessly
2795 0.9 (8 October 2010)
2797 - use relative paths when opening files inside the current working directory
2798 in order to keep buffer listings as brief as possible (patch from Matthew
2801 0.8.1 (14 September 2010)
2803 - fix mapping issues for users who have set |'notimeout'| (patch from Sung
2806 0.8 (19 August 2010)
2808 - overrides for the default mappings can now be lists of strings, allowing
2809 multiple mappings to be defined for any given action
2810 - <Leader>t mapping only set up if no other map for |:CommandT| exists
2811 (patch from Scott Bronson)
2812 - prevent folds from appearing in the match listing
2813 - tweaks to avoid the likelihood of "Not enough room" errors when trying to
2815 - watch out for "nil" windows when restoring window dimensions
2816 - optimizations (avoid some repeated downcasing)
2817 - move all Ruby files under the "command-t" subdirectory and avoid polluting
2818 the "Vim" module namespace
2822 - large overhaul of the scoring algorithm to make the ordering of returned
2823 results more intuitive; given the scope of the changes and room for
2824 optimization of the new algorithm, this release is labelled as "beta"
2828 - handle more |'wildignore'| patterns by delegating to Vim's own |expand()|
2829 function; with this change it is now viable to exclude patterns such as
2830 'vendor/rails/**' in addition to filename-only patterns like '*.o' and
2831 '.git' (patch from Mike Lundy)
2832 - always sort results alphabetically for empty search strings; this eliminates
2833 filesystem-specific variations (patch from Mike Lundy)
2837 - |:CommandT| now accepts an optional parameter to specify the starting
2838 directory, temporarily overriding the usual default of Vim's |:pwd|
2839 - fix truncated paths when operating from root directory
2841 0.5.1 (11 April 2010)
2843 - fix for Ruby 1.9 compatibility regression introduced in 0.5
2844 - documentation enhancements, specifically targetted at Windows users
2848 - |:CommandTFlush| now re-evaluates settings, allowing changes made via |let|
2849 to be picked up without having to restart Vim
2850 - fix premature abort when scanning very deep directory hierarchies
2851 - remove broken |<Esc>| key mapping on vt100 and xterm terminals
2852 - provide settings for overriding default mappings
2853 - minor performance optimization
2857 - add |g:CommandTMatchWindowAtTop| setting (patch from Zak Johnson)
2858 - documentation fixes and enhancements
2859 - internal refactoring and simplification
2863 - add |g:CommandTMaxHeight| setting for controlling the maximum height of the
2864 match window (patch from Lucas de Vries)
2865 - fix bug where |'list'| setting might be inappropriately set after dismissing
2867 - compatibility fix for different behaviour of "autoload" under Ruby 1.9.1
2868 - avoid "highlight group not found" warning when run under a version of Vim
2869 that does not have syntax highlighting support
2870 - open in split when opening normally would fail due to |'hidden'| and
2875 - compatibility fixes for compilation under Ruby 1.9 series
2876 - compatibility fixes for compilation under Ruby 1.8.5
2877 - compatibility fixes for Windows and other non-UNIX platforms
2878 - suppress "mapping already exists" message if <Leader>t mapping is already
2879 defined when plug-in is loaded
2880 - exclude paths based on |'wildignore'| setting rather than a hardcoded
2885 - initial public release
2887 ------------------------------------------------------------------------------
2889 plugin/command-t.vim [[[1
2892 " Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
2894 " Redistribution and use in source and binary forms, with or without
2895 " modification, are permitted provided that the following conditions are met:
2897 " 1. Redistributions of source code must retain the above copyright notice,
2898 " this list of conditions and the following disclaimer.
2899 " 2. Redistributions in binary form must reproduce the above copyright notice,
2900 " this list of conditions and the following disclaimer in the documentation
2901 " and/or other materials provided with the distribution.
2903 " THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2904 " AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2905 " IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2906 " ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
2907 " LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2908 " CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2909 " SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2910 " INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2911 " CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2912 " ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2913 " POSSIBILITY OF SUCH DAMAGE.
2915 if exists("g:command_t_loaded")
2918 let g:command_t_loaded = 1
2920 command CommandTBuffer call <SID>CommandTShowBufferFinder()
2921 command -nargs=? -complete=dir CommandT call <SID>CommandTShowFileFinder(<q-args>)
2922 command CommandTFlush call <SID>CommandTFlush()
2924 if !hasmapto(':CommandT<CR>')
2925 silent! nmap <unique> <silent> <Leader>t :CommandT<CR>
2928 if !hasmapto(':CommandTBuffer<CR>')
2929 silent! nmap <unique> <silent> <Leader>b :CommandTBuffer<CR>
2932 function s:CommandTRubyWarning()
2934 echo "command-t.vim requires Vim to be compiled with Ruby support"
2935 echo "For more information type: :help command-t"
2939 function s:CommandTShowBufferFinder()
2941 ruby $command_t.show_buffer_finder
2943 call s:CommandTRubyWarning()
2947 function s:CommandTShowFileFinder(arg)
2949 ruby $command_t.show_file_finder
2951 call s:CommandTRubyWarning()
2955 function s:CommandTFlush()
2957 ruby $command_t.flush
2959 call s:CommandTRubyWarning()
2967 function CommandTHandleKey(arg)
2968 ruby $command_t.handle_key
2971 function CommandTBackspace()
2972 ruby $command_t.backspace
2975 function CommandTDelete()
2976 ruby $command_t.delete
2979 function CommandTAcceptSelection()
2980 ruby $command_t.accept_selection
2983 function CommandTAcceptSelectionTab()
2984 ruby $command_t.accept_selection :command => 'tabe'
2987 function CommandTAcceptSelectionSplit()
2988 ruby $command_t.accept_selection :command => 'sp'
2991 function CommandTAcceptSelectionVSplit()
2992 ruby $command_t.accept_selection :command => 'vs'
2995 function CommandTToggleFocus()
2996 ruby $command_t.toggle_focus
2999 function CommandTCancel()
3000 ruby $command_t.cancel
3003 function CommandTSelectNext()
3004 ruby $command_t.select_next
3007 function CommandTSelectPrev()
3008 ruby $command_t.select_prev
3011 function CommandTClear()
3012 ruby $command_t.clear
3015 function CommandTCursorLeft()
3016 ruby $command_t.cursor_left
3019 function CommandTCursorRight()
3020 ruby $command_t.cursor_right
3023 function CommandTCursorEnd()
3024 ruby $command_t.cursor_end
3027 function CommandTCursorStart()
3028 ruby $command_t.cursor_start
3032 # require Ruby files
3034 # prepare controller
3035 require 'command-t/vim'
3036 require 'command-t/controller'
3037 $command_t = CommandT::Controller.new
3039 load_path_modified = false
3040 ::VIM::evaluate('&runtimepath').to_s.split(',').each do |path|
3041 lib = "#{path}/ruby"
3042 if !$LOAD_PATH.include?(lib) and File.exist?(lib)
3044 load_path_modified = true
3047 retry if load_path_modified
3049 # could get here if C extension was not compiled, or was compiled
3050 # for the wrong architecture or Ruby version
3051 require 'command-t/stub'
3052 $command_t = CommandT::Stub.new