diff options
author | Simon Ruderich <simon@ruderich.org> | 2010-10-08 01:00:00 +0000 |
---|---|---|
committer | Simon Ruderich <simon@ruderich.org> | 2010-10-08 01:00:00 +0000 |
commit | 89f947bf57f0515fca7b9777b77fb032a9479f01 (patch) | |
tree | 7d1da4e6d76cb032bcfcf7b40a75a7dddd0822f6 /vim-mode | |
parent | vim_mode: Fix :map on a placeholder mapping. (diff) | |
download | irssi-scripts-89f947bf57f0515fca7b9777b77fb032a9479f01.tar.gz irssi-scripts-89f947bf57f0515fca7b9777b77fb032a9479f01.zip |
vim_mode: Add ~/.irssi/vim_moderc as vimrc-like configuration file.
Diffstat (limited to 'vim-mode')
-rw-r--r-- | vim-mode/vim_mode.pl | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 5e33bf4..4a58273 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -69,6 +69,8 @@ # * Display windows: :ls :buffers # * Display registers: :reg[isters] :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 # * Mappings: :map - display custom mappings # :map {lhs} {rhs} - add mapping # @@ -96,6 +98,19 @@ # * vim_windows: displays windows selected with :b # # +# Configuration +# +# Additionally to the irssi settings described above vim_mode can be +# configured through an external configuration file named "vim_moderc" located +# in ~/.irssi/vim_moderc. If available it's loaded on startup and every +# supported ex-command is run. It's syntax is similar to "vimrc". To (re)load +# it while vim_mode is running use :so[urce]. +# +# Supported ex-commands: +# +# * :map +# +# # Installation: # # As always copy the script into .irssi/scripts and load it with @@ -345,6 +360,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 }, + source => { char => 'source', func => \&ex_source, type => C_EX }, + so => { char => 'so', func => \&ex_source, type => C_EX }, }; # MAPPINGS @@ -1641,6 +1658,24 @@ sub _parse_mapping_reverse { return $string; } +sub ex_source { + # so[urce], but only loads the vim_moderc file at the moment + + open my $file, '<', Irssi::get_irssi_dir() . '/vim_moderc' or return; + + while (my $line = <$file>) { + next if $line =~ /^\s*$/ or $line =~ /^\s*"/; + + chomp $line; + # :map {lhs} {rhs} + if ($line =~ /^\s*map (\S+) (\S+)$/) { + ex_map($line); + } else { + _warn_ex('source', "command not supported: $line"); + } + } +} + sub _warn_ex { my ($command, $description) = @_; my $message = "Error in ex-mode command $command"; @@ -2205,6 +2240,9 @@ sub vim_mode_init { Irssi::settings_add_bool('vim_mode', 'vim_mode_utf8', 1); Irssi::settings_add_int('vim_mode', 'vim_mode_max_undo_lines', 50); + # Load the vim_moderc file if it exists. + ex_source('source'); + setup_changed(); _reset_undo_buffer(); } |