From 79db18ffd51b7469e0793f5878d3e5509f22e9da Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Thu, 7 Oct 2010 00:39:15 +0100 Subject: updated config with some handy aliases. --- test/irssi/config | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/test/irssi/config b/test/irssi/config index 3fb5019..3b32ee9 100644 --- a/test/irssi/config +++ b/test/irssi/config @@ -166,7 +166,7 @@ aliases = { botaway = "/away auto-away [\002BX\002-MsgLog On] (Away since 1:43 am Mon Aug 24)"; vim = "script load vim_mode.pl"; unvim = "/script unload vim_mode"; - prompt = "script load prompt_replace.pl"; + pl = "script load prompt_replace.pl"; }; statusbar = { @@ -268,9 +268,10 @@ statusbar = { }; prompt = { items = { - new_prompt = { priority = "0"; }; + uberprompt = { priority = "-1"; }; input = { priority = "10"; }; }; + position = "100"; }; promptadd = { disabled = "yes"; }; }; @@ -288,6 +289,8 @@ settings = { mass_hilight_action = "/echo $nick"; mass_hilight_threshold = "0"; vim_mode_debug = "yes"; + superprompt_format = "%K[%W$tag%c/%K$cumode%n$*%K]%n "; + uberprompt_format = "[$*] "; }; "fe-common/core" = { bell_beeps = "yes"; }; "irc/core" = { ctcp_userinfo_reply = ""; }; @@ -304,5 +307,9 @@ keyboard = ( { key = "meta-h"; id = "command"; data = "echo moo /echo moo"; }, { key = "meta-q"; id = "command"; data = "echo bacons"; }, { key = "meta-c"; id = "command"; data = "echo moo ; /echo bar"; }, - { key = "meta-l"; id = "command"; data = "visual "; } + { key = "meta-l"; id = "command"; data = "visual "; }, + { key = "meta-m"; id = "command"; data = "redraw "; }, + { key = "^V"; id = "command"; data = "visual "; }, + { key = "^F"; id = "command"; data = "visual toggle"; }, + { key = "^G"; id = "command"; data = "visual clear"; } ); -- cgit v1.2.3 From 7a8b3aa0ea4571c278d68cea51c4ccd10fc7a011 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Fri, 8 Oct 2010 21:22:24 +0200 Subject: vim_mode: Fix display of 'more' statusbar when scrolling. Reported by estragib. --- vim-mode/vim_mode.pl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 28e254d..feea4c6 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -1300,6 +1300,8 @@ sub cmd_ctrl_d { $count = $window->{height} / 2; } $window->view()->scroll($count); + + Irssi::statusbar_items_redraw('more'); return (undef, undef); } sub cmd_ctrl_u { @@ -1311,6 +1313,8 @@ sub cmd_ctrl_u { $count = $window->{height} / 2; } $window->view()->scroll($count * -1); + + Irssi::statusbar_items_redraw('more'); return (undef, undef); } sub cmd_ctrl_f { @@ -1318,13 +1322,14 @@ sub cmd_ctrl_f { my $window = Irssi::active_win(); $window->view()->scroll($count * $window->{height}); + + Irssi::statusbar_items_redraw('more'); return (undef, undef); } sub cmd_ctrl_b { my ($count, $pos, $repeat) = @_; - cmd_ctrl_f($count * -1, $pos, $repeat); - return (undef, undef); + return cmd_ctrl_f($count * -1, $pos, $repeat); } sub cmd_ctrl_wj { -- cgit v1.2.3 From 61f3be581251267d6d10969e28771505889b20ba Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Fri, 8 Oct 2010 21:35:37 +0200 Subject: vim_mode: Fix :map with {rhs} with only one char. --- vim-mode/vim_mode.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index feea4c6..5d6dfe1 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -1574,7 +1574,7 @@ sub ex_map { my ($arg_str) = @_; # :map {lhs} {rhs} - if ($arg_str =~ /^map (\S+) (\S.+)$/) { + if ($arg_str =~ /^map (\S+) (\S.*)$/) { my $lhs = _parse_mapping($1); my $rhs = $2; @@ -1683,7 +1683,7 @@ sub ex_source { chomp $line; # :map {lhs} {rhs}, keep in sync with ex_map() - if ($line =~ /^\s*map (\S+) (\S.+)$/) { + if ($line =~ /^\s*map (\S+) (\S.*)$/) { ex_map($line); } else { _warn_ex('source', "command not supported: $line"); -- cgit v1.2.3 From 2feb53299d4a8303cb5d34e31f3af960bbe04209 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Fri, 8 Oct 2010 20:41:26 +0100 Subject: added TODO file based on rudi_s' list. --- vim-mode/TODO | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 vim-mode/TODO diff --git a/vim-mode/TODO b/vim-mode/TODO new file mode 100644 index 0000000..c7358d6 --- /dev/null +++ b/vim-mode/TODO @@ -0,0 +1,49 @@ +- fix known bugs and known todos! +- esc is a little slow as ins->cmd mode key +- 3"ap doesn't work but "a3p does +- search with / and ? in history + first search on current line, then wrap to history +- implement tab completion for ex-mode +- recheck everything end of the line related +- marks +- text-objects +- 2daW doesn't work at end of line, should do nothing +- undo/redo positions aren't perfect yet +- :imap +- :map +- custom scripts (vim-like functions) which can be mapped + - surroundings, with an external script if somebody writes it +- Ctrl-R = to evaluate expressions, first only simple math +- Ctrl-R shouldn't have a timeout in insert mode +- % + + # Ignore invalid operator/char combinations. + #} elsif ($operator and ($char eq 'j' or $char eq 'k')) { + # # FIXME + # print "Invalid operator/char: $operator $char" if DEBUG; + # $skip = 1; + +- undo/redo positions _suck_ +- cc/dd . doesn't work + +- daw is not correctly displayed in status line, it shows d_a instead of da + +- :map ,, w + :map ,,, b + ,,, - very short pause - ,,, doesn't work; possibly because of + flush_pending_map(). + +- support :map gX iINSERT TEXT and similar stuff (suggested by estragib) +- it would be nice if :ls somehow indicated current and alternate buffer + (maybe activity too?) (suggested by estragib) +- :map irssi functions, like :map /clear (/ sounds good as prefix), + suggested by estragib +- add :mkvimrc to write mappings to .irssi/vim_moderc, suggested by estragib +- < estragib> oh, i can't map \ either + < estragib> hehe, definitely something to do with escaping. \\ prints \ +- "-- more --" isn't removed when scrolling down with command-mode scroll + commands +- < estragib> there's a minimal difference to vim when yanking with yB: + abc def ghi jklbhyBP + < estragib> vim : abc def ghighi jkl + < estragib> vim-mode: abc def ghi ghi jkl -- cgit v1.2.3 From 38f9d6cd9bee0940367500ae0223b2320edf80c2 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Fri, 8 Oct 2010 22:27:33 +0200 Subject: vim_mode: :map supports in {rhs}. --- vim-mode/vim_mode.pl | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 5d6dfe1..07968d4 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -82,14 +82,15 @@ # # {lhs} is the key combination to be mapped, {rhs} the target. The <> notation # is used (e.g. is Ctrl-F), case is ignored. Supported <> keys: -# -, , , , . Mapping ex-mode and irssi commands -# is supported. Only default mappings can be used in {rhs}. +# -, , , , , . Mapping ex-mode and irssi +# commands is supported. Only default mappings can be used in {rhs}. # Examples: # :map w W # to remap w to work like W # :map gb :bnext # to map gb to call :bnext # :map gB :bprev # :map /clear # map Ctrl-L to irssi command /clear # :map /window goto 1 +# :map - disable , it does nothing now # # # The following irssi settings are available: @@ -243,6 +244,8 @@ sub C_INSERT () { 4 } sub C_EX () { 5 } # irssi commands sub C_IRSSI () { 6 } +# does nothing +sub C_NOP () { 7 } # word and non-word regex, keep in sync with setup_changed()! my $word = qr/[\w_]/o; @@ -1598,6 +1601,12 @@ sub ex_map { func => substr($rhs, 1), type => C_IRSSI, }; + # does nothing + } elsif (lc $rhs eq '') { + $command = { char => '', + func => undef, + type => C_NOP, + }; # command-mode command } else { $rhs = _parse_mapping($2); @@ -2044,6 +2053,10 @@ sub handle_command_cmd { print "Processing irssi-command: $map->{char} ($cmd->{char})" if DEBUG; Irssi::command($cmd->{func}); return 1; # call _stop(); + # does nothing. + } elsif ($cmd->{type} == C_NOP) { + print "Processing : $map->{char}" if DEBUG; + return 1; # call _stop(); } # text-objects (i a) are simulated with $movement -- cgit v1.2.3 From e369746edd750d429fc1c98f798350f811709dc7 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Fri, 8 Oct 2010 22:33:05 +0200 Subject: vim_mode: Update documentation. --- vim-mode/vim_mode.pl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 07968d4..3a2bdec 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -67,7 +67,7 @@ # :bp[rev] - switch to previous window # * Close window: :bd[elete] # * Display windows: :ls :buffers -# * Display registers: :reg[isters] :di[splay] {args} +# * Display registers: :reg[isters] {args} :di[splay] {args} # * Display undolist: :undol[ist] (mostly used for debugging) # * Source files :so[urce] - only sources vim_moderc at the moment, # {file} not supported @@ -85,10 +85,10 @@ # -, , , , , . Mapping ex-mode and irssi # commands is supported. Only default mappings can be used in {rhs}. # Examples: -# :map w W # to remap w to work like W -# :map gb :bnext # to map gb to call :bnext +# :map w W - to remap w to work like W +# :map gb :bnext - to map gb to call :bnext # :map gB :bprev -# :map /clear # map Ctrl-L to irssi command /clear +# :map /clear - map Ctrl-L to irssi command /clear # :map /window goto 1 # :map - disable , it does nothing now # -- cgit v1.2.3 From 04adf6f39a5941c9475f77e4676df3c545881039 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Fri, 8 Oct 2010 22:33:34 +0200 Subject: vim_mode: Update TODO file. --- vim-mode/TODO | 4 ---- 1 file changed, 4 deletions(-) diff --git a/vim-mode/TODO b/vim-mode/TODO index c7358d6..7b83c7c 100644 --- a/vim-mode/TODO +++ b/vim-mode/TODO @@ -8,9 +8,7 @@ - marks - text-objects - 2daW doesn't work at end of line, should do nothing -- undo/redo positions aren't perfect yet - :imap -- :map - custom scripts (vim-like functions) which can be mapped - surroundings, with an external script if somebody writes it - Ctrl-R = to evaluate expressions, first only simple math @@ -36,8 +34,6 @@ - support :map gX iINSERT TEXT and similar stuff (suggested by estragib) - it would be nice if :ls somehow indicated current and alternate buffer (maybe activity too?) (suggested by estragib) -- :map irssi functions, like :map /clear (/ sounds good as prefix), - suggested by estragib - add :mkvimrc to write mappings to .irssi/vim_moderc, suggested by estragib - < estragib> oh, i can't map \ either < estragib> hehe, definitely something to do with escaping. \\ prints \ -- cgit v1.2.3 From d2263ffcb0d32517a60c3093e87702179cff5a9d Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Fri, 8 Oct 2010 22:58:22 +0200 Subject: vim_mode: Add :mkv[imrc]. --- vim-mode/vim_mode.pl | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 3a2bdec..f18fb09 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -73,6 +73,7 @@ # {file} not supported # * Mappings: :map - display custom mappings # :map {lhs} {rhs} - add mapping +# * Save mappings: :mkv[imrc] - like in Vim, but [file] not supported # * Substitute: :s/// - i and g are supported as flags, only /// can be # used as separator, uses Perl regex instead of # Vim regex @@ -383,6 +384,8 @@ my $commands_ex map => { char => ':map', func => \&ex_map, type => C_EX }, source => { char => ':source', func => \&ex_source, type => C_EX }, so => { char => ':so', func => \&ex_source, type => C_EX }, + mkvimrc => { char => ':mkvimrc', func => \&ex_mkvimrc, type => C_EX }, + mkv => { char => ':mkv', func => \&ex_mkvimrc, type => C_EX }, }; # MAPPINGS @@ -1700,6 +1703,29 @@ sub ex_source { } } +sub ex_mkvimrc { + # :mkv[imrc], [file] not supported + + my $vim_moderc = Irssi::get_irssi_dir(). '/vim_moderc'; + if (-f $vim_moderc) { + return _warn_ex('mkvimrc', "$vim_moderc already exists"); + } + + open my $file, '>', $vim_moderc or return; + + # copied from ex_map() + foreach my $key (sort keys %$maps) { + my $map = $maps->{$key}; + my $cmd = $map->{cmd}; + if (defined $cmd) { + next if $map->{char} eq $cmd->{char}; # skip default mappings + print $file "$map->{char} $cmd->{char}\n"; + } + } + + close $file; +} + sub _warn_ex { my ($command, $description) = @_; my $message = "Error in ex-mode command $command"; -- cgit v1.2.3 From ff5fb6c40953421e40f4118473547096474f35de Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sat, 9 Oct 2010 01:17:49 +0200 Subject: vim_mode: Fix :map with ex-commands. Broken in d736f605126e368124b3ff8ed4db5b28f83b650f. --- vim-mode/vim_mode.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index f18fb09..065411e 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -2072,7 +2072,7 @@ sub handle_command_cmd { # ex-mode command doesn't need any additional arguments. if ($cmd->{type} == C_EX) { print "Processing ex-command: $map->{char} ($cmd->{char})" if DEBUG; - $cmd->{func}->($cmd->{char}); + $cmd->{func}->(substr $cmd->{char}, 1); return 1; # call _stop() # As can irssi commands. } elsif ($cmd->{type} == C_IRSSI) { -- cgit v1.2.3 From 3389ded1e95cb545ac83f5c8194ef4c0dbd43429 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sat, 9 Oct 2010 01:20:03 +0200 Subject: vim_mode: Fix :mkv[imrc]. --- vim-mode/vim_mode.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 065411e..6f219dc 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -1719,7 +1719,7 @@ sub ex_mkvimrc { my $cmd = $map->{cmd}; if (defined $cmd) { next if $map->{char} eq $cmd->{char}; # skip default mappings - print $file "$map->{char} $cmd->{char}\n"; + print $file "map $map->{char} $cmd->{char}\n"; } } -- cgit v1.2.3 From da1f8fac4198a8fa88f9e5e61e1fd1283b914b50 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sat, 9 Oct 2010 01:29:08 +0200 Subject: vim_moderc: Add [!] to :mkv[imrc]. --- vim-mode/vim_mode.pl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 6f219dc..575d697 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -73,7 +73,7 @@ # {file} not supported # * Mappings: :map - display custom mappings # :map {lhs} {rhs} - add mapping -# * Save mappings: :mkv[imrc] - like in Vim, but [file] not supported +# * Save mappings: :mkv[imrc][!] - like in Vim, but [file] not supported # * Substitute: :s/// - i and g are supported as flags, only /// can be # used as separator, uses Perl regex instead of # Vim regex @@ -1704,10 +1704,12 @@ sub ex_source { } sub ex_mkvimrc { - # :mkv[imrc], [file] not supported + my ($arg_str) = @_; + + # :mkv[imrc][!], [file] not supported my $vim_moderc = Irssi::get_irssi_dir(). '/vim_moderc'; - if (-f $vim_moderc) { + if (-f $vim_moderc and $arg_str !~ /^mkv(?:imrc)?!$/) { return _warn_ex('mkvimrc', "$vim_moderc already exists"); } -- cgit v1.2.3 From a676f809891739c143f52c52c72e28ef296ccc15 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sat, 9 Oct 2010 01:57:10 +0200 Subject: vim_mode: Fix vim_mode.pl crash with invalid regex in :b. --- vim-mode/vim_mode.pl | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 575d697..4eacf55 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -1520,10 +1520,16 @@ sub ex_buffer { Irssi::command('window last'); # Go to best regex matching window. } else { - my $matches = _matching_windows($buffer); - if (scalar @$matches > 0) { - $window = @$matches[0]->{window}; - $item = @$matches[0]->{item}; + eval { + my $matches = _matching_windows($buffer); + if (scalar @$matches > 0) { + $window = @$matches[0]->{window}; + $item = @$matches[0]->{item}; + } + }; + # Catch errors in /$buffer/ regex. + if ($@) { + _warn($@); } } @@ -1831,8 +1837,14 @@ sub b_windows_cb { my $buffer = $1; if ($buffer !~ /^[0-9]$/ and $buffer ne '#') { # Display matching windows. - my $matches = _matching_windows($buffer); - $windows = join ',', map { $_->{text} } @$matches; + eval { + my $matches = _matching_windows($buffer); + $windows = join ',', map { $_->{text} } @$matches; + }; + # Catch errors in /$buffer/ regex. + if ($@) { + _warn($@); + } } } -- cgit v1.2.3 From 587ea385a19bed9e389d55d43e428be9cfede575 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sat, 9 Oct 2010 02:09:10 +0200 Subject: vim_mode: Update TODO file. --- vim-mode/TODO | 3 --- 1 file changed, 3 deletions(-) diff --git a/vim-mode/TODO b/vim-mode/TODO index 7b83c7c..e225f3e 100644 --- a/vim-mode/TODO +++ b/vim-mode/TODO @@ -34,11 +34,8 @@ - support :map gX iINSERT TEXT and similar stuff (suggested by estragib) - it would be nice if :ls somehow indicated current and alternate buffer (maybe activity too?) (suggested by estragib) -- add :mkvimrc to write mappings to .irssi/vim_moderc, suggested by estragib - < estragib> oh, i can't map \ either < estragib> hehe, definitely something to do with escaping. \\ prints \ -- "-- more --" isn't removed when scrolling down with command-mode scroll - commands - < estragib> there's a minimal difference to vim when yanking with yB: abc def ghi jklbhyBP < estragib> vim : abc def ghighi jkl -- cgit v1.2.3 From 2fc2e4fb9822362c9a94e3222ca5e4d10813faf3 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sat, 9 Oct 2010 02:27:17 +0200 Subject: vim_mode: Remove unnecessary sub cmd_space(), use cmd_l(). --- vim-mode/vim_mode.pl | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 4eacf55..9cc1ae4 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -269,7 +269,7 @@ my $commands # arrow like movement h => { char => 'h', func => \&cmd_h, type => C_NORMAL }, l => { char => 'l', func => \&cmd_l, type => C_NORMAL }, - ' ' => { char => '', func => \&cmd_space, type => C_NORMAL }, + ' ' => { char => '', func => \&cmd_l, type => C_NORMAL }, # history movement j => { char => 'j', func => \&cmd_j, type => C_NORMAL }, k => { char => 'k', func => \&cmd_k, type => C_NORMAL }, @@ -627,10 +627,6 @@ sub cmd_l { $pos = _fix_input_pos($pos, $length); return (undef, $pos); } -sub cmd_space { - my ($count, $pos, $repeat) = @_; - return cmd_l($count, $pos); -} # later history (down) sub cmd_j { -- cgit v1.2.3 From 9acb5260382391d327a85566e1addcf1dcea5af8 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sat, 9 Oct 2010 15:33:24 +0200 Subject: vim_mode: Prevent invalid operator/command combinations. --- vim-mode/vim_mode.pl | 85 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 31 deletions(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 9cc1ae4..ad75ede 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -271,11 +271,14 @@ my $commands l => { char => 'l', func => \&cmd_l, type => C_NORMAL }, ' ' => { char => '', func => \&cmd_l, type => C_NORMAL }, # history movement - j => { char => 'j', func => \&cmd_j, type => C_NORMAL }, - k => { char => 'k', func => \&cmd_k, type => C_NORMAL }, - gg => { char => 'gg', func => \&cmd_gg, type => C_NORMAL }, + 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 }, + 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 }, @@ -307,58 +310,71 @@ my $commands '$' => { char => '$', func => \&cmd_dollar, type => C_NORMAL }, # delete chars x => { char => 'x', func => \&cmd_x, type => C_NORMAL, - repeatable => 1 }, + repeatable => 1, no_operator => 1 }, X => { char => 'X', func => \&cmd_X, type => C_NORMAL, - repeatable => 1 }, + repeatable => 1, no_operator => 1 }, + # C_NORMAL is correct, operator c takes care of insert mode s => { char => 's', func => \&cmd_s, type => C_NORMAL, - repeatable => 1 }, # operator c takes care of insert mode + repeatable => 1, no_operator => 1 }, + # C_NORMAL is correct, operator c takes care of insert mode S => { char => 'S', func => \&cmd_S, type => C_NORMAL, - repeatable => 1 }, # operator c takes care of insert mode + repeatable => 1, no_operator => 1 }, # insert mode i => { char => 'i', func => \&cmd_i, type => C_INSERT, - repeatable => 1 }, + repeatable => 1, no_operator => 1 }, I => { char => 'I', func => \&cmd_I, type => C_INSERT, - repeatable => 1 }, + repeatable => 1, no_operator => 1 }, a => { char => 'a', func => \&cmd_a, type => C_INSERT, - repeatable => 1 }, + repeatable => 1, no_operator => 1 }, A => { char => 'A', func => \&cmd_A, type => C_INSERT, - repeatable => 1 }, + repeatable => 1, no_operator => 1 }, # replace r => { char => 'r', func => \&cmd_r, type => C_NEEDSKEY, - repeatable => 1 }, + repeatable => 1, no_operator => 1 }, # paste p => { char => 'p', func => \&cmd_p, type => C_NORMAL, - repeatable => 1 }, + repeatable => 1, no_operator => 1 }, P => { char => 'P', func => \&cmd_P, type => C_NORMAL, - repeatable => 1 }, + repeatable => 1, no_operator => 1 }, # to end of line C => { char => 'C', func => \&cmd_C, type => C_NORMAL, - repeatable => 1 }, + repeatable => 1, no_operator => 1 }, D => { char => 'D', func => \&cmd_D, type => C_NORMAL, - repeatable => 1 }, + repeatable => 1, no_operator => 1 }, # scrolling - "\x05" => { char => '', func => \&cmd_ctrl_d, type => C_NORMAL }, + "\x05" => { char => '', func => \&cmd_ctrl_d, type => C_NORMAL, + no_operator => 1 }, "\x04" => { char => '', func => \&cmd_ctrl_d, type => C_NORMAL, - needs_count => 1 }, - "\x19" => { char => '', func => \&cmd_ctrl_u, type => C_NORMAL }, + needs_count => 1, no_operator => 1 }, + "\x19" => { char => '', func => \&cmd_ctrl_u, type => C_NORMAL, + no_operator => 1 }, "\x15" => { char => '', func => \&cmd_ctrl_u, type => C_NORMAL, - needs_count => 1 }, - "\x06" => { char => '', func => \&cmd_ctrl_f, type => C_NORMAL }, - "\x02" => { char => '', func => \&cmd_ctrl_b, type => C_NORMAL }, + needs_count => 1, no_operator => 1 }, + "\x06" => { char => '', func => \&cmd_ctrl_f, type => C_NORMAL, + no_operator => 1 }, + "\x02" => { char => '', func => \&cmd_ctrl_b, type => C_NORMAL, + no_operator => 1 }, # window switching - "\x17j" => { char => 'j', func => \&cmd_ctrl_wj, type => C_NORMAL }, - "\x17k" => { char => 'k', func => \&cmd_ctrl_wk, type => C_NORMAL }, - "\x1e" => { char => '', func => \&cmd_ctrl_6, type => C_NORMAL }, + "\x17j" => { char => 'j', func => \&cmd_ctrl_wj, type => C_NORMAL, + no_operator => 1 }, + "\x17k" => { char => 'k', func => \&cmd_ctrl_wk, type => C_NORMAL, + no_operator => 1 }, + "\x1e" => { char => '', func => \&cmd_ctrl_6, type => C_NORMAL, + no_operator => 1 }, # misc '~' => { char => '~', func => \&cmd_tilde, type => C_NORMAL, - repeatable => 1 }, - '"' => { char => '"', func => \&cmd_register, type => C_NEEDSKEY }, - '.' => { char => '.', type => C_NORMAL, repeatable => 1 }, + repeatable => 1, no_operator => 1 }, + '"' => { char => '"', func => \&cmd_register, type => C_NEEDSKEY, + no_operator => 1 }, + '.' => { char => '.', type => C_NORMAL, repeatable => 1, + no_operator => 1 }, ':' => { char => ':', type => C_NORMAL }, "\n" => { char => '', type => C_NORMAL }, # return # undo - 'u' => { char => 'u', func => \&cmd_undo, type => C_NORMAL }, - "\x12" => { char => '', func => \&cmd_redo, type => C_NORMAL }, + 'u' => { char => 'u', func => \&cmd_undo, type => C_NORMAL, + no_operator => 1 }, + "\x12" => { char => '', func => \&cmd_redo, type => C_NORMAL, + no_operator => 1 }, }; # All available commands in Ex-Mode. @@ -2174,6 +2190,13 @@ sub handle_command_cmd { } } + # Ignore invalid operator/command combinations. + if ($operator and $cmd->{no_operator}) { + print "Invalid operator/command: $operator->{char} $cmd->{char}" + if DEBUG; + $skip = 1; + } + if ($skip) { print "Skipping movement and operator." if DEBUG; } else { -- cgit v1.2.3 From dd2e9a766e4fc7de278681f4658ba42c8b74e2a5 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sat, 9 Oct 2010 15:59:31 +0200 Subject: vim_mode: Add :unm[ap] {lhs}. --- vim-mode/vim_mode.pl | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index ad75ede..9d8e04b 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -73,6 +73,7 @@ # {file} not supported # * Mappings: :map - display custom mappings # :map {lhs} {rhs} - add mapping +# :unm[ap] {lhs} - remove custom mapping # * Save mappings: :mkv[imrc][!] - like in Vim, but [file] not supported # * Substitute: :s/// - i and g are supported as flags, only /// can be # used as separator, uses Perl regex instead of @@ -92,6 +93,7 @@ # :map /clear - map Ctrl-L to irssi command /clear # :map /window goto 1 # :map - disable , it does nothing now +# :unmap - restore default behavior of after disabling it # # # The following irssi settings are available: @@ -398,6 +400,8 @@ my $commands_ex undolist => { char => ':undolist', func => \&ex_undolist, type => C_EX }, undol => { char => ':undol', func => \&ex_undolist, type => C_EX }, map => { char => ':map', func => \&ex_map, type => C_EX }, + unmap => { char => ':unmap', func => \&ex_unmap, type => C_EX }, + unm => { char => ':unm', func => \&ex_unmap, type => C_EX }, source => { char => ':source', func => \&ex_source, type => C_EX }, so => { char => ':so', func => \&ex_source, type => C_EX }, mkvimrc => { char => ':mkvimrc', func => \&ex_mkvimrc, type => C_EX }, @@ -1657,6 +1661,25 @@ sub ex_map { _warn_ex('map'); } } +sub ex_unmap { + my ($arg_str) = @_; + + # :unm[ap] {lhs} + if ($arg_str !~ /^unm(?:ap)? (\S+)$/) { + return _warn_ex('unmap'); + } + + my $lhs = _parse_mapping($1); + if (not defined $lhs) { + return _warn_ex('unmap', 'invalid {lhs}'); + # Prevent unmapping of unknown or default mappings. + } elsif (not exists $maps->{$lhs} or not defined $maps->{$lhs}->{cmd} or + ($commands->{$lhs} and $maps->{$lhs}->{cmd} == $commands->{$lhs})) { + return _warn_ex('unmap', "$1 not found"); + } + + delete_map($lhs); +} sub _parse_mapping { my ($string) = @_; @@ -2485,6 +2508,45 @@ sub add_map { $maps->{$keys}->{char} = _parse_mapping_reverse($keys); $maps->{$keys}->{cmd} = $command; } +sub delete_map { + my ($keys) = @_; + + # Abort for non-existent mappings or placeholder mappings. + return if not exists $maps->{$keys} or not defined $maps->{$keys}->{cmd}; + + my @add = (); + + # If no maps need the current key, then remove it and all other + # unnecessary keys in the "tree". + if (keys %{$maps->{$keys}->{maps}} == 0) { + my $tmp = $keys; + while (length $tmp > 1) { + my $map = substr $tmp, -1, 1, ''; + delete $maps->{$tmp}->{maps}->{$tmp . $map}; + if (not $maps->{$tmp}->{cmd} and keys %{$maps->{$tmp}->{maps}} == 0) { + push @add, $tmp; + delete $maps->{$tmp}; + } else { + last; + } + } + } + + if (keys %{$maps->{$keys}->{maps}} > 0) { + $maps->{$keys}->{cmd} = undef; + } else { + delete $maps->{$keys}; + } + push @add, $keys; + + # Restore default keybindings in case we :unmaped a or a remapped + # key. + foreach my $key (@add) { + if (exists $commands->{$key}) { + add_map($key, $commands->{$key}); + } + } +} sub _commit_line { -- cgit v1.2.3 From 90352618f680723a1a6a6cf59aec93917d64dbb1 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sat, 9 Oct 2010 16:39:29 +0100 Subject: factored all the visual stuff out of prompt_replace into its own file. --- prompt_info/prompt_replace.pl | 171 +++------------------------------------ prompt_info/visual.pl | 184 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 196 insertions(+), 159 deletions(-) create mode 100644 prompt_info/visual.pl diff --git a/prompt_info/prompt_replace.pl b/prompt_info/prompt_replace.pl index 20fb7b1..c9bfcc8 100644 --- a/prompt_info/prompt_replace.pl +++ b/prompt_info/prompt_replace.pl @@ -25,41 +25,10 @@ sub DEBUG () { 1 } my $prompt_data = undef; my $prompt_item = undef; -my $region_active = 0; - -my ($term_w, $term_h) = (0, 0); - -# visual region selected. -my ($region_start, $region_end) = (0, 0); -my $region_content = ''; - my $prompt_format = ''; init(); -sub update_terminal_size { - - my @stty_data = qx/stty -a/; - my $line = $stty_data[0]; - - # linux - # speed 38400 baud; rows 36; columns 126; line = 0; - if ($line =~ m/rows (\d+); columns (\d+);/) { - $term_h = $1; - $term_w = $2; - # osx - # speed 9600 baud; 40 rows; 235 columns; - } elsif ($line =~ m/(\d+) rows; (\d+) columns;/) { - $term_h = $1; - $term_w = $2; - } else { - # guess? - $term_h = 24; - $term_w = 80; - } - - print "Terminal detected as $term_w cols by $term_h rows" if DEBUG; -} sub prompt_subcmd_handler { my ($data, $server, $item) = @_; @@ -67,57 +36,21 @@ sub prompt_subcmd_handler { Irssi::command_runsub('prompt', $data, $server, $item); } -sub visual_subcmd_handler { - my ($data, $server, $item) = @_; - $data =~ s/\s+$//g; # strip trailing whitespace. - Irssi::command_runsub('visual', $data, $server, $item); -} - sub init { - Irssi::statusbar_item_register ('uberprompt', 0, 'uberprompt_draw'); + Irssi::statusbar_item_register('uberprompt', 0, 'uberprompt_draw'); Irssi::settings_add_str('uberprompt', 'uberprompt_format', '[$*] '); - Irssi::command_bind("prompt", \&prompt_subcmd_handler); - Irssi::command_bind('prompt on', \&replace_prompt_items); + Irssi::command_bind("prompt", \&prompt_subcmd_handler); + Irssi::command_bind('prompt on', \&replace_prompt_items); Irssi::command_bind('prompt off', \&restore_prompt_items); Irssi::command_bind('prompt set', sub { Irssi::signal_emit 'change prompt', shift; }); Irssi::command_bind('prompt clear', sub { Irssi::signal_emit 'change prompt', '$p'; }); - # misc faff - Irssi::command_bind('visual', \&visual_subcmd_handler); - Irssi::command_bind('visual toggle', \&cmd_toggle_visual); - Irssi::command_bind('visual clear', \&cmd_clear_visual); - - Irssi::command("^BIND ^F /visual toggle"); - Irssi::command("^BIND ^G /visual clear"); - - Irssi::command_bind 'print_test', - sub { - Irssi::gui_printtext(0, 0, '%8hello there%n'); - }; - - # redraw interception - Irssi::signal_add_last('command redraw', \&augment_redraw); - Irssi::signal_add_first('gui key pressed', \&ctrl_l_intercept); - - # for updating the overlay. - Irssi::signal_add_last ('gui key pressed', \&key_pressed); - - # things to refresh the overlay for. - Irssi::signal_add('window changed', \&uberprompt_refresh); - Irssi::signal_add('window name changed', \&uberprompt_refresh); - Irssi::signal_add('window changed automatic', \&uberprompt_refresh); - Irssi::signal_add('window item changed', \&uberprompt_refresh); - - Irssi::signal_add('terminal resized', \&update_terminal_size); - Irssi::signal_add('setup changed', \&reload_settings); - - # so we know where the bottom line is - update_terminal_size(); + Irssi::signal_add('setup changed', \&reload_settings); # intialise the prompt format. reload_settings(); @@ -128,13 +61,12 @@ sub init { # the actual API signal. Irssi::signal_register({'change prompt' => [qw/string/]}); Irssi::signal_add('change prompt' => \&change_prompt_sig); - - } sub change_prompt_sig { my ($text) = @_; + # TODO: mroe intelligence about where to insert $p? $text = '$p' . $text; print "Got prompt change sig with: $text" if DEBUG; @@ -149,9 +81,9 @@ sub change_prompt_sig { } } - sub UNLOAD { # remove uberprompt and return the original ones. + print "Removing uberprompt and restoring original"; restore_prompt_items(); } @@ -187,19 +119,19 @@ sub uberprompt_draw { } else { $p_copy = $default_prompt; } + $p_copy =~ s/\$/\$\$/g; # escape all $ symbols + $p_copy =~ s/\\/\\\\/g; # escape backslashes. + print "Redrawing with: $p_copy, size-only: $get_size_only" if DEBUG; $prompt_item = $sb_item; - $sb_item->default_handler($get_size_only, $p_copy, '', 0); -} + my $ret = $sb_item->default_handler($get_size_only, $p_copy, '', 0); -sub augment_redraw { - print "Redraw called" if DEBUG; - uberprompt_refresh(); - Irssi::timeout_add_once(10, \&refresh_visual_overlay, 0); + return $ret; } + sub uberprompt_refresh { Irssi::statusbar_items_redraw('uberprompt'); } @@ -211,82 +143,6 @@ sub cmd_clear_visual { Irssi::statusbar_items_redraw('input'); } -sub cmd_toggle_visual { - - $region_active = not $region_active; - - if ($region_active) { - $region_start = _pos(); - $region_end = 0; # reset end marker. - print "visual mode started at $region_start" if DEBUG; - } else { - $region_end = _pos(); - print "Visual mode ended at $region_end" if DEBUG; - - if ($region_end > $region_start) { - my $input = Irssi::parse_special('$L', 0, 0); - my $str = substr($input, $region_start, $region_end - $region_start); - print "Region selected: $str" if DEBUG; - } else { - print "Invalid region selection: [ $region_start - $region_end ]" - if DEBUG; - $region_start = $region_end = 0; - } - cmd_clear_visual(); - } -} - -sub ctrl_l_intercept { - my $key = shift; - - if ($key == 12) { # C-l - print "C-l pressed" if DEBUG; - Irssi::command("redraw"); - Irssi::signal_stop(); - } elsif ($key == 10) { # RET - _clear_visual_region(); - } -} - -sub key_pressed { - # this handler needs to be last so the actual character is printed by irssi - # before we overlay on it. Otherwise things are all a bit off-by-1 - return unless $region_active; - - refresh_visual_overlay(); -} - -sub _clear_visual_region { - print "Clearing Region markers" if DEBUG; - $region_end = 0; - $region_start = 0; -} - - -sub refresh_visual_overlay { - - my $end_pos = $region_end; - $end_pos ||= _pos(); # if not set, take current position as end. - - my $len = $end_pos - $region_start; - return unless $len; # no point drawing an empty overlay - - my $input = Irssi::parse_special('$L'); - my $offset = $prompt_item->{size} + $region_start; - - my $text = substr($input, $region_start, $len); - - print "printing '$text' at $offset [$region_start, $end_pos] ($len)" if DEBUG; - - $text = '%8' . $text . '%8'; - _draw_overlay($offset, $text, $len); - -} - -sub _draw_overlay { - my ($offset, $text, $len) = @_; - Irssi::gui_printtext($offset, $term_h, $text); -} sub replace_prompt_items { # remove existing ones. @@ -332,9 +188,6 @@ sub _sbar_command { Irssi::command($command); } -sub _pos { - return Irssi::gui_input_get_pos(); -} # bit of fakery so things don't complain about the lack of prompt_info (hoepfully) diff --git a/prompt_info/visual.pl b/prompt_info/visual.pl new file mode 100644 index 0000000..5941fe0 --- /dev/null +++ b/prompt_info/visual.pl @@ -0,0 +1,184 @@ +use strict; +use warnings; + +use Irssi; +use Irssi::TextUI; # for sbar_items_redraw +use Data::Dumper; + + + +our $VERSION = "0.1"; +our %IRSSI = + ( + authors => "shabble", + contact => 'shabble+irssi@metavore.org, shabble@#irssi/Freenode', + name => "prompt_info", + description => "Helper script for dynamically adding text " + . "into the input-bar prompt.", + license => "Public Domain", + changed => "24/7/2010" + ); + +sub DEBUG () { 1 } +#sub DEBUG () { 0 } + +my $region_active = 0; + +my ($term_w, $term_h) = (0, 0); + +# visual region selected. +my ($region_start, $region_end) = (0, 0); +my $region_content = ''; + +sub update_terminal_size { + + my @stty_data = qx/stty -a/; + my $line = $stty_data[0]; + + # linux + # speed 38400 baud; rows 36; columns 126; line = 0; + if ($line =~ m/rows (\d+); columns (\d+);/) { + $term_h = $1; + $term_w = $2; + # osx + # speed 9600 baud; 40 rows; 235 columns; + } elsif ($line =~ m/(\d+) rows; (\d+) columns;/) { + $term_h = $1; + $term_w = $2; + } else { + # guess? + $term_h = 24; + $term_w = 80; + } + + print "Terminal detected as $term_w cols by $term_h rows" if DEBUG; +} + +sub visual_subcmd_handler { + my ($data, $server, $item) = @_; + $data =~ s/\s+$//g; # strip trailing whitespace. + Irssi::command_runsub('visual', $data, $server, $item); +} + +sub init { + + # misc faff + Irssi::command_bind('visual', \&visual_subcmd_handler); + Irssi::command_bind('visual toggle', \&cmd_toggle_visual); + Irssi::command_bind('visual clear', \&cmd_clear_visual); + + Irssi::command("^BIND ^F /visual toggle"); + Irssi::command("^BIND ^G /visual clear"); + + Irssi::command_bind 'print_test', + sub { + Irssi::gui_printtext(0, 0, '%8hello there%n'); + }; + + # redraw interception + Irssi::signal_add_last('command redraw', \&augment_redraw); + Irssi::signal_add_first('gui key pressed', \&ctrl_l_intercept); + + # for updating the overlay. + Irssi::signal_add_last ('gui key pressed', \&key_pressed); + + # things to refresh the overlay for. + Irssi::signal_add('window changed', \&uberprompt_refresh); + Irssi::signal_add('window name changed', \&uberprompt_refresh); + Irssi::signal_add('window changed automatic', \&uberprompt_refresh); + Irssi::signal_add('window item changed', \&uberprompt_refresh); + + Irssi::signal_add('terminal resized', \&update_terminal_size); + + # so we know where the bottom line is + update_terminal_size(); + + +} +sub augment_redraw { + print "Redraw called" if DEBUG; + uberprompt_refresh(); + Irssi::timeout_add_once(10, \&refresh_visual_overlay, 0); +} + + +sub cmd_toggle_visual { + + $region_active = not $region_active; + + if ($region_active) { + $region_start = _pos(); + $region_end = 0; # reset end marker. + print "visual mode started at $region_start" if DEBUG; + } else { + $region_end = _pos(); + print "Visual mode ended at $region_end" if DEBUG; + + if ($region_end > $region_start) { + my $input = Irssi::parse_special('$L', 0, 0); + my $str = substr($input, $region_start, $region_end - $region_start); + print "Region selected: $str" if DEBUG; + } else { + print "Invalid region selection: [ $region_start - $region_end ]" + if DEBUG; + $region_start = $region_end = 0; + } + cmd_clear_visual(); + } +} + +sub ctrl_l_intercept { + my $key = shift; + + if ($key == 12) { # C-l + print "C-l pressed" if DEBUG; + Irssi::command("redraw"); + Irssi::signal_stop(); + } elsif ($key == 10) { # RET + _clear_visual_region(); + } +} + +sub key_pressed { + # this handler needs to be last so the actual character is printed by irssi + # before we overlay on it. Otherwise things are all a bit off-by-1 + return unless $region_active; + + refresh_visual_overlay(); +} + +sub _clear_visual_region { + print "Clearing Region markers" if DEBUG; + $region_end = 0; + $region_start = 0; +} + + +sub refresh_visual_overlay { + + my $end_pos = $region_end; + $end_pos ||= _pos(); # if not set, take current position as end. + + my $len = $end_pos - $region_start; + return unless $len; # no point drawing an empty overlay + + my $input = Irssi::parse_special('$L'); + my $offset = $prompt_item->{size} + $region_start; + + my $text = substr($input, $region_start, $len); + + print "printing '$text' at $offset [$region_start, $end_pos] ($len)" if DEBUG; + + $text = '%8' . $text . '%8'; + _draw_overlay($offset, $text, $len); + +} + +sub _draw_overlay { + my ($offset, $text, $len) = @_; + Irssi::gui_printtext($offset, $term_h, $text); +} + +sub _pos { + return Irssi::gui_input_get_pos(); +} -- cgit v1.2.3 From 7dd9bb7fe62e4ec10a80bd8df7942ee33e203e87 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sat, 9 Oct 2010 16:40:44 +0100 Subject: renamed prompt_replace to uberprompt --- prompt_info/prompt_replace.pl | 195 ------------------------------------------ prompt_info/uberprompt.pl | 195 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 195 insertions(+), 195 deletions(-) delete mode 100644 prompt_info/prompt_replace.pl create mode 100644 prompt_info/uberprompt.pl diff --git a/prompt_info/prompt_replace.pl b/prompt_info/prompt_replace.pl deleted file mode 100644 index c9bfcc8..0000000 --- a/prompt_info/prompt_replace.pl +++ /dev/null @@ -1,195 +0,0 @@ -use strict; -use warnings; - -use Irssi; -use Irssi::TextUI; # for sbar_items_redraw -use Data::Dumper; - - - -our $VERSION = "0.1"; -our %IRSSI = - ( - authors => "shabble", - contact => 'shabble+irssi@metavore.org, shabble@#irssi/Freenode', - name => "prompt_info", - description => "Helper script for dynamically adding text " - . "into the input-bar prompt.", - license => "Public Domain", - changed => "24/7/2010" - ); - -sub DEBUG () { 1 } -#sub DEBUG () { 0 } - -my $prompt_data = undef; -my $prompt_item = undef; - -my $prompt_format = ''; - -init(); - - -sub prompt_subcmd_handler { - my ($data, $server, $item) = @_; - $data =~ s/\s+$//g; # strip trailing whitespace. - Irssi::command_runsub('prompt', $data, $server, $item); -} - -sub init { - - Irssi::statusbar_item_register('uberprompt', 0, 'uberprompt_draw'); - - Irssi::settings_add_str('uberprompt', 'uberprompt_format', '[$*] '); - - Irssi::command_bind("prompt", \&prompt_subcmd_handler); - Irssi::command_bind('prompt on', \&replace_prompt_items); - Irssi::command_bind('prompt off', \&restore_prompt_items); - Irssi::command_bind('prompt set', - sub { Irssi::signal_emit 'change prompt', shift; }); - Irssi::command_bind('prompt clear', - sub { Irssi::signal_emit 'change prompt', '$p'; }); - - Irssi::signal_add('setup changed', \&reload_settings); - - # intialise the prompt format. - reload_settings(); - - # install our statusbars. - replace_prompt_items(); - - # the actual API signal. - Irssi::signal_register({'change prompt' => [qw/string/]}); - Irssi::signal_add('change prompt' => \&change_prompt_sig); -} - -sub change_prompt_sig { - my ($text) = @_; - - # TODO: mroe intelligence about where to insert $p? - $text = '$p' . $text; - print "Got prompt change sig with: $text" if DEBUG; - - my $changed; - $changed = defined $prompt_data ? $prompt_data ne $text : 1; - - $prompt_data = $text; - - if ($changed) { - print "Redrawing prompt" if DEBUG; - uberprompt_refresh(); - } -} - -sub UNLOAD { - # remove uberprompt and return the original ones. - print "Removing uberprompt and restoring original"; - restore_prompt_items(); -} - -sub reload_settings { - my $new = Irssi::settings_get_str('uberprompt_format'); - if ($prompt_format ne $new) { - print "Updated prompt format" if DEBUG; - $prompt_format = $new; - Irssi::abstracts_register(['uberprompt', $prompt_format]); - } -} - -sub uberprompt_draw { - my ($sb_item, $get_size_only) = @_; - - my $default_prompt = ''; - - my $window = Irssi::active_win; - - # hack to produce the same defaults as prompt/prompt_empty sbars. - - if (scalar( () = $window->items )) { - $default_prompt = '{uberprompt $[.15]itemname}'; - } else { - $default_prompt = '{uberprompt $winname}'; - } - - my $p_copy = $prompt_data; - - if (defined $prompt_data) { - # replace the special marker '$p' with the original prompt. - $p_copy =~ s/\$p/$default_prompt/; - } else { - $p_copy = $default_prompt; - } - $p_copy =~ s/\$/\$\$/g; # escape all $ symbols - $p_copy =~ s/\\/\\\\/g; # escape backslashes. - - print "Redrawing with: $p_copy, size-only: $get_size_only" if DEBUG; - - $prompt_item = $sb_item; - - my $ret = $sb_item->default_handler($get_size_only, $p_copy, '', 0); - - return $ret; -} - - -sub uberprompt_refresh { - Irssi::statusbar_items_redraw('uberprompt'); -} - - -sub cmd_clear_visual { - _clear_visual_region(); - #refresh_visual_overlay(); - Irssi::statusbar_items_redraw('input'); -} - - -sub replace_prompt_items { - # remove existing ones. - print "Removing original prompt" if DEBUG; - - _sbar_command('prompt', 'remove', 'prompt'); - _sbar_command('prompt', 'remove', 'prompt_empty'); - - # add the new one. - - _sbar_command('prompt', 'add', 'uberprompt', - qw/-alignment left -before input -priority '-1'/); - - _sbar_command('prompt', 'position', '100'); -} - -sub restore_prompt_items { - - _sbar_command('prompt', 'remove', 'uberprompt'); - - print "Restoring original prompt" if DEBUG; - - _sbar_command('prompt', 'add', 'prompt', - qw/-alignment left -before input -priority '-1'/); - _sbar_command('prompt', 'add', 'prompt_empty', - qw/-alignment left -after prompt -priority '-1'/); - - _sbar_command('prompt', 'position', '100'); - -} - -sub _sbar_command { - my ($bar, $cmd, $item, @args) = @_; - - my $args_str = join ' ', @args; - - $args_str .= ' ' if length $args_str && defined $item; - - my $command = sprintf 'STATUSBAR %s %s %s%s', - $bar, $cmd, $args_str, defined($item)?$item:''; - - print "Running command: $command" if DEBUG; - Irssi::command($command); -} - - - -# bit of fakery so things don't complain about the lack of prompt_info (hoepfully) - -%Irssi::Script::prompt_info:: = (); diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl new file mode 100644 index 0000000..c9bfcc8 --- /dev/null +++ b/prompt_info/uberprompt.pl @@ -0,0 +1,195 @@ +use strict; +use warnings; + +use Irssi; +use Irssi::TextUI; # for sbar_items_redraw +use Data::Dumper; + + + +our $VERSION = "0.1"; +our %IRSSI = + ( + authors => "shabble", + contact => 'shabble+irssi@metavore.org, shabble@#irssi/Freenode', + name => "prompt_info", + description => "Helper script for dynamically adding text " + . "into the input-bar prompt.", + license => "Public Domain", + changed => "24/7/2010" + ); + +sub DEBUG () { 1 } +#sub DEBUG () { 0 } + +my $prompt_data = undef; +my $prompt_item = undef; + +my $prompt_format = ''; + +init(); + + +sub prompt_subcmd_handler { + my ($data, $server, $item) = @_; + $data =~ s/\s+$//g; # strip trailing whitespace. + Irssi::command_runsub('prompt', $data, $server, $item); +} + +sub init { + + Irssi::statusbar_item_register('uberprompt', 0, 'uberprompt_draw'); + + Irssi::settings_add_str('uberprompt', 'uberprompt_format', '[$*] '); + + Irssi::command_bind("prompt", \&prompt_subcmd_handler); + Irssi::command_bind('prompt on', \&replace_prompt_items); + Irssi::command_bind('prompt off', \&restore_prompt_items); + Irssi::command_bind('prompt set', + sub { Irssi::signal_emit 'change prompt', shift; }); + Irssi::command_bind('prompt clear', + sub { Irssi::signal_emit 'change prompt', '$p'; }); + + Irssi::signal_add('setup changed', \&reload_settings); + + # intialise the prompt format. + reload_settings(); + + # install our statusbars. + replace_prompt_items(); + + # the actual API signal. + Irssi::signal_register({'change prompt' => [qw/string/]}); + Irssi::signal_add('change prompt' => \&change_prompt_sig); +} + +sub change_prompt_sig { + my ($text) = @_; + + # TODO: mroe intelligence about where to insert $p? + $text = '$p' . $text; + print "Got prompt change sig with: $text" if DEBUG; + + my $changed; + $changed = defined $prompt_data ? $prompt_data ne $text : 1; + + $prompt_data = $text; + + if ($changed) { + print "Redrawing prompt" if DEBUG; + uberprompt_refresh(); + } +} + +sub UNLOAD { + # remove uberprompt and return the original ones. + print "Removing uberprompt and restoring original"; + restore_prompt_items(); +} + +sub reload_settings { + my $new = Irssi::settings_get_str('uberprompt_format'); + if ($prompt_format ne $new) { + print "Updated prompt format" if DEBUG; + $prompt_format = $new; + Irssi::abstracts_register(['uberprompt', $prompt_format]); + } +} + +sub uberprompt_draw { + my ($sb_item, $get_size_only) = @_; + + my $default_prompt = ''; + + my $window = Irssi::active_win; + + # hack to produce the same defaults as prompt/prompt_empty sbars. + + if (scalar( () = $window->items )) { + $default_prompt = '{uberprompt $[.15]itemname}'; + } else { + $default_prompt = '{uberprompt $winname}'; + } + + my $p_copy = $prompt_data; + + if (defined $prompt_data) { + # replace the special marker '$p' with the original prompt. + $p_copy =~ s/\$p/$default_prompt/; + } else { + $p_copy = $default_prompt; + } + $p_copy =~ s/\$/\$\$/g; # escape all $ symbols + $p_copy =~ s/\\/\\\\/g; # escape backslashes. + + print "Redrawing with: $p_copy, size-only: $get_size_only" if DEBUG; + + $prompt_item = $sb_item; + + my $ret = $sb_item->default_handler($get_size_only, $p_copy, '', 0); + + return $ret; +} + + +sub uberprompt_refresh { + Irssi::statusbar_items_redraw('uberprompt'); +} + + +sub cmd_clear_visual { + _clear_visual_region(); + #refresh_visual_overlay(); + Irssi::statusbar_items_redraw('input'); +} + + +sub replace_prompt_items { + # remove existing ones. + print "Removing original prompt" if DEBUG; + + _sbar_command('prompt', 'remove', 'prompt'); + _sbar_command('prompt', 'remove', 'prompt_empty'); + + # add the new one. + + _sbar_command('prompt', 'add', 'uberprompt', + qw/-alignment left -before input -priority '-1'/); + + _sbar_command('prompt', 'position', '100'); +} + +sub restore_prompt_items { + + _sbar_command('prompt', 'remove', 'uberprompt'); + + print "Restoring original prompt" if DEBUG; + + _sbar_command('prompt', 'add', 'prompt', + qw/-alignment left -before input -priority '-1'/); + _sbar_command('prompt', 'add', 'prompt_empty', + qw/-alignment left -after prompt -priority '-1'/); + + _sbar_command('prompt', 'position', '100'); + +} + +sub _sbar_command { + my ($bar, $cmd, $item, @args) = @_; + + my $args_str = join ' ', @args; + + $args_str .= ' ' if length $args_str && defined $item; + + my $command = sprintf 'STATUSBAR %s %s %s%s', + $bar, $cmd, $args_str, defined($item)?$item:''; + + print "Running command: $command" if DEBUG; + Irssi::command($command); +} + + + +# bit of fakery so things don't complain about the lack of prompt_info (hoepfully) + +%Irssi::Script::prompt_info:: = (); -- cgit v1.2.3 From b39c8d2a1472f75ffeb0dd3215f65a6930373ab8 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sat, 9 Oct 2010 16:49:50 +0100 Subject: actually properly fixed the escaping of stuff now. --- prompt_info/uberprompt.pl | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index c9bfcc8..0a2dc6a 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -61,6 +61,11 @@ sub init { # the actual API signal. Irssi::signal_register({'change prompt' => [qw/string/]}); Irssi::signal_add('change prompt' => \&change_prompt_sig); + + # other scripts (specifically overlay/visual) can subscribe to + # this event to be notified when the prompt changes. + # arguments are new contents (string), new length (int) + Irssi::signal_register({'prompt changed' => [qw/string int/]}); } sub change_prompt_sig { @@ -104,7 +109,7 @@ sub uberprompt_draw { my $window = Irssi::active_win; # hack to produce the same defaults as prompt/prompt_empty sbars. - + print Dumper($sb_item); if (scalar( () = $window->items )) { $default_prompt = '{uberprompt $[.15]itemname}'; } else { @@ -115,19 +120,21 @@ sub uberprompt_draw { if (defined $prompt_data) { # replace the special marker '$p' with the original prompt. - $p_copy =~ s/\$p/$default_prompt/; + $p_copy =~ s/\$/\$\$/g; # escape all $ symbols + $p_copy =~ s/\\/\\\\/g; # escape backslashes. + + $p_copy =~ s/\$\$p/$default_prompt/; + } else { $p_copy = $default_prompt; } - $p_copy =~ s/\$/\$\$/g; # escape all $ symbols - $p_copy =~ s/\\/\\\\/g; # escape backslashes. print "Redrawing with: $p_copy, size-only: $get_size_only" if DEBUG; $prompt_item = $sb_item; my $ret = $sb_item->default_handler($get_size_only, $p_copy, '', 0); - + #Irssi::signal_emit('prompt changed', return $ret; } -- cgit v1.2.3 From d80d66a287910526f119c06bcecff42a7ab15b79 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sat, 9 Oct 2010 17:27:24 +0100 Subject: documented uberprompt better, and added the 'prompt changed' signal --- prompt_info/uberprompt.pl | 71 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 3 deletions(-) diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 0a2dc6a..6c012c4 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -1,3 +1,63 @@ +# This script replaces the default prompt status-bar item with one capable +# of displaying additional information, under either user control or via +# scripts. +# +# Installation: +# +# Place script in ~/.irssi/scripts/ and potentially symlink into autorun/ +# to ensure it starts at irssi startup. +# +# If not using autorun, manually load the script via: +# +# /script load uberprompt.pl +# +# Usage: +# +# Although the script is designed primarily for other scripts to set +# status information into the prompt, the following commands are available: +# +# /prompt set - sets the prompt to the given argument. $p in the argument will +# be replaced by the original prompt content. +# /prompt clear - clears the additional data provided to the prompt. +# /prompt on - enables the uberprompt (things may get confused if this is used +# whilst the prompt is already enabled) +# /prompt off - restore the original irssi prompt and prompt_empty statusbars. +# unloading the script has the same effect. +# +# Usage from other Scripts: +# +# signal_emit 'change prompt' 'some_string $p other string'; +# +# will set the prompt to include that content. +# +# You can also be notified when the prompt changes in response to the previous +# signal or manual commands via: +# +# signal_add 'prompt changed', sub { my ($text, $len) = @_; ... do something ... }; +# +# LICENCE: +# +# Copyright (c) 2010 Tom Feist +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + + use strict; use warnings; @@ -15,7 +75,7 @@ our %IRSSI = name => "prompt_info", description => "Helper script for dynamically adding text " . "into the input-bar prompt.", - license => "Public Domain", + license => "MIT", changed => "24/7/2010" ); @@ -108,8 +168,9 @@ sub uberprompt_draw { my $window = Irssi::active_win; + #print Dumper($sb_item); + # hack to produce the same defaults as prompt/prompt_empty sbars. - print Dumper($sb_item); if (scalar( () = $window->items )) { $default_prompt = '{uberprompt $[.15]itemname}'; } else { @@ -134,7 +195,11 @@ sub uberprompt_draw { $prompt_item = $sb_item; my $ret = $sb_item->default_handler($get_size_only, $p_copy, '', 0); - #Irssi::signal_emit('prompt changed', + # TODO: do this properly, and also make sure it's only emitted once per + # change. + + Irssi::signal_emit('prompt changed', $p_copy, $sb_item->{size}); + return $ret; } -- cgit v1.2.3 From 217d7296f79de207639bf4d47cbfd15d54ec5129 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sat, 9 Oct 2010 17:58:39 +0100 Subject: added some debug logging to catch 'prompt changed' --- prompt_info/uberprompt.pl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 6c012c4..6056d3f 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -67,7 +67,7 @@ use Data::Dumper; -our $VERSION = "0.1"; +our $VERSION = "0.2"; our %IRSSI = ( authors => "shabble", @@ -83,7 +83,7 @@ sub DEBUG () { 1 } #sub DEBUG () { 0 } my $prompt_data = undef; -my $prompt_item = undef; +#my $prompt_item = undef; my $prompt_format = ''; @@ -126,6 +126,16 @@ sub init { # this event to be notified when the prompt changes. # arguments are new contents (string), new length (int) Irssi::signal_register({'prompt changed' => [qw/string int/]}); + if (DEBUG) { + Irssi::signal_add 'prompt changed', \&debug_prompt_changed; + } +} + +sub debug_prompt_changed { + my ($text, $len) = @_; + my $exp = Irssi::current_theme()->format_expand($text, 0); + my $ps = Irssi::parse_special($exp); + print "DEBUG: Got $text = $exp = $ps, length: $len"; } sub change_prompt_sig { @@ -192,8 +202,6 @@ sub uberprompt_draw { print "Redrawing with: $p_copy, size-only: $get_size_only" if DEBUG; - $prompt_item = $sb_item; - my $ret = $sb_item->default_handler($get_size_only, $p_copy, '', 0); # TODO: do this properly, and also make sure it's only emitted once per # change. -- cgit v1.2.3 From 73487a72a5988da26f8a57e80d2fa68dfa9d2a01 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sat, 9 Oct 2010 18:01:13 +0100 Subject: moved more functions out into visual.pl, cleaned up some of the formatting. --- prompt_info/uberprompt.pl | 13 ------------- prompt_info/visual.pl | 7 +++++++ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 6056d3f..bf7380b 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -83,13 +83,11 @@ sub DEBUG () { 1 } #sub DEBUG () { 0 } my $prompt_data = undef; -#my $prompt_item = undef; my $prompt_format = ''; init(); - sub prompt_subcmd_handler { my ($data, $server, $item) = @_; $data =~ s/\s+$//g; # strip trailing whitespace. @@ -211,19 +209,10 @@ sub uberprompt_draw { return $ret; } - sub uberprompt_refresh { Irssi::statusbar_items_redraw('uberprompt'); } - -sub cmd_clear_visual { - _clear_visual_region(); - #refresh_visual_overlay(); - Irssi::statusbar_items_redraw('input'); -} - - sub replace_prompt_items { # remove existing ones. print "Removing original prompt" if DEBUG; @@ -268,8 +257,6 @@ sub _sbar_command { Irssi::command($command); } - - # bit of fakery so things don't complain about the lack of prompt_info (hoepfully) %Irssi::Script::prompt_info:: = (); diff --git a/prompt_info/visual.pl b/prompt_info/visual.pl index 5941fe0..1413d0d 100644 --- a/prompt_info/visual.pl +++ b/prompt_info/visual.pl @@ -95,6 +95,13 @@ sub init { } +sub cmd_clear_visual { + _clear_visual_region(); + #refresh_visual_overlay(); + Irssi::statusbar_items_redraw('input'); +} + + sub augment_redraw { print "Redraw called" if DEBUG; uberprompt_refresh(); -- cgit v1.2.3 From 497389336904a9bc1f0fe4d87ed5aae29a0f80d5 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sat, 9 Oct 2010 22:00:07 +0100 Subject: added Bugs section in comments describing crash bug when debug enabled. Rare enough to not really be a problem, I hope. --- prompt_info/uberprompt.pl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index bf7380b..3146c67 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -35,6 +35,12 @@ # # signal_add 'prompt changed', sub { my ($text, $len) = @_; ... do something ... }; # +# Bugs: +# +# * Resizing the terminal rapidly whilst using this script in debug mode +# may cause irssi to crash. See bug report at +# http://bugs.irssi.org/index.php?do=details&task_id=772 for details. +# # LICENCE: # # Copyright (c) 2010 Tom Feist -- cgit v1.2.3 From 6012b57692ee31ad43abf0270fe29f1ed313e6d9 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sat, 9 Oct 2010 22:02:48 +0100 Subject: added doc about uberprompt_format setting --- prompt_info/uberprompt.pl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 3146c67..a192780 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -24,6 +24,18 @@ # /prompt off - restore the original irssi prompt and prompt_empty statusbars. # unloading the script has the same effect. # +# Additionally, the format for the prompt can be set via: +# +# /set uberprompt_format +# +# The default is [$*], which is the same as the default provided in default.theme. +# Changing this setting will update the prompt immediately, unlike editing your theme. +# +# NOTE: this setting completely overrides the prompt="..." line in your .theme +# file, and may cause unexpected behaviour if your theme wishes to set a +# different form of prompt. It can be simply copied from the theme file into +# the above setting. +# # Usage from other Scripts: # # signal_emit 'change prompt' 'some_string $p other string'; -- cgit v1.2.3 From d2e68afdbcf321b2051269e4419478eb7bccc387 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sat, 9 Oct 2010 22:10:20 +0100 Subject: added uberprompt_debug as an irssi setting. defaults to off. --- prompt_info/uberprompt.pl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index a192780..d5f66b2 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -97,8 +97,10 @@ our %IRSSI = changed => "24/7/2010" ); -sub DEBUG () { 1 } -#sub DEBUG () { 0 } + +my $DEBUG_ENABLED = 0; + +sub DEBUG { $DEBUG_ENABLED } my $prompt_data = undef; @@ -117,6 +119,7 @@ sub init { Irssi::statusbar_item_register('uberprompt', 0, 'uberprompt_draw'); Irssi::settings_add_str('uberprompt', 'uberprompt_format', '[$*] '); + Irssi::settings_add_bool('uberprompt', 'uberprompt_debug', 0); Irssi::command_bind("prompt", \&prompt_subcmd_handler); Irssi::command_bind('prompt on', \&replace_prompt_items); @@ -179,6 +182,9 @@ sub UNLOAD { } sub reload_settings { + + $DEBUG_ENABLED = Irssi::settings_get_bool('uberprompt_debug'); + my $new = Irssi::settings_get_str('uberprompt_format'); if ($prompt_format ne $new) { print "Updated prompt format" if DEBUG; -- cgit v1.2.3 From a89e3f5572c010a02a498a542affb0c014c2807e Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 10 Oct 2010 00:35:23 +0200 Subject: vim_mode: Support counts with mapped ex-commands. --- vim-mode/vim_mode.pl | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 9d8e04b..fad440a 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -49,7 +49,9 @@ # * Switch split windows: Ctrl-W j Ctrl-W k # * Undo/Redo: u Ctrl-R # -# Counts and combinations work as well, e.g. d5fx or 3iabc +# Counts and combinations work as well, e.g. d5fx or 3iabc. Counts also +# work with mapped ex-commands (see below), e.g. if you map gb to do :bn, then +# 2gb will switch to the second next buffer. # Repeat also supports counts. # # The following insert mode mappings are supported: @@ -2121,7 +2123,15 @@ sub handle_command_cmd { # ex-mode command doesn't need any additional arguments. if ($cmd->{type} == C_EX) { print "Processing ex-command: $map->{char} ($cmd->{char})" if DEBUG; - $cmd->{func}->(substr $cmd->{char}, 1); + + if (not $numeric_prefix) { + $numeric_prefix = 1; + } + while ($numeric_prefix-- > 0) { + $cmd->{func}->(substr $cmd->{char}, 1); + } + $numeric_prefix = undef; + return 1; # call _stop() # As can irssi commands. } elsif ($cmd->{type} == C_IRSSI) { -- cgit v1.2.3 From fb0e4bbaaf74e9072b5af9d32f9fded2b4a0d50c Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 10 Oct 2010 00:36:22 +0200 Subject: vim_mode: Mapped irssi and commands reset count. --- vim-mode/vim_mode.pl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index fad440a..e866a23 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -2137,10 +2137,14 @@ sub handle_command_cmd { } elsif ($cmd->{type} == C_IRSSI) { print "Processing irssi-command: $map->{char} ($cmd->{char})" if DEBUG; Irssi::command($cmd->{func}); + + $numeric_prefix = undef; return 1; # call _stop(); # does nothing. } elsif ($cmd->{type} == C_NOP) { print "Processing : $map->{char}" if DEBUG; + + $numeric_prefix = undef; return 1; # call _stop(); } -- cgit v1.2.3 From 143ae36a262401892e6fff8f610375ed9c67ffdb Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 10 Oct 2010 01:05:22 +0200 Subject: vim_mode: Allow mappings with numbers. But not as the first key. --- vim-mode/vim_mode.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index e866a23..181d854 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -2066,8 +2066,8 @@ sub handle_command_cmd { } # Counts - if (!$movement and ($char =~ m/[1-9]/ or - ($numeric_prefix && $char =~ m/[0-9]/))) { + if (!$movement and !$pending_map and + ($char =~ m/[1-9]/ or ($numeric_prefix && $char =~ m/[0-9]/))) { print "Processing numeric prefix: $char" if DEBUG; handle_numeric_prefix($char); return 1; # call _stop() -- cgit v1.2.3 From bb2167d04668a8537afdd3217d3786e353048eaa Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 10 Oct 2010 01:11:06 +0200 Subject: vim_mode: Support arguments to mapped ex-arguments. --- vim-mode/vim_mode.pl | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 181d854..879f0e0 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -92,6 +92,7 @@ # :map w W - to remap w to work like W # :map gb :bnext - to map gb to call :bnext # :map gB :bprev +# :map g1 :b 1 - to map g1 to switch to buffer 1 # :map /clear - map Ctrl-L to irssi command /clear # :map /window goto 1 # :map - disable , it does nothing now @@ -1616,11 +1617,14 @@ sub ex_map { my $command; # Ex-mode command if (index($rhs, ':') == 0) { - $rhs = substr $rhs, 1; - if (not exists $commands_ex->{$rhs}) { - return _warn_ex('map', "$2 not found"); + $rhs =~ /^:(\S+)(\s.+)?$/; + if (not exists $commands_ex->{$1}) { + return _warn_ex('map', "$rhs not found"); } else { - $command = $commands_ex->{$rhs}; + $command = { char => $rhs, + func => $commands_ex->{$1}->{func}, + type => C_EX, + }; } # Irssi command } elsif (index($rhs, '/') == 0) { @@ -2119,8 +2123,7 @@ sub handle_command_cmd { return 1; # call _stop() } - # Ex-mode commands can also be bound in command mode. Works only if the - # ex-mode command doesn't need any additional arguments. + # Ex-mode commands can also be bound in command mode. if ($cmd->{type} == C_EX) { print "Processing ex-command: $map->{char} ($cmd->{char})" if DEBUG; -- cgit v1.2.3 From b5f5fceb141736dcfb667f2d5935e0791b9546c6 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 10 Oct 2010 01:26:18 +0200 Subject: vim_mode: Whitespace only change. --- vim-mode/vim_mode.pl | 72 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 24 deletions(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 879f0e0..1746c3b 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -385,30 +385,54 @@ my $commands # All available commands in Ex-Mode. my $commands_ex = { - s => { char => ':s', func => \&ex_substitute, type => C_EX }, - bnext => { char => ':bnext', func => \&ex_bnext, type => C_EX }, - bn => { char => ':bn', func => \&ex_bnext, type => C_EX }, - bprev => { char => ':bprev', func => \&ex_bprev, type => C_EX }, - bp => { char => ':bp', func => \&ex_bprev, type => C_EX }, - bdelete => { char => ':bdelete', func => \&ex_bdelete, type => C_EX }, - bd => { char => ':bd', func => \&ex_bdelete, type => C_EX }, - buffer => { char => ':buffer', func => \&ex_buffer, type => C_EX }, - b => { char => ':b', func => \&ex_buffer, type => C_EX }, - registers => { char => ':registers', func => \&ex_registers, type => C_EX }, - reg => { char => ':reg', func => \&ex_registers, type => C_EX }, - display => { char => ':display', func => \&ex_registers, type => C_EX }, - di => { char => ':di', func => \&ex_registers, type => C_EX }, - buffers => { char => ':buffer', func => \&ex_buffers, type => C_EX }, - ls => { char => ':ls', func => \&ex_buffers, type => C_EX }, - undolist => { char => ':undolist', func => \&ex_undolist, type => C_EX }, - undol => { char => ':undol', func => \&ex_undolist, type => C_EX }, - map => { char => ':map', func => \&ex_map, type => C_EX }, - unmap => { char => ':unmap', func => \&ex_unmap, type => C_EX }, - unm => { char => ':unm', func => \&ex_unmap, type => C_EX }, - source => { char => ':source', func => \&ex_source, type => C_EX }, - so => { char => ':so', func => \&ex_source, type => C_EX }, - mkvimrc => { char => ':mkvimrc', func => \&ex_mkvimrc, type => C_EX }, - mkv => { char => ':mkv', func => \&ex_mkvimrc, type => C_EX }, + s => { char => ':s', func => \&ex_substitute, + type => C_EX }, + bnext => { char => ':bnext', func => \&ex_bnext, + type => C_EX }, + bn => { char => ':bn', func => \&ex_bnext, + type => C_EX }, + bprev => { char => ':bprev', func => \&ex_bprev, + type => C_EX }, + bp => { char => ':bp', func => \&ex_bprev, + type => C_EX }, + bdelete => { char => ':bdelete', func => \&ex_bdelete, + type => C_EX }, + bd => { char => ':bd', func => \&ex_bdelete, + type => C_EX }, + buffer => { char => ':buffer', func => \&ex_buffer, + type => C_EX }, + b => { char => ':b', func => \&ex_buffer, + type => C_EX }, + registers => { char => ':registers', func => \&ex_registers, + type => C_EX }, + reg => { char => ':reg', func => \&ex_registers, + type => C_EX }, + display => { char => ':display', func => \&ex_registers, + type => C_EX }, + di => { char => ':di', func => \&ex_registers, + type => C_EX }, + buffers => { char => ':buffer', func => \&ex_buffers, + type => C_EX }, + ls => { char => ':ls', func => \&ex_buffers, + type => C_EX }, + undolist => { char => ':undolist', func => \&ex_undolist, + type => C_EX }, + undol => { char => ':undol', func => \&ex_undolist, + type => C_EX }, + map => { char => ':map', func => \&ex_map, + type => C_EX }, + unmap => { char => ':unmap', func => \&ex_unmap, + type => C_EX }, + unm => { char => ':unm', func => \&ex_unmap, + type => C_EX }, + source => { char => ':source', func => \&ex_source, + type => C_EX }, + so => { char => ':so', func => \&ex_source, + type => C_EX }, + mkvimrc => { char => ':mkvimrc', func => \&ex_mkvimrc, + type => C_EX }, + mkv => { char => ':mkv', func => \&ex_mkvimrc, + type => C_EX }, }; # MAPPINGS -- cgit v1.2.3 From 7d6d8c7f375ab15e587809773c3af014ed55135f Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 10 Oct 2010 01:51:23 +0200 Subject: vim_mode: Display command in statusbar after flushing pending map. Reported by estragib. --- vim-mode/vim_mode.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 1746c3b..4101579 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -2064,6 +2064,7 @@ sub flush_pending_map { $pending_map ne $old_pending_map; handle_command_cmd(undef); + Irssi::statusbar_items_redraw("vim_mode"); } sub handle_numeric_prefix { -- cgit v1.2.3 From d01581b027fa24fba5a0c1cd73667a1c1fa5a7bb Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 10 Oct 2010 02:47:09 +0200 Subject: vim_mode: Support counts with ex-commands. This supports e.g. :5b, :5bd, :bd 5. --- vim-mode/vim_mode.pl | 117 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 84 insertions(+), 33 deletions(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 4101579..828f5a8 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -60,14 +60,14 @@ # # Ex-mode supports (activated by : in command mode) the following commands: # -# * Switching buffers: :b - switch to channel number -# :b# - switch to last channel +# * Switching buffers: :[N]b [N] - switch to channel number +# :b# - switch to last channel # :b # :b / # :buffer {args} (same as :b) -# :bn[ext] - switch to next window -# :bp[rev] - switch to previous window -# * Close window: :bd[elete] +# :[N]bn[ext] [N] - switch to next window +# :[N]bp[rev] [N] - switch to previous window +# * Close window: :[N]bd[elete] [N] # * Display windows: :ls :buffers # * Display registers: :reg[isters] {args} :di[splay] {args} # * Display undolist: :undol[ist] (mostly used for debugging) @@ -93,6 +93,7 @@ # :map gb :bnext - to map gb to call :bnext # :map gB :bprev # :map g1 :b 1 - to map g1 to switch to buffer 1 +# :map gb :b - to map gb to :b, 1gb switches to buffer 1, 5gb to 5 # :map /clear - map Ctrl-L to irssi command /clear # :map /window goto 1 # :map - disable , it does nothing now @@ -388,21 +389,21 @@ my $commands_ex s => { char => ':s', func => \&ex_substitute, type => C_EX }, bnext => { char => ':bnext', func => \&ex_bnext, - type => C_EX }, + type => C_EX, uses_count => 1 }, bn => { char => ':bn', func => \&ex_bnext, - type => C_EX }, + type => C_EX, uses_count => 1 }, bprev => { char => ':bprev', func => \&ex_bprev, - type => C_EX }, + type => C_EX, uses_count => 1 }, bp => { char => ':bp', func => \&ex_bprev, - type => C_EX }, + type => C_EX, uses_count => 1 }, bdelete => { char => ':bdelete', func => \&ex_bdelete, - type => C_EX }, + type => C_EX, uses_count => 1 }, bd => { char => ':bd', func => \&ex_bdelete, - type => C_EX }, + type => C_EX, uses_count => 1 }, buffer => { char => ':buffer', func => \&ex_buffer, - type => C_EX }, + type => C_EX, uses_count => 1 }, b => { char => ':b', func => \&ex_buffer, - type => C_EX }, + type => C_EX, uses_count => 1 }, registers => { char => ':registers', func => \&ex_registers, type => C_EX }, reg => { char => ':reg', func => \&ex_registers, @@ -1490,19 +1491,26 @@ sub _fix_input_pos { sub cmd_ex_command { my $arg_str = join '', @ex_buf; - if ($arg_str !~ /^([a-z]+)/) { + if ($arg_str !~ /^(\d*)?([a-z]+)/) { return _warn("Invalid Ex-mode command!"); } - if (not exists $commands_ex->{$1}) { - return _warn("Ex-mode $1 doesn't exist!"); + # Abort if command doesn't exist or used with count for unsupported + # commands. + if (not exists $commands_ex->{$2} or + ($1 ne '' and not $commands_ex->{$2}->{uses_count})) { + return _warn("Ex-mode $1$2 doesn't exist!"); } - $commands_ex->{$1}->{func}($arg_str); + my $count = $1; + if ($count eq '') { + $count = undef; + } + $commands_ex->{$2}->{func}($arg_str, $count); } sub ex_substitute { - my ($arg_str) = @_; + my ($arg_str, $count) = @_; # :s/// if ($arg_str =~ m|^s/(.+)/(.*)/([ig]*)|) { @@ -1538,25 +1546,67 @@ sub ex_substitute { } sub ex_bnext { - Irssi::command('window next'); + my ($arg_str, $count) = @_; + + if (not defined $count) { + if ($arg_str =~ /^bn(?:ext)?\s(\d+)$/) { + $count = $1; + } else { + $count = 1; + } + } + + while ($count-- > 0) { + Irssi::command('window next'); + } } sub ex_bprev { - Irssi::command('window previous'); + my ($arg_str, $count) = @_; + + if (not defined $count) { + if ($arg_str =~ /^bp(?:rev)?\s(\d+)$/) { + $count = $1; + } else { + $count = 1; + } + } + + while ($count-- > 0) { + Irssi::command('window previous'); + } } sub ex_bdelete { + my ($arg_str, $count) = @_; + + if (not defined $count) { + if ($arg_str =~ /^bd(?:elete)?\s(\d+)$/) { + $count = $1; + } + } + + if (defined $count) { + my $window = Irssi::window_find_refnum($count); + if (not $window) { + return; + } + $window->set_active(); + } Irssi::command('window close'); } sub ex_buffer { - my ($arg_str) = @_; + my ($arg_str, $count) = @_; # :b[buffer] {args} - if ($arg_str =~ m|^b(?:uffer)?\s*(.+)$|) { + if ($arg_str =~ m|^b(?:uffer)?\s*(.+)$| or defined $count) { my $window; my $item; my $buffer = $1; + # :[N]:b[uffer] + if (defined $count) { + $window = Irssi::window_find_refnum($count); # Go to window number. - if ($buffer =~ /^[0-9]+$/) { + } elsif ($buffer =~ /^[0-9]+$/) { $window = Irssi::window_find_refnum($buffer); # Go to previous window. } elsif ($buffer eq '#') { @@ -1588,7 +1638,7 @@ sub ex_buffer { } sub ex_registers { - my ($arg_str) = @_; + my ($arg_str, $count) = @_; # :reg[isters] {arg} and :di[splay] {arg} if ($arg_str =~ /^(?:reg(?:isters)?|di(?:splay)?)(?:\s+(.+)$)?/) { @@ -1618,15 +1668,19 @@ sub ex_registers { } sub ex_buffers { + my ($arg_str, $count) = @_; + Irssi::command('window list'); } sub ex_undolist { + my ($arg_str, $count) = @_; + _print_undo_buffer(); } sub ex_map { - my ($arg_str) = @_; + my ($arg_str, $count) = @_; # :map {lhs} {rhs} if ($arg_str =~ /^map (\S+) (\S.*)$/) { @@ -1692,7 +1746,7 @@ sub ex_map { } } sub ex_unmap { - my ($arg_str) = @_; + my ($arg_str, $count) = @_; # :unm[ap] {lhs} if ($arg_str !~ /^unm(?:ap)? (\S+)$/) { @@ -1757,6 +1811,8 @@ sub _parse_mapping_reverse { } sub ex_source { + my ($arg_str, $count) = @_; + # :so[urce], but only loads the vim_moderc file at the moment open my $file, '<', Irssi::get_irssi_dir() . '/vim_moderc' or return; @@ -1775,7 +1831,7 @@ sub ex_source { } sub ex_mkvimrc { - my ($arg_str) = @_; + my ($arg_str, $count) = @_; # :mkv[imrc][!], [file] not supported @@ -2152,12 +2208,7 @@ sub handle_command_cmd { if ($cmd->{type} == C_EX) { print "Processing ex-command: $map->{char} ($cmd->{char})" if DEBUG; - if (not $numeric_prefix) { - $numeric_prefix = 1; - } - while ($numeric_prefix-- > 0) { - $cmd->{func}->(substr $cmd->{char}, 1); - } + $cmd->{func}->(substr($cmd->{char}, 1), $numeric_prefix); $numeric_prefix = undef; return 1; # call _stop() -- cgit v1.2.3 From 34fd58554a4369523a02bde26bdd75bf09c76ff0 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 10 Oct 2010 03:13:22 +0200 Subject: vim_mode: Fix :bd from displaying buffers matching d. --- vim-mode/vim_mode.pl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 828f5a8..2eefd66 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -1952,9 +1952,10 @@ sub b_windows_cb { my $windows = ''; - # A little code duplication of cmd_ex_command()! + # A little code duplication of cmd_ex_command(), but \s+ instead of \s* so + # :bd doesn't display buffers matching d. my $arg_str = join '', @ex_buf; - if ($arg_str =~ m|^b(?:uffer)?\s*(.+)$|) { + if ($arg_str =~ m|^b(?:uffer)?\s+(.+)$|) { my $buffer = $1; if ($buffer !~ /^[0-9]$/ and $buffer ne '#') { # Display matching windows. -- cgit v1.2.3 From 5e058e0b5780e504043c75fd5b0af6fca9f99d65 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 10 Oct 2010 03:18:39 +0200 Subject: vim_mode: Document :mapping ex-commands doesn't need . --- vim-mode/vim_mode.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 2eefd66..17e7454 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -87,7 +87,8 @@ # {lhs} is the key combination to be mapped, {rhs} the target. The <> notation # is used (e.g. is Ctrl-F), case is ignored. Supported <> keys: # -, , , , , . Mapping ex-mode and irssi -# commands is supported. Only default mappings can be used in {rhs}. +# commands is supported. When mapping ex-mode commands the trailing is +# not necessary. Only default mappings can be used in {rhs}. # Examples: # :map w W - to remap w to work like W # :map gb :bnext - to map gb to call :bnext -- cgit v1.2.3 From def8af6d0454a8feae873d7df3afedb550807222 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 10 Oct 2010 03:40:37 +0200 Subject: vim_mode: Add known bug. --- vim-mode/vim_mode.pl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 17e7454..f84c523 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -165,6 +165,9 @@ # Known bugs: # # * count before register doesn't work: e.g. 3"ap doesn't work, but "a3p does +# * mapping an incomplete ex-command doesn't open the ex-mode with the partial +# command (e.g. :map gb :b causes an error instead of opening the ex-mode +# and displaying :b) # * undo/redo positions are mostly wrong # # -- cgit v1.2.3 From b97f23c09096d3c40bf15417dad1f6a1e3c447c7 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 10 Oct 2010 03:42:29 +0200 Subject: vim_mode: :map {lhs} displays matching mappings. --- vim-mode/vim_mode.pl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index f84c523..f2bd978 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -74,6 +74,7 @@ # * Source files :so[urce] - only sources vim_moderc at the moment, # {file} not supported # * Mappings: :map - display custom mappings +# :map {lhs} - display mappings starting with {lhs} # :map {lhs} {rhs} - add mapping # :unm[ap] {lhs} - remove custom mapping # * Save mappings: :mkv[imrc][!] - like in Vim, but [file] not supported @@ -1733,14 +1734,18 @@ sub ex_map { } add_map($lhs, $command); - # :map - } elsif ($arg_str eq 'map') { + # :map [lhs] + } elsif ($arg_str eq 'map' or $arg_str =~ /^map (\S+)$/) { + # Necessary for case insensitive matchings. lc alone won't work. + my $search = _parse_mapping_reverse(_parse_mapping($1)); + my $active_window = Irssi::active_win(); foreach my $key (sort keys %$maps) { my $map = $maps->{$key}; my $cmd = $map->{cmd}; if (defined $cmd) { next if $map->{char} eq $cmd->{char}; # skip default mappings + next if $map->{char} !~ /^\Q$search\E/; # skip non-matches $active_window->print(sprintf "%-15s %s", $map->{char}, $cmd->{char}); } -- cgit v1.2.3 From aee98a7b35bba8c93c027ed9042ff24f117e1b2e Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 10 Oct 2010 03:57:52 +0200 Subject: vim_mode: Add in command mode. is also mappable now. --- vim-mode/vim_mode.pl | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index f2bd978..77a4908 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -87,9 +87,9 @@ # # {lhs} is the key combination to be mapped, {rhs} the target. The <> notation # is used (e.g. is Ctrl-F), case is ignored. Supported <> keys: -# -, , , , , . Mapping ex-mode and irssi -# commands is supported. When mapping ex-mode commands the trailing is -# not necessary. Only default mappings can be used in {rhs}. +# -, , , , , , . Mapping ex-mode and +# irssi commands is supported. When mapping ex-mode commands the trailing +# is not necessary. Only default mappings can be used in {rhs}. # Examples: # :map w W - to remap w to work like W # :map gb :bnext - to map gb to call :bnext @@ -278,9 +278,10 @@ 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 }, - ' ' => { char => '', 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 }, @@ -1799,6 +1800,9 @@ sub _parse_mapping_bracket { # } elsif ($string eq 'cr') { $string = "\n"; + # + } elsif ($string eq 'bs') { + $string = chr(127); # Invalid char, return special string to recognize the error. } else { $string = ''; @@ -1811,6 +1815,7 @@ sub _parse_mapping_reverse { # Convert char to . $string =~ s/ //g; $string =~ s/\n//g; + $string =~ s/\x7F//g; # Convert Ctrl-X to . $string =~ s/([\x01-\x1A])/""/ge; # Convert Ctrl-6 and Ctrl-^ to . -- cgit v1.2.3 From a46cff6a006ce5c7488057432fa4e239e0d8519a Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 10 Oct 2010 04:07:09 +0200 Subject: vim_mode: Add to movement docs. --- vim-mode/vim_mode.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 77a4908..e1e92f2 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -22,7 +22,7 @@ # * Insert/Command mode. Escape and Ctrl-C enter command mode. # /set vim_mode_cmd_seq j allows to use jj as Escape (any other character # can be used as well). -# * Cursor motion: h l 0 ^ $ f t F T +# * Cursor motion: h l 0 ^ $ f t F T # * History motion: j k gg G # gg moves to the oldest (first) history line. # G without a count moves to the current input line, with a count it goes to -- cgit v1.2.3 From 1b68997bf5ea9e2bfbb317a12ed9371ee478d494 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 10 Oct 2010 18:16:28 +0200 Subject: vim_mode: Fix B with operators. --- vim-mode/vim_mode.pl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index e1e92f2..4fe334f 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -308,8 +308,7 @@ my $commands ge => { char => 'ge', func => \&cmd_ge, type => C_NORMAL, selection_needs_move_right => 1 }, W => { char => 'W', func => \&cmd_W, type => C_NORMAL }, - B => { char => 'B', func => \&cmd_B, type => C_NORMAL, - selection_needs_move_right => 1 }, + B => { char => 'B', func => \&cmd_B, type => C_NORMAL }, E => { char => 'E', func => \&cmd_E, type => C_NORMAL }, gE => { char => 'gE', func => \&cmd_gE, type => C_NORMAL, selection_needs_move_right => 1 }, -- cgit v1.2.3 From 8291c7aa38cebf5884e919c8a81e884e9b3bc809 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 10 Oct 2010 18:26:09 +0200 Subject: vim_mode: Correctly display pending text-objects. --- vim-mode/vim_mode.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 4fe334f..3dbdebc 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -313,8 +313,8 @@ 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 }, -- cgit v1.2.3 From 7f0cebd0197ebfd93d6b9c7c9f58c7dd10581e9f Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 10 Oct 2010 18:45:08 +0200 Subject: vim_mode: Fix pasting registers containing only "0". Reported by estragib. --- vim-mode/vim_mode.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 3dbdebc..20562a7 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -561,7 +561,7 @@ sub insert_ctrl_r { my ($key) = @_; my $char = chr($key); - return if not defined $registers->{$char} or not $registers->{$char}; + return if not defined $registers->{$char} or $registers->{$char} eq ''; my $pos = _insert_at_position($registers->{$char}, 1, _input_pos()); _input_pos($pos + 1); @@ -1329,7 +1329,7 @@ sub cmd_P { sub _paste_at_position { my ($count, $pos) = @_; - return if not $registers->{$register}; + return if $registers->{$register} eq ''; return _insert_at_position($registers->{$register}, $count, $pos); } -- cgit v1.2.3 From a3c1eabb6272b0cff113a557dba10913e85f4ab1 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sun, 10 Oct 2010 19:03:35 +0100 Subject: added a bunch of documentation (provisional atm, pending implementation), and started cleanup of code --- prompt_info/uberprompt.pl | 117 +++++++++++++++++++++++++++++++--------------- 1 file changed, 79 insertions(+), 38 deletions(-) diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index d5f66b2..f026a91 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -2,7 +2,7 @@ # of displaying additional information, under either user control or via # scripts. # -# Installation: +# INSTALL: # # Place script in ~/.irssi/scripts/ and potentially symlink into autorun/ # to ensure it starts at irssi startup. @@ -11,11 +11,16 @@ # # /script load uberprompt.pl # -# Usage: +# If you have a custom prompt format, you may need to copy it to the +# uberprompt_format setting. See below for details. +# +# USAGE: # # Although the script is designed primarily for other scripts to set # status information into the prompt, the following commands are available: # +# TODO: Document positional settings. +# # /prompt set - sets the prompt to the given argument. $p in the argument will # be replaced by the original prompt content. # /prompt clear - clears the additional data provided to the prompt. @@ -26,21 +31,43 @@ # # Additionally, the format for the prompt can be set via: # +# UBERPROMPT FORMAT: +# # /set uberprompt_format # # The default is [$*], which is the same as the default provided in default.theme. # Changing this setting will update the prompt immediately, unlike editing your theme. # +# An additional variable available within this format is '$uber', which expands to +# the content of prompt data provided with the UP_INNER placement argument. For all +# other placement arguments, it will expand to the empty string ''. +# # NOTE: this setting completely overrides the prompt="..." line in your .theme # file, and may cause unexpected behaviour if your theme wishes to set a # different form of prompt. It can be simply copied from the theme file into # the above setting. # -# Usage from other Scripts: +# Usage from other Scripts: signal 'change prompt' => 'string' => position +# +# eg: +# +# signal_emit 'change prompt' 'some_string', UberPrompt::UP_INNER; # -# signal_emit 'change prompt' 'some_string $p other string'; +# will set the prompt to include that content, by default '[$* some_string]' # -# will set the prompt to include that content. +# The possible position arguments are: +# +# UP_PRE - place the provided string before the prompt -- $string$prompt +# UP_INNER - place the provided string inside the prompt -- {prompt $* $string} +# UP_POST - place the provided string after the prompt -- $prompt$string +# UP_ONLY - replace the prompt with the provided string -- $string +# +# All strings may use the special variable '$prompt' to include the prompt +# verbatim at that position in the string. It is probably only useful for +# the UP_ONLY mode however. '$prompt_nt' will include the prompt, minus any +# trailing whitespace. +# +# NOTIFICATIONS: # # You can also be notified when the prompt changes in response to the previous # signal or manual commands via: @@ -75,7 +102,6 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. - use strict; use warnings; @@ -83,8 +109,6 @@ use Irssi; use Irssi::TextUI; # for sbar_items_redraw use Data::Dumper; - - our $VERSION = "0.2"; our %IRSSI = ( @@ -99,11 +123,10 @@ our %IRSSI = my $DEBUG_ENABLED = 0; - sub DEBUG { $DEBUG_ENABLED } my $prompt_data = undef; - +my $prompt_changed = 0; my $prompt_format = ''; init(); @@ -118,8 +141,9 @@ sub init { Irssi::statusbar_item_register('uberprompt', 0, 'uberprompt_draw'); - Irssi::settings_add_str('uberprompt', 'uberprompt_format', '[$*] '); + Irssi::settings_add_str('uberprompt', 'uberprompt_format', '[$* $uber] '); Irssi::settings_add_bool('uberprompt', 'uberprompt_debug', 0); + Irssi::settings_add_bool('uberprompt', 'uberprompt_autostart', 1); Irssi::command_bind("prompt", \&prompt_subcmd_handler); Irssi::command_bind('prompt on', \&replace_prompt_items); @@ -134,34 +158,46 @@ sub init { # intialise the prompt format. reload_settings(); - # install our statusbars. - replace_prompt_items(); + # install our statusbars if required. + if (Irssi::settings_get_bool('uberprompt_autostart')) { + replace_prompt_items(); + } + + # API signals - # the actual API signal. - Irssi::signal_register({'change prompt' => [qw/string/]}); - Irssi::signal_add('change prompt' => \&change_prompt_sig); + Irssi::signal_register({'change prompt' => [qw/string int/]}); + Irssi::signal_add('change prompt' => \&change_prompt_handler); # other scripts (specifically overlay/visual) can subscribe to # this event to be notified when the prompt changes. # arguments are new contents (string), new length (int) Irssi::signal_register({'prompt changed' => [qw/string int/]}); + if (DEBUG) { Irssi::signal_add 'prompt changed', \&debug_prompt_changed; } } +sub reload_settings { + + $DEBUG_ENABLED = Irssi::settings_get_bool('uberprompt_debug'); + + my $new = Irssi::settings_get_str('uberprompt_format'); + if ($prompt_format ne $new) { + print "Updated prompt format" if DEBUG; + $prompt_format = $new; + Irssi::abstracts_register(['uberprompt', $prompt_format]); + } +} + sub debug_prompt_changed { my ($text, $len) = @_; - my $exp = Irssi::current_theme()->format_expand($text, 0); - my $ps = Irssi::parse_special($exp); print "DEBUG: Got $text = $exp = $ps, length: $len"; } -sub change_prompt_sig { +sub change_prompt_handler { my ($text) = @_; - # TODO: mroe intelligence about where to insert $p? - $text = '$p' . $text; print "Got prompt change sig with: $text" if DEBUG; my $changed; @@ -181,22 +217,11 @@ sub UNLOAD { restore_prompt_items(); } -sub reload_settings { - - $DEBUG_ENABLED = Irssi::settings_get_bool('uberprompt_debug'); - - my $new = Irssi::settings_get_str('uberprompt_format'); - if ($prompt_format ne $new) { - print "Updated prompt format" if DEBUG; - $prompt_format = $new; - Irssi::abstracts_register(['uberprompt', $prompt_format]); - } -} sub uberprompt_draw { my ($sb_item, $get_size_only) = @_; - my $default_prompt = ''; + my $actual_prompt = ''; my $window = Irssi::active_win; @@ -204,19 +229,24 @@ sub uberprompt_draw { # hack to produce the same defaults as prompt/prompt_empty sbars. if (scalar( () = $window->items )) { - $default_prompt = '{uberprompt $[.15]itemname}'; + $actual_prompt = '{uberprompt $[.15]itemname}'; } else { - $default_prompt = '{uberprompt $winname}'; + $actual_prompt = '{uberprompt $winname}'; } my $p_copy = $prompt_data; if (defined $prompt_data) { - # replace the special marker '$p' with the original prompt. - $p_copy =~ s/\$/\$\$/g; # escape all $ symbols + if ($prompt_data =~ m/\$\$p/) { + $p_copy =~ s/\$\$p/$default_prompt/; + + # replace the special marker '$p' with the original prompt. + } else { + $p_copy = $prompt_format; + $p_copy =~ s/\$ + } $p_copy =~ s/\\/\\\\/g; # escape backslashes. - $p_copy =~ s/\$\$p/$default_prompt/; } else { $p_copy = $default_prompt; @@ -225,8 +255,12 @@ sub uberprompt_draw { print "Redrawing with: $p_copy, size-only: $get_size_only" if DEBUG; my $ret = $sb_item->default_handler($get_size_only, $p_copy, '', 0); + + # TODO: do this properly, and also make sure it's only emitted once per # change. + my $exp = Irssi::current_theme()->format_expand($text, 0); + my $ps = Irssi::parse_special($exp); Irssi::signal_emit('prompt changed', $p_copy, $sb_item->{size}); @@ -284,3 +318,10 @@ sub _sbar_command { # bit of fakery so things don't complain about the lack of prompt_info (hoepfully) %Irssi::Script::prompt_info:: = (); + +package UberPrompt; + +sub UP_PRE () { 0 } +sub UP_INNER () { 1 } +sub UP_POST () { 2 } +sub UP_ONLY () { 3 } -- cgit v1.2.3 From 9a55a5a02458693c2297d19e7c8017deb9938191 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sun, 10 Oct 2010 21:16:03 +0100 Subject: implemented the various prompt addition modes as documented. tests so far look good. --- prompt_info/uberprompt.pl | 134 ++++++++++++++++++++++++++++------------------ 1 file changed, 82 insertions(+), 52 deletions(-) diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index f026a91..cc01e52 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -55,7 +55,7 @@ # # will set the prompt to include that content, by default '[$* some_string]' # -# The possible position arguments are: +# The possible position arguments are the following strings: # # UP_PRE - place the provided string before the prompt -- $string$prompt # UP_INNER - place the provided string inside the prompt -- {prompt $* $string} @@ -125,18 +125,26 @@ our %IRSSI = my $DEBUG_ENABLED = 0; sub DEBUG { $DEBUG_ENABLED } -my $prompt_data = undef; -my $prompt_changed = 0; -my $prompt_format = ''; +my $prompt_data = undef; +my $prompt_data_pos = 'UP_INNER'; + +my $prompt_last = ''; +my $prompt_format = ''; init(); sub prompt_subcmd_handler { my ($data, $server, $item) = @_; - $data =~ s/\s+$//g; # strip trailing whitespace. + $data =~ s/\s+$//g; # strip trailing whitespace. Irssi::command_runsub('prompt', $data, $server, $item); } +sub UNLOAD { + # remove uberprompt and return the original ones. + print "Removing uberprompt and restoring original"; + restore_prompt_items(); +} + sub init { Irssi::statusbar_item_register('uberprompt', 0, 'uberprompt_draw'); @@ -149,9 +157,16 @@ sub init { Irssi::command_bind('prompt on', \&replace_prompt_items); Irssi::command_bind('prompt off', \&restore_prompt_items); Irssi::command_bind('prompt set', - sub { Irssi::signal_emit 'change prompt', shift; }); + sub { + my $args = shift; + $args =~ s/^\s*(\w+)\s*(.*$)/$2/; + my $mode = 'UP_' . uc($1); + Irssi::signal_emit 'change prompt', $args, $mode; + }); Irssi::command_bind('prompt clear', - sub { Irssi::signal_emit 'change prompt', '$p'; }); + sub { + Irssi::signal_emit 'change prompt', '$p', 'UP_POST'; + }); Irssi::signal_add('setup changed', \&reload_settings); @@ -165,7 +180,7 @@ sub init { # API signals - Irssi::signal_register({'change prompt' => [qw/string int/]}); + Irssi::signal_register({'change prompt' => [qw/string string/]}); Irssi::signal_add('change prompt' => \&change_prompt_handler); # other scripts (specifically overlay/visual) can subscribe to @@ -186,83 +201,105 @@ sub reload_settings { if ($prompt_format ne $new) { print "Updated prompt format" if DEBUG; $prompt_format = $new; + $prompt_format =~ s/\$uber/\$\$uber/; Irssi::abstracts_register(['uberprompt', $prompt_format]); } } sub debug_prompt_changed { my ($text, $len) = @_; - print "DEBUG: Got $text = $exp = $ps, length: $len"; + + $text =~ s/%/%%/g; + + print "DEBUG: Got $text, length: $len"; } sub change_prompt_handler { - my ($text) = @_; + my ($text, $pos) = @_; - print "Got prompt change sig with: $text" if DEBUG; + print "Got prompt change signal with: $text, $pos" if DEBUG; - my $changed; - $changed = defined $prompt_data ? $prompt_data ne $text : 1; + my ($changed_text, $changed_pos); + $changed_text = defined $prompt_data ? $prompt_data ne $text : 1; + $changed_pos = defined $prompt_data_pos ? $prompt_data_pos ne $pos : 1; - $prompt_data = $text; + $prompt_data = $text; + $prompt_data_pos = $pos; - if ($changed) { + if ($changed_text || $changed_pos) { print "Redrawing prompt" if DEBUG; uberprompt_refresh(); } } -sub UNLOAD { - # remove uberprompt and return the original ones. - print "Removing uberprompt and restoring original"; - restore_prompt_items(); +sub _escape_prompt_special { + my $str = shift; + $str =~ s/\$/\$\$/g; + $str =~ s/\\/\\\\/g; + return $str; } - sub uberprompt_draw { my ($sb_item, $get_size_only) = @_; - my $actual_prompt = ''; - my $window = Irssi::active_win; + my $prompt_arg = ''; - #print Dumper($sb_item); - - # hack to produce the same defaults as prompt/prompt_empty sbars. + # default prompt sbar arguments (from config) if (scalar( () = $window->items )) { - $actual_prompt = '{uberprompt $[.15]itemname}'; + $prompt_arg = '$[.15]{itemname}'; } else { - $actual_prompt = '{uberprompt $winname}'; + $prompt_arg = '${winname}'; } - my $p_copy = $prompt_data; + my $prompt = ''; # rendered content of the prompt. + my $theme = Irssi::current_theme; - if (defined $prompt_data) { - if ($prompt_data =~ m/\$\$p/) { - $p_copy =~ s/\$\$p/$default_prompt/; + $prompt = $theme->format_expand("{uberprompt $prompt_arg}"); - # replace the special marker '$p' with the original prompt. - } else { - $p_copy = $prompt_format; - $p_copy =~ s/\$ - } - $p_copy =~ s/\\/\\\\/g; # escape backslashes. + if ($prompt_data_pos eq 'UP_ONLY') { + $prompt =~ s/\$\$uber//; # no need for recursive prompting, I hope. + + # TODO: only compute this if necessary? + my $prompt_nt = $prompt; + $prompt_nt =~ s/\s+$//; + + my $pdata_copy = $prompt_data; + $pdata_copy =~ s/\$prompt_nt/$prompt_nt/; + $pdata_copy =~ s/\$prompt/$prompt/; + + $prompt = $pdata_copy; + + } elsif ($prompt_data_pos eq 'UP_INNER' && defined $prompt_data) { + my $esc = _escape_prompt_special($prompt_data); + $prompt =~ s/\$\$uber/$esc/; } else { - $p_copy = $default_prompt; + # remove the $uber marker + $prompt =~ s/\$\$uber//; + + # and add the additional text at the appropriate position. + if ($prompt_data_pos eq 'UP_PRE') { + $prompt = $prompt_data . $prompt; + } elsif ($prompt_data_pos eq 'UP_POST') { + $prompt .= $prompt_data; + } } - print "Redrawing with: $p_copy, size-only: $get_size_only" if DEBUG; + print "Redrawing with: $prompt, size-only: $get_size_only" if DEBUG; - my $ret = $sb_item->default_handler($get_size_only, $p_copy, '', 0); + if ($prompt ne $prompt_last) { - # TODO: do this properly, and also make sure it's only emitted once per - # change. - my $exp = Irssi::current_theme()->format_expand($text, 0); - my $ps = Irssi::parse_special($exp); + # print "Emitting prompt changed signal" if DEBUG; + # my $exp = Irssi::current_theme()->format_expand($text, 0); + my $ps = Irssi::parse_special($prompt); - Irssi::signal_emit('prompt changed', $p_copy, $sb_item->{size}); + Irssi::signal_emit('prompt changed', $ps, length($ps)); + $prompt_last = $prompt; + } + my $ret = $sb_item->default_handler($get_size_only, $prompt, '', 0); return $ret; } @@ -318,10 +355,3 @@ sub _sbar_command { # bit of fakery so things don't complain about the lack of prompt_info (hoepfully) %Irssi::Script::prompt_info:: = (); - -package UberPrompt; - -sub UP_PRE () { 0 } -sub UP_INNER () { 1 } -sub UP_POST () { 2 } -sub UP_ONLY () { 3 } -- cgit v1.2.3 From ecf7327440954c61e65027b983489b76002a0436 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 10 Oct 2010 22:39:07 +0200 Subject: vim_mode: Fix warning when mapping :map. --- vim-mode/vim_mode.pl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 20562a7..f9bb2ff 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -1737,7 +1737,9 @@ sub ex_map { # :map [lhs] } elsif ($arg_str eq 'map' or $arg_str =~ /^map (\S+)$/) { # Necessary for case insensitive matchings. lc alone won't work. - my $search = _parse_mapping_reverse(_parse_mapping($1)); + my $search = $1; + $search = '' if not defined $search; + $search = _parse_mapping_reverse(_parse_mapping($search)); my $active_window = Irssi::active_win(); foreach my $key (sort keys %$maps) { -- cgit v1.2.3 From b2bcef1f165be98916fb2b67121baa225a269098 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sun, 10 Oct 2010 21:40:10 +0100 Subject: removed compat mode for prompt-info, since we no longer adhere to the same signal params --- prompt_info/uberprompt.pl | 3 --- 1 file changed, 3 deletions(-) diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index cc01e52..45a5d0b 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -352,6 +352,3 @@ sub _sbar_command { Irssi::command($command); } -# bit of fakery so things don't complain about the lack of prompt_info (hoepfully) - -%Irssi::Script::prompt_info:: = (); -- cgit v1.2.3 From 6c06bc858315a0802c0b901555873de4eccaf966 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sun, 10 Oct 2010 21:47:40 +0100 Subject: re-added additional signals to refresh prompt when needed --- prompt_info/uberprompt.pl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 45a5d0b..390e8e5 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -149,7 +149,7 @@ sub init { Irssi::statusbar_item_register('uberprompt', 0, 'uberprompt_draw'); - Irssi::settings_add_str('uberprompt', 'uberprompt_format', '[$* $uber] '); + Irssi::settings_add_str('uberprompt', 'uberprompt_format', '[$*$uber] '); Irssi::settings_add_bool('uberprompt', 'uberprompt_debug', 0); Irssi::settings_add_bool('uberprompt', 'uberprompt_autostart', 1); @@ -173,6 +173,12 @@ sub init { # intialise the prompt format. reload_settings(); + # make sure we redraw when necessary. + Irssi::signal_add('window changed', \&uberprompt_draw); + Irssi::signal_add('window name changed', \&uberprompt_draw); + Irssi::signal_add('window changed automatic', \&uberprompt_draw); + Irssi::signal_add('window item changed', \&uberprompt_draw); + # install our statusbars if required. if (Irssi::settings_get_bool('uberprompt_autostart')) { replace_prompt_items(); -- cgit v1.2.3 From 43424b9438dff43a056e4563b47e1f334dd94a25 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sun, 10 Oct 2010 22:56:19 +0100 Subject: added a brief proof-of-concept for loading/reloading additional functions on the fly from within irssi scripts. --- feature-tests/subscript.pl | 78 ++++++++++++++++++++++++++++++++++++++++++++++ feature-tests/test.sub | 6 ++++ 2 files changed, 84 insertions(+) create mode 100644 feature-tests/subscript.pl create mode 100644 feature-tests/test.sub diff --git a/feature-tests/subscript.pl b/feature-tests/subscript.pl new file mode 100644 index 0000000..74a5afe --- /dev/null +++ b/feature-tests/subscript.pl @@ -0,0 +1,78 @@ +use strict; +use Irssi; +use Irssi::TextUI; # for sbar_items_redraw + +use vars qw($VERSION %IRSSI); + +$VERSION = "0.1"; + +%IRSSI = ( + authors => "shabble", + contact => 'shabble+irssi@metavore.org, shabble@#irssi/Freenode', + name => "", + description => "", + license => "Public Domain", + changed => "" +); + +my $functions = {}; + +init(); + +sub load { + my $file = shift; + my $funcs; + if (-f $file) { + print "Loading from file: $file"; + $funcs = do $file; + } + + return unless ref $funcs eq 'HASH'; + print "Got hashref from file"; + + foreach my $name (keys %$funcs) { + my $func = $funcs->{$name}; + $functions->{$name} = $func; + } + + $functions = $funcs; + print "Loaded " . scalar(keys(%$funcs)) . " functions"; +} + +sub init { + Irssi::command_bind('subload', \&cmd_subload); + Irssi::command_bind('sublist', \&cmd_sublist); + Irssi::command_bind('subcall', \&cmd_subcall); +} + +sub cmd_subload { + my $args = shift; + print "Going to load: $args"; + load($args); +} + +sub cmd_sublist { + foreach my $name (keys %$functions) { + my $func = $functions->{$name}; + print "Function: $name => $func"; + } +} + +sub cmd_subcall { + my $args = shift; + my ($cmd, $cmdargs); + if ($args =~ m/^(\w+\b)(.*)$/) { + $cmd = $1; $cmdargs = $2; + } else { + print "Couldn't parse $args"; + return; + } + my $fun = $functions->{$cmd}; + + if (ref $fun eq 'CODE') { + print "Calling $cmd with $cmdargs"; + $fun->($cmdargs); + } else { + print "$cmd is not a coderef. cannot run"; + } +} diff --git a/feature-tests/test.sub b/feature-tests/test.sub new file mode 100644 index 0000000..6a24879 --- /dev/null +++ b/feature-tests/test.sub @@ -0,0 +1,6 @@ +{ + 'moo' => sub { print "Moo" }, + 'hello' => sub { print join(", ", @_) } +}; + + -- cgit v1.2.3 From 745b2901e2f635d6a57cbe3e40695a6fe751f97b Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sun, 10 Oct 2010 23:11:52 +0100 Subject: tidied up loading code, added demo of calling func in outer scope --- feature-tests/subscript.pl | 26 +++++++++++++++++++++++--- feature-tests/test.sub | 3 ++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/feature-tests/subscript.pl b/feature-tests/subscript.pl index 74a5afe..8550409 100644 --- a/feature-tests/subscript.pl +++ b/feature-tests/subscript.pl @@ -19,6 +19,10 @@ my $functions = {}; init(); +sub _input { + return int rand 1000; +} + sub load { my $file = shift; my $funcs; @@ -26,16 +30,32 @@ sub load { print "Loading from file: $file"; $funcs = do $file; } + if (not defined $funcs) { + if ($@) { + print "failed to parse $file: $@"; - return unless ref $funcs eq 'HASH'; - print "Got hashref from file"; + } elsif ($!) { + print "failed to read $file: $!"; + + } + return; + } + my $ref = ref $funcs; + if ($ref ne 'HASH') { + print "$file didn't return a hashref: ", defined $ref ? $ref : 'undef'; + return; + } foreach my $name (keys %$funcs) { my $func = $funcs->{$name}; + if (exists $functions->{$name}) { + print "Redefining function $name"; + } else { + print "adding function: $name"; + } $functions->{$name} = $func; } - $functions = $funcs; print "Loaded " . scalar(keys(%$funcs)) . " functions"; } diff --git a/feature-tests/test.sub b/feature-tests/test.sub index 6a24879..350e89d 100644 --- a/feature-tests/test.sub +++ b/feature-tests/test.sub @@ -1,6 +1,7 @@ { 'moo' => sub { print "Moo" }, - 'hello' => sub { print join(", ", @_) } + 'hello' => sub { print join(", ", @_) }, + 'inp' => sub { print "input is : ", _input(); }, }; -- cgit v1.2.3 From 9c10de27005fedff0460e4f951be55bebebde98f Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Mon, 11 Oct 2010 19:28:59 +0100 Subject: modified buildpod to account for repo rename --- docs/buildpod.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/buildpod.pl b/docs/buildpod.pl index dfddf54..debaa3b 100755 --- a/docs/buildpod.pl +++ b/docs/buildpod.pl @@ -32,7 +32,7 @@ sub new { q(find something obviously wrong, or have requests ), q(for further documentation on topics not yet ), q(filled out, please ), - q(create an issue), + q(create an issue), " on my Github page, and I'll see what I can do.

", ); @@ -90,7 +90,7 @@ package main; use File::Copy; -my $output_dir = "../../tmp/shab-irssi-scripts/docs/"; +my $output_dir = "../../tmp/irssi-scripts/docs/"; my $batchconv = Pod::Simple::HTMLBatch::Custom->new; my $css = 'podstyle.css'; -- cgit v1.2.3 From 0759c5aed971ad08b8838dd84d5baeb649deabbb Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Mon, 11 Oct 2010 21:03:26 +0100 Subject: modified rl_history_search to use uberprompt, and added INSTALL section to header comments --- history-search/rl_history_search.pl | 42 ++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/history-search/rl_history_search.pl b/history-search/rl_history_search.pl index 83ff934..f63a6d7 100644 --- a/history-search/rl_history_search.pl +++ b/history-search/rl_history_search.pl @@ -1,29 +1,39 @@ # Search within your typed history as you type (like ctrl-R in bash) -# Usage: - +# +# INSTALL: +# +# This script requires that you have first installed and loaded 'uberprompt.pl' +# Uberprompt can be downloaded from: +# +# http://github.com/shabble/irssi-scripts/raw/master/prompt_info/uberprompt.pl +# +# and follow the instructions at the top of that file for installation. +# +# USAGE: +# # * Setup: /bind ^R /history_search_start - +# # * Then type ctrl-R and type what you're searching for - +# # * You can cycle through multiple matches with ^R (older matches), and # ^S (newer matches) - +# # NOTE: Ctrl-S may not work if you have software flow control configured for # your terminal. It may appear to freeze irssi entirely. If this happens, it can # be restored with Ctrl-Q, but you will be unable to use the Ctrl-S binding. # You can disable flow control by running the command `stty -ixon' in your # terminal, or setting `defflow off' in your ~/.screenrc if using GNU Screen. - +# # * Hitting enter selects a match and terminates search mode. - +# # * You can use ^G to exit search mode without selecting. - +# # * Any other ctrl- or meta- key binding will terminate search mode, leaving the # selected item in the input line. - +# # Original script Copyright 2007 Wouter Coekaerts # Heavy modifications by Shabble , 2010. - +# # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or @@ -53,7 +63,7 @@ $VERSION = '1.0'; description => 'Search within your typed history as you type' . ' (like ctrl-R in readline applications)', license => 'GPLv2 or later', - url => 'http://github.com/shabble/shab-irssi-scripts/tree/master/history-search/', + url => 'http://github.com/shabble/irssi-scripts/tree/master/history-search/', changed => '24/7/2010' ); @@ -67,7 +77,7 @@ my $match_index = 0; sub DEBUG () { 0 } -# check we have prompt_info loaded. +# check we have uberprompt loaded. sub script_is_loaded { my $name = shift; @@ -79,7 +89,7 @@ sub script_is_loaded { return $retval; } -unless (script_is_loaded('prompt_info')) { +unless (script_is_loaded('uberprompt')) { die "This script requires 'prompt_info' in order to work. " . "Please load it and try again"; } else { @@ -105,11 +115,13 @@ sub history_search { sub history_exit { $search_active = 0; - Irssi::signal_emit('change prompt', ''); + Irssi::signal_emit('change prompt', '', 'UP_INNER'); } sub update_history_prompt { - Irssi::signal_emit('change prompt', " reverse-i-search: \`$search_str'"); + Irssi::signal_emit('change prompt', + " reverse-i-search: \`$search_str'", + 'UP_INNER'); } sub update_history_matches { -- cgit v1.2.3 From 365fa468c5e2bd566e1f0be5945eb3c0c873ecf5 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Mon, 11 Oct 2010 21:11:06 +0100 Subject: history search now uses colour to indicate matches/no-matches --- history-search/rl_history_search.pl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/history-search/rl_history_search.pl b/history-search/rl_history_search.pl index f63a6d7..64f4f20 100644 --- a/history-search/rl_history_search.pl +++ b/history-search/rl_history_search.pl @@ -90,7 +90,7 @@ sub script_is_loaded { } unless (script_is_loaded('uberprompt')) { - die "This script requires 'prompt_info' in order to work. " + die "This script requires 'uberprompt.pl' in order to work. " . "Please load it and try again"; } else { history_init(); @@ -119,8 +119,10 @@ sub history_exit { } sub update_history_prompt { + my $col = scalar(@search_matches) ? '%g' : '%r'; Irssi::signal_emit('change prompt', - " reverse-i-search: \`$search_str'", + ' reverse-i-search: `' . $col . $search_str + . '%n' . "'", 'UP_INNER'); } -- cgit v1.2.3 From 9e2e49faf7730daf70b56b4fa35716eb6eefddb3 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Wed, 13 Oct 2010 02:09:42 +0100 Subject: updated history search to use a irssi setting 'histsearch_debug' to enable debugging output. --- history-search/rl_history_search.pl | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/history-search/rl_history_search.pl b/history-search/rl_history_search.pl index 64f4f20..32d42a3 100644 --- a/history-search/rl_history_search.pl +++ b/history-search/rl_history_search.pl @@ -75,7 +75,8 @@ my @search_matches = (); my $match_index = 0; -sub DEBUG () { 0 } +my $DEBUG_ENABLED = 0; +sub DEBUG () { $DEBUG_ENABLED } # check we have uberprompt loaded. @@ -97,11 +98,21 @@ unless (script_is_loaded('uberprompt')) { } sub history_init { + Irssi::settings_add_bool('history_search', 'histsearch_debug', 0); + Irssi::command_bind('history_search_start', \&history_search); - #Irssi::command_bind('history_search_exit', \&history_search_exit); + + Irssi::signal_add ('setup changed' => \&setup_changed); Irssi::signal_add_first('gui key pressed' => \&handle_keypress); + + setup_changed(); } +sub setup_changed { + $DEBUG_ENABLED = Irssi::settings_get_bool('histsearch_debug'); +} + + sub history_search { $search_active = 1; $search_str = ''; -- cgit v1.2.3 From bb5d73900d48c9d5da071ee534ecc4dcfb2c8bf6 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Wed, 13 Oct 2010 02:10:21 +0100 Subject: added documentation, debug setting: 'scrollminder_debug', partially updated to use uberprompt --- scrolled-reminder/scrolled_reminder.pl | 87 ++++++++++++++++++++++++++++------ 1 file changed, 73 insertions(+), 14 deletions(-) diff --git a/scrolled-reminder/scrolled_reminder.pl b/scrolled-reminder/scrolled_reminder.pl index b69e3df..113e2a3 100644 --- a/scrolled-reminder/scrolled_reminder.pl +++ b/scrolled-reminder/scrolled_reminder.pl @@ -1,3 +1,58 @@ +# ABOUT: +# +# This script attempts to prevent you from responding accidentally to long-finished +# conversations if you have scrolled back and are not viewing the current activity +# of the channel. +# +# If you attempt to send a message when you are not at the most recent point in the +# channel buffer, it will intercept the message and offer you a menu of options +# instead. +# +# USAGE: +# +# When scrolled up and sending a message, the subsequent prompt has the following +# options: +# +# * Ctrl-C - cancel sending the message. It remains in your input line, but is not +# sent to the channel. +# * Ctrl-K - send the message to the channel. The input line is cleared. +# * Space - Jump to the bottom (most recent) part of the channel buffer. +# Unlike the first two, this does not cancel the prompt, so it allows +# you to determine if your message is still appropriate before sending. +# +# +# INSTALL: +# +# This script requires that you have first installed and loaded 'uberprompt.pl' +# Uberprompt can be downloaded from: +# +# http://github.com/shabble/irssi-scripts/raw/master/prompt_info/uberprompt.pl +# +# and follow the instructions at the top of that file for installation. +# +# LICENCE: +# +# Copyright (c) 2010 Tom Feist +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# + use strict; use warnings; @@ -7,16 +62,8 @@ use Irssi::Irc; use Data::Dumper; -# Everyone is permitted to copy and distribute verbatim or modified -# copies of this license document, and changing it is allowed as long -# as the name is changed. - -# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE -# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - -# 0. You just DO WHAT THE FUCK YOU WANT TO. - -sub DEBUG () { 1 } +my $DEBUG_ENABLED = 0; +sub DEBUG () { $DEBUG_ENABLED } our $VERSION = '0.01'; our %IRSSI = @@ -27,8 +74,8 @@ our %IRSSI = description => 'Requires confirmation to messages sent' . 'when the current window is scrolled up', - license => 'WTFPL; http://sam.zoy.org/wtfpl/', - url => 'http://github.com/shabble/shab-irssi-scripts/' + license => 'MIT', + url => 'http://github.com/shabble/irssi-scripts/' . 'tree/master/scrolled-reminder/', ); @@ -44,8 +91,8 @@ sub script_is_loaded { return $retval; } -unless (script_is_loaded('prompt_info')) { - die "This script requires 'prompt_info' in order to work. " +unless (script_is_loaded('uberprompt')) { + die "This script requires the 'uberprompt.pl' script in order to work. " . "Please load it and try again"; } else { scroll_reminder_init(); @@ -56,11 +103,23 @@ my $pending_input = {}; my $active; sub scroll_reminder_init { + + $permit_pending = 0; $active = 0; + + Irssi::settings_add_bool('scrollminder', 'scrollminder_debug', 0); + # we need to be first so we can intercept stuff. Irssi::signal_add_first('send text', \&handle_send_text); Irssi::signal_add_first('gui key pressed', \&handle_keypress); + Irssi::signal_add('setup changed' => \&setup_changed); + + setup_changed(); +} + +sub setup_changed { + $DEBUG_ENABLED = Irssi::settings_get_bool('scrollminder_debug'); } ################################################################ -- cgit v1.2.3 From 80305f6c0c471acc643882281829a5c391310552 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Wed, 13 Oct 2010 02:16:08 +0100 Subject: fix to uberprompt calling the wrong draw function from signalhandlers --- prompt_info/uberprompt.pl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 390e8e5..3bb3155 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -174,10 +174,10 @@ sub init { reload_settings(); # make sure we redraw when necessary. - Irssi::signal_add('window changed', \&uberprompt_draw); - Irssi::signal_add('window name changed', \&uberprompt_draw); - Irssi::signal_add('window changed automatic', \&uberprompt_draw); - Irssi::signal_add('window item changed', \&uberprompt_draw); + Irssi::signal_add('window changed', \&uberprompt_refresh); + Irssi::signal_add('window name changed', \&uberprompt_refresh); + Irssi::signal_add('window changed automatic', \&uberprompt_refresh); + Irssi::signal_add('window item changed', \&uberprompt_refresh); # install our statusbars if required. if (Irssi::settings_get_bool('uberprompt_autostart')) { -- cgit v1.2.3 From 85c2340feb5753d99febcfb06ff0f9d3edda2bae Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Wed, 13 Oct 2010 02:20:44 +0100 Subject: scrollminder now uses uberprompt properly (UP_INNER mode) --- scrolled-reminder/scrolled_reminder.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scrolled-reminder/scrolled_reminder.pl b/scrolled-reminder/scrolled_reminder.pl index 113e2a3..b1deb9c 100644 --- a/scrolled-reminder/scrolled_reminder.pl +++ b/scrolled-reminder/scrolled_reminder.pl @@ -240,5 +240,5 @@ sub set_prompt { my $msg = shift; # add a leading space unless we're trying to clear it entirely. $msg = ' ' . $msg if length $msg; - Irssi::signal_emit('change prompt', $msg); + Irssi::signal_emit('change prompt', $msg, 'UP_INNER'); } -- cgit v1.2.3 From 8edb0c6866d7263a11efa11bbee4e2f738ac7d35 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Wed, 13 Oct 2010 12:35:07 +0100 Subject: fixed undef bug in uberprompt --- prompt_info/uberprompt.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 3bb3155..79717ae 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -125,7 +125,7 @@ our %IRSSI = my $DEBUG_ENABLED = 0; sub DEBUG { $DEBUG_ENABLED } -my $prompt_data = undef; +my $prompt_data = ''; my $prompt_data_pos = 'UP_INNER'; my $prompt_last = ''; -- cgit v1.2.3 From 3eb58a871f1c6d9697d479a0237fd33d628eb414 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Wed, 13 Oct 2010 12:37:23 +0100 Subject: removed a defined-or which needs perl 5.10 --- history-search/rl_history_search.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/history-search/rl_history_search.pl b/history-search/rl_history_search.pl index 32d42a3..eebb6c7 100644 --- a/history-search/rl_history_search.pl +++ b/history-search/rl_history_search.pl @@ -139,7 +139,7 @@ sub update_history_prompt { sub update_history_matches { my ($match_str) = @_; - $match_str //= $search_str; + $match_str = $search_str unless defined $match_str; my %unique; my @matches = grep { m/\Q$match_str/i } @history_cache; -- cgit v1.2.3 From ee9ce3db10956e86dc667ccb700e46ebdf34660e Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Wed, 13 Oct 2010 12:56:04 +0100 Subject: switched vim_mode to using uberprompt --- vim-mode/vim_mode.pl | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index f9bb2ff..a00421a 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -2261,8 +2261,11 @@ sub handle_command_cmd { if ($operator) { # But allow cc/dd/yy. if ($operator == $cmd) { - print "Processing line operator: $map->{char} ($cmd->{char})" + print "Processing line operator: ", + $map->{char}, " (", + $cmd->{char} ,")" if DEBUG; + my $pos = _input_pos(); $cmd->{func}->(0, _input_len(), undef, 0); # Restore position for yy. @@ -2284,8 +2287,8 @@ sub handle_command_cmd { # Start Ex mode. } elsif ($cmd == $commands->{':'}) { - if (not script_is_loaded('prompt_info')) { - _warn("Warning: Ex mode requires the 'prompt_info' script. " . + if (not script_is_loaded('uberprompt')) { + _warn("Warning: Ex mode requires the 'uberprompt' script. " . "Please load it and try again."); } else { _update_mode(M_EX); @@ -2783,7 +2786,7 @@ sub _set_prompt { my $msg = shift; # add a leading space unless we're trying to clear it entirely. $msg = ' ' . $msg if length $msg; - Irssi::signal_emit('change prompt', $msg); + Irssi::signal_emit('change prompt', $msg, 'UP_INNER'); } sub _warn { -- cgit v1.2.3 From 46f32ac80dfc4d5542f0a01a1996d15d4ce11157 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Thu, 14 Oct 2010 19:02:17 +0100 Subject: fixed problem with uberprompt sometimes starting on RHS of input line. --- prompt_info/uberprompt.pl | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 79717ae..76660b2 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -335,13 +335,7 @@ sub restore_prompt_items { print "Restoring original prompt" if DEBUG; - _sbar_command('prompt', 'add', 'prompt', - qw/-alignment left -before input -priority '-1'/); - _sbar_command('prompt', 'add', 'prompt_empty', - qw/-alignment left -after prompt -priority '-1'/); - - _sbar_command('prompt', 'position', '100'); - + _sbar_command('prompt', 'reset'); } sub _sbar_command { -- cgit v1.2.3 From 49f84645e3e0fbd2d34e80236d93a518deebc5c9 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Thu, 14 Oct 2010 20:58:25 +0100 Subject: added list of all signals, including internal ones. --- docs/allsigs-uniq.txt | 358 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 358 insertions(+) create mode 100644 docs/allsigs-uniq.txt diff --git a/docs/allsigs-uniq.txt b/docs/allsigs-uniq.txt new file mode 100644 index 0000000..4dc83e3 --- /dev/null +++ b/docs/allsigs-uniq.txt @@ -0,0 +1,358 @@ +"away mode changed" +"awaylog show" +"ban type changed" +"beep" +"channel created" +"channel destroyed" +"channel joined" +"channel rejoin new" +"channel sync" +"channel wholist" +"chanquery abort" +"chanquery ban end" +"chanquery ban" +"chanquery mode" +"chanquery who end" +"chat protocol created" +"chat protocol deinit" +"chat protocol destroyed" +"chat protocol unknown" +"chatnet destroyed" +"chatnet read" +"chatnet saved" +"complete command action" +"complete command alias" +"complete command away" +"complete command bind" +"complete command cat" +"complete command connect" +"complete command dcc send" +"complete command disconnect" +"complete command format" +"complete command help" +"complete command load" +"complete command msg" +"complete command query" +"complete command rawlog open" +"complete command rawlog save" +"complete command recode remove" +"complete command reconnect" +"complete command reload" +"complete command save" +"complete command script load" +"complete command script unload" +"complete command server add" +"complete command server remove" +"complete command server" +"complete command set" +"complete command stats" +"complete command toggle" +"complete command topic" +"complete command unalias" +"complete command window goto" +"complete command window item move" +"complete command window server" +"complete erase command action" +"complete erase command msg" +"complete erase command query" +"complete word" +"ctcp action" +"ctcp msg clientinfo" +"ctcp msg dcc accept" +"ctcp msg dcc chat" +"ctcp msg dcc resume" +"ctcp msg dcc send" +"ctcp msg dcc" +"ctcp msg ping" +"ctcp msg time" +"ctcp msg userinfo" +"ctcp msg version" +"ctcp msg" +"ctcp reply dcc reject" +"ctcp reply dcc" +"ctcp reply ping" +"ctcp reply" +"dcc chat message" +"dcc closed" +"dcc connected" +"dcc ctcp action" +"dcc ctcp dcc" +"dcc destroyed" +"dcc error close not found" +"dcc error connect" +"dcc error ctcp" +"dcc error file create" +"dcc error file open" +"dcc error get not found" +"dcc error send exists" +"dcc error send no route" +"dcc error unknown type" +"dcc error write" +"dcc list print" +"dcc rejected" +"dcc reply dcc" +"dcc reply send pasv" +"dcc request send" +"dcc request" +"dcc server started" +"default command server" +"default command" +"default ctcp msg dcc" +"default ctcp msg" +"default ctcp reply dcc" +"default ctcp reply" +"default dcc ctcp" +"default event numeric" +"default event" +"error command" +"event 001" +"event 004" +"event 005" +"event 221" +"event 254" +"event 271" +"event 272" +"event 281" +"event 301" +"event 302" +"event 303" +"event 305" +"event 306" +"event 311" +"event 312" +"event 313" +"event 314" +"event 315" +"event 317" +"event 318" +"event 319" +"event 324" +"event 326" +"event 327" +"event 328" +"event 329" +"event 330" +"event 332" +"event 333" +"event 338" +"event 341" +"event 344" +"event 345" +"event 346" +"event 347" +"event 348" +"event 349" +"event 352" +"event 353" +"event 364" +"event 365" +"event 367" +"event 368" +"event 369" +"event 372" +"event 375" +"event 376" +"event 377" +"event 378" +"event 379" +"event 381" +"event 386" +"event 387" +"event 388" +"event 389" +"event 396" +"event 401" +"event 403" +"event 404" +"event 405" +"event 407" +"event 408" +"event 421" +"event 422" +"event 432" +"event 433" +"event 436" +"event 437" +"event 438" +"event 439" +"event 442" +"event 465" +"event 470" +"event 471" +"event 472" +"event 473" +"event 474" +"event 475" +"event 476" +"event 477" +"event 478" +"event 479" +"event 482" +"event 486" +"event 489" +"event 494" +"event 506" +"event 707" +"event 716" +"event 717" +"event 728" +"event 729" +"event connected" +"event empty" +"event error" +"event invite" +"event join" +"event kick" +"event kill" +"event mode" +"event nick" +"event notice" +"event part" +"event ping" +"event pong" +"event privmsg" +"event quit" +"event silence" +"event topic" +"event wallops" +"exec input" +"expando timer" +"flood" +"gui dialog" +"gui entry redirect" +"gui exit" +"gui key pressed" +"gui page scrolled" +"gui print text finished" +"gui print text" +"gui window create override" +"gui window created" +"ignore changed" +"ignore created" +"ignore destroyed" +"irssi init finished" +"irssi init read settings" +"lag ping error" +"layout reset" +"layout restore item" +"layout restore window" +"layout restore" +"layout save item" +"layout save window" +"layout save" +"list subcommands" +"log config read" +"log config save" +"log create failed" +"log locked" +"log new" +"log written" +"mainwindow destroyed" +"mainwindow moved" +"mainwindow resized" +"message dcc action" +"message dcc ctcp" +"message dcc own" +"message dcc own_action" +"message dcc own_ctcp" +"message dcc" +"message irc mode" +"message irc own_action" +"message join" +"message own_private" +"message own_public" +"message private" +"message public" +"message quit" +"module error" +"module loaded" +"module unloaded" +"netsplit new" +"nickfind event whois" +"nicklist changed" +"nicklist host changed" +"nicklist new" +"nicklist remove" +"notifylist away changed" +"notifylist event whois away" +"notifylist event whois end" +"notifylist event whois" +"notifylist event" +"notifylist joined" +"notifylist left" +"pidwait" +"print format" +"print starting" +"print text" +"proxy client dump" +"query created" +"query destroyed" +"query nick changed" +"query server changed" +"reload" +"requested usermode change" +"script destroyed" +"script error" +"send command" +"send text" +"server add fill" +"server connect copy" +"server connect failed" +"server connected" +"server connecting" +"server disconnected" +"server event" +"server incoming" +"server lag disconnect" +"server lag" +"server looking" +"server nick changed" +"server quit" +"server reconnect not found" +"server reconnect remove" +"server reconnect save status" +"server sendmsg" +"server setup fill chatnet" +"server setup fill connect" +"server setup fill reconn" +"server setup read" +"server setup saved" +"session restore channel" +"session restore nick" +"session restore server" +"session restore" +"session save channel" +"session save server" +"session save" +"settings errors" +"setup changed" +"setup reread" +"silent event who" +"silent event whois" +"terminal resized" +"theme changed" +"theme destroyed" +"user mode changed" +"userhost event" +"whois away" +"whois default event" +"whois end" +"whois event not found" +"whois event" +"whois oper" +"whois try whowas" +"whowas away" +"whowas event end" +"whowas event" +"window activity" +"window changed automatic" +"window changed" +"window created" +"window dehilight" +"window destroyed" +"window history changed" +"window item remove" +"window item server changed" +"window print info" +"window refnum changed" +"window server changed" -- cgit v1.2.3 From 85ab93558d23470dd7a3f043354980a82226ece7 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Thu, 14 Oct 2010 21:00:05 +0100 Subject: uberprompt: hopefully fixed RHS positioning on script autorun --- prompt_info/uberprompt.pl | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 76660b2..0581dd3 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -80,6 +80,14 @@ # may cause irssi to crash. See bug report at # http://bugs.irssi.org/index.php?do=details&task_id=772 for details. # +# TODO: +# +# * report failure (somehow) to clients if hte prompt is disabled. +# * fix issue at autorun startup with sbar item doesn't exist. +# +# +# +# # LICENCE: # # Copyright (c) 2010 Tom Feist @@ -114,7 +122,7 @@ our %IRSSI = ( authors => "shabble", contact => 'shabble+irssi@metavore.org, shabble@#irssi/Freenode', - name => "prompt_info", + name => "uberprompt", description => "Helper script for dynamically adding text " . "into the input-bar prompt.", license => "MIT", @@ -131,7 +139,25 @@ my $prompt_data_pos = 'UP_INNER'; my $prompt_last = ''; my $prompt_format = ''; -init(); +pre_init(); + +sub pre_init { + # my $start_time = Irssi::parse_special('$F'); + # my $now = time(); + # my $delta = $now - $start_time; + + # print "Delta is $delta"; + # if ($delta < 2) { + # print "starting a bit later"; + # Irssi::timeout_add_once(5000, \&init, undef); + # } else { + # print "starting immediately"; + + # init(); + # } + Irssi::command('statusbar prompt reset'); + init(); +} sub prompt_subcmd_handler { my ($data, $server, $item) = @_; @@ -146,7 +172,6 @@ sub UNLOAD { } sub init { - Irssi::statusbar_item_register('uberprompt', 0, 'uberprompt_draw'); Irssi::settings_add_str('uberprompt', 'uberprompt_format', '[$*$uber] '); -- cgit v1.2.3 From 1c802f8cbfbc93c868fbc4eb2517be749b971068 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Thu, 14 Oct 2010 21:53:29 +0200 Subject: vim_mode: Move all settings to $settings hash. --- vim-mode/vim_mode.pl | 52 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index a00421a..ac859a2 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -454,12 +454,20 @@ foreach my $char (keys %$commands) { # GLOBAL VARIABLES -my $DEBUG_ENABLED = 0; - -sub DEBUG { $DEBUG_ENABLED } +# all vim_mode settings, must be enabled in vim_mode_init() before usage +my $settings + = { + # print debug output + debug => 0, + # use UTF-8 internally for string calculations/manipulations + utf8 => 1, + # esc-shortcut in insert mode + cmd_seq => '', + # not used yet + max_undo_lines => 50, + }; -# use UTF-8 internally for string calculations/manipulations -my $utf8 = 1; +sub DEBUG { $settings->{debug} } # buffer to keep track of the last N keystrokes, used for Esc detection and # insert mode mappings @@ -712,7 +720,7 @@ sub cmd_j { } elsif ($history_index >= 0) { my $history = $history[$history_index]; # History is not in UTF-8! - if ($utf8) { + if ($settings->{utf8}) { $history = decode_utf8($history); } _input($history); @@ -744,7 +752,7 @@ sub cmd_k { if ($history_index >= 0) { my $history = $history[$history_index]; # History is not in UTF-8! - if ($utf8) { + if ($settings->{utf8}) { $history = decode_utf8($history); } _input($history); @@ -781,7 +789,7 @@ sub cmd_G { my $history = $history[$history_index]; # History is not in UTF-8! - if ($utf8) { + if ($settings->{utf8}) { $history = decode_utf8($history); } _input($history); @@ -2481,38 +2489,40 @@ sub vim_mode_init { sub setup_changed { my $value; - # Delete all possible imaps created by /set vim_mode_cmd_seq. - foreach my $char ('a' .. 'z') { - delete $imaps->{$char}; + if ($settings->{cmd_seq} ne '') { + delete $imaps->{$settings->{cmd_seq}}; } - $value = Irssi::settings_get_str('vim_mode_cmd_seq'); - if ($value) { + if ($value eq '') { + $settings->{cmd_seq} = $value; + } else { if (length $value == 1) { $imaps->{$value} = { 'map' => $value, 'func' => sub { _update_mode(M_CMD) } }; + $settings->{cmd_seq} = $value; } else { _warn("Error: vim_mode_cmd_seq must be a single character"); } } - $DEBUG_ENABLED = Irssi::settings_get_bool('vim_mode_debug'); + $settings->{debug} = Irssi::settings_get_bool('vim_mode_debug'); my $new_utf8 = Irssi::settings_get_bool('vim_mode_utf8'); - - if ($new_utf8 != $utf8) { + if ($new_utf8 != $settings->{utf8}) { # recompile the patterns when switching to/from utf-8 $word = qr/[\w_]/o; $non_word = qr/[^\w_\s]/o; - } + $settings->{utf8} = $new_utf8; + } if ($new_utf8 and (!$^V or $^V lt v5.8.1)) { _warn("Warning: UTF-8 isn't supported very well in perl < 5.8.1! " . "Please disable the vim_mode_utf8 setting."); } - $utf8 = $new_utf8; + $settings->{max_undo_lines} + = Irssi::settings_get_int('vim_mode_max_undo_lines'); } sub UNLOAD { @@ -2545,7 +2555,7 @@ sub _add_undo_entry { unshift @undo_buffer, [$line, $pos]; $undo_index = 0; } - my $max = Irssi::settings_get_int('vim_mode_max_undo_lines'); + my $max = $settings->{max_undo_lines}; } sub _restore_undo_entry { @@ -2671,12 +2681,12 @@ sub _input { my $current_data = Irssi::parse_special('$L', 0, 0); - if ($utf8) { + if ($settings->{utf8}) { $current_data = decode_utf8($current_data); } if (defined $data) { - if ($utf8) { + if ($settings->{utf8}) { Irssi::gui_input_set(encode_utf8($data)); } else { Irssi::gui_input_set($data); -- cgit v1.2.3 From c0af8a14674404f878c0c97bfc684e98ec0a2289 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Thu, 14 Oct 2010 22:31:42 +0200 Subject: vim_mode: Add :se[t]. --- vim-mode/vim_mode.pl | 105 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 82 insertions(+), 23 deletions(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index ac859a2..58d153f 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -81,6 +81,9 @@ # * Substitute: :s/// - i and g are supported as flags, only /// can be # used as separator, uses Perl regex instead of # Vim regex +# * Settings: :se[t] - display all options +# :se[t] {option} - display all matching options +# :se[t] {option} {value} - change option to value # # # Mappings: @@ -102,11 +105,19 @@ # :unmap - restore default behavior of after disabling it # # -# The following irssi settings are available: +# Settings: +# +# The settings are stored as irssi settings and can be set using /set as usual +# (prepend vim_mode_ to setting name) or using the :set ex-command. The +# following settings are available: +# +# * utf8: support UTF-8 characters, boolean, default on +# * debug: enable debug output, boolean, default off +# * cmd_seq: char that when double-pressed simulates , string, default '' +# +# In contrast to irssi's settings, :set accepts 0 and 1 as values for boolean +# settings. # -# * vim_mode_utf8: support UTF-8 characters, default on -# * vim_mode_debug: enable debug output, default off -# * vim_mode_cmd_seq: char that when double-pressed simulates # # The following statusbar items are available: # @@ -259,6 +270,11 @@ sub C_IRSSI () { 6 } # does nothing sub C_NOP () { 7 } +# setting types, match irssi types as they are stored as irssi settings +sub S_BOOL () { 0 } +sub S_INT () { 1 } +sub S_STR () { 2 } + # word and non-word regex, keep in sync with setup_changed()! my $word = qr/[\w_]/o; my $non_word = qr/[^\w_\s]/o; @@ -439,6 +455,10 @@ my $commands_ex type => C_EX }, mkv => { char => ':mkv', func => \&ex_mkvimrc, type => C_EX }, + se => { char => ':se', func => \&ex_set, + type => C_EX }, + set => { char => ':set', func => \&ex_set, + type => C_EX }, }; # MAPPINGS @@ -458,16 +478,16 @@ foreach my $char (keys %$commands) { my $settings = { # print debug output - debug => 0, + debug => { type => S_BOOL, value => 0 }, # use UTF-8 internally for string calculations/manipulations - utf8 => 1, + utf8 => { type => S_BOOL, value => 1 }, # esc-shortcut in insert mode - cmd_seq => '', + cmd_seq => { type => S_STR, value => '' }, # not used yet - max_undo_lines => 50, + max_undo_lines => { type => S_INT, value => 50 }, }; -sub DEBUG { $settings->{debug} } +sub DEBUG { $settings->{debug}->{value} } # buffer to keep track of the last N keystrokes, used for Esc detection and # insert mode mappings @@ -720,7 +740,7 @@ sub cmd_j { } elsif ($history_index >= 0) { my $history = $history[$history_index]; # History is not in UTF-8! - if ($settings->{utf8}) { + if ($settings->{utf8}->{value}) { $history = decode_utf8($history); } _input($history); @@ -752,7 +772,7 @@ sub cmd_k { if ($history_index >= 0) { my $history = $history[$history_index]; # History is not in UTF-8! - if ($settings->{utf8}) { + if ($settings->{utf8}->{value}) { $history = decode_utf8($history); } _input($history); @@ -789,7 +809,7 @@ sub cmd_G { my $history = $history[$history_index]; # History is not in UTF-8! - if ($settings->{utf8}) { + if ($settings->{utf8}->{value}) { $history = decode_utf8($history); } _input($history); @@ -1878,6 +1898,45 @@ sub ex_mkvimrc { close $file; } +sub ex_set { + my ($arg_str, $count) = @_; + + # :se[t] [option] [value] + if ($arg_str =~ /^se(?:t)?(?:\s(\S+)(?:\s(.+)$)?)?/) { + # :se[t] {option} {value} + if (defined $1 and defined $2) { + if (not exists $settings->{$1}) { + return _warn_ex('map', "setting '$1' not found"); + } + my $name = $1; + my $value = $2; + # Also accept numeric values for boolean options. + if ($settings->{$name}->{type} == S_BOOL and + $value !~ /^(on|off)$/) { + $value = $value ? 'on' : 'off'; + } + Irssi::command("set vim_mode_$name $value"); + + # :se[t] [option] + } else { + my $search = defined $1 ? $1 : ''; + my $active_window = Irssi::active_win(); + foreach my $setting (sort keys %$settings) { + next if $setting !~ /^\Q$search\E/; # skip non-matches + my $value = $settings->{$setting}->{value}; + # Irssi only accepts 'on' and 'off' as values for boolean + # options. + if ($settings->{$setting}->{type} == S_BOOL) { + $value = $value ? 'on' : 'off'; + } + $active_window->print($setting . '=' . $value); + } + } + } else { + _warn_ex('map'); + } +} + sub _warn_ex { my ($command, $description) = @_; my $message = "Error in ex-mode command $command"; @@ -2489,39 +2548,39 @@ sub vim_mode_init { sub setup_changed { my $value; - if ($settings->{cmd_seq} ne '') { - delete $imaps->{$settings->{cmd_seq}}; + if ($settings->{cmd_seq}->{value} ne '') { + delete $imaps->{$settings->{cmd_seq}->{value}}; } $value = Irssi::settings_get_str('vim_mode_cmd_seq'); if ($value eq '') { - $settings->{cmd_seq} = $value; + $settings->{cmd_seq}->{value} = $value; } else { if (length $value == 1) { $imaps->{$value} = { 'map' => $value, 'func' => sub { _update_mode(M_CMD) } }; - $settings->{cmd_seq} = $value; + $settings->{cmd_seq}->{value} = $value; } else { _warn("Error: vim_mode_cmd_seq must be a single character"); } } - $settings->{debug} = Irssi::settings_get_bool('vim_mode_debug'); + $settings->{debug}->{value} = Irssi::settings_get_bool('vim_mode_debug'); my $new_utf8 = Irssi::settings_get_bool('vim_mode_utf8'); - if ($new_utf8 != $settings->{utf8}) { + if ($new_utf8 != $settings->{utf8}->{value}) { # recompile the patterns when switching to/from utf-8 $word = qr/[\w_]/o; $non_word = qr/[^\w_\s]/o; - $settings->{utf8} = $new_utf8; + $settings->{utf8}->{value} = $new_utf8; } if ($new_utf8 and (!$^V or $^V lt v5.8.1)) { _warn("Warning: UTF-8 isn't supported very well in perl < 5.8.1! " . "Please disable the vim_mode_utf8 setting."); } - $settings->{max_undo_lines} + $settings->{max_undo_lines}->{value} = Irssi::settings_get_int('vim_mode_max_undo_lines'); } @@ -2555,7 +2614,7 @@ sub _add_undo_entry { unshift @undo_buffer, [$line, $pos]; $undo_index = 0; } - my $max = $settings->{max_undo_lines}; + my $max = $settings->{max_undo_lines}->{value}; } sub _restore_undo_entry { @@ -2681,12 +2740,12 @@ sub _input { my $current_data = Irssi::parse_special('$L', 0, 0); - if ($settings->{utf8}) { + if ($settings->{utf8}->{value}) { $current_data = decode_utf8($current_data); } if (defined $data) { - if ($settings->{utf8}) { + if ($settings->{utf8}->{value}) { Irssi::gui_input_set(encode_utf8($data)); } else { Irssi::gui_input_set($data); -- cgit v1.2.3 From d1447815225b8c60db83dd687661e203314f707f Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Thu, 14 Oct 2010 22:33:36 +0200 Subject: vim_mode: Mention that :set only sets vim_mode settings. --- vim-mode/vim_mode.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 58d153f..6ff8c78 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -116,7 +116,7 @@ # * cmd_seq: char that when double-pressed simulates , string, default '' # # In contrast to irssi's settings, :set accepts 0 and 1 as values for boolean -# settings. +# settings, but only vim_mode's settings can be set/displayed. # # # The following statusbar items are available: -- cgit v1.2.3