command-t 1.11 → 1.11.1

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.
@@ -7,34 +7,27 @@ module CommandT
7
7
  class FileScanner
8
8
  # Uses git ls-files to scan for files
9
9
  class GitFileScanner < FindFileScanner
10
- def paths
11
- @paths[@path] ||= begin
12
- Dir.chdir(@path) do
13
- set_wild_ignore(@wild_ignore)
14
- prepare_paths
10
+ def paths!
11
+ Dir.chdir(@path) do
12
+ stdin, stdout, stderr = Open3.popen3(*[
13
+ 'git',
14
+ 'ls-files',
15
+ '--exclude-standard',
16
+ @path
17
+ ])
15
18
 
16
- stdin, stdout, stderr = Open3.popen3(*[
17
- 'git',
18
- 'ls-files',
19
- '--exclude-standard',
20
- @path
21
- ])
19
+ all_files = stdout.readlines.
20
+ map { |path| path.chomp }.
21
+ reject { |path| path_excluded?(path, 0) }.
22
+ take(@max_files).
23
+ to_a
22
24
 
23
- all_files = stdout.readlines.
24
- map { |path| path.chomp }.
25
- reject { |path| path_excluded?(path, 0) }.
26
- take(@max_files).
27
- to_a
28
-
29
- # will fall back to find if not a git repository or there's an error
30
- stderr.gets ? super : all_files
31
- end
32
- rescue Errno::ENOENT => e
33
- # git executable not present and executable
34
- super
35
- ensure
36
- set_wild_ignore(@base_wild_ignore)
25
+ # will fall back to find if not a git repository or there's an error
26
+ stderr.gets ? super : all_files
37
27
  end
28
+ rescue Errno::ENOENT => e
29
+ # git executable not present and executable
30
+ super
38
31
  end
39
32
  end # class GitFileScanner
40
33
  end # class FileScanner
@@ -1,37 +1,32 @@
1
1
  # Copyright 2010-2014 Greg Hurrell. All rights reserved.
2
2
  # Licensed under the terms of the BSD 2-clause license.
3
3
 
4
- require 'command-t/vim'
5
4
  require 'command-t/scanner/file_scanner'
6
5
 
7
6
  module CommandT
8
7
  class FileScanner
9
8
  # Pure Ruby implementation of a file scanner.
10
9
  class RubyFileScanner < FileScanner
11
- def paths
12
- super || begin
13
- @paths[@path] = []
14
- @depth = 0
15
- @files = 0
16
- set_wild_ignore(@wild_ignore)
17
- add_paths_for_directory @path, @paths[@path]
18
- rescue FileLimitExceeded
19
- ensure
20
- set_wild_ignore(@base_wild_ignore)
21
- end
22
- @paths[@path]
10
+ def paths!
11
+ accumulator = []
12
+ @depth = 0
13
+ @files = 0
14
+ add_paths_for_directory(@path, accumulator)
15
+ accumulator
16
+ rescue FileLimitExceeded
17
+ accumulator
23
18
  end
24
19
 
25
20
  private
26
21
 
27
- def looped_symlink? path
22
+ def looped_symlink?(path)
28
23
  if File.symlink?(path)
29
24
  target = File.expand_path(File.readlink(path), File.dirname(path))
30
25
  target.include?(@path) || @path.include?(target)
31
26
  end
32
27
  end
33
28
 
34
- def add_paths_for_directory dir, accumulator
29
+ def add_paths_for_directory(dir, accumulator)
35
30
  Dir.foreach(dir) do |entry|
36
31
  next if ['.', '..'].include?(entry)
37
32
  path = File.join(dir, entry)
@@ -39,13 +34,13 @@ module CommandT
39
34
  if File.file?(path)
40
35
  @files += 1
41
36
  raise FileLimitExceeded if @files > @max_files
42
- accumulator << path[@prefix_len + 1..-1]
37
+ accumulator << path[@prefix_len..-1]
43
38
  elsif File.directory?(path)
44
39
  next if @depth >= @max_depth
45
40
  next if (entry.match(/\A\./) && !@scan_dot_directories)
46
41
  next if looped_symlink?(path)
47
42
  @depth += 1
48
- add_paths_for_directory path, accumulator
43
+ add_paths_for_directory(path, accumulator)
49
44
  @depth -= 1
