command-t 1.13 → 2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.txt +209 -67
  4. data/Rakefile +47 -57
  5. data/doc/command-t.txt +209 -67
  6. data/doc/tags +9 -0
  7. data/plugin/command-t.vim +22 -13
  8. data/ruby/command-t.rb +7 -2
  9. data/ruby/command-t/Makefile +32 -32
  10. data/ruby/command-t/controller.rb +33 -25
  11. data/ruby/command-t/depend +1 -1
  12. data/ruby/command-t/ext.bundle +0 -0
  13. data/ruby/command-t/ext.c +1 -1
  14. data/ruby/command-t/ext.h +1 -1
  15. data/ruby/command-t/extconf.rb +1 -1
  16. data/ruby/command-t/finder.rb +7 -1
  17. data/ruby/command-t/finder/buffer_finder.rb +5 -1
  18. data/ruby/command-t/finder/file_finder.rb +5 -1
  19. data/ruby/command-t/finder/jump_finder.rb +5 -1
  20. data/ruby/command-t/finder/mru_buffer_finder.rb +5 -1
  21. data/ruby/command-t/finder/tag_finder.rb +5 -1
  22. data/ruby/command-t/match.c +5 -2
  23. data/ruby/command-t/match.h +2 -1
  24. data/ruby/command-t/match_window.rb +36 -21
  25. data/ruby/command-t/matcher.c +12 -2
  26. data/ruby/command-t/matcher.h +1 -1
  27. data/ruby/command-t/metadata/fallback.rb +12 -0
  28. data/ruby/command-t/mru.rb +1 -1
  29. data/ruby/command-t/path_utilities.rb +1 -1
  30. data/ruby/command-t/prompt.rb +7 -6
  31. data/ruby/command-t/ruby_compat.h +1 -1
  32. data/ruby/command-t/scanner.rb +1 -1
  33. data/ruby/command-t/scanner/buffer_scanner.rb +1 -1
  34. data/ruby/command-t/scanner/file_scanner.rb +1 -4
  35. data/ruby/command-t/scanner/file_scanner/find_file_scanner.rb +1 -1
  36. data/ruby/command-t/scanner/file_scanner/git_file_scanner.rb +1 -1
  37. data/ruby/command-t/scanner/file_scanner/ruby_file_scanner.rb +3 -1
  38. data/ruby/command-t/scanner/file_scanner/watchman_file_scanner.rb +1 -1
  39. data/ruby/command-t/scanner/jump_scanner.rb +1 -1
  40. data/ruby/command-t/scanner/mru_buffer_scanner.rb +1 -1
  41. data/ruby/command-t/scanner/tag_scanner.rb +1 -1
  42. data/ruby/command-t/scm_utilities.rb +1 -1
  43. data/ruby/command-t/settings.rb +2 -1
  44. data/ruby/command-t/stub.rb +1 -1
  45. data/ruby/command-t/util.rb +1 -1
  46. data/ruby/command-t/vim.rb +3 -3
  47. data/ruby/command-t/vim/screen.rb +1 -1
  48. data/ruby/command-t/vim/window.rb +1 -1
  49. data/ruby/command-t/watchman.c +1 -1
  50. data/ruby/command-t/watchman.h +1 -1
  51. metadata +3 -4
  52. data/ruby/command-t/metadata.rb +0 -8
  53. data/ruby/command-t/scanner/file_scanner/file_limit_exceeded.rb +0 -10
@@ -1,4 +1,4 @@
1
- # Copyright 2010-2014 Greg Hurrell. All rights reserved.
1
+ # Copyright 2010-present Greg Hurrell. All rights reserved.
2
2
  # Licensed under the terms of the BSD 2-clause license.
3
3
 
4
4
  module CommandT
@@ -24,6 +24,10 @@ module CommandT
24
24
  def flush
25
25
  @scanner.flush
26
26
  end
27
+
28
+ def name
29
+ 'Files'
30
+ end
27
31
  end # class FileFinder
28
32
  end # class Finder
29
33
  end # module CommandT
