Class: CommandT::Controller
- Inherits:
-
Object
- Object
- CommandT::Controller
- Includes:
- PathUtilities, SCMUtilities
- Defined in:
- lib/command-t/controller.rb
Class Method Summary collapse
-
.guard(method) ⇒ Object
Wraps ‘method` in a `rescue` clause that attempts to print some useful information to the screen before re-raising any exception.
Instance Method Summary collapse
- #accept_selection(options = {}) ⇒ Object
-
#active_finder ⇒ Object
For possible use in status lines.
- #backspace ⇒ Object
- #cancel ⇒ Object
- #clear ⇒ Object
- #clear_prev_word ⇒ Object
- #cursor_end ⇒ Object
- #cursor_left ⇒ Object
- #cursor_right ⇒ Object
- #cursor_start ⇒ Object
- #delete ⇒ Object
- #flush ⇒ Object
- #handle_key ⇒ Object
- #hide ⇒ Object
-
#initialize ⇒ Controller
constructor
A new instance of Controller.
-
#is_own_buffer(buffer_number) ⇒ Object
For possible use in status lines.
- #leave ⇒ Object
- #list_matches(options = {}) ⇒ Object
-
#path ⇒ Object
For possible use in status lines.
-
#quickfix ⇒ Object
Take current matches and stick them in the quickfix window.
- #refresh ⇒ Object
- #remove_buffer ⇒ Object
-
#return_is_own_buffer(buffer_number) ⇒ Object
For possible use in status lines.
- #select_next ⇒ Object
- #select_prev ⇒ Object
- #show_buffer_finder ⇒ Object
- #show_command_finder ⇒ Object
- #show_file_finder ⇒ Object
- #show_help_finder ⇒ Object
- #show_history_finder ⇒ Object
- #show_jump_finder ⇒ Object
- #show_line_finder ⇒ Object
- #show_mru_finder ⇒ Object
- #show_search_finder ⇒ Object
- #show_tag_finder ⇒ Object
- #split_command ⇒ Object
- #tab_command ⇒ Object
- #toggle_focus ⇒ Object
- #unload ⇒ Object
- #vsplit_command ⇒ Object
Constructor Details
#initialize ⇒ Controller
Returns a new instance of Controller.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/command-t/controller.rb', line 27 def initialize encoding = VIM::get_string('g:CommandTEncoding') if encoding begin encoding = Encoding.find(encoding) Encoding.default_external = encoding Encoding.default_internal = encoding rescue end end @nowait = '<nowait>' if ::VIM::evaluate('v:version') >= 704 end |
Class Method Details
.guard(method) ⇒ Object
Wraps ‘method` in a `rescue` clause that attempts to print some useful information to the screen before re-raising any exception. Without this, most of the useful output is unhelpfully swallowed by Vim.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/command-t/controller.rb', line 12 def self.guard(method) class_eval <<-END alias original_#{method} #{method} def #{method}(*args, &block) original_#{method}(*args, &block) rescue Exception => e backtrace = e.backtrace trimmed = backtrace.take(backtrace.length - 2) text = VIM::escape_for_single_quotes trimmed.join("\n") ::VIM::command "echo '\#{text}'" raise e end END end |
Instance Method Details
#accept_selection(options = {}) ⇒ Object
235 236 237 238 239 |
# File 'lib/command-t/controller.rb', line 235 def accept_selection( = {}) selection = @match_window.selection hide open_selection(selection, ) unless selection.nil? end |
#active_finder ⇒ Object
For possible use in status lines.
41 42 43 |
# File 'lib/command-t/controller.rb', line 41 def active_finder @active_finder && @active_finder.class.name end |
#backspace ⇒ Object
207 208 209 210 211 212 |
# File 'lib/command-t/controller.rb', line 207 def backspace if @focus == prompt prompt.backspace! update end end |
#cancel ⇒ Object
249 250 251 |
# File 'lib/command-t/controller.rb', line 249 def cancel hide end |
#clear ⇒ Object
264 265 266 267 |
# File 'lib/command-t/controller.rb', line 264 def clear prompt.clear! list_matches! end |
#clear_prev_word ⇒ Object
270 271 272 273 |
# File 'lib/command-t/controller.rb', line 270 def clear_prev_word prompt.clear_prev_word! list_matches! end |
#cursor_end ⇒ Object
286 287 288 |
# File 'lib/command-t/controller.rb', line 286 def cursor_end prompt.cursor_end if @focus == prompt end |
#cursor_left ⇒ Object
276 277 278 |
# File 'lib/command-t/controller.rb', line 276 def cursor_left prompt.cursor_left if @focus == prompt end |
#cursor_right ⇒ Object
281 282 283 |
# File 'lib/command-t/controller.rb', line 281 def cursor_right prompt.cursor_right if @focus == prompt end |
#cursor_start ⇒ Object
291 292 293 |
# File 'lib/command-t/controller.rb', line 291 def cursor_start prompt.cursor_start if @focus == prompt end |
#delete ⇒ Object
215 216 217 218 219 220 |
# File 'lib/command-t/controller.rb', line 215 def delete if @focus == prompt prompt.delete! update end end |
#flush ⇒ Object
187 188 189 190 191 192 193 |
# File 'lib/command-t/controller.rb', line 187 def flush @file_finder = nil @max_height = nil @min_height = nil @prompt = nil @tag_finder = nil end |
#handle_key ⇒ Object
196 197 198 199 200 201 202 203 204 |
# File 'lib/command-t/controller.rb', line 196 def handle_key key = ::VIM::evaluate('a:arg').to_i.chr if @focus == prompt prompt.add! key update else @match_window.find key end end |
#hide ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/command-t/controller.rb', line 154 def hide @match_window.leave if VIM::Window.select @initial_window if @initial_buffer.number == 0 # upstream bug: buffer number misreported as 0 # see: https://wincent.com/issues/1617 ::VIM::command "silent b #{@initial_buffer.name}" else ::VIM::command "silent b #{@initial_buffer.number}" end end end |
#is_own_buffer(buffer_number) ⇒ Object
For possible use in status lines.
51 52 53 |
# File 'lib/command-t/controller.rb', line 51 def is_own_buffer(buffer_number) @match_window && buffer_number == @match_window.buffer_number end |
#leave ⇒ Object
296 297 298 |
# File 'lib/command-t/controller.rb', line 296 def leave @match_window.leave end |
#list_matches(options = {}) ⇒ Object
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/command-t/controller.rb', line 304 def list_matches( = {}) return unless @needs_update || [:force] @matches = @active_finder.sorted_matches_for( prompt.abbrev, :case_sensitive => case_sensitive?, :limit => match_limit, :threads => CommandT::Util.processor_count, :ignore_spaces => VIM::get_bool('g:CommandTIgnoreSpaces', true), :recurse => VIM::get_bool('g:CommandTRecursiveMatch', true) ) @match_window.matches = @matches # Scanner may have overwritten prompt to show progress. prompt.redraw @needs_update = false end |
#path ⇒ Object
For possible use in status lines.
46 47 48 |
# File 'lib/command-t/controller.rb', line 46 def path @path end |
#quickfix ⇒ Object
Take current matches and stick them in the quickfix window.
168 169 170 171 172 173 174 175 176 177 |
# File 'lib/command-t/controller.rb', line 168 def quickfix hide matches = @matches.map do |match| "{ 'filename': '#{VIM::escape_for_single_quotes match}' }" end.join(', ') ::VIM::command 'call setqflist([' + matches + '])' ::VIM::command 'cope' end |
#refresh ⇒ Object
180 181 182 183 184 |
# File 'lib/command-t/controller.rb', line 180 def refresh return unless @active_finder && @active_finder.respond_to?(:flush) @active_finder.flush list_matches! end |
#remove_buffer ⇒ Object
223 224 225 226 227 228 229 230 231 232 |
# File 'lib/command-t/controller.rb', line 223 def remove_buffer return unless @active_finder.class <= CommandT::Finder::BufferFinder selection = @match_window.selection if @initial_buffer.name != selection ::VIM::command "bd #{selection}" end list_matches! hide end |
#return_is_own_buffer(buffer_number) ⇒ Object
For possible use in status lines.
56 57 58 59 60 61 62 |
# File 'lib/command-t/controller.rb', line 56 def return_is_own_buffer(buffer_number) if is_own_buffer(buffer_number) ::VIM::command 'return 1' else ::VIM::command 'return 0' end end |
#select_next ⇒ Object
254 255 256 |
# File 'lib/command-t/controller.rb', line 254 def select_next @match_window.select_next end |
#select_prev ⇒ Object
259 260 261 |
# File 'lib/command-t/controller.rb', line 259 def select_prev @match_window.select_prev end |
#show_buffer_finder ⇒ Object
64 65 66 67 68 |
# File 'lib/command-t/controller.rb', line 64 def show_buffer_finder @path = VIM::pwd @active_finder = buffer_finder show end |
#show_command_finder ⇒ Object
71 72 73 74 75 |
# File 'lib/command-t/controller.rb', line 71 def show_command_finder @path = VIM::pwd @active_finder = command_finder show end |
#show_file_finder ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/command-t/controller.rb', line 127 def show_file_finder # optional parameter will be desired starting directory, or "" arg = ::VIM::evaluate('a:arg') if arg && arg.size > 0 @path = File.(arg, VIM::pwd) else traverse = VIM::get_string('g:CommandTTraverseSCM') || 'file' case traverse when 'file' @path = nearest_ancestor(VIM::current_file_dir, scm_markers) || VIM::pwd when 'dir' @path = nearest_ancestor(VIM::pwd, scm_markers) || VIM::pwd else @path = VIM::pwd end end @active_finder = file_finder file_finder.path = @path show rescue Errno::ENOENT # probably a problem with the optional parameter @match_window.print_no_such_file_or_directory end |
#show_help_finder ⇒ Object
78 79 80 81 82 |
# File 'lib/command-t/controller.rb', line 78 def show_help_finder @path = VIM::pwd @active_finder = help_finder show end |
#show_history_finder ⇒ Object
85 86 87 88 89 |
# File 'lib/command-t/controller.rb', line 85 def show_history_finder @path = VIM::pwd @active_finder = history_finder show end |
#show_jump_finder ⇒ Object
92 93 94 95 96 |
# File 'lib/command-t/controller.rb', line 92 def show_jump_finder @path = VIM::pwd @active_finder = jump_finder show end |
#show_line_finder ⇒ Object
99 100 101 102 103 |
# File 'lib/command-t/controller.rb', line 99 def show_line_finder @path = VIM::pwd @active_finder = line_finder show end |
#show_mru_finder ⇒ Object
106 107 108 109 110 |
# File 'lib/command-t/controller.rb', line 106 def show_mru_finder @path = VIM::pwd @active_finder = mru_finder show end |
#show_search_finder ⇒ Object
113 114 115 116 117 |
# File 'lib/command-t/controller.rb', line 113 def show_search_finder @path = VIM::pwd @active_finder = search_finder show end |
#show_tag_finder ⇒ Object
120 121 122 123 124 |
# File 'lib/command-t/controller.rb', line 120 def show_tag_finder @path = VIM::pwd @active_finder = tag_finder show end |
#split_command ⇒ Object
328 329 330 |
# File 'lib/command-t/controller.rb', line 328 def split_command VIM::get_string('g:CommandTAcceptSelectionSplitCommand') || 'CommandTOpen split' end |
#tab_command ⇒ Object
324 325 326 |
# File 'lib/command-t/controller.rb', line 324 def tab_command VIM::get_string('g:CommandTAcceptSelectionTabCommand') || 'CommandTOpen tabedit' end |
#toggle_focus ⇒ Object
242 243 244 245 246 |
# File 'lib/command-t/controller.rb', line 242 def toggle_focus @focus.unfocus # old focus @focus = @focus == prompt ? @match_window : prompt @focus.focus # new focus end |
#unload ⇒ Object
300 301 302 |
# File 'lib/command-t/controller.rb', line 300 def unload @match_window.unload end |
#vsplit_command ⇒ Object
332 333 334 |
# File 'lib/command-t/controller.rb', line 332 def vsplit_command VIM::get_string('g:CommandTAcceptSelectionVSplitCommand') || 'CommandTOpen vsplit' end |