diff options
author | Tom Feist <shabble@metavore.org> | 2011-04-08 22:54:12 +0000 |
---|---|---|
committer | Tom Feist <shabble@metavore.org> | 2011-04-08 22:54:12 +0000 |
commit | 3d98203505b1509852e0ee88a484daf4cb812a73 (patch) | |
tree | 28405954ad12b6d244095d0b45c2554b8c13e09f /vim-mode/vim_mode.pl | |
parent | vim-mode: minimal ex-mode tab-completion. Completes provided only the current (diff) | |
parent | vim-mode/vim_mode: cleanup of commands, and fix bug preventing ex mode from (diff) | |
download | irssi-scripts-3d98203505b1509852e0ee88a484daf4cb812a73.tar.gz irssi-scripts-3d98203505b1509852e0ee88a484daf4cb812a73.zip |
Merge branch 'map_leader'
Conflicts:
vim-mode/vim_mode.pl
Diffstat (limited to 'vim-mode/vim_mode.pl')
-rw-r--r-- | vim-mode/vim_mode.pl | 90 |
1 files changed, 58 insertions, 32 deletions
diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 6ce4d22..b279790 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -319,19 +319,19 @@ my $commands repeatable => 1 }, # arrow like movement - h => { char => 'h', func => \&cmd_h, type => C_NORMAL }, - l => { char => 'l', func => \&cmd_l, type => C_NORMAL }, + h => { char => 'h', func => \&cmd_h, type => C_NORMAL }, + l => { char => 'l', func => \&cmd_l, type => C_NORMAL }, "\x7F" => { char => '<BS>', func => \&cmd_h, type => C_NORMAL }, ' ' => { char => '<Space>', func => \&cmd_l, type => C_NORMAL }, # history movement - j => { char => 'j', func => \&cmd_j, type => C_NORMAL, - no_operator => 1 }, - k => { char => 'k', func => \&cmd_k, type => C_NORMAL, - no_operator => 1 }, - gg => { char => 'gg', func => \&cmd_gg, type => C_NORMAL, - no_operator => 1 }, - G => { char => 'G', func => \&cmd_G, type => C_NORMAL, - needs_count => 1, no_operator => 1 }, + j => { char => 'j', func => \&cmd_j, type => C_NORMAL, + no_operator => 1 }, + k => { char => 'k', func => \&cmd_k, type => C_NORMAL, + no_operator => 1 }, + gg => { char => 'gg', func => \&cmd_gg, type => C_NORMAL, + no_operator => 1 }, + G => { char => 'G', func => \&cmd_G, type => C_NORMAL, + needs_count => 1, no_operator => 1 }, # char movement, take an additional parameter and use $movement f => { char => 'f', func => \&cmd_f, type => C_NEEDSKEY, selection_needs_move_right => 1 }, @@ -354,11 +354,11 @@ my $commands gE => { char => 'gE', func => \&cmd_gE, type => C_NORMAL, selection_needs_move_right => 1 }, # text-objects, leading _ means can't be mapped! - _i => { char => 'i', func => \&cmd__i, type => C_TEXTOBJECT }, - _a => { char => 'a', func => \&cmd__a, type => C_TEXTOBJECT }, + _i => { char => 'i', func => \&cmd__i, type => C_TEXTOBJECT }, + _a => { char => 'a', func => \&cmd__a, type => C_TEXTOBJECT }, # line movement - '0' => { char => '0', func => \&cmd_0, type => C_NORMAL }, - '^' => { char => '^', func => \&cmd_caret, type => C_NORMAL }, + '0' => { char => '0', func => \&cmd_0, type => C_NORMAL }, + '^' => { char => '^', func => \&cmd_caret, type => C_NORMAL }, '$' => { char => '$', func => \&cmd_dollar, type => C_NORMAL }, # delete chars x => { char => 'x', func => \&cmd_x, type => C_NORMAL, @@ -433,7 +433,7 @@ my $commands my $commands_ex = { # arrow keys - not actually used, see handle_input_buffer() - + # TODO: make these work. "\e[A" => { char => ':exprev', func => \&ex_history_back, type => C_EX }, "\e[B" => { char => ':exnext', func => \&ex_history_fwd, @@ -518,6 +518,16 @@ my $commands_ex # default command mode mappings my $maps = {}; +# current imap still pending (first character entered) +my $imap = undef; + +# maps for insert mode +my $imaps + = { + # CTRL-R, insert register + "\x12" => { map => undef, func => \&insert_ctrl_r }, + }; + # GLOBAL VARIABLES @@ -538,6 +548,8 @@ my $settings ex_history_size => { type => S_INT, value => 100 }, # prompt_leading_space prompt_leading_space => { type => S_BOOL, value => 1 }, + # <Leader> value for prepending to commands. + map_leader => { type => S_STR, value => '\\' }, }; sub DEBUG { $settings->{debug}->{value} } @@ -602,19 +614,6 @@ my $registers '*' => '', # same '_' => '', # black hole register, always empty }; -foreach my $char ('a' .. 'z') { - $registers->{$char} = ''; -} - -# current imap still pending (first character entered) -my $imap = undef; - -# maps for insert mode -my $imaps - = { - # CTRL-R, insert register - "\x12" => { map => undef, func => \&insert_ctrl_r }, - }; # index into the history list (for j,k) my $history_index = undef; @@ -645,8 +644,10 @@ sub script_is_loaded { sub insert_ctrl_r { my ($key) = @_; - + _debug("ctrl-r called"); my $char = chr($key); + _debug("ctrl-r called with $char"); + return if not defined $registers->{$char} or $registers->{$char} eq ''; my $pos = _insert_at_position($registers->{$char}, 1, _input_pos()); @@ -2040,6 +2041,7 @@ sub _parse_mapping { my ($string) = @_; $string =~ s/<([^>]+)>/_parse_mapping_bracket($1)/ge; + _warn("Parse mapping: $string"); if (index($string, '<invalid>') != -1) { return undef; } @@ -2065,6 +2067,8 @@ sub _parse_mapping_bracket { # <BS> } elsif ($string eq 'bs') { $string = chr(127); + } elsif ($string eq 'leader') { + $string = $settings->{map_leader}->{value}; # Invalid char, return special string to recognize the error. } else { $string = '<invalid>'; @@ -2078,6 +2082,10 @@ sub _parse_mapping_reverse { _warn("Unable to reverse-map command: " . join('', @ex_buf)); return; } + + my $escaped_leader = quotemeta($settings->{map_leader}->{value}); + $string =~ s/$escaped_leader/<Leader>/g; + # Convert char to <char-name>. $string =~ s/ /<Space>/g; $string =~ s/\n/<CR>/g; @@ -2092,6 +2100,9 @@ sub _parse_mapping_reverse { sub _parse_partial_command_reverse { my ($string) = @_; + my $escaped_leader = quotemeta($settings->{map_leader}->{value}); + $string =~ s/$escaped_leader/<Leader>/g; + # Convert Ctrl-X to ^X. $string =~ s/([\x01-\x1A])/"^" . chr(ord($1) + 64)/ge; # Convert Ctrl-6 and Ctrl-^ to <C-^>. @@ -2331,8 +2342,10 @@ sub got_key { $input_buf_timer = Irssi::timeout_add_once(10, \&handle_input_buffer, undef); print "Buffer Timer tag: $input_buf_timer" if DEBUG; + } elsif ($mode == M_INS) { - if ($key == 3) { # Ctrl-C enter command mode + + if ($key == 3) { # Ctrl-C enters command mode _update_mode(M_CMD); _stop(); return; @@ -2392,6 +2405,13 @@ sub got_key { Irssi::statusbar_items_redraw("vim_mode"); } elsif ($mode == M_EX) { + + if ($key == 3) { # C-c cancels Ex mdoe as well. + _update_mode(M_CMD); + _stop(); + return; + } + handle_command_ex($key); } } @@ -2830,7 +2850,7 @@ sub _tab_complete { sub vim_mode_init { Irssi::signal_add_first 'gui key pressed' => \&got_key; - Irssi::statusbar_item_register ('vim_mode', 0, 'vim_mode_cb'); + Irssi::statusbar_item_register ('vim_mode', 0, 'vim_mode_cb'); Irssi::statusbar_item_register ('vim_windows', 0, 'b_windows_cb'); # Register all available settings. @@ -2838,6 +2858,10 @@ sub vim_mode_init { _setting_register($name); } + foreach my $char ('a' .. 'z') { + $registers->{$char} = ''; + } + setup_changed(); Irssi::signal_add 'setup changed' => \&setup_changed; @@ -2856,6 +2880,8 @@ sub vim_mode_init { if ($settings->{start_cmd}->{value}) { _update_mode(M_CMD); + } else { + _update_mode(M_INS); } } @@ -3040,7 +3066,7 @@ sub delete_map { } push @add, $keys; - # Restore default keybindings in case we :unmaped a <Nop> or a remapped + # Restore default keybindings in case we :unmapped a <Nop> or a remapped # key. foreach my $key (@add) { if (exists $commands->{$key}) { |