Changeset 4815492


Ignore:
Timestamp:
Dec 28, 2009, 12:03:28 AM (10 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, 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)
Message:
Completion: Allow for separate display and replacement strings.
File:
1 edited

Legend:

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

    r48d130b r4815492  
    3131    my @words = get_completions($ctx);
    3232    return unless @words;
    33     my $prefix = common_prefix(@words);
     33    my $prefix = common_prefix(map {completion_value($_)} @words);
    3434
    3535    if($prefix) {
     
    4444}
    4545
     46=head1 COMPLETIONS
     47
     48A COMPLETION is either a simple string, or a reference to an array
     49containing two or more values.
     50
     51In the former case, the string use used for both the text to display,
     52as well as the result of the completion, and is assumed to be a full
     53completion.
     54
     55An 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
     64sub completion_text {
     65    my $c = shift;
     66    return $c unless ref($c) eq 'ARRAY';
     67    return $c->[0];
     68}
     69
     70sub completion_value {
     71    my $c = shift;
     72    return $c unless ref($c) eq 'ARRAY';
     73    return $c->[1];
     74}
     75
    4676sub insert_completion {
    4777    my $ctx = shift;
    48     my $completion = BarnOwl::quote(shift);
     78    my $completion = BarnOwl::quote(completion_value(shift));
    4979    my $unique = shift;
    5080
     
    6696sub show_completions {
    6797    my @words = @_;
    68     my $all = BarnOwl::quote(@words);
     98    my $all = BarnOwl::quote(map {completion_text($_)} @words);
    6999    my $width = BarnOwl::getnumcols();
    70100    if (length($all) > $width-1) {
     
    98128        my $word = $ctx->words->[$ctx->word];
    99129        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);
    101131        }
    102132        return;
Note: See TracChangeset for help on using the changeset viewer.