- Timestamp:
- Dec 28, 2009, 12:03:28 AM (15 years ago)
- Branches:
- master, release-1.10, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 880311d
- Parents:
- 4d26776
- git-author:
- Nelson Elhage <nelhage@mit.edu> (12/24/09 16:44:52)
- git-committer:
- Nelson Elhage <nelhage@mit.edu> (12/28/09 00:03:28)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
perl/lib/BarnOwl/Completion.pm
r48d130b r4815492 31 31 my @words = get_completions($ctx); 32 32 return unless @words; 33 my $prefix = common_prefix( @words);33 my $prefix = common_prefix(map {completion_value($_)} @words); 34 34 35 35 if($prefix) { … … 44 44 } 45 45 46 =head1 COMPLETIONS 47 48 A COMPLETION is either a simple string, or a reference to an array 49 containing two or more values. 50 51 In the former case, the string use used for both the text to display, 52 as well as the result of the completion, and is assumed to be a full 53 completion. 54 55 An arrayref completion consists of 56 57 [$display_text, $replacement_value]. 58 59 $display_text will be printed in the case of ambiguous completions, 60 $replacement_value will be used to substitute the value in. 61 62 =cut 63 64 sub completion_text { 65 my $c = shift; 66 return $c unless ref($c) eq 'ARRAY'; 67 return $c->[0]; 68 } 69 70 sub completion_value { 71 my $c = shift; 72 return $c unless ref($c) eq 'ARRAY'; 73 return $c->[1]; 74 } 75 46 76 sub insert_completion { 47 77 my $ctx = shift; 48 my $completion = BarnOwl::quote( shift);78 my $completion = BarnOwl::quote(completion_value(shift)); 49 79 my $unique = shift; 50 80 … … 66 96 sub show_completions { 67 97 my @words = @_; 68 my $all = BarnOwl::quote( @words);98 my $all = BarnOwl::quote(map {completion_text($_)} @words); 69 99 my $width = BarnOwl::getnumcols(); 70 100 if (length($all) > $width-1) { … … 98 128 my $word = $ctx->words->[$ctx->word]; 99 129 if(exists($completers{$cmd})) { 100 return grep { $_=~ m{^\Q$word\E}} $completers{$cmd}->($ctx);130 return grep {completion_value($_) =~ m{^\Q$word\E}} $completers{$cmd}->($ctx); 101 131 } 102 132 return;
Note: See TracChangeset
for help on using the changeset viewer.