diff options
Diffstat (limited to '')
-rw-r--r-- | vim-mode/vim_mode.pl | 66 |
1 files changed, 38 insertions, 28 deletions
diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index b9818bd..d61db3d 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -403,7 +403,7 @@ my $commands '~' => { char => '~', func => \&cmd_tilde, type => C_NORMAL, repeatable => 1, no_operator => 1 }, '"' => { char => '"', func => \&cmd_register, type => C_NEEDSKEY, - no_operator => 1, dont_clear_partial_keys => 1 }, + no_operator => 1 }, '.' => { char => '.', type => C_NORMAL, repeatable => 1, no_operator => 1 }, ':' => { char => ':', type => C_NORMAL }, @@ -527,10 +527,6 @@ my $numeric_prefix = undef; my $operator = undef; # vi movements, only used when a movement needs more than one key (like f t). my $movement = undef; - -# current partial command = all pending keys currently entered -my $partial_command = ''; - # last vi command, used by . my $last = { @@ -1476,8 +1472,6 @@ sub cmd_register { return (undef, undef); } - $partial_command .= $char; - # make sure black hole register is always empty if ($char eq '_') { $registers->{_} = ''; @@ -1905,6 +1899,16 @@ sub _parse_mapping_reverse { return $string; } +sub _parse_partial_command_reverse { + my ($string) = @_; + + # Convert Ctrl-X to ^X. + $string =~ s/([\x01-\x1A])/"^" . chr(ord($1) + 64)/ge; + # Convert Ctrl-6 and Ctrl-^ to <C-^>. + $string =~ s/\x1E/^^/g; + + return $string; +} sub ex_source { my ($arg_str, $count) = @_; @@ -2065,10 +2069,27 @@ sub vim_mode_cb { $mode_str = '%_Ex%_'; } else { $mode_str = '%_Command%_'; - if ($partial_command) { - my $p_copy = $partial_command; - $p_copy =~ s/\\/\\\\\\\\/g; - $mode_str .= " ($p_copy)"; + if ($register ne '"' or $numeric_prefix or $operator or $movement or + $pending_map) { + my $partial = ''; + if ($register ne '"') { + $partial .= '"' . $register; + } + if ($numeric_prefix) { + $partial .= $numeric_prefix; + } + if ($operator) { + $partial .= $operator->{char}; + } + if ($movement) { + $partial .= $movement->{char}; + } + if (defined $pending_map) { + $partial .= $pending_map; + } + $partial = _parse_partial_command_reverse($partial); + $partial =~ s/\\/\\\\\\\\/g; + $mode_str .= " ($partial)"; } } $sb_item->default_handler($get_size_only, "{sb $mode_str}", '', 0); @@ -2284,7 +2305,6 @@ sub handle_command_cmd { ($char =~ m/[1-9]/ or ($numeric_prefix && $char =~ m/[0-9]/))) { print "Processing numeric prefix: $char" if DEBUG; handle_numeric_prefix($char); - $partial_command .= $char; return 1; # call _stop() } @@ -2303,8 +2323,6 @@ sub handle_command_cmd { } elsif (exists $maps->{$char}) { $map = $maps->{$char}; - $partial_command .= $char; - # We have multiple mappings starting with this key sequence. if (!$pending_map_flushed and scalar keys %{$map->{maps}} > 0) { if (not defined $pending_map) { @@ -2324,7 +2342,6 @@ sub handle_command_cmd { print "No mapping found for $char" if DEBUG; $pending_map = undef; $numeric_prefix = undef; - $partial_command = ''; return 1; # call _stop() } @@ -2335,7 +2352,6 @@ sub handle_command_cmd { # Make sure we have a valid $cmd. if (not defined $cmd) { print "Bug in pending_map_flushed() $map->{char}" if DEBUG; - $partial_command = ''; return 1; # call _stop() } @@ -2346,7 +2362,6 @@ sub handle_command_cmd { $cmd->{func}->(substr($cmd->{char}, 1), $numeric_prefix); $numeric_prefix = undef; - $partial_command = ''; return 1; # call _stop() # As can irssi commands. } elsif ($cmd->{type} == C_IRSSI) { @@ -2354,14 +2369,12 @@ sub handle_command_cmd { Irssi::command($cmd->{func}); $numeric_prefix = undef; - $partial_command = ''; return 1; # call _stop(); # <Nop> does nothing. } elsif ($cmd->{type} == C_NOP) { print "Processing <Nop>: $map->{char}" if DEBUG; $numeric_prefix = undef; - $partial_command = ''; return 1; # call _stop(); } @@ -2393,6 +2406,9 @@ sub handle_command_cmd { # Restore position for yy. if ($cmd == $commands->{y}) { _input_pos($pos); + # And save undo for other operators. + } else { + _add_undo_entry(_input(), _input_pos()); } if ($register ne '"') { print 'Changing register to "' if DEBUG; @@ -2402,7 +2418,6 @@ sub handle_command_cmd { $numeric_prefix = undef; $operator = undef; $movement = undef; - $partial_command = ''; # Set new operator. } else { $operator = $cmd; @@ -2526,10 +2541,6 @@ sub handle_command_cmd { $last->{movement} = $movement; $last->{register} = $register; } - - if (!$cmd->{dont_clear_partial_keys}) { - $partial_command = ''; - } } # Reset the count unless we go into insert mode, _update_mode() needs @@ -2802,10 +2813,12 @@ sub delete_map { sub _commit_line { _update_mode(M_INS); - _reset_undo_buffer('', 0); + # separate from call above as _update_mode() does additional internal work # and we need to make sure it gets correctly called. _update_mode(M_CMD) if $settings->{start_cmd}->{value}; + + _reset_undo_buffer('', 0); } sub _input { @@ -2897,8 +2910,6 @@ sub _update_mode { # It's necessary when pressing enter so the next line can be repeated. } elsif ($mode == M_CMD and $new_mode == M_INS) { $last->{cmd} = $commands->{i}; - - $partial_command = ''; # Make sure prompt is cleared when leaving ex mode. } elsif ($mode == M_EX and $new_mode != M_EX) { _set_prompt(''); @@ -2918,7 +2929,6 @@ sub _update_mode { $register = '"'; $pending_map = undef; - $partial_command = ''; # Also clear ex-mode buffer. @ex_buf = (); |