From 4d83ae6e3f6044e3e4c9bf1d87054c13ce5751a6 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Wed, 6 Apr 2011 11:18:11 +0100 Subject: vim_mode: C-c cancels ex mode. Start of variable support. --- vim-mode/vim_mode.pl | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index e247e35..d04324e 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -538,6 +538,8 @@ my $settings ex_history_size => { type => S_INT, value => 100 }, # prompt_leading_space prompt_leading_space => { type => S_BOOL, value => 1 }, + # value for prepending to commands. + map_leader => { type => S_STR, value => '\\' }, }; sub DEBUG { $settings->{debug}->{value} } @@ -2040,6 +2042,7 @@ sub _parse_mapping { my ($string) = @_; $string =~ s/<([^>]+)>/_parse_mapping_bracket($1)/ge; + _warn("Parse mapping: $string"); if (index($string, '') != -1) { return undef; } @@ -2065,6 +2068,8 @@ sub _parse_mapping_bracket { # } 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 = ''; @@ -2074,6 +2079,9 @@ sub _parse_mapping_bracket { sub _parse_mapping_reverse { my ($string) = @_; + my $escaped_leader = quotemeta($settings->{map_leader}->{value}); + $string =~ s/$escaped_leader//g; + # Convert char to . $string =~ s/ //g; $string =~ s/\n//g; @@ -2088,6 +2096,9 @@ sub _parse_mapping_reverse { sub _parse_partial_command_reverse { my ($string) = @_; + my $escaped_leader = quotemeta($settings->{map_leader}->{value}); + $string =~ s/$escaped_leader//g; + # Convert Ctrl-X to ^X. $string =~ s/([\x01-\x1A])/"^" . chr(ord($1) + 64)/ge; # Convert Ctrl-6 and Ctrl-^ to . @@ -2327,8 +2338,8 @@ 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 + } elsif ($mode == M_INS or $mode == M_EX) { + if ($key == 3) { # Ctrl-C enters command mode, or cancels ex mode. _update_mode(M_CMD); _stop(); return; @@ -3032,7 +3043,7 @@ sub delete_map { } push @add, $keys; - # Restore default keybindings in case we :unmaped a or a remapped + # Restore default keybindings in case we :unmapped a or a remapped # key. foreach my $key (@add) { if (exists $commands->{$key}) { -- cgit v1.2.3 From 2b4ab381564d4d68b387113b51915646ae928dfb Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Thu, 7 Apr 2011 00:47:11 +0100 Subject: updates to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 507e2dc..80ea4ea 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /nightfrog /modules/*/*.so /modules/*/*.o +/vim-mode/TAGS -- cgit v1.2.3 From 05c157bad1b47d1e861708c581c5c2620909d007 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Thu, 7 Apr 2011 00:47:47 +0100 Subject: vim-mode/vim_mode: cleanup of commands, and fix bug preventing ex mode from working (oops). --- vim-mode/vim_mode.pl | 78 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index d04324e..906905f 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 => '', func => \&cmd_h, type => C_NORMAL }, ' ' => { char => '', 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 @@ -604,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; @@ -647,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()); @@ -2338,8 +2337,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 or $mode == M_EX) { - if ($key == 3) { # Ctrl-C enters command mode, or cancels ex mode. + + } elsif ($mode == M_INS) { + + if ($key == 3) { # Ctrl-C enters command mode _update_mode(M_CMD); _stop(); return; @@ -2399,6 +2400,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); } } @@ -2833,7 +2841,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. @@ -2841,6 +2849,10 @@ sub vim_mode_init { _setting_register($name); } + foreach my $char ('a' .. 'z') { + $registers->{$char} = ''; + } + setup_changed(); Irssi::signal_add 'setup changed' => \&setup_changed; @@ -2859,6 +2871,8 @@ sub vim_mode_init { if ($settings->{start_cmd}->{value}) { _update_mode(M_CMD); + } else { + _update_mode(M_INS); } } -- cgit v1.2.3