Changeset 5368d75 for perl


Ignore:
Timestamp:
Jul 27, 2009, 11:23:57 PM (15 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
0fee298
Parents:
6e48560
git-author:
Nelson Elhage <nelhage@mit.edu> (07/25/09 23:03:45)
git-committer:
Nelson Elhage <nelhage@mit.edu> (07/27/09 23:23:57)
Message:
Implement tab completion by replacing the entire word.

Replace the entire word, instead of just appending the new text. Among
other things, this lets us deal with expansions that need to be quoted
much better.
File:
1 edited

Legend:

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

    r6e48560 r5368d75  
    1515
    1616use BarnOwl::Completion::Context;
    17 use BarnOwl::Editwin qw(text_before_point text_after_point);
     17use BarnOwl::Editwin qw(save_excursion text_before_point text_after_point
     18                        point_move replace_region);
    1819
    1920use List::Util qw(max first);
     
    3233    my $word = $ctx->words->[$ctx->word];
    3334
    34     if($prefix && $prefix ne $word) {
    35         if(scalar @words == 1) {
    36             $prefix .= ' ';
    37         }
    38        
    39         BarnOwl::Editwin::insert_text(substr($prefix, length($word)));
     35    if($prefix) {
     36        insert_completion($ctx, $prefix, scalar @words == 1);
    4037    }
    4138
    4239    if(scalar @words > 1) {
    4340        show_completions(@words);
     41    } else {
     42        BarnOwl::message('');
     43    }
     44}
     45
     46sub insert_completion {
     47    my $ctx = shift;
     48    my $completion = shift;
     49    my $unique = shift;
     50
     51    save_excursion {
     52        point_move($ctx->word_start - $ctx->point);
     53        BarnOwl::Editwin::set_mark();
     54        point_move($ctx->word_end - $ctx->word_start);
     55        replace_region(BarnOwl::quote($completion));
     56    };
     57    if($unique && $ctx->word == (scalar @{$ctx->words} - 1)) {
     58        save_excursion {
     59            BarnOwl::Editwin::set_mark();
     60            replace_region(' ');
     61        };
     62        point_move(1);
    4463    }
    4564}
Note: See TracChangeset for help on using the changeset viewer.