@@ -1,4 +1,4 @@
1
- # Copyright 2011-2014 Greg Hurrell. All rights reserved.
1
+ # Copyright 2011-present Greg Hurrell. All rights reserved.
2
2
  # Licensed under the terms of the BSD 2-clause license.
3
3
 
4
4
  module CommandT
@@ -8,6 +8,10 @@ module CommandT
8
8
  @scanner = Scanner::JumpScanner.new
9
9
  @matcher = Matcher.new @scanner, :always_show_dot_files => true
10
10
  end
11
+
12
+ def name
13
+ 'Jumps'
14
+ end
11
15
  end # class JumpFinder
12
16
  end # class Finder
13
17
  end # module CommandT
@@ -1,4 +1,4 @@
1
- # Copyright 2014 Greg Hurrell. All rights reserved.
1
+ # Copyright 2014-present Greg Hurrell. All rights reserved.
2
2
  # Licensed under the terms of the BSD 2-clause license.
3
3
 
4
4
  module CommandT
@@ -23,6 +23,10 @@ module CommandT
23
23
  matches
24
24
  end
25
25
  end
26
+
27
+ def name
28
+ 'Recent'
29
+ end
26
30
  end # class MRUBufferFinder
27
31
  end # class Finder
28
32
  end # CommandT
@@ -1,4 +1,4 @@
1
- # Copyright 2011-2014 Greg Hurrell. All rights reserved.
1
+ # Copyright 2011-present Greg Hurrell. All rights reserved.
2
2
  # Licensed under the terms of the BSD 2-clause license.
3
3
 
4
4
  module CommandT
@@ -21,6 +21,10 @@ module CommandT
21
21
  def flush
22
22
  @scanner.flush
23
23
  end
24
+
25
+ def name
26
+ 'Tags'
27
+ end
24
28
  end # class TagFinder
25
29
  end # class Finder
26
30
  end # module CommandT
@@ -1,4 +1,4 @@
1
- // Copyright 2010-2014 Greg Hurrell. All rights reserved.
1
+ // Copyright 2010-present Greg Hurrell. All rights reserved.
2
2
  // Licensed under the terms of the BSD 2-clause license.
3
3
 
4
4
  #include <float.h> /* for DBL_MAX */
@@ -16,6 +16,7 @@ typedef struct {
16
16
  int always_show_dot_files; // boolean
17
17
  int never_show_dot_files; // boolean
18
18
  int case_sensitive; // boolean
19
+ int recurse; // boolean
19
20
  double *memo; // memoization
20
21
  } matchinfo_t;
21
22
 
@@ -94,7 +95,7 @@ double recursive_match(matchinfo_t *m, // sharable meta-data
94
95
  score_for_char *= factor;
95
96
  }
96
97
 