50
45
  end
51
46
  end
@@ -3,7 +3,6 @@
3
3
 
4
4
  require 'pathname'
5
5
  require 'socket'
6
- require 'command-t/vim'
7
6
  require 'command-t/vim/path_utilities'
8
7
  require 'command-t/scanner/file_scanner'
9
8
  require 'command-t/scanner/file_scanner/find_file_scanner'
@@ -20,43 +19,38 @@ module CommandT
20
19
  # requested path.
21
20
  class WatchmanUnavailable < RuntimeError; end
22
21
 
23
- def paths
24
- @paths[@path] ||= begin
25
- prepare_paths
26
- sockname = Watchman::Utils.load(
27
- %x{watchman --output-encoding=bser get-sockname}
28
- )['sockname']
29
- raise WatchmanUnavailable unless $?.exitstatus.zero?
30
-
31
- UNIXSocket.open(sockname) do |socket|
32
- root = Pathname.new(@path).realpath.to_s
33
- roots = Watchman::Utils.query(['watch-list'], socket)['roots']
34
- if !roots.include?(root)
35
- # this path isn't being watched yet; try to set up watch
36
- result = Watchman::Utils.query(['watch', root], socket)
37
-
38
- # root_restrict_files setting may prevent Watchman from working
39
- raise WatchmanUnavailable if result.has_key?('error')
40
- end
41
-
42
- query = ['query', root, {
43
- 'expression' => ['type', 'f'],
44
- 'fields' => ['name'],
45
- }]
46
- paths = Watchman::Utils.query(query, socket)
47
-
48
- # could return error if watch is removed
49
- raise WatchmanUnavailable if paths.has_key?('error')
50
-
51
- @paths[@path] = paths['files']
22
+ def paths!
23
+ sockname = Watchman::Utils.load(
24
+ %x{watchman --output-encoding=bser get-sockname}
25
+ )['sockname']
26
+ raise WatchmanUnavailable unless $?.exitstatus.zero?
27
+
28
+ UNIXSocket.open(sockname) do |socket|
29
+ root = Pathname.new(@path).realpath.to_s
30
+ roots = Watchman::Utils.query(['watch-list'], socket)['roots']
31
+ if !roots.include?(root)
32
+ # this path isn't being watched yet; try to set up watch
33
+ result = Watchman::Utils.query(['watch', root], socket)
34
+
35
+ # root_restrict_files setting may prevent Watchman from working
36
+ raise WatchmanUnavailable if result.has_key?('error')
52
37
  end
53
- end
54
38
 
55
- @paths[@path]
56
- rescue Errno::ENOENT, WatchmanUnavailable
57
- # watchman executable not present, or unable to fulfil request
58
- super
39
+ query = ['query', root, {
40
+ 'expression' => ['type', 'f'],
41
+ 'fields' => ['name'],
42
+ }]
43
+ paths = Watchman::Utils.query(query, socket)
44
+
45
+ # could return error if watch is removed
46
+ raise WatchmanUnavailable if paths.has_key?('error')
47
+
48
+ paths['files']
49
+ end
59
50
  end
51
+ rescue Errno::ENOENT, WatchmanUnavailable
52
+ # watchman executable not present, or unable to fulfil request
53
+ super
60
54
  end # class WatchmanFileScanner
61
55
  end # class FileScanner
62
56
  end # module CommandT
@@ -1,7 +1,6 @@
1
1
  # Copyright 2011-2014 Greg Hurrell. All rights reserved.
2
2
  # Licensed under the terms of the BSD 2-clause license.
3
3
 
4
- require 'command-t/vim'
5
4
  require 'command-t/vim/path_utilities'
6
5
  require 'command-t/scanner'
7
6
 
@@ -23,7 +22,7 @@ module CommandT
23
22
 
24
23
  private
25
24
 
26
- def line_contains_filename? line
25
+ def line_contains_filename?(line)
27
26
  line.split.count > 3
28
27
  end
29
28
 
@@ -1,14 +1,13 @@
1
1
  # Copyright 2011-2014 Greg Hurrell. All rights reserved.
2
2
  # Licensed under the terms of the BSD 2-clause license.
3
3
 
4
- require 'command-t/vim'
5
4
  require 'command-t/scanner'
6
5
 
7
6
  module CommandT
