Changeset fbe04c6


Ignore:
Timestamp:
Feb 26, 2013, 2:00:50 PM (8 years ago)
Author:
David Benjamin <davidben@mit.edu>
Children:
bf5f09f
Parents:
acef4ad
git-author:
David Benjamin <davidben@mit.edu> (02/25/13 18:27:35)
git-committer:
David Benjamin <davidben@mit.edu> (02/26/13 14:00:50)
Message:
Revamp set/unset completion

- unset <tab> only completes takes_on_off variables
- Variables with validsettings <path> complete as file paths
- Variables with validsettings a comma-separated list of options
  complete appropriately.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • perl/lib/BarnOwl/Complete/Client.pm

    r76682af rfbe04c6  
    146146sub complete_set {
    147147    my $ctx = shift;
     148    my $is_unset = ($ctx->words->[0] eq "unset");
     149
     150    # Shift away the -q if seen.
     151    my $seen_q = 0;
     152    if ($ctx->word > 1 && $ctx->words->[1] eq "-q") {
     153        $seen_q = 1;
     154        $ctx = $ctx->shift_words(1);
     155    }
     156
     157    # First argument is the variable.
    148158    if ($ctx->word == 1) {
    149         return ("-q", complete_variable());
    150     }
    151     if ($ctx->word == 2 && $ctx->words->[1] eq "-q") {
    152         return complete_variable();
     159        my @vars = complete_variable();
     160        if ($is_unset) {
     161            # Only complete the variables which are unsettable.
     162            @vars = grep { BarnOwl::get_variable_info($_)->{takes_on_off} } @vars;
     163        }
     164        unshift(@vars, "-q") unless $seen_q;
     165        return @vars;
     166    }
     167    # For set, second argument is the value.
     168    if (!$is_unset && $ctx->word == 2) {
     169        # Parse what we can out of validsettings.
     170        my $info;
     171        eval { $info = BarnOwl::get_variable_info($ctx->words->[1]) };
     172        return if $@;
     173        if ($info->{validsettings} eq "<path>") {
     174            return complete_file($ctx->words->[2]);
     175        } elsif ($info->{validsettings} !~ /^<.*>$/) {
     176            # Assume it's a comma-separated list of values;
     177            return split(",", $info->{validsettings});
     178        }
    153179    }
    154180    return;
    155 }
    156 sub complete_set_args {
    157     my $ctx = shift;
    158     my $arg = shift;
    159     return if $arg;
    160     return complete_variable();
    161181}
    162182
Note: See TracChangeset for help on using the changeset viewer.