Changeset b73bcbb
- Timestamp:
- Jul 27, 2009, 11:23:57 PM (15 years ago)
- Branches:
- master, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 82a6e8b
- Parents:
- 0fee298
- git-author:
- Nelson Elhage <nelhage@mit.edu> (07/27/09 21:17:06)
- git-committer:
- Nelson Elhage <nelhage@mit.edu> (07/27/09 23:23:57)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
perl/lib/BarnOwl/Completion.pm
r0fee298 rb73bcbb 19 19 20 20 use List::Util qw(max first); 21 22 our %completers = (); 21 23 22 24 sub do_complete { … … 62 64 } 63 65 64 sub get_completions {65 my $ctx = shift;66 if($ctx->word == 0) {67 return complete_command($ctx->words->[0]);68 } else {69 return;70 }71 }72 73 sub complete_command {74 my $cmd = shift;75 return grep {$_ =~ m{^\Q$cmd\E}} @BarnOwl::all_commands;76 }77 78 66 sub show_completions { 79 67 my @words = @_; … … 101 89 } 102 90 91 92 sub get_completions { 93 my $ctx = shift; 94 my @words = (); 95 if($ctx->word == 0) { 96 return complete_command($ctx->words->[0]); 97 } else { 98 my $cmd = $ctx->words->[0]; 99 my $word = $ctx->words->[$ctx->word]; 100 if(exists($completers{$cmd})) { 101 return grep {$_ =~ m{^\Q$word\E}} $completers{$cmd}->($ctx); 102 } 103 return; 104 } 105 } 106 107 sub complete_command { 108 my $cmd = shift; 109 return grep {$_ =~ m{^\Q$cmd\E}} @BarnOwl::all_commands; 110 } 111 112 sub register_completer { 113 my $cmd = shift; 114 my $completer = shift; 115 $completers{$cmd} = $completer; 116 } 117 118 sub load_completers { 119 opendir(my $dh, BarnOwl::get_data_dir() . "/" . "lib/BarnOwl/Complete/") or return; 120 while(my $name = readdir($dh)) { 121 next if $name =~ m{^\.}; 122 next unless $name =~ m{[.]pm$}; 123 $name =~ s{[.]pm$}{}; 124 eval "use BarnOwl::Complete::$name"; 125 } 126 } 127 128 $BarnOwl::Hooks::startup->add("BarnOwl::Completion::load_completers"); 129 103 130 1;
Note: See TracChangeset
for help on using the changeset viewer.