diff options
author | Tom Feist <shabble@metavore.org> | 2010-11-04 20:17:29 +0000 |
---|---|---|
committer | Tom Feist <shabble@metavore.org> | 2010-11-04 20:17:29 +0000 |
commit | 6f57144f84f617395a11096774e846d83534e941 (patch) | |
tree | 3e2502538d8a8109cf17f2b5ec68d012ca9dfbfa /vim-mode | |
parent | add support for 'prompt length request' signal, which responds with a standard (diff) | |
download | irssi-scripts-6f57144f84f617395a11096774e846d83534e941.tar.gz irssi-scripts-6f57144f84f617395a11096774e846d83534e941.zip |
start of tab completion for :ex commands
Diffstat (limited to '')
-rw-r--r-- | vim-mode/vim_mode.pl | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index bc56f09..46c256c 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -600,6 +600,11 @@ my $history_pos = 0; my @undo_buffer; my $undo_index = undef; + +my @tab_candidates; +my $completion_active = 0; +my $completion_string = ''; + sub script_is_loaded { my $name = shift; print "Checking if $name is loaded" if DEBUG; @@ -1219,7 +1224,7 @@ sub cmd__a { "^($word+\\s+|$non_word+\\s+)", $pos, 1); - if ($new_pos != -1 and + if ($new_pos != -1 and (not defined $cur_pos or $cur_pos > $new_pos + 1)) { @@ -2731,6 +2736,11 @@ sub handle_command_ex { cmd_ex_command(); _update_mode(M_CMD); + } elsif ($key == 9) { # TAB + print "Tab pressed" if DEBUG; + print "Ex buf contains: " . join('', @ex_buf) if DEBUG; + @tab_candidates = _tab_complete(join('', @ex_buf), [keys %$commands_ex]); + # Ignore control characters for now. } elsif ($key < 32) { # TODO: use them later, e.g. completion @@ -2746,6 +2756,18 @@ sub handle_command_ex { _stop(); } +sub _tab_complete { + my ($input, $source) = @_; + my @out; + foreach my $item (@$source) { + if ($item =~ m/^\Q$input\E/) { + push @out, $item; + } + } + + return sort { $a cmp $b } @out; +} + sub vim_mode_init { Irssi::signal_add_first 'gui key pressed' => \&got_key; Irssi::signal_add 'setup changed' => \&setup_changed; |