From 07f1d7cb26257aceb6e400e6e400d31e28381a5a Mon Sep 17 00:00:00 2001 From: Wincent Colaiuta Date: Thu, 29 Apr 2010 08:41:06 +0200 Subject: [PATCH] Handle non-existent directories passed to :CommandT Gracefully handle non-existent directories passed in via ":CommandT path". Note that we catch the Errno:ENOENT exception only when the match window is shown, because we're interested in advising the user when they enter a dud path. (In contrast, we let Errno::ENOENT exceptions at other times just bubble up, as may be the case if the user has something funky with their filesystem and stuff appears in the listing but later claims to not exist.) This closes feature request #1522: https://wincent.com/issues/1522 Signed-off-by: Wincent Colaiuta --- ruby/command-t/controller.rb | 3 +++ ruby/command-t/match_window.rb | 29 +++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/ruby/command-t/controller.rb b/ruby/command-t/controller.rb index 6fe76cd4..51277ce7 100644 --- a/ruby/command-t/controller.rb +++ b/ruby/command-t/controller.rb @@ -46,6 +46,9 @@ def show @prompt.focus register_for_key_presses clear # clears prompt and list matches + rescue Errno::ENOENT + # probably a problem with the optional parameter + @match_window.print_no_such_file_or_directory end def hide diff --git a/ruby/command-t/match_window.rb b/ruby/command-t/match_window.rb index ee252f7a..0739ac6b 100644 --- a/ruby/command-t/match_window.rb +++ b/ruby/command-t/match_window.rb @@ -77,6 +77,7 @@ def initialize options = {} if VIM::has_syntax? VIM::command "syntax match CommandTSelection \"^#{@@selection_marker}.\\+$\"" VIM::command 'syntax match CommandTNoEntries "^-- NO MATCHES --$"' + VIM::command 'syntax match CommandTNoEntries "^-- NO SUCH FILE OR DIRECTORY --$"' VIM::command 'highlight link CommandTSelection Visual' VIM::command 'highlight link CommandTNoEntries Error' VIM::evaluate 'clearmatches()' @@ -183,8 +184,21 @@ def selection @matches[@selection] end + def print_no_such_file_or_directory + print_error 'NO SUCH FILE OR DIRECTORY' + end + private + def print_error msg + return unless @window.select + unlock + clear + @window.height = 1 + @buffer[1] = "-- #{msg} --" + lock + end + def restore_window_dimensions # sort from tallest to shortest @windows.sort! { |a, b| b.height <=> a.height } @@ -219,16 +233,15 @@ def print_match idx # Print all matches. def print_matches - return unless @window.select - unlock - clear match_count = @matches.length - actual_lines = 1 - @window_width = @window.width # update cached value if match_count == 0 - @window.height = actual_lines - @buffer[1] = '-- NO MATCHES --' + print_error 'NO MATCHES' else + return unless @window.select + unlock + clear + actual_lines = 1 + @window_width = @window.width # update cached value max_lines = VIM::Screen.lines - 5 max_lines = 1 if max_lines < 0 actual_lines = match_count > max_lines ? max_lines : match_count @@ -241,8 +254,8 @@ def print_matches @buffer.append line - 1, match_text_for_idx(idx) end end + lock end - lock end # Prepare padding for match text (trailing spaces) so that selection