Changes in perl/lib/BarnOwl/Completion.pm [880311d:48d130b]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
perl/lib/BarnOwl/Completion.pm
r880311d r48d130b 31 31 my @words = get_completions($ctx); 32 32 return unless @words; 33 my $prefix = common_prefix( map {completion_value($_)}@words);33 my $prefix = common_prefix(@words); 34 34 35 35 if($prefix) { 36 insert_completion($ctx, $prefix, 37 scalar @words == 1 && completion_done($words[0])); 36 insert_completion($ctx, $prefix, scalar @words == 1); 38 37 } 39 38 … … 45 44 } 46 45 47 =head1 COMPLETIONS48 49 A COMPLETION is either a simple string, or a reference to an array50 containing two or more values.51 52 In the former case, the string use used for both the text to display,53 as well as the result of the completion, and is assumed to be a full54 completion.55 56 An arrayref completion consists of57 58 [$display_text, $replacement_value[, $completion_done] ].59 60 $display_text will be printed in the case of ambiguous completions,61 $replacement_value will be used to substitute the value in. If there62 is only a single completion for a given word, a space will be appended63 after the completion iff $completion_done is true (or missing).64 65 =cut66 67 sub completion_text {68 my $c = shift;69 return $c unless ref($c) eq 'ARRAY';70 return $c->[0];71 }72 73 sub completion_value {74 my $c = shift;75 return $c unless ref($c) eq 'ARRAY';76 return $c->[1];77 }78 79 sub completion_done {80 my $c = shift;81 return 1 if ref($c) ne 'ARRAY' or @$c < 3;82 return $c->[2];83 }84 85 46 sub insert_completion { 86 47 my $ctx = shift; 87 my $completion = BarnOwl::quote( completion_value(shift));88 my $ done = shift;48 my $completion = BarnOwl::quote(shift); 49 my $unique = shift; 89 50 90 if($ done) {51 if($unique) { 91 52 $completion .= " "; 92 53 } … … 105 66 sub show_completions { 106 67 my @words = @_; 107 my $all = BarnOwl::quote( map {completion_text($_)}@words);68 my $all = BarnOwl::quote(@words); 108 69 my $width = BarnOwl::getnumcols(); 109 70 if (length($all) > $width-1) { … … 137 98 my $word = $ctx->words->[$ctx->word]; 138 99 if(exists($completers{$cmd})) { 139 return grep { completion_value($_)=~ m{^\Q$word\E}} $completers{$cmd}->($ctx);100 return grep {$_ =~ m{^\Q$word\E}} $completers{$cmd}->($ctx); 140 101 } 141 102 return;
Note: See TracChangeset
for help on using the changeset viewer.