command-t 1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,30 @@
|
|
1
|
+
// Copyright 2010 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
|
+
#include <ruby.h>
|
25
|
+
|
26
|
+
extern VALUE CommandTMatcher_initialize(int argc, VALUE *argv, VALUE self);
|
27
|
+
extern VALUE CommandTMatcher_sorted_matches_for(VALUE self, VALUE abbrev, VALUE options);
|
28
|
+
|
29
|
+
// most likely the function will be subsumed by the sorted_matcher_for function
|
30
|
+
extern VALUE CommandTMatcher_matches_for(VALUE self, VALUE abbrev);
|
@@ -0,0 +1,165 @@
|
|
1
|
+
# Copyright 2010 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
|
+
module CommandT
|
25
|
+
# Abuse the status line as a prompt.
|
26
|
+
class Prompt
|
27
|
+
attr_accessor :abbrev
|
28
|
+
|
29
|
+
def initialize
|
30
|
+
@abbrev = '' # abbreviation entered so far
|
31
|
+
@col = 0 # cursor position
|
32
|
+
@has_focus = false
|
33
|
+
end
|
34
|
+
|
35
|
+
# Erase whatever is displayed in the prompt line,
|
36
|
+
# effectively disposing of the prompt
|
37
|
+
def dispose
|
38
|
+
::VIM::command 'echo'
|
39
|
+
::VIM::command 'redraw'
|
40
|
+
end
|
41
|
+
|
42
|
+
# Clear any entered text.
|
43
|
+
def clear!
|
44
|
+
@abbrev = ''
|
45
|
+
@col = 0
|
46
|
+
redraw
|
47
|
+
end
|
48
|
+
|
49
|
+
# Insert a character at (before) the current cursor position.
|
50
|
+
def add! char
|
51
|
+
left, cursor, right = abbrev_segments
|
52
|
+
@abbrev = left + char + cursor + right
|
53
|
+
@col += 1
|
54
|
+
redraw
|
55
|
+
end
|
56
|
+
|
57
|
+
# Delete a character to the left of the current cursor position.
|
58
|
+
def backspace!
|
59
|
+
if @col > 0
|
60
|
+
left, cursor, right = abbrev_segments
|
61
|
+
@abbrev = left.chop! + cursor + right
|
62
|
+
@col -= 1
|
63
|
+
redraw
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Delete a character at the current cursor position.
|
68
|
+
def delete!
|
69
|
+
if @col < @abbrev.length
|
70
|
+
left, cursor, right = abbrev_segments
|
71
|
+
@abbrev = left + right
|
72
|
+
redraw
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def cursor_left
|
77
|
+
if @col > 0
|
78
|
+
@col -= 1
|
79
|
+
redraw
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def cursor_right
|
84
|
+
if @col < @abbrev.length
|
85
|
+
@col += 1
|
86
|
+
redraw
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def cursor_end
|
91
|
+
if @col < @abbrev.length
|
92
|
+
@col = @abbrev.length
|
93
|
+
redraw
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def cursor_start
|
98
|
+
if @col != 0
|
99
|
+
@col = 0
|
100
|
+
redraw
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def redraw
|
105
|
+
if @has_focus
|
106
|
+
prompt_highlight = 'Comment'
|
107
|
+
normal_highlight = 'None'
|
108
|
+
cursor_highlight = 'Underlined'
|
109
|
+
else
|
110
|
+
prompt_highlight = 'NonText'
|
111
|
+
normal_highlight = 'NonText'
|
112
|
+
cursor_highlight = 'NonText'
|
113
|
+
end
|
114
|
+
left, cursor, right = abbrev_segments
|
115
|
+
components = [prompt_highlight, '>>', 'None', ' ']
|
116
|
+
components += [normal_highlight, left] unless left.empty?
|
117
|
+
components += [cursor_highlight, cursor] unless cursor.empty?
|
118
|
+
components += [normal_highlight, right] unless right.empty?
|
119
|
+
components += [cursor_highlight, ' '] if cursor.empty?
|
120
|
+
set_status *components
|
121
|
+
end
|
122
|
+
|
123
|
+
def focus
|
124
|
+
unless @has_focus
|
125
|
+
@has_focus = true
|
126
|
+
redraw
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def unfocus
|
131
|
+
if @has_focus
|
132
|
+
@has_focus = false
|
133
|
+
redraw
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
private
|
138
|
+
|
139
|
+
# Returns the @abbrev string divided up into three sections, any of
|
140
|
+
# which may actually be zero width, depending on the location of the
|
141
|
+
# cursor:
|
142
|
+
# - left segment (to left of cursor)
|
143
|
+
# - cursor segment (character at cursor)
|
144
|
+
# - right segment (to right of cursor)
|
145
|
+
def abbrev_segments
|
146
|
+
left = @abbrev[0, @col]
|
147
|
+
cursor = @abbrev[@col, 1]
|
148
|
+
right = @abbrev[(@col + 1)..-1] || ''
|
149
|
+
[left, cursor, right]
|
150
|
+
end
|
151
|
+
|
152
|
+
def set_status *args
|
153
|
+
# see ':help :echo' for why forcing a redraw here helps
|
154
|
+
# prevent the status line from getting inadvertantly cleared
|
155
|
+
# after our echo commands
|
156
|
+
::VIM::command 'redraw'
|
157
|
+
while (highlight = args.shift) and (text = args.shift) do
|
158
|
+
text = VIM::escape_for_single_quotes text
|
159
|
+
::VIM::command "echohl #{highlight}"
|
160
|
+
::VIM::command "echon '#{text}'"
|
161
|
+
end
|
162
|
+
::VIM::command 'echohl None'
|
163
|
+
end
|
164
|
+
end # class Prompt
|
165
|
+
end # module CommandT
|
@@ -0,0 +1,49 @@
|
|
1
|
+
// Copyright 2010 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
|
+
#include <ruby.h>
|
25
|
+
|
26
|
+
// for compatibility with older versions of Ruby which don't declare RSTRING_PTR
|
27
|
+
#ifndef RSTRING_PTR
|
28
|
+
#define RSTRING_PTR(s) (RSTRING(s)->ptr)
|
29
|
+
#endif
|
30
|
+
|
31
|
+
// for compatibility with older versions of Ruby which don't declare RSTRING_LEN
|
32
|
+
#ifndef RSTRING_LEN
|
33
|
+
#define RSTRING_LEN(s) (RSTRING(s)->len)
|
34
|
+
#endif
|
35
|
+
|
36
|
+
// for compatibility with older versions of Ruby which don't declare RARRAY_PTR
|
37
|
+
#ifndef RARRAY_PTR
|
38
|
+
#define RARRAY_PTR(a) (RARRAY(a)->ptr)
|
39
|
+
#endif
|
40
|
+
|
41
|
+
// for compatibility with older versions of Ruby which don't declare RARRAY_LEN
|
42
|
+
#ifndef RARRAY_LEN
|
43
|
+
#define RARRAY_LEN(a) (RARRAY(a)->len)
|
44
|
+
#endif
|
45
|
+
|
46
|
+
// for compatibility with older versions of Ruby which don't declare RFLOAT_VALUE
|
47
|
+
#ifndef RFLOAT_VALUE
|
48
|
+
#define RFLOAT_VALUE(f) (RFLOAT(f)->value)
|
49
|
+
#endif
|
@@ -0,0 +1,28 @@
|
|
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/vim'
|
25
|
+
|
26
|
+
module CommandT
|
27
|
+
class Scanner; end
|
28
|
+
end # module CommandT
|
@@ -0,0 +1,42 @@
|
|
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/vim'
|
25
|
+
require 'command-t/vim/path_utilities'
|
26
|
+
require 'command-t/scanner'
|
27
|
+
|
28
|
+
module CommandT
|
29
|
+
# Returns a list of all open buffers.
|
30
|
+
class BufferScanner < Scanner
|
31
|
+
include VIM::PathUtilities
|
32
|
+
|
33
|
+
def paths
|
34
|
+
(0..(::VIM::Buffer.count - 1)).map do |n|
|
35
|
+
buffer = ::VIM::Buffer[n]
|
36
|
+
if buffer.name # beware, may be nil
|
37
|
+
relative_path_under_working_directory buffer.name
|
38
|
+
end
|
39
|
+
end.compact
|
40
|
+
end
|
41
|
+
end # class BufferScanner
|
42
|
+
end # module CommandT
|
@@ -0,0 +1,94 @@
|
|
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/vim'
|
25
|
+
require 'command-t/scanner'
|
26
|
+
|
27
|
+
module CommandT
|
28
|
+
# Reads the current directory recursively for the paths to all regular files.
|
29
|
+
class FileScanner < Scanner
|
30
|
+
class FileLimitExceeded < ::RuntimeError; end
|
31
|
+
|
32
|
+
def initialize path = Dir.pwd, options = {}
|
33
|
+
@path = path
|
34
|
+
@max_depth = options[:max_depth] || 15
|
35
|
+
@max_files = options[:max_files] || 10_000
|
36
|
+
@scan_dot_directories = options[:scan_dot_directories] || false
|
37
|
+
end
|
38
|
+
|
39
|
+
def paths
|
40
|
+
return @paths unless @paths.nil?
|
41
|
+
begin
|
42
|
+
@paths = []
|
43
|
+
@depth = 0
|
44
|
+
@files = 0
|
45
|
+
@prefix_len = @path.chomp('/').length
|
46
|
+
add_paths_for_directory @path, @paths
|
47
|
+
rescue FileLimitExceeded
|
48
|
+
end
|
49
|
+
@paths
|
50
|
+
end
|
51
|
+
|
52
|
+
def flush
|
53
|
+
@paths = nil
|
54
|
+
end
|
55
|
+
|
56
|
+
def path= str
|
57
|
+
if @path != str
|
58
|
+
@path = str
|
59
|
+
flush
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def path_excluded? path
|
66
|
+
# first strip common prefix (@path) from path to match VIM's behavior
|
67
|
+
path = path[(@prefix_len + 1)..-1]
|
68
|
+
path = VIM::escape_for_single_quotes path
|
69
|
+
::VIM::evaluate("empty(expand(fnameescape('#{path}')))").to_i == 1
|
70
|
+
end
|
71
|
+
|
72
|
+
def add_paths_for_directory dir, accumulator
|
73
|
+
Dir.foreach(dir) do |entry|
|
74
|
+
next if ['.', '..'].include?(entry)
|
75
|
+
path = File.join(dir, entry)
|
76
|
+
unless path_excluded?(path)
|
77
|
+
if File.file?(path)
|
78
|
+
@files += 1
|
79
|
+
raise FileLimitExceeded if @files > @max_files
|
80
|
+
accumulator << path[@prefix_len + 1..-1]
|
81
|
+
elsif File.directory?(path)
|
82
|
+
next if @depth >= @max_depth
|
83
|
+
next if (entry.match(/\A\./) && !@scan_dot_directories)
|
84
|
+
@depth += 1
|
85
|
+
add_paths_for_directory path, accumulator
|
86
|
+
@depth -= 1
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
rescue Errno::EACCES
|
91
|
+
# skip over directories for which we don't have access
|
92
|
+
end
|
93
|
+
end # class FileScanner
|
94
|
+
end # module CommandT
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# Copyright 2010 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
|
+
module CommandT
|
25
|
+
# Convenience class for saving and restoring global settings.
|
26
|
+
class Settings
|
27
|
+
def initialize
|
28
|
+
save
|
29
|
+
end
|
30
|
+
|
31
|
+
def save
|
32
|
+
@timeoutlen = get_number 'timeoutlen'
|
33
|
+
@report = get_number 'report'
|
34
|
+
@sidescroll = get_number 'sidescroll'
|
35
|
+
@sidescrolloff = get_number 'sidescrolloff'
|
36
|
+
@timeout = get_bool 'timeout'
|
37
|
+
@equalalways = get_bool 'equalalways'
|
38
|
+
@hlsearch = get_bool 'hlsearch'
|
39
|
+
@insertmode = get_bool 'insertmode'
|
40
|
+
@showcmd = get_bool 'showcmd'
|
41
|
+
end
|
42
|
+
|
43
|
+
def restore
|
44
|
+
set_number 'timeoutlen', @timeoutlen
|
45
|
+
set_number 'report', @report
|
46
|
+
set_number 'sidescroll', @sidescroll
|
47
|
+
set_number 'sidescrolloff', @sidescrolloff
|
48
|
+
set_bool 'timeout', @timeout
|
49
|
+
set_bool 'equalalways', @equalalways
|
50
|
+
set_bool 'hlsearch', @hlsearch
|
51
|
+
set_bool 'insertmode', @insertmode
|
52
|
+
set_bool 'showcmd', @showcmd
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def get_number setting
|
58
|
+
::VIM::evaluate("&#{setting}").to_i
|
59
|
+
end
|
60
|
+
|
61
|
+
def get_bool setting
|
62
|
+
::VIM::evaluate("&#{setting}").to_i == 1
|
63
|
+
end
|
64
|
+
|
65
|
+
def set_number setting, value
|
66
|
+
::VIM::set_option "#{setting}=#{value}"
|
67
|
+
end
|
68
|
+
|
69
|
+
def set_bool setting, value
|
70
|
+
if value
|
71
|
+
::VIM::set_option setting
|
72
|
+
else
|
73
|
+
::VIM::set_option "no#{setting}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end # class Settings
|
77
|
+
end # module CommandT
|