8
7
  class TagScanner < Scanner
9
8
  attr_reader :include_filenames
10
9
 
11
- def initialize options = {}
10
+ def initialize(options = {})
12
11
  @include_filenames = options[:include_filenames] || false
13
12
  @cached_tags = nil
14
13
  end
@@ -1,6 +1,8 @@
1
1
  # Copyright 2010-2014 Greg Hurrell. All rights reserved.
2
2
  # Licensed under the terms of the BSD 2-clause license.
3
3
 
4
+ require 'command-t/vim'
5
+
4
6
  module CommandT
5
7
  # Convenience class for saving and restoring global settings.
6
8
  class Settings
@@ -52,13 +54,13 @@ module CommandT
52
54
 
53
55
  case value
54
56
  when TrueClass, FalseClass
55
- @settings.push([setting, get_bool(setting)]) if global?(setting)
57
+ @settings.push([setting, VIM::get_bool("&#{setting}")]) if global?(setting)
56
58
  set_bool setting, value
57
59
  when Numeric
58
- @settings.push([setting, get_number(setting)]) if global?(setting)
60
+ @settings.push([setting, VIM::get_number("&#{setting}")]) if global?(setting)
59
61
  set_number setting, value
60
62
  when String
61
- @settings.push([setting, get_string(setting)]) if global?(setting)
63
+ @settings.push([setting, VIM::get_string("&#{setting}")]) if global?(setting)
62
64
  set_string setting, value
63
65
  end
64
66
  end
@@ -82,18 +84,6 @@ module CommandT
82
84
  GLOBAL_SETTINGS.include?(setting)
83
85
  end
84
86
 
85
- def get_bool(setting)
86
- ::VIM::evaluate("&#{setting}").to_i == 1
87
- end
88
-
89
- def get_number(setting)
90
- ::VIM::evaluate("&#{setting}").to_i
91
- end
92
-
93
- def get_string(name)
94
- ::VIM::evaluate("&#{name}").to_s
95
- end
96
-
97
87
  def set_bool(setting, value)
98
88
  command = global?(setting) ? 'set' : 'setlocal'
99
89
  setting = value ? setting : "no#{setting}"
@@ -3,9 +3,10 @@
3
3
 
4
4
  module CommandT
5
5
  class Stub
6
+ @@patch_level = defined?(RUBY_PATCHLEVEL) ? RUBY_PATCHLEVEL : '[unknown]'
6
7
  @@load_error = ['command-t.vim could not load the C extension',
7
8
  'Please see INSTALLATION and TROUBLE-SHOOTING in the help',
8
- "Vim Ruby version: #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}",
9
+ "Vim Ruby version: #{RUBY_VERSION}-p#{@@patch_level}",
9
10
  'For more information type: :help command-t']
10
11
 
