command-t 1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +5 -0
- data/LICENSE +22 -0
- data/README.txt +779 -0
- data/Rakefile +217 -0
- data/doc/README.txt +779 -0
- data/doc/command-t.txt +736 -0
- data/plugin/command-t.vim +164 -0
- data/ruby/command-t/Makefile +181 -0
- data/ruby/command-t/controller.rb +317 -0
- data/ruby/command-t/depend +24 -0
- data/ruby/command-t/ext.c +65 -0
- data/ruby/command-t/ext.h +36 -0
- data/ruby/command-t/extconf.rb +32 -0
- data/ruby/command-t/finder.rb +52 -0
- data/ruby/command-t/finder/buffer_finder.rb +35 -0
- data/ruby/command-t/finder/file_finder.rb +35 -0
- data/ruby/command-t/match.c +189 -0
- data/ruby/command-t/match.h +29 -0
- data/ruby/command-t/match_window.rb +377 -0
- data/ruby/command-t/matcher.c +164 -0
- data/ruby/command-t/matcher.h +30 -0
- data/ruby/command-t/prompt.rb +165 -0
- data/ruby/command-t/ruby_compat.h +49 -0
- data/ruby/command-t/scanner.rb +28 -0
- data/ruby/command-t/scanner/buffer_scanner.rb +42 -0
- data/ruby/command-t/scanner/file_scanner.rb +94 -0
- data/ruby/command-t/settings.rb +77 -0
- data/ruby/command-t/stub.rb +46 -0
- data/ruby/command-t/vim.rb +43 -0
- data/ruby/command-t/vim/path_utilities.rb +40 -0
- data/ruby/command-t/vim/screen.rb +32 -0
- data/ruby/command-t/vim/window.rb +38 -0
- metadata +97 -0
@@ -0,0 +1,164 @@
|
|
1
|
+
" command-t.vim
|
2
|
+
" Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
|
3
|
+
"
|
4
|
+
" Redistribution and use in source and binary forms, with or without
|
5
|
+
" modification, are permitted provided that the following conditions are met:
|
6
|
+
"
|
7
|
+
" 1. Redistributions of source code must retain the above copyright notice,
|
8
|
+
" this list of conditions and the following disclaimer.
|
9
|
+
" 2. Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
" this list of conditions and the following disclaimer in the documentation
|
11
|
+
" and/or other materials provided with the distribution.
|
12
|
+
"
|
13
|
+
" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
14
|
+
" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
15
|
+
" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
16
|
+
" ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
|
17
|
+
" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
18
|
+
" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
19
|
+
" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
20
|
+
" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
21
|
+
" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
22
|
+
" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
23
|
+
" POSSIBILITY OF SUCH DAMAGE.
|
24
|
+
|
25
|
+
if exists("g:command_t_loaded")
|
26
|
+
finish
|
27
|
+
endif
|
28
|
+
let g:command_t_loaded = 1
|
29
|
+
|
30
|
+
command CommandTBuffer call <SID>CommandTShowBufferFinder()
|
31
|
+
command -nargs=? -complete=dir CommandT call <SID>CommandTShowFileFinder(<q-args>)
|
32
|
+
command CommandTFlush call <SID>CommandTFlush()
|
33
|
+
|
34
|
+
if !hasmapto(':CommandT<CR>')
|
35
|
+
silent! nmap <unique> <silent> <Leader>t :CommandT<CR>
|
36
|
+
endif
|
37
|
+
|
38
|
+
if !hasmapto(':CommandTBuffer<CR>')
|
39
|
+
silent! nmap <unique> <silent> <Leader>b :CommandTBuffer<CR>
|
40
|
+
endif
|
41
|
+
|
42
|
+
function s:CommandTRubyWarning()
|
43
|
+
echohl WarningMsg
|
44
|
+
echo "command-t.vim requires Vim to be compiled with Ruby support"
|
45
|
+
echo "For more information type: :help command-t"
|
46
|
+
echohl none
|
47
|
+
endfunction
|
48
|
+
|
49
|
+
function s:CommandTShowBufferFinder()
|
50
|
+
if has('ruby')
|
51
|
+
ruby $command_t.show_buffer_finder
|
52
|
+
else
|
53
|
+
call s:CommandTRubyWarning()
|
54
|
+
endif
|
55
|
+
endfunction
|
56
|
+
|
57
|
+
function s:CommandTShowFileFinder(arg)
|
58
|
+
if has('ruby')
|
59
|
+
ruby $command_t.show_file_finder
|
60
|
+
else
|
61
|
+
call s:CommandTRubyWarning()
|
62
|
+
endif
|
63
|
+
endfunction
|
64
|
+
|
65
|
+
function s:CommandTFlush()
|
66
|
+
if has('ruby')
|
67
|
+
ruby $command_t.flush
|
68
|
+
else
|
69
|
+
call s:CommandTRubyWarning()
|
70
|
+
endif
|
71
|
+
endfunction
|
72
|
+
|
73
|
+
if !has('ruby')
|
74
|
+
finish
|
75
|
+
endif
|
76
|
+
|
77
|
+
function CommandTHandleKey(arg)
|
78
|
+
ruby $command_t.handle_key
|
79
|
+
endfunction
|
80
|
+
|
81
|
+
function CommandTBackspace()
|
82
|
+
ruby $command_t.backspace
|
83
|
+
endfunction
|
84
|
+
|
85
|
+
function CommandTDelete()
|
86
|
+
ruby $command_t.delete
|
87
|
+
endfunction
|
88
|
+
|
89
|
+
function CommandTAcceptSelection()
|
90
|
+
ruby $command_t.accept_selection
|
91
|
+
endfunction
|
92
|
+
|
93
|
+
function CommandTAcceptSelectionTab()
|
94
|
+
ruby $command_t.accept_selection :command => 'tabe'
|
95
|
+
endfunction
|
96
|
+
|
97
|
+
function CommandTAcceptSelectionSplit()
|
98
|
+
ruby $command_t.accept_selection :command => 'sp'
|
99
|
+
endfunction
|
100
|
+
|
101
|
+
function CommandTAcceptSelectionVSplit()
|
102
|
+
ruby $command_t.accept_selection :command => 'vs'
|
103
|
+
endfunction
|
104
|
+
|
105
|
+
function CommandTToggleFocus()
|
106
|
+
ruby $command_t.toggle_focus
|
107
|
+
endfunction
|
108
|
+
|
109
|
+
function CommandTCancel()
|
110
|
+
ruby $command_t.cancel
|
111
|
+
endfunction
|
112
|
+
|
113
|
+
function CommandTSelectNext()
|
114
|
+
ruby $command_t.select_next
|
115
|
+
endfunction
|
116
|
+
|
117
|
+
function CommandTSelectPrev()
|
118
|
+
ruby $command_t.select_prev
|
119
|
+
endfunction
|
120
|
+
|
121
|
+
function CommandTClear()
|
122
|
+
ruby $command_t.clear
|
123
|
+
endfunction
|
124
|
+
|
125
|
+
function CommandTCursorLeft()
|
126
|
+
ruby $command_t.cursor_left
|
127
|
+
endfunction
|
128
|
+
|
129
|
+
function CommandTCursorRight()
|
130
|
+
ruby $command_t.cursor_right
|
131
|
+
endfunction
|
132
|
+
|
133
|
+
function CommandTCursorEnd()
|
134
|
+
ruby $command_t.cursor_end
|
135
|
+
endfunction
|
136
|
+
|
137
|
+
function CommandTCursorStart()
|
138
|
+
ruby $command_t.cursor_start
|
139
|
+
endfunction
|
140
|
+
|
141
|
+
ruby << EOF
|
142
|
+
# require Ruby files
|
143
|
+
begin
|
144
|
+
# prepare controller
|
145
|
+
require 'command-t/vim'
|
146
|
+
require 'command-t/controller'
|
147
|
+
$command_t = CommandT::Controller.new
|
148
|
+
rescue LoadError
|
149
|
+
load_path_modified = false
|
150
|
+
::VIM::evaluate('&runtimepath').to_s.split(',').each do |path|
|
151
|
+
lib = "#{path}/ruby"
|
152
|
+
if !$LOAD_PATH.include?(lib) and File.exist?(lib)
|
153
|
+
$LOAD_PATH << lib
|
154
|
+
load_path_modified = true
|
155
|
+
end
|
156
|
+
end
|
157
|
+
retry if load_path_modified
|
158
|
+
|
159
|
+
# could get here if C extension was not compiled, or was compiled
|
160
|
+
# for the wrong architecture or Ruby version
|
161
|
+
require 'command-t/stub'
|
162
|
+
$command_t = CommandT::Stub.new
|
163
|
+
end
|
164
|
+
EOF
|
@@ -0,0 +1,181 @@
|
|
1
|
+
|
2
|
+
SHELL = /bin/sh
|
3
|
+
|
4
|
+
#### Start of system configuration section. ####
|
5
|
+
|
6
|
+
srcdir = .
|
7
|
+
topdir = /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin10.0
|
8
|
+
hdrdir = $(topdir)
|
9
|
+
VPATH = $(srcdir):$(topdir):$(hdrdir)
|
10
|
+
exec_prefix = $(prefix)
|
11
|
+
prefix = $(DESTDIR)/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr
|
12
|
+
sharedstatedir = $(prefix)/com
|
13
|
+
mandir = $(DESTDIR)/usr/share/man
|
14
|
+
psdir = $(docdir)
|
15
|
+
oldincludedir = $(DESTDIR)/usr/include
|
16
|
+
localedir = $(datarootdir)/locale
|
17
|
+
bindir = $(exec_prefix)/bin
|
18
|
+
libexecdir = $(exec_prefix)/libexec
|
19
|
+
sitedir = $(DESTDIR)/Library/Ruby/Site
|
20
|
+
htmldir = $(docdir)
|
21
|
+
vendorarchdir = $(vendorlibdir)/$(sitearch)
|
22
|
+
includedir = $(prefix)/include
|
23
|
+
infodir = $(DESTDIR)/usr/share/info
|
24
|
+
vendorlibdir = $(vendordir)/$(ruby_version)
|
25
|
+
sysconfdir = $(prefix)/etc
|
26
|
+
libdir = $(exec_prefix)/lib
|
27
|
+
sbindir = $(exec_prefix)/sbin
|
28
|
+
rubylibdir = $(libdir)/ruby/$(ruby_version)
|
29
|
+
docdir = $(datarootdir)/doc/$(PACKAGE)
|
30
|
+
dvidir = $(docdir)
|
31
|
+
vendordir = $(libdir)/ruby/vendor_ruby
|
32
|
+
datarootdir = $(prefix)/share
|
33
|
+
pdfdir = $(docdir)
|
34
|
+
archdir = $(rubylibdir)/$(arch)
|
35
|
+
sitearchdir = $(sitelibdir)/$(sitearch)
|
36
|
+
datadir = $(datarootdir)
|
37
|
+
localstatedir = $(prefix)/var
|
38
|
+
sitelibdir = $(sitedir)/$(ruby_version)
|
39
|
+
|
40
|
+
CC = gcc
|
41
|
+
LIBRUBY = $(LIBRUBY_SO)
|
42
|
+
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
43
|
+
LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
|
44
|
+
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)
|
45
|
+
|
46
|
+
RUBY_EXTCONF_H =
|
47
|
+
CFLAGS = -fno-common -arch i386 -arch x86_64 -g -Os -pipe -fno-common -DENABLE_DTRACE -fno-common -pipe -fno-common $(cflags)
|
48
|
+
INCFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir)
|
49
|
+
DEFS =
|
50
|
+
CPPFLAGS = -DHAVE_RUBY_H -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE $(DEFS) $(cppflags)
|
51
|
+
CXXFLAGS = $(CFLAGS)
|
52
|
+
ldflags = -L. -arch i386 -arch x86_64
|
53
|
+
dldflags =
|
54
|
+
archflag =
|
55
|
+
DLDFLAGS = $(ldflags) $(dldflags) $(archflag)
|
56
|
+
LDSHARED = cc -arch i386 -arch x86_64 -pipe -bundle -undefined dynamic_lookup
|
57
|
+
AR = ar
|
58
|
+
EXEEXT =
|
59
|
+
|
60
|
+
RUBY_INSTALL_NAME = ruby
|
61
|
+
RUBY_SO_NAME = ruby
|
62
|
+
arch = universal-darwin10.0
|
63
|
+
sitearch = universal-darwin10.0
|
64
|
+
ruby_version = 1.8
|
65
|
+
ruby = /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
|
66
|
+
RUBY = $(ruby)
|
67
|
+
RM = rm -f
|
68
|
+
MAKEDIRS = mkdir -p
|
69
|
+
INSTALL = /usr/bin/install -c
|
70
|
+
INSTALL_PROG = $(INSTALL) -m 0755
|
71
|
+
INSTALL_DATA = $(INSTALL) -m 644
|
72
|
+
COPY = cp
|
73
|
+
|
74
|
+
#### End of system configuration section. ####
|
75
|
+
|
76
|
+
preload =
|
77
|
+
|
78
|
+
libpath = . $(libdir)
|
79
|
+
LIBPATH = -L. -L$(libdir)
|
80
|
+
DEFFILE =
|
81
|
+
|
82
|
+
CLEANFILES = mkmf.log
|
83
|
+
DISTCLEANFILES =
|
84
|
+
|
85
|
+
extout =
|
86
|
+
extout_prefix =
|
87
|
+
target_prefix =
|
88
|
+
LOCAL_LIBS =
|
89
|
+
LIBS = $(LIBRUBYARG_SHARED) -lpthread -ldl
|
90
|
+
SRCS = ext.c match.c matcher.c
|
91
|
+
OBJS = ext.o match.o matcher.o
|
92
|
+
TARGET = ext
|
93
|
+
DLLIB = $(TARGET).bundle
|
94
|
+
EXTSTATIC =
|
95
|
+
STATIC_LIB =
|
96
|
+
|
97
|
+
BINDIR = $(bindir)
|
98
|
+
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
99
|
+
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
|
100
|
+
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
|
101
|
+
|
102
|
+
TARGET_SO = $(DLLIB)
|
103
|
+
CLEANLIBS = $(TARGET).bundle $(TARGET).il? $(TARGET).tds $(TARGET).map
|
104
|
+
CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
|
105
|
+
|
106
|
+
all: $(DLLIB)
|
107
|
+
static: $(STATIC_LIB)
|
108
|
+
|
109
|
+
clean:
|
110
|
+
@-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
|
111
|
+
|
112
|
+
distclean: clean
|
113
|
+
@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
|
114
|
+
@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
|
115
|
+
|
116
|
+
realclean: distclean
|
117
|
+
install: install-so install-rb
|
118
|
+
|
119
|
+
install-so: $(RUBYARCHDIR)
|
120
|
+
install-so: $(RUBYARCHDIR)/$(DLLIB)
|
121
|
+
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
|
122
|
+
$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
|
123
|
+
install-rb: pre-install-rb install-rb-default
|
124
|
+
install-rb-default: pre-install-rb-default
|
125
|
+
pre-install-rb: Makefile
|
126
|
+
pre-install-rb-default: Makefile
|
127
|
+
$(RUBYARCHDIR):
|
128
|
+
$(MAKEDIRS) $@
|
129
|
+
|
130
|
+
site-install: site-install-so site-install-rb
|
131
|
+
site-install-so: install-so
|
132
|
+
site-install-rb: install-rb
|
133
|
+
|
134
|
+
.SUFFIXES: .c .m .cc .cxx .cpp .C .o
|
135
|
+
|
136
|
+
.cc.o:
|
137
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
138
|
+
|
139
|
+
.cxx.o:
|
140
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
141
|
+
|
142
|
+
.cpp.o:
|
143
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
144
|
+
|
145
|
+
.C.o:
|
146
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
147
|
+
|
148
|
+
.c.o:
|
149
|
+
$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
|
150
|
+
|
151
|
+
$(DLLIB): $(OBJS) Makefile
|
152
|
+
@-$(RM) $@
|
153
|
+
$(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
###
|
158
|
+
# Copyright 2010 Wincent Colaiuta. All rights reserved.
|
159
|
+
#
|
160
|
+
# Redistribution and use in source and binary forms, with or without
|
161
|
+
# modification, are permitted provided that the following conditions are met:
|
162
|
+
#
|
163
|
+
# 1. Redistributions of source code must retain the above copyright notice,
|
164
|
+
# this list of conditions and the following disclaimer.
|
165
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
166
|
+
# this list of conditions and the following disclaimer in the documentation
|
167
|
+
# and/or other materials provided with the distribution.
|
168
|
+
#
|
169
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
170
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
171
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
172
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
|
173
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
174
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
175
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
176
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
177
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
178
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
179
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
180
|
+
|
181
|
+
CFLAGS += -std=c99 -Wall -Wextra -Wno-unused-parameter
|
@@ -0,0 +1,317 @@
|
|
1
|
+
# Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
|
2
|
+
#
|
3
|
+
# Redistribution and use in source and binary forms, with or without
|
4
|
+
# modification, are permitted provided that the following conditions are met:
|
5
|
+
#
|
6
|
+
# 1. Redistributions of source code must retain the above copyright notice,
|
7
|
+
# this list of conditions and the following disclaimer.
|
8
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer in the documentation
|
10
|
+
# and/or other materials provided with the distribution.
|
11
|
+
#
|
12
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
13
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
14
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
15
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
|
16
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
17
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
18
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
19
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
20
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
21
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
22
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
23
|
+
|
24
|
+
require 'command-t/finder/buffer_finder'
|
25
|
+
require 'command-t/finder/file_finder'
|
26
|
+
require 'command-t/match_window'
|
27
|
+
require 'command-t/prompt'
|
28
|
+
require 'command-t/vim/path_utilities'
|
29
|
+
|
30
|
+
module CommandT
|
31
|
+
class Controller
|
32
|
+
include VIM::PathUtilities
|
33
|
+
|
34
|
+
def initialize
|
35
|
+
@prompt = Prompt.new
|
36
|
+
@buffer_finder = CommandT::BufferFinder.new
|
37
|
+
set_up_file_finder
|
38
|
+
set_up_max_height
|
39
|
+
end
|
40
|
+
|
41
|
+
def show_buffer_finder
|
42
|
+
@path = VIM::pwd
|
43
|
+
@active_finder = @buffer_finder
|
44
|
+
show
|
45
|
+
end
|
46
|
+
|
47
|
+
def show_file_finder
|
48
|
+
# optional parameter will be desired starting directory, or ""
|
49
|
+
@path = File.expand_path(::VIM::evaluate('a:arg'), VIM::pwd)
|
50
|
+
@file_finder.path = @path
|
51
|
+
@active_finder = @file_finder
|
52
|
+
show
|
53
|
+
rescue Errno::ENOENT
|
54
|
+
# probably a problem with the optional parameter
|
55
|
+
@match_window.print_no_such_file_or_directory
|
56
|
+
end
|
57
|
+
|
58
|
+
def hide
|
59
|
+
@match_window.close
|
60
|
+
if VIM::Window.select @initial_window
|
61
|
+
if @initial_buffer.number == 0
|
62
|
+
# upstream bug: buffer number misreported as 0
|
63
|
+
# see: https://wincent.com/issues/1617
|
64
|
+
::VIM::command "silent b #{@initial_buffer.name}"
|
65
|
+
else
|
66
|
+
::VIM::command "silent b #{@initial_buffer.number}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def flush
|
72
|
+
set_up_max_height
|
73
|
+
set_up_file_finder
|
74
|
+
end
|
75
|
+
|
76
|
+
def handle_key
|
77
|
+
key = ::VIM::evaluate('a:arg').to_i.chr
|
78
|
+
if @focus == @prompt
|
79
|
+
@prompt.add! key
|
80
|
+
list_matches
|
81
|
+
else
|
82
|
+
@match_window.find key
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def backspace
|
87
|
+
if @focus == @prompt
|
88
|
+
@prompt.backspace!
|
89
|
+
list_matches
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def delete
|
94
|
+
if @focus == @prompt
|
95
|
+
@prompt.delete!
|
96
|
+
list_matches
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def accept_selection options = {}
|
101
|
+
selection = @match_window.selection
|
102
|
+
hide
|
103
|
+
open_selection(selection, options) unless selection.nil?
|
104
|
+
end
|
105
|
+
|
106
|
+
def toggle_focus
|
107
|
+
@focus.unfocus # old focus
|
108
|
+
@focus = @focus == @prompt ? @match_window : @prompt
|
109
|
+
@focus.focus # new focus
|
110
|
+
end
|
111
|
+
|
112
|
+
def cancel
|
113
|
+
hide
|
114
|
+
end
|
115
|
+
|
116
|
+
def select_next
|
117
|
+
@match_window.select_next
|
118
|
+
end
|
119
|
+
|
120
|
+
def select_prev
|
121
|
+
@match_window.select_prev
|
122
|
+
end
|
123
|
+
|
124
|
+
def clear
|
125
|
+
@prompt.clear!
|
126
|
+
list_matches
|
127
|
+
end
|
128
|
+
|
129
|
+
def cursor_left
|
130
|
+
@prompt.cursor_left if @focus == @prompt
|
131
|
+
end
|
132
|
+
|
133
|
+
def cursor_right
|
134
|
+
@prompt.cursor_right if @focus == @prompt
|
135
|
+
end
|
136
|
+
|
137
|
+
def cursor_end
|
138
|
+
@prompt.cursor_end if @focus == @prompt
|
139
|
+
end
|
140
|
+
|
141
|
+
def cursor_start
|
142
|
+
@prompt.cursor_start if @focus == @prompt
|
143
|
+
end
|
144
|
+
|
145
|
+
def leave
|
146
|
+
@match_window.leave
|
147
|
+
end
|
148
|
+
|
149
|
+
def unload
|
150
|
+
@match_window.unload
|
151
|
+
end
|
152
|
+
|
153
|
+
private
|
154
|
+
|
155
|
+
def show
|
156
|
+
@initial_window = $curwin
|
157
|
+
@initial_buffer = $curbuf
|
158
|
+
@match_window = MatchWindow.new \
|
159
|
+
:prompt => @prompt,
|
160
|
+
:match_window_at_top => get_bool('g:CommandTMatchWindowAtTop'),
|
161
|
+
:match_window_reverse => get_bool('g:CommandTMatchWindowReverse')
|
162
|
+
@focus = @prompt
|
163
|
+
@prompt.focus
|
164
|
+
register_for_key_presses
|
165
|
+
clear # clears prompt and lists matches
|
166
|
+
end
|
167
|
+
|
168
|
+
def set_up_max_height
|
169
|
+
@max_height = get_number('g:CommandTMaxHeight') || 0
|
170
|
+
end
|
171
|
+
|
172
|
+
def set_up_file_finder
|
173
|
+
@file_finder = CommandT::FileFinder.new nil,
|
174
|
+
:max_files => get_number('g:CommandTMaxFiles'),
|
175
|
+
:max_depth => get_number('g:CommandTMaxDepth'),
|
176
|
+
:always_show_dot_files => get_bool('g:CommandTAlwaysShowDotFiles'),
|
177
|
+
:never_show_dot_files => get_bool('g:CommandTNeverShowDotFiles'),
|
178
|
+
:scan_dot_directories => get_bool('g:CommandTScanDotDirectories')
|
179
|
+
end
|
180
|
+
|
181
|
+
def exists? name
|
182
|
+
::VIM::evaluate("exists(\"#{name}\")").to_i != 0
|
183
|
+
end
|
184
|
+
|
185
|
+
def get_number name
|
186
|
+
exists?(name) ? ::VIM::evaluate("#{name}").to_i : nil
|
187
|
+
end
|
188
|
+
|
189
|
+
def get_bool name
|
190
|
+
exists?(name) ? ::VIM::evaluate("#{name}").to_i != 0 : nil
|
191
|
+
end
|
192
|
+
|
193
|
+
def get_string name
|
194
|
+
exists?(name) ? ::VIM::evaluate("#{name}").to_s : nil
|
195
|
+
end
|
196
|
+
|
197
|
+
# expect a string or a list of strings
|
198
|
+
def get_list_or_string name
|
199
|
+
return nil unless exists?(name)
|
200
|
+
list_or_string = ::VIM::evaluate("#{name}")
|
201
|
+
if list_or_string.kind_of?(Array)
|
202
|
+
list_or_string.map { |item| item.to_s }
|
203
|
+
else
|
204
|
+
list_or_string.to_s
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
# Backslash-escape space, \, |, %, #, "
|
209
|
+
def sanitize_path_string str
|
210
|
+
# for details on escaping command-line mode arguments see: :h :
|
211
|
+
# (that is, help on ":") in the Vim documentation.
|
212
|
+
str.gsub(/[ \\|%#"]/, '\\\\\0')
|
213
|
+
end
|
214
|
+
|
215
|
+
def default_open_command
|
216
|
+
if !get_bool('&hidden') && get_bool('&modified')
|
217
|
+
'sp'
|
218
|
+
else
|
219
|
+
'e'
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
def ensure_appropriate_window_selection
|
224
|
+
# normally we try to open the selection in the current window, but there
|
225
|
+
# is one exception:
|
226
|
+
#
|
227
|
+
# - we don't touch any "unlisted" buffer with buftype "nofile" (such as
|
228
|
+
# NERDTree or MiniBufExplorer); this is to avoid things like the "Not
|
229
|
+
# enough room" error which occurs when trying to open in a split in a
|
230
|
+
# shallow (potentially 1-line) buffer like MiniBufExplorer is current
|
231
|
+
#
|
232
|
+
# Other "unlisted" buffers, such as those with buftype "help" are treated
|
233
|
+
# normally.
|
234
|
+
initial = $curwin
|
235
|
+
while true do
|
236
|
+
break unless ::VIM::evaluate('&buflisted').to_i == 0 &&
|
237
|
+
::VIM::evaluate('&buftype').to_s == 'nofile'
|
238
|
+
::VIM::command 'wincmd w' # try next window
|
239
|
+
break if $curwin == initial # have already tried all
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
def open_selection selection, options = {}
|
244
|
+
command = options[:command] || default_open_command
|
245
|
+
selection = File.expand_path selection, @path
|
246
|
+
selection = relative_path_under_working_directory selection
|
247
|
+
selection = sanitize_path_string selection
|
248
|
+
ensure_appropriate_window_selection
|
249
|
+
::VIM::command "silent #{command} #{selection}"
|
250
|
+
end
|
251
|
+
|
252
|
+
def map key, function, param = nil
|
253
|
+
::VIM::command "noremap <silent> <buffer> #{key} " \
|
254
|
+
":call CommandT#{function}(#{param})<CR>"
|
255
|
+
end
|
256
|
+
|
257
|
+
def xterm?
|
258
|
+
!!(::VIM::evaluate('&term') =~ /\Axterm/)
|
259
|
+
end
|
260
|
+
|
261
|
+
def vt100?
|
262
|
+
!!(::VIM::evaluate('&term') =~ /\Avt100/)
|
263
|
+
end
|
264
|
+
|
265
|
+
def register_for_key_presses
|
266
|
+
# "normal" keys (interpreted literally)
|
267
|
+
numbers = ('0'..'9').to_a.join
|
268
|
+
lowercase = ('a'..'z').to_a.join
|
269
|
+
uppercase = lowercase.upcase
|
270
|
+
punctuation = '<>`@#~!"$%&/()=+*-_.,;:?\\\'{}[] ' # and space
|
271
|
+
(numbers + lowercase + uppercase + punctuation).each_byte do |b|
|
272
|
+
map "<Char-#{b}>", 'HandleKey', b
|
273
|
+
end
|
274
|
+
|
275
|
+
# "special" keys (overridable by settings)
|
276
|
+
{ 'Backspace' => '<BS>',
|
277
|
+
'Delete' => '<Del>',
|
278
|
+
'AcceptSelection' => '<CR>',
|
279
|
+
'AcceptSelectionSplit' => ['<C-CR>', '<C-s>'],
|
280
|
+
'AcceptSelectionTab' => '<C-t>',
|
281
|
+
'AcceptSelectionVSplit' => '<C-v>',
|
282
|
+
'ToggleFocus' => '<Tab>',
|
283
|
+
'Cancel' => ['<C-c>', '<Esc>'],
|
284
|
+
'SelectNext' => ['<C-n>', '<C-j>', '<Down>'],
|
285
|
+
'SelectPrev' => ['<C-p>', '<C-k>', '<Up>'],
|
286
|
+
'Clear' => '<C-u>',
|
287
|
+
'CursorLeft' => ['<Left>', '<C-h>'],
|
288
|
+
'CursorRight' => ['<Right>', '<C-l>'],
|
289
|
+
'CursorEnd' => '<C-e>',
|
290
|
+
'CursorStart' => '<C-a>' }.each do |key, value|
|
291
|
+
if override = get_list_or_string("g:CommandT#{key}Map")
|
292
|
+
[override].flatten.each do |mapping|
|
293
|
+
map mapping, key
|
294
|
+
end
|
295
|
+
else
|
296
|
+
[value].flatten.each do |mapping|
|
297
|
+
map mapping, key unless mapping == '<Esc>' && (xterm? || vt100?)
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
# Returns the desired maximum number of matches, based on available
|
304
|
+
# vertical space and the g:CommandTMaxHeight option.
|
305
|
+
def match_limit
|
306
|
+
limit = VIM::Screen.lines - 5
|
307
|
+
limit = 1 if limit < 0
|
308
|
+
limit = [limit, @max_height].min if @max_height > 0
|
309
|
+
limit
|
310
|
+
end
|
311
|
+
|
312
|
+
def list_matches
|
313
|
+
matches = @active_finder.sorted_matches_for @prompt.abbrev, :limit => match_limit
|
314
|
+
@match_window.matches = matches
|
315
|
+
end
|
316
|
+
end # class Controller
|
317
|
+
end # module commandT
|