97
- if (++j < m->haystack_len) {
98
+ if (++j < m->haystack_len && m->recurse) {
98
99
  // bump cursor one char to the right and
99
100
  // use recursion to try and find a better match
100
101
  double sub_score = recursive_match(m, j, i, last_idx, score);
@@ -125,6 +126,7 @@ void calculate_match(VALUE str,
125
126
  VALUE case_sensitive,
126
127
  VALUE always_show_dot_files,
127
128
  VALUE never_show_dot_files,
129
+ VALUE recurse,
128
130
  match_t *out)
129
131
  {
130
132
  long i, max;
@@ -138,6 +140,7 @@ void calculate_match(VALUE str,
138
140
  m.always_show_dot_files = always_show_dot_files == Qtrue;
139
141
  m.never_show_dot_files = never_show_dot_files == Qtrue;
140
142
  m.case_sensitive = case_sensitive;
143
+ m.recurse = recurse == Qtrue;
141
144
 
142
145
  // calculate score
143
146
  score = 1.0;
@@ -1,4 +1,4 @@
1
- // Copyright 2010-2014 Greg Hurrell. All rights reserved.
1
+ // Copyright 2010-present Greg Hurrell. All rights reserved.
2
2
  // Licensed under the terms of the BSD 2-clause license.
3
3
 
4
4
  #include <ruby.h>
@@ -14,4 +14,5 @@ extern void calculate_match(VALUE str,
14
14
  VALUE case_sensitive,
15
15
  VALUE always_show_dot_files,
16
16
  VALUE never_show_dot_files,
17
+ VALUE recurse,
17
18
  match_t *out);
@@ -1,4 +1,4 @@
1
- # Copyright 2010-2015 Greg Hurrell. All rights reserved.
1
+ # Copyright 2010-present Greg Hurrell. All rights reserved.
2
2
  # Licensed under the terms of the BSD 2-clause license.
3
3
 
4
4
  require 'ostruct'
@@ -20,6 +20,9 @@ module CommandT
20
20
  @prompt = options[:prompt]
21
21
  @reverse_list = options[:match_window_reverse]
22
22
 
23
+ quoted_name = VIM::escape_for_single_quotes(options[:name])
24
+ escaped_name = ::VIM::evaluate("fnameescape('#{quoted_name}')")
25
+
23
26
  # save existing window dimensions so we can restore them later
24
27
  @windows = (0..(::VIM::Window.count - 1)).map do |i|
25
28
  OpenStruct.new(
@@ -43,26 +46,31 @@ module CommandT
43
46
 
44
47
  # show match window
45
48
  split_location = options[:match_window_at_top] ? 'topleft' : 'botright'
46
- if @@buffer # still have buffer from last time
47
- ::VIM::command "silent! #{split_location} #{@@buffer.number}sbuffer"
48
- raise "Can't re-open GoToFile buffer" unless $curbuf.number == @@buffer.number
49
+ if ((number = buffer_number)) # still have buffer from last time
50
+ ::VIM::command "silent! #{split_location} #{number}sbuffer"
51
+ if $curbuf.number != number
52
+ raise "Can't re-open Command-T match listing buffer"
53
+ end
49
54
  $curwin.height = 1
55
+ ::VIM::command "0file"
56
+ ::VIM::command "keepalt file #{escaped_name}"
50
57
  else # creating match window for first time and set it up
51
- ::VIM::command "silent! #{split_location} 1split GoToFile"
52
- set 'bufhidden', 'unload' # unload buf when no longer displayed
53
- set 'buftype', 'nofile' # buffer is not related to any file
54
- set 'modifiable', false # prevent manual edits
55
- set 'readonly', false # avoid W10 "Changing a readonly file"
56
- set 'swapfile', false # don't create a swapfile
57
- set 'wrap', false # don't soft-wrap
58
- set 'number', false # don't show line numbers
59
- set 'list', false # don't use List mode (visible tabs etc)
60
- set 'foldcolumn', 0 # don't show a fold column at side
61
- set 'foldlevel', 99 # don't fold anything
62
- set 'cursorline', false # don't highlight line cursor is on
63
- set 'spell', false # spell-checking off
64
- set 'buflisted', false # don't show up in the buffer list
65
- set 'textwidth', 0 # don't hard-wrap (break long lines)
58
+ ::VIM::command "silent! keepalt #{split_location} 1split #{escaped_name}"
59
+ set 'bufhidden', 'unload' # unload buf when no longer displayed
60
+ set 'buftype', 'nofile' # buffer is not related to any file
61
+ set 'filetype', 'command-t' # provide for detectability/extensibility
62
+ set 'modifiable', false # prevent manual edits
63
+ set 'readonly', false # avoid W10 "Changing a readonly file"
64
+ set 'swapfile', false # don't create a swapfile
65
+ set 'wrap', false # don't soft-wrap
66
+ set 'number', false # don't show line numbers
67
+ set 'list', false # don't use List mode (visible tabs etc)
68
+ set 'foldcolumn', 0 # don't show a fold column at side
69
+ set 'foldlevel', 99 # don't fold anything
70
+ set 'cursorline', false # don't highlight line cursor is on
71
+ set 'spell', false # spell-checking off
72
+ set 'buflisted', false # don't show up in the buffer list
73
+ set 'textwidth', 0 # don't hard-wrap (break long lines)
66
74
 
67
75
  # don't show the color column
68
76
  set 'colorcolumn', 0 if VIM::exists?('+colorcolumn')
@@ -71,7 +79,9 @@ module CommandT
71
79
  set 'relativenumber', false if VIM::exists?('+relativenumber')
72
80
 
73
81
  # sanity check: make sure the buffer really was created
74
- raise "Can't find GoToFile buffer" unless $curbuf.name.match /GoToFile\z/
82
+ if File.basename($curbuf.name) != options[:name]
83
+ raise "Can't find Command-T match listing buffer"
84
+ end
75
85
  @@buffer = $curbuf
76
86
  end
77
87
 
@@ -117,6 +127,9 @@ module CommandT
117
127
 
118
128
  def buffer_number
119
129
  @@buffer && @@buffer.number
130
+ rescue Vim::DeletedBufferError
131
+ # Beware of people manually deleting Command-T's hidden, unlisted buffer.
132
+ @@buffer = nil
120
133
  end
121
134
 
122
135
  def close
@@ -140,7 +153,9 @@ module CommandT
140
153
  # For more details, see: https://wincent.com/issues/1617
141
154
  if $curbuf.number == 0
142
155
  # use bwipeout as bunload fails if passed the name of a hidden buffer
143
- ::VIM::command 'silent! bwipeout! GoToFile'
156
+ base = File.basename($curbuf.name)
157
+ escaped_name = ::VIM::evaluate("fnameescape('#{base}')")
158
+ ::VIM::command "silent! bwipeout! #{escaped_name}"
144
159
  @@buffer = nil
145
160
  else
146
161
  ::VIM::command "silent! bunload! #{@@buffer.number}"
@@ -1,4 +1,4 @@
1
- // Copyright 2010-2014 Greg Hurrell. All rights reserved.
1
+ // Copyright 2010-present Greg Hurrell. All rights reserved.
2
2
  // Licensed under the terms of the BSD 2-clause license.
3
3
 
4
4
  #include <stdlib.h> /* for qsort() */
@@ -90,6 +90,7 @@ typedef struct {
90
90
  VALUE abbrev;
91
91
  VALUE always_show_dot_files;
92
92
  VALUE never_show_dot_files;
93
+ VALUE recurse;
93
94
  } thread_args_t;
94
95
 
95
96
  void *match_thread(void *thread_args)
@@ -103,6 +104,7 @@ void *match_thread(void *thread_args)
103
104
  args->case_sensitive,
104
105
  args->always_show_dot_files,
105
106
  args->never_show_dot_files,
107
+ args->recurse,
106
108
  &args->matches[i]);
107
109
  }
108
110
 
@@ -123,8 +125,10 @@ VALUE CommandTMatcher_sorted_matches_for(int argc, VALUE *argv, VALUE self)
123
125
  VALUE always_show_dot_files;
124
126
  VALUE limit_option;
125
127
  VALUE never_show_dot_files;
128
+ VALUE ignore_spaces;
126
129
  VALUE options;
127
130
  VALUE paths;
131
+ VALUE recurse;
128
132
  VALUE results;
129
133
  VALUE scanner;
130
134
  VALUE sort_option;
@@ -136,16 +140,21 @@ VALUE CommandTMatcher_sorted_matches_for(int argc, VALUE *argv, VALUE self)
136
140
  if (NIL_P(abbrev))
137
141
  rb_raise(rb_eArgError, "nil abbrev");
138
142
 
139
- // check optional options has for overrides
143
+ // check optional options hash for overrides
140
144
  case_sensitive = CommandT_option_from_hash("case_sensitive", options);
141
145
  limit_option = CommandT_option_from_hash("limit", options);
142
146
  threads_option = CommandT_option_from_hash("threads", options);
143
147
  sort_option = CommandT_option_from_hash("sort", options);
148
+ ignore_spaces = CommandT_option_from_hash("ignore_spaces", options);
149
+ recurse = CommandT_option_from_hash("recurse", options);
144
150
 
145
151
  abbrev = StringValue(abbrev);
146
152
  if (case_sensitive != Qtrue)
147
153
  abbrev = rb_funcall(abbrev, rb_intern("downcase"), 0);
148
154
 
155
+ if (ignore_spaces == Qtrue)
156
+ abbrev = rb_funcall(abbrev, rb_intern("delete"), 1, rb_str_new2(" "));
157
+
149
158
  // get unsorted matches
150
159
  scanner = rb_iv_get(self, "@scanner");
151
160
  paths = rb_funcall(scanner, rb_intern("paths"), 0);
@@ -181,6 +190,7 @@ VALUE CommandTMatcher_sorted_matches_for(int argc, VALUE *argv, VALUE self)
181
190
  thread_args[i].abbrev = abbrev;
182
191
  thread_args[i].always_show_dot_files = always_show_dot_files;
183
192
  thread_args[i].never_show_dot_files = never_show_dot_files;
193
+ thread_args[i].recurse = recurse;
184
194
 
185
195
  #ifdef HAVE_PTHREAD_H
186
196
  if (i == thread_count - 1) {
@@ -1,4 +1,4 @@
1
- // Copyright 2010-2014 Greg Hurrell. All rights reserved.
1
+ // Copyright 2010-present Greg Hurrell. All rights reserved.
2
2
  // Licensed under the terms of the BSD 2-clause license.
3
3
 
4
4
  #include <ruby.h>
@@ -0,0 +1,12 @@
1
+ # Copyright 2015-present Greg Hurrell. All rights reserved.
2
+ # Licensed under the terms of the BSD 2-clause license.
3
+
4
+ module CommandT
5
+ module Metadata
6
+ # This file gets overwritten with actual data during the installation
7
+ # process (when `ruby extconf.rb` is run).
8
+ EXPECTED_RUBY_VERSION = '[unknown]'
9
+ EXPECTED_RUBY_PATCHLEVEL = '[unknown]'
10
+ UNKNOWN = true
11
+ end # module Metadata
12
+ end # module CommandT
@@ -1,4 +1,4 @@
1
- # Copyright 2014 Greg Hurrell. All rights reserved.
1
+ # Copyright 2014-present Greg Hurrell. All rights reserved.
2
2
  # Licensed under the terms of the BSD 2-clause license.
3
3
 
4
4
  module CommandT
@@ -1,4 +1,4 @@
1
- # Copyright 2010-2014 Greg Hurrell. All rights reserved.
1
+ # Copyright 2010-present Greg Hurrell. All rights reserved.
2
2
  # Licensed under the terms of the BSD 2-clause license.
3
3
 
4
4
  module CommandT
@@ -1,4 +1,4 @@
1
- # Copyright 2010-2014 Greg Hurrell. All rights reserved.
1
+ # Copyright 2010-present Greg Hurrell. All rights reserved.
2
2
  # Licensed under the terms of the BSD 2-clause license.
3
3
 
4
4
  module CommandT
@@ -6,10 +6,11 @@ module CommandT
6
6
  class Prompt
7
7
  attr_accessor :abbrev
8
8
 
9
- def initialize
10
- @abbrev = '' # abbreviation entered so far
11
- @col = 0 # cursor position
12
- @has_focus = false
9
+ def initialize(options = {})
10
+ @abbrev = '' # abbreviation entered so far
11
+ @col = 0 # cursor position
12
+ @cursor_color = options[:cursor_color] || 'Underlined'
13
+ @has_focus = false
13
14
  end
14
15
 
15
16
  # Erase whatever is displayed in the prompt line,
@@ -117,7 +118,7 @@ module CommandT
117
118
  if @has_focus
118
119
  prompt_highlight = 'Comment'
119
120
  normal_highlight = 'None'
120
- cursor_highlight = 'Underlined'
121
+ cursor_highlight = @cursor_color
121
122
  else
122
123
  prompt_highlight = 'NonText'
123
124
  normal_highlight = 'NonText'
@@ -1,4 +1,4 @@
1
- // Copyright 2010-2014 Greg Hurrell. All rights reserved.
1
+ // Copyright 2010-present Greg Hurrell. All rights reserved.
2
2
  // Licensed under the terms of the BSD 2-clause license.
3
3
 
4
4
  #include <ruby.h>
@@ -1,4 +1,4 @@
1
- # Copyright 2010-2014 Greg Hurrell. All rights reserved.
1
+ # Copyright 2010-present Greg Hurrell. All rights reserved.
2
2
  # Licensed under the terms of the BSD 2-clause license.
3
3
 
4
4
  module CommandT
@@ -1,4 +1,4 @@
1
- # Copyright 2010-2014 Greg Hurrell. All rights reserved.
1
+ # Copyright 2010-present Greg Hurrell. All rights reserved.
2
2
  # Licensed under the terms of the BSD 2-clause license.
3
3
 
4
4
  module CommandT
@@ -1,4 +1,4 @@
1
- # Copyright 2010-2014 Greg Hurrell. All rights reserved.
1
+ # Copyright 2010-present Greg Hurrell. All rights reserved.
2
2
  # Licensed under the terms of the BSD 2-clause license.
3
3
 
4
4
  module CommandT
@@ -9,9 +9,6 @@ module CommandT
9
9
  # obtain file listings via different strategies (for examples, see the
10
10
  # RubyFileScanner and FindFileScanner subclasses).
11
11
  class FileScanner < Scanner
12
- # Errors
13
- autoload :FileLimitExceeded, 'command-t/scanner/file_scanner/file_limit_exceeded'
14
-
15
12
  # Subclasses
16
13
  autoload :FindFileScanner, 'command-t/scanner/file_scanner/find_file_scanner'
17
14
  autoload :GitFileScanner, 'command-t/scanner/file_scanner/git_file_scanner'
@@ -1,4 +1,4 @@
1
- # Copyright 2014 Greg Hurrell. All rights reserved.
1
+ # Copyright 2014-present Greg Hurrell. All rights reserved.
2
2
  # Licensed under the terms of the BSD 2-clause license.
3
3
 
4
4
  require 'open3'
@@ -1,4 +1,4 @@
1
- # Copyright 2014 Greg Hurrell. All rights reserved.
1
+ # Copyright 2014-present Greg Hurrell. All rights reserved.
2
2
  # Licensed under the terms of the BSD 2-clause license.
3
3
 
4
4
  module CommandT
@@ -1,9 +1,11 @@
1
- # Copyright 2010-2014 Greg Hurrell. All rights reserved.
1
+ # Copyright 2010-present Greg Hurrell. All rights reserved.
2
2
  # Licensed under the terms of the BSD 2-clause license.
3
3
 
4
4
  module CommandT
5
5
  class Scanner
6
6
  class FileScanner
7
+ FileLimitExceeded = Class.new(::RuntimeError)
8
+
7
9
  # Pure Ruby implementation of a file scanner.
8
10
  class RubyFileScanner < FileScanner
9
11
  def paths!
@@ -1,4 +1,4 @@
1
- # Copyright 2014 Greg Hurrell. All rights reserved.
1
+ # Copyright 2014-present Greg Hurrell. All rights reserved.
2
2
  # Licensed under the terms of the BSD 2-clause license.
3
3
 
4
4
  require 'pathname'
@@ -1,4 +1,4 @@
1
- # Copyright 2011-2014 Greg Hurrell. All rights reserved.
1
+ # Copyright 2011-present Greg Hurrell. All rights reserved.
2
2
  # Licensed under the terms of the BSD 2-clause license.
3
3
 
4
4
  module CommandT
@@ -1,4 +1,4 @@
1
- # Copyright 2014 Greg Hurrell. All rights reserved.
1
+ # Copyright 2014-present Greg Hurrell. All rights reserved.
2
2
  # Licensed under the terms of the BSD 2-clause license.
3
3
 
4
4
  module CommandT
@@ -1,4 +1,4 @@
1
- # Copyright 2011-2014 Greg Hurrell. All rights reserved.
1
+ # Copyright 2011-present Greg Hurrell. All rights reserved.
2
2
  # Licensed under the terms of the BSD 2-clause license.
3
3
 
4
4
  module CommandT
@@ -1,4 +1,4 @@
1
- # Copyright 2014 Greg Hurrell. All rights reserved.
1
+ # Copyright 2014-present Greg Hurrell. All rights reserved.
2
2
  # Licensed under the terms of the BSD 2-clause license.
3
3
 
4
4
  module CommandT