11
12
  [
@@ -21,7 +22,7 @@ module CommandT
21
22
 
22
23
  private
23
24
 
24
- def warn *msg
25
+ def warn(*msg)
25
26
  ::VIM::command 'echohl WarningMsg'
26
27
  msg.each { |m| ::VIM::command "echo '#{m}'" }
27
28
  ::VIM::command 'echohl none'
@@ -6,42 +6,66 @@ require 'command-t/vim/window'
6
6
 
7
7
  module CommandT
8
8
  module VIM
9
- def self.has_syntax?
10
- ::VIM::evaluate('has("syntax")').to_i != 0
11
- end
9
+ class << self
10
+ # Check for the existence of a feature such as "conceal" or "syntax".
11
+ def has?(feature)
12
+ ::VIM::evaluate(%{has("#{feature}")}).to_i != 0
13
+ end
12
14
 
13
- def self.exists? str
14
- ::VIM::evaluate(%{exists("#{str}")}).to_i != 0
15
- end
15
+ # Check for the presence of a setting such as:
16
+ #
17
+ # - g:CommandTSmartCase (plug-in setting)
18
+ # - &wildignore (Vim setting)
19
+ # - +cursorcolumn (Vim setting, that works)
20
+ #
21
+ def exists?(str)
22
+ ::VIM::evaluate(%{exists("#{str}")}).to_i != 0
23
+ end
16
24
 
17
- def self.has_conceal?
18
- ::VIM::evaluate('has("conceal")').to_i != 0
19
- end
25
+ def get_number(name)
26
+ exists?(name) ? ::VIM::evaluate("#{name}").to_i : nil
27
+ end
20
28
 
21
- def self.pwd
22
- ::VIM::evaluate 'getcwd()'
23
- end
29
+ def get_bool(name)
30
+ exists?(name) ? ::VIM::evaluate("#{name}").to_i != 0 : nil
31
+ end
24
32
 
25
- def self.wild_ignore
26
- exists?('&wildignore') && ::VIM::evaluate('&wildignore').to_s
27
- end
33
+ def get_string(name)
34
+ exists?(name) ? ::VIM::evaluate("#{name}").to_s : nil
35
+ end
28
36
 
29
- def self.current_file_dir
30
- ::VIM::evaluate 'expand("%:p:h")'
31
- end
37
+ # expect a string or a list of strings
38
+ def get_list_or_string(name)
39
+ return nil unless exists?(name)
40
+ list_or_string = ::VIM::evaluate("#{name}")
41
+ if list_or_string.kind_of?(Array)
42
+ list_or_string.map { |item| item.to_s }
43
+ else
44
+ list_or_string.to_s
45
+ end
46
+ end
32
47
 
33
- # Execute cmd, capturing the output into a variable and returning it.
34
- def self.capture cmd
35
- ::VIM::command 'silent redir => g:command_t_captured_output'
36
- ::VIM::command cmd
37
- ::VIM::command 'silent redir END'
38
- ::VIM::evaluate 'g:command_t_captured_output'
39
- end
48
+ def pwd
49
+ ::VIM::evaluate 'getcwd()'
50
+ end
51
+
52
+ def current_file_dir
53
+ ::VIM::evaluate 'expand("%:p:h")'
54
+ end
55
+
56
+ # Execute cmd, capturing the output into a variable and returning it.
57
+ def capture(cmd)
58
+ ::VIM::command 'silent redir => g:command_t_captured_output'
59
+ ::VIM::command cmd
60
+ ::VIM::command 'silent redir END'
61
+ ::VIM::evaluate 'g:command_t_captured_output'
62
+ end
40
63
 
41
- # Escape a string for safe inclusion in a Vim single-quoted string
42
- # (single quotes escaped by doubling, everything else is literal)
43
- def self.escape_for_single_quotes str
44
- str.gsub "'", "''"
64
+ # Escape a string for safe inclusion in a Vim single-quoted string
65
+ # (single quotes escaped by doubling, everything else is literal)
66
+ def escape_for_single_quotes(str)
67
+ str.gsub "'", "''"
68
+ end
45
69
  end
46
70
  end # module VIM
47
71
  end # module CommandT
@@ -9,7 +9,7 @@ module CommandT
9
9
 
10
10
  private
11
11
 
12
- def relative_path_under_working_directory path
12
+ def relative_path_under_working_directory(path)
13
13
  # any path under the working directory will be specified as a relative
14
14
  # path to improve the readability of the buffer list etc
15
15
  pwd = File.expand_path(VIM::pwd) + '/'
@@ -4,8 +4,10 @@
4
4
  module CommandT
5
5
  module VIM
6
6
  module Screen
7
- def self.lines
8
- ::VIM::evaluate('&lines').to_i
7
+ class << self
8
+ def lines
9
+ ::VIM::evaluate('&lines').to_i
10
+ end
9
11
  end
10
12
  end # module Screen
11
13
  end # module VIM
@@ -3,16 +3,18 @@
3
3
 
4
4
  module CommandT
5
5
  module VIM
6
- class Window
7
- def self.select window
8
- return true if $curwin == window
9
- initial = $curwin
10
- while true do
11
- ::VIM::command 'wincmd w' # cycle through windows
12
- return true if $curwin == window # have selected desired window
13
- return false if $curwin == initial # have already looped through all
6
+ module Window
7
+ class << self
8
+ def select(window)
9
+ return true if $curwin == window
10
+ initial = $curwin
11
+ while true do
12
+ ::VIM::command 'wincmd w' # cycle through windows
13
+ return true if $curwin == window # have selected desired window
14
+ return false if $curwin == initial # have already looped through all
15
+ end
14
16
  end
15
17
  end
16
- end # class Window
18
+ end # module Window
17
19
  end # module VIM
18
20
  end # module CommandT