aboutsummaryrefslogtreecommitdiffstats
path: root/vim-mode/vim_mode.pl
diff options
context:
space:
mode:
authorSimon Ruderich <simon@ruderich.org>2010-10-07 02:11:52 +0000
committerSimon Ruderich <simon@ruderich.org>2010-10-07 02:11:52 +0000
commit69fe95c5c37a4b68115a340e8292bb2d693d4e4b (patch)
treebc5e8c445e40577745223487afe52fc9eca48fad /vim-mode/vim_mode.pl
parentvim_mode: Add comments before each code section. (diff)
downloadirssi-scripts-69fe95c5c37a4b68115a340e8292bb2d693d4e4b.tar.gz
irssi-scripts-69fe95c5c37a4b68115a340e8292bb2d693d4e4b.zip
vim_mode: Separate Ex-mode commands.
Diffstat (limited to '')
-rw-r--r--vim-mode/vim_mode.pl90
1 files changed, 74 insertions, 16 deletions
diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl
index fe155e2..3cb141a 100644
--- a/vim-mode/vim_mode.pl
+++ b/vim-mode/vim_mode.pl
@@ -303,6 +303,24 @@ my $commands
"\x12" => { char => '<c-r>', func => \&cmd_redo, type => C_NORMAL },
};
+# All available commands in Ex-Mode.
+my $commands_ex
+ = {
+ s => \&ex_substitute,
+ bn => \&ex_bnext,
+ bp => \&ex_bprev,
+ bd => \&ex_bdelete,
+ buffer => \&ex_buffer,
+ b => \&ex_buffer,
+ registers => \&ex_registers,
+ reg => \&ex_registers,
+ display => \&ex_registers,
+ di => \&ex_registers,
+ buffers => \&ex_buffers,
+ ls => \&ex_buffers,
+ undolist => \&ex_undolist,
+ undol => \&ex_undolist,
+ };
# MAPPINGS
@@ -1352,6 +1370,21 @@ sub _fix_input_pos {
sub cmd_ex_command {
my $arg_str = join '', @ex_buf;
+
+ if ($arg_str !~ /^([a-z]+)/) {
+ return _warn("Invalid Ex-mode command!");
+ }
+
+ if (not exists $commands_ex->{$1}) {
+ return _warn("Ex-mode $1 doesn't exist!");
+ }
+
+ $commands_ex->{$1}($arg_str);
+}
+
+sub ex_substitute {
+ my ($arg_str) = @_;
+
if ($arg_str =~ m|^s/(.+)/(.*)/([ig]*)|) {
my ($search, $replace, $flags) = ($1, $2, $3);
print "Searching for $search, replace: $replace, flags; $flags"
@@ -1379,17 +1412,25 @@ sub cmd_ex_command {
print "New line is: $line" if DEBUG;
_input($line);
- # :bn
- } elsif ($arg_str eq 'bn') {
- Irssi::command('window next');
- # :bp
- } elsif ($arg_str eq 'bp') {
- Irssi::command('window previous');
- # :bd
- } elsif ($arg_str eq 'bd') {
- Irssi::command('window close');
+ } else {
+ _warn_ex('s');
+ }
+}
+
+sub ex_bnext {
+ Irssi::command('window next');
+}
+sub ex_bprev {
+ Irssi::command('window previous');
+}
+sub ex_bdelete {
+ Irssi::command('window close');
+}
+sub ex_buffer {
+ my ($arg_str) = @_;
+
# :b[buffer] {args}
- } elsif ($arg_str =~ m|^b(?:uffer)?\s*(.+)$|) {
+ if ($arg_str =~ m|^b(?:uffer)?\s*(.+)$|) {
my $window;
my $item;
my $buffer = $1;
@@ -1415,9 +1456,16 @@ sub cmd_ex_command {
$item->set_active();
}
}
+ } else {
+ _warn_ex('buffer');
+ }
+}
+
+sub ex_registers {
+ my ($arg_str) = @_;
# :reg[isters] {arg} and :di[splay] {arg}
- } elsif ($arg_str =~ /^(?:reg(?:isters)?|di(?:splay)?)(?:\s+(.+)$)?/) {
+ if ($arg_str =~ /^(?:reg(?:isters)?|di(?:splay)?)(?:\s+(.+)$)?/) {
my @regs;
if ($1) {
my $regs = $1;
@@ -1433,14 +1481,24 @@ sub cmd_ex_command {
$active_window->print("register $key: $registers->{$key}");
}
}
- # :ls and :buffers
- } elsif ($arg_str eq 'ls' or $arg_str eq 'buffers') {
- Irssi::command('window list');
- } elsif ($arg_str eq 'undol' or $arg_str eq 'undolist') {
- _print_undo_buffer();
+ } else {
+ _warn_ex(':reigsters');
}
}
+sub ex_buffers {
+ Irssi::command('window list');
+}
+
+sub ex_undolist {
+ _print_undo_buffer();
+}
+
+sub _warn_ex {
+ my ($command) = @_;
+ _warn("Error in ex-mode command $command");
+}
+
sub _matching_windows {
my ($buffer) = @_;