Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • perl/lib/BarnOwl/Completion.pm

    r880311d r48d130b  
    3131    my @words = get_completions($ctx);
    3232    return unless @words;
    33     my $prefix = common_prefix(map {completion_value($_)} @words);
     33    my $prefix = common_prefix(@words);
    3434
    3535    if($prefix) {
    36         insert_completion($ctx, $prefix,
    37                           scalar @words == 1 && completion_done($words[0]));
     36        insert_completion($ctx, $prefix, scalar @words == 1);
    3837    }
    3938
     
    4544}
    4645
    47 =head1 COMPLETIONS
    48 
    49 A COMPLETION is either a simple string, or a reference to an array
    50 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 full
    54 completion.
    55 
    56 An arrayref completion consists of
    57 
    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 there
    62 is only a single completion for a given word, a space will be appended
    63 after the completion iff $completion_done is true (or missing).
    64 
    65 =cut
    66 
    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 
    8546sub insert_completion {
    8647    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;
    8950
    90     if($done) {
     51    if($unique) {
    9152        $completion .= " ";
    9253    }
     
    10566sub show_completions {
    10667    my @words = @_;
    107     my $all = BarnOwl::quote(map {completion_text($_)} @words);
     68    my $all = BarnOwl::quote(@words);
    10869    my $width = BarnOwl::getnumcols();
    10970    if (length($all) > $width-1) {
     
    13798        my $word = $ctx->words->[$ctx->word];
    13899        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);
    140101        }
    141102        return;
Note: See TracChangeset for help on using the changeset viewer.