Skip to content

Commit

Permalink
Handle non-existent directories passed to :CommandT
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
wincent committed Apr 29, 2010
1 parent a8242b4 commit 07f1d7c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
3 changes: 3 additions & 0 deletions ruby/command-t/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 21 additions & 8 deletions ruby/command-t/match_window.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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()'
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 07f1d7c

Please sign in